mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] Closes https://github.com/mozilla-mobile/fenix/issues/9346: Add ViewIdlingResource for Reader View UI tests (https://github.com/mozilla-mobile/fenix/pull/9347)
This commit is contained in:
parent
cb727abda5
commit
c42f203e39
@ -0,0 +1,32 @@
|
||||
package org.mozilla.fenix.helpers
|
||||
|
||||
import android.view.View
|
||||
import androidx.test.espresso.IdlingResource
|
||||
|
||||
class ViewVisibilityIdlingResource(
|
||||
private val view: View,
|
||||
private val expectedVisibility: Int
|
||||
) : IdlingResource {
|
||||
private var resourceCallback: IdlingResource.ResourceCallback? = null
|
||||
private var isIdle: Boolean = false
|
||||
|
||||
override fun getName(): String {
|
||||
return ViewVisibilityIdlingResource::class.java.name + ":" + view.id + ":" + expectedVisibility
|
||||
}
|
||||
|
||||
override fun isIdleNow(): Boolean {
|
||||
if (isIdle) return true
|
||||
|
||||
isIdle = view.visibility == expectedVisibility
|
||||
|
||||
if (isIdle) {
|
||||
resourceCallback?.onTransitionToIdle()
|
||||
}
|
||||
|
||||
return isIdle
|
||||
}
|
||||
|
||||
override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) {
|
||||
this.resourceCallback = callback
|
||||
}
|
||||
}
|
@ -4,19 +4,20 @@
|
||||
|
||||
package org.mozilla.fenix.ui
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import android.view.View
|
||||
import okhttp3.mockwebserver.MockWebServer
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
import org.mozilla.fenix.ui.robots.navigationToolbar
|
||||
import org.mozilla.fenix.ui.robots.readerViewRobot
|
||||
import androidx.test.espresso.IdlingRegistry
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.ViewVisibilityIdlingResource
|
||||
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
|
||||
/**
|
||||
* Tests for verifying basic functionality of content context menus
|
||||
@ -29,7 +30,7 @@ import org.mozilla.fenix.ui.robots.readerViewRobot
|
||||
|
||||
class ReaderViewTest {
|
||||
private lateinit var mockWebServer: MockWebServer
|
||||
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
private var readerViewNotificationDot: ViewVisibilityIdlingResource? = null
|
||||
|
||||
@get:Rule
|
||||
val activityIntentTestRule = HomeActivityIntentTestRule()
|
||||
@ -40,11 +41,17 @@ class ReaderViewTest {
|
||||
setDispatcher(AndroidAssetDispatcher())
|
||||
start()
|
||||
}
|
||||
|
||||
readerViewNotificationDot = ViewVisibilityIdlingResource(
|
||||
activityIntentTestRule.activity.findViewById(R.id.notification_dot),
|
||||
View.VISIBLE
|
||||
)
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
mockWebServer.shutdown()
|
||||
IdlingRegistry.getInstance().unregister(readerViewNotificationDot)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,6 +71,8 @@ class ReaderViewTest {
|
||||
verifyPageContent(readerViewPage.content)
|
||||
}
|
||||
|
||||
IdlingRegistry.getInstance().register(readerViewNotificationDot)
|
||||
|
||||
readerViewRobot {
|
||||
verifyReaderViewDetected(true)
|
||||
}
|
||||
@ -112,6 +121,8 @@ class ReaderViewTest {
|
||||
verifyPageContent(readerViewPage.content)
|
||||
}
|
||||
|
||||
IdlingRegistry.getInstance().register(readerViewNotificationDot)
|
||||
|
||||
readerViewRobot {
|
||||
verifyReaderViewDetected(true)
|
||||
}
|
||||
@ -142,6 +153,8 @@ class ReaderViewTest {
|
||||
verifyPageContent(readerViewPage.content)
|
||||
}
|
||||
|
||||
IdlingRegistry.getInstance().register(readerViewNotificationDot)
|
||||
|
||||
readerViewRobot {
|
||||
verifyReaderViewDetected(true)
|
||||
}
|
||||
@ -166,7 +179,6 @@ class ReaderViewTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Intermittent failure. Fix in https://github.com/mozilla-mobile/fenix/issues/9188")
|
||||
fun verifyReaderViewAppearanceFontToggle() {
|
||||
val readerViewPage =
|
||||
TestAssetHelper.getLoremIpsumAsset(mockWebServer)
|
||||
@ -176,6 +188,8 @@ class ReaderViewTest {
|
||||
verifyPageContent(readerViewPage.content)
|
||||
}
|
||||
|
||||
IdlingRegistry.getInstance().register(readerViewNotificationDot)
|
||||
|
||||
readerViewRobot {
|
||||
verifyReaderViewDetected(true)
|
||||
}
|
||||
@ -209,6 +223,8 @@ class ReaderViewTest {
|
||||
verifyPageContent(readerViewPage.content)
|
||||
}
|
||||
|
||||
IdlingRegistry.getInstance().register(readerViewNotificationDot)
|
||||
|
||||
readerViewRobot {
|
||||
verifyReaderViewDetected(true)
|
||||
}
|
||||
@ -248,6 +264,8 @@ class ReaderViewTest {
|
||||
verifyPageContent(readerViewPage.content)
|
||||
}
|
||||
|
||||
IdlingRegistry.getInstance().register(readerViewNotificationDot)
|
||||
|
||||
readerViewRobot {
|
||||
verifyReaderViewDetected(true)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user