Skip to content

Commit

Permalink
Fixed ZimHostFragment failing on API level 33 (Android 13) because …
Browse files Browse the repository at this point in the history
…it has the `SYSTEM_ALERT_WINDOW` permission which is not grantable through code on Android 13, so we have removed this permission from our `ZimHostFragment` test as well as from our other test cases since we had added this to fix the test cases because without this permission test cases were not launching on API level 21, and now our minimum SDK version is 24 so this permission is no longer needed.
  • Loading branch information
MohitMaliDeveloper committed Oct 26, 2023
1 parent e45eaff commit 4d9c5d2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 67 deletions.
17 changes: 4 additions & 13 deletions app/src/androidTest/java/org/kiwix/kiwixmobile/BaseActivityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package org.kiwix.kiwixmobile

import android.Manifest.permission
import android.content.Context
import android.os.Build
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
Expand All @@ -35,18 +34,10 @@ import org.kiwix.kiwixmobile.main.KiwixMainActivity
abstract class BaseActivityTest {
open lateinit var activityScenario: ActivityScenario<KiwixMainActivity>

private val permissions = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
arrayOf(
permission.READ_EXTERNAL_STORAGE,
permission.WRITE_EXTERNAL_STORAGE,
permission.SYSTEM_ALERT_WINDOW
)
} else {
arrayOf(
permission.READ_EXTERNAL_STORAGE,
permission.WRITE_EXTERNAL_STORAGE
)
}
private val permissions = arrayOf(
permission.READ_EXTERNAL_STORAGE,
permission.WRITE_EXTERNAL_STORAGE
)

@get:Rule
var permissionRules: GrantPermissionRule =
Expand Down
19 changes: 5 additions & 14 deletions app/src/androidTest/java/org/kiwix/kiwixmobile/NetworkTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
package org.kiwix.kiwixmobile

import android.Manifest
import android.os.Build
import android.util.Log
import androidx.test.core.app.ActivityScenario
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.espresso.Espresso
import androidx.test.espresso.IdlingPolicies
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn
import com.adevinta.android.barista.interaction.BaristaDialogInteractions
Expand Down Expand Up @@ -58,18 +57,10 @@ class NetworkTest {
// @Inject
// MockWebServer mockWebServer

private val permissions = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.SYSTEM_ALERT_WINDOW
)
} else {
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
}
private val permissions = arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)

@Rule
@JvmField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.kiwix.kiwixmobile.language

import android.Manifest
import android.app.Instrumentation
import android.os.Build
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import androidx.test.ext.junit.rules.ActivityScenarioRule
Expand Down Expand Up @@ -50,18 +49,10 @@ class LanguageFragmentTest {
@get:Rule
var activityScenarioRule = ActivityScenarioRule(KiwixMainActivity::class.java)

private val permissions = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.SYSTEM_ALERT_WINDOW
)
} else {
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
}
private val permissions = arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)

@Rule
@JvmField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.kiwix.kiwixmobile.settings

import android.Manifest
import android.os.Build
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
import androidx.test.platform.app.InstrumentationRegistry
Expand Down Expand Up @@ -46,18 +45,10 @@ class KiwixSettingsFragmentTest {
@get:Rule
var activityScenarioRule = ActivityScenarioRule(KiwixMainActivity::class.java)

private val permissions = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.SYSTEM_ALERT_WINDOW
)
} else {
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
}
private val permissions = arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)

@Rule
@JvmField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.kiwix.kiwixmobile.splash

import android.Manifest
import android.content.Context
import android.os.Build
import androidx.preference.PreferenceManager
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso
Expand Down Expand Up @@ -59,18 +58,10 @@ class KiwixSplashActivityTest {
private val activityScenario: ActivityScenario<KiwixMainActivity> =
ActivityScenario.launch(KiwixMainActivity::class.java)

private val permissions = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.SYSTEM_ALERT_WINDOW
)
} else {
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
}
private val permissions = arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)

@Rule
@JvmField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class ZimHostFragmentTest {
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.SYSTEM_ALERT_WINDOW,
Manifest.permission.NEARBY_WIFI_DEVICES
)
} else {
Expand Down

0 comments on commit 4d9c5d2

Please sign in to comment.