Testing file opening from browser, file manager, and via file piker on tablet in CI.

This commit is contained in:
MohitMaliFtechiz 2024-09-30 14:48:41 +05:30 committed by MohitMaliFtechiz
parent 968cbfa19a
commit 9fadeff0cc
3 changed files with 96 additions and 2 deletions

View File

@ -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

View File

@ -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
@ -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/" +
@ -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()
@ -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

View File

@ -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