Skip to content

Commit

Permalink
Testing file opening from browser, file manager, and via file piker o…
Browse files Browse the repository at this point in the history
…n tablet in CI.
  • Loading branch information
MohitMaliDeveloper authored and MohitMaliFtechiz committed Sep 30, 2024
1 parent 968cbfa commit 9fadeff
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ jobs:
~/.android/adb*
key: avd-${{ matrix.api-level }}

- name: File Opening test on Tablet
if: ${{ matrix.api-level!=25 }}
uses: reactivecircus/android-emulator-runner@v2
env:
GRADLE_OPTS: "-Dorg.gradle.internal.http.connectionTimeout=60000 -Dorg.gradle.internal.http.socketTimeout=60000 -Dorg.gradle.internal.network.retry.max.attempts=6 -Dorg.gradle.internal.network.retry.initial.backOff=2000"
with:
api-level: ${{ matrix.api-level }}
target: default
arch: x86_64
profile: pixel_tablet
ram-size: 3072M
cores: 4
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
force-avd-creation: true
sdcard-path-or-size: 1024M
emulator-boot-timeout: 1200
heap-size: 512M
script: bash contrib/instrumentation-file-opening-on-tablet.sh

- name: Create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.kiwix.kiwixmobile.localLibrary
import android.content.ContentValues
import android.content.Context
import android.content.Intent
import android.media.MediaScannerConnection
import android.net.Uri
import android.os.Build
import android.provider.MediaStore
Expand Down Expand Up @@ -163,7 +164,6 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
"application%2Foctet-stream"
)
)
testCopyMoveDialogShowing(Uri.parse("content://media/external/downloads/2825"))
testCopyMoveDialogShowing(
Uri.parse(
"content://org.mozilla.firefox.DownloadProvider/" +
Expand All @@ -174,10 +174,10 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
}

private fun testCopyMoveDialogShowing(uri: Uri) {
sharedPreferenceUtil.copyMoveZimFilePermissionDialog = false
ActivityScenario.launch<KiwixMainActivity>(
createDeepLinkIntent(uri)
).onActivity {}
sharedPreferenceUtil.copyMoveZimFilePermissionDialog = false
copyMoveFileHandler {
assertCopyMovePermissionDialogDisplayed()
clickOnCancel()
Expand Down Expand Up @@ -261,6 +261,12 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
contentValues.clear()
contentValues.put(MediaStore.Downloads.IS_PENDING, false)
resolver.update(uri, contentValues, null, null)
MediaScannerConnection.scanFile(
context,
arrayOf(uri.toString()),
arrayOf("application/octet-stream"),
null
)
}

return uri
Expand Down
68 changes: 68 additions & 0 deletions contrib/instrumentation-file-opening-on-tablet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

# Enable Wi-Fi on the emulator
adb shell svc wifi enable
adb logcat -c
# shellcheck disable=SC2035
adb logcat *:E -v color &

PACKAGE_NAME="org.kiwix.kiwixmobile"
TEST_PACKAGE_NAME="${PACKAGE_NAME}.test"
TEST_SERVICES_PACKAGE="androidx.test.services"
TEST_ORCHESTRATOR_PACKAGE="androidx.test.orchestrator"
# Function to check if the application is installed
is_app_installed() {
adb shell pm list packages | grep -q "$1"
}

if is_app_installed "$PACKAGE_NAME"; then
adb uninstall "${PACKAGE_NAME}"
fi

if is_app_installed "$TEST_PACKAGE_NAME"; then
adb uninstall "${TEST_PACKAGE_NAME}"
fi

if is_app_installed "$TEST_SERVICES_PACKAGE"; then
adb uninstall "${TEST_SERVICES_PACKAGE}"
fi

if is_app_installed "$TEST_ORCHESTRATOR_PACKAGE"; then
adb uninstall "${TEST_ORCHESTRATOR_PACKAGE}"
fi

retry=0
while [ $retry -le 3 ]; do
if ./gradlew connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=org.kiwix.kiwixmobile.localLibrary.OpeningFilesFromStorageTest "-Dorg.gradle.jvmargs=-Xmx16G -XX:+UseParallelGC" -Dfile.encoding=UTF-8; then
echo "connectedDebugAndroidTest for file opening in tablet succeeded" >&2
break
else
adb kill-server
adb start-server
# Enable Wi-Fi on the emulator
adb shell svc wifi enable
adb logcat -c
# shellcheck disable=SC2035
adb logcat *:E -v color &

if is_app_installed "$PACKAGE_NAME"; then
adb uninstall "${PACKAGE_NAME}"
fi
if is_app_installed "$TEST_PACKAGE_NAME"; then
adb uninstall "${TEST_PACKAGE_NAME}"
fi
if is_app_installed "$TEST_SERVICES_PACKAGE"; then
adb uninstall "${TEST_SERVICES_PACKAGE}"
fi

if is_app_installed "$TEST_ORCHESTRATOR_PACKAGE"; then
adb uninstall "${TEST_ORCHESTRATOR_PACKAGE}"
fi
./gradlew clean
retry=$(( retry + 1 ))
if [ $retry -eq 3 ]; then
adb exec-out screencap -p >screencap.png
exit 1
fi
fi
done

0 comments on commit 9fadeff

Please sign in to comment.