Added a method to detect the UI Theme (#6542)
parent
ebdfe8184e
commit
0cfde5b86a
|
@ -4,13 +4,14 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.ui
|
package org.mozilla.fenix.ui
|
||||||
|
|
||||||
|
import android.content.res.Configuration
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import androidx.test.uiautomator.UiDevice
|
import androidx.test.uiautomator.UiDevice
|
||||||
import okhttp3.mockwebserver.MockWebServer
|
import okhttp3.mockwebserver.MockWebServer
|
||||||
import org.junit.Rule
|
|
||||||
import org.junit.Before
|
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
|
import org.junit.Before
|
||||||
import org.junit.Ignore
|
import org.junit.Ignore
|
||||||
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||||
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
||||||
|
@ -43,6 +44,16 @@ class SettingsBasicsTest {
|
||||||
mockWebServer.shutdown()
|
mockWebServer.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getUiTheme(): Boolean {
|
||||||
|
val mode = activityTestRule.activity.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)
|
||||||
|
|
||||||
|
return when (mode) {
|
||||||
|
Configuration.UI_MODE_NIGHT_YES -> true // dark theme is set
|
||||||
|
Configuration.UI_MODE_NIGHT_NO -> false // dark theme is not set, using light theme
|
||||||
|
else -> false // default option is light theme
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
// Walks through settings menu and sub-menus to ensure all items are present
|
// Walks through settings menu and sub-menus to ensure all items are present
|
||||||
fun settingsMenuBasicsItemsTests() {
|
fun settingsMenuBasicsItemsTests() {
|
||||||
|
@ -115,19 +126,18 @@ class SettingsBasicsTest {
|
||||||
// Verify history and bookmarks are gone
|
// Verify history and bookmarks are gone
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("This is a stub test, ignore for now")
|
|
||||||
@Test
|
@Test
|
||||||
fun changeThemeSetting() {
|
fun changeThemeSetting() {
|
||||||
// Open 3dot (main) menu
|
homeScreen {
|
||||||
// Select settings
|
}.openThreeDotMenu {
|
||||||
// Verify default theme appears as "Light"
|
}.openSettings {
|
||||||
// Select theme to enter theme sub-menu
|
}.openThemeSubMenu {
|
||||||
// Verify them sub-menu has 3 options: "Light", "Dark" and "Set by Battery Saver"
|
verifyThemes()
|
||||||
// Select "Dark" theme
|
selectDarkMode()
|
||||||
// Verify them is changed to Dark
|
verifyDarkThemeApplied(getUiTheme())
|
||||||
// Optional:
|
selectLightMode()
|
||||||
// Select "Set by battery saver"
|
verifyLightThemeApplied(getUiTheme())
|
||||||
// Verify theme changes based on battery saver
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("This is a stub test, ignore for now")
|
@Ignore("This is a stub test, ignore for now")
|
||||||
|
|
|
@ -6,14 +6,17 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.ui.robots
|
package org.mozilla.fenix.ui.robots
|
||||||
|
|
||||||
import androidx.test.espresso.Espresso
|
|
||||||
import androidx.test.espresso.Espresso.onView
|
import androidx.test.espresso.Espresso.onView
|
||||||
import androidx.test.espresso.action.ViewActions
|
import androidx.test.espresso.action.ViewActions
|
||||||
import androidx.test.espresso.assertion.ViewAssertions
|
import androidx.test.espresso.assertion.ViewAssertions
|
||||||
import androidx.test.espresso.matcher.ViewMatchers
|
import androidx.test.espresso.matcher.ViewMatchers
|
||||||
|
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import androidx.test.uiautomator.UiDevice
|
import androidx.test.uiautomator.UiDevice
|
||||||
import org.hamcrest.CoreMatchers
|
import org.hamcrest.CoreMatchers.allOf
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.mozilla.fenix.helpers.click
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of Robot Pattern for the settings Theme sub menu.
|
* Implementation of Robot Pattern for the settings Theme sub menu.
|
||||||
|
@ -22,6 +25,14 @@ class SettingsSubMenuThemeRobot {
|
||||||
|
|
||||||
fun verifyThemes() = assertThemes()
|
fun verifyThemes() = assertThemes()
|
||||||
|
|
||||||
|
fun verifyLightThemeApplied(expected: Boolean) = assertFalse("Light theme not selected", expected)
|
||||||
|
|
||||||
|
fun verifyDarkThemeApplied(expected: Boolean) = assertTrue("Dark theme not selected", expected)
|
||||||
|
|
||||||
|
fun selectDarkMode() = darkModeToggle().click()
|
||||||
|
|
||||||
|
fun selectLightMode() = lightModeToggle().click()
|
||||||
|
|
||||||
class Transition {
|
class Transition {
|
||||||
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||||
|
|
||||||
|
@ -36,9 +47,9 @@ class SettingsSubMenuThemeRobot {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun assertThemes() {
|
private fun assertThemes() {
|
||||||
onView(ViewMatchers.withText("Light"))
|
onView(withText("Light"))
|
||||||
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||||
onView(ViewMatchers.withText("Dark"))
|
onView(withText("Dark"))
|
||||||
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
.check(ViewAssertions.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||||
// Conditionally unavailable on API 25
|
// Conditionally unavailable on API 25
|
||||||
// onView(ViewMatchers.withText("Follow device theme"))
|
// onView(ViewMatchers.withText("Follow device theme"))
|
||||||
|
@ -46,4 +57,8 @@ private fun assertThemes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun goBackButton() =
|
private fun goBackButton() =
|
||||||
Espresso.onView(CoreMatchers.allOf(ViewMatchers.withContentDescription("Navigate up")))
|
onView(allOf(ViewMatchers.withContentDescription("Navigate up")))
|
||||||
|
|
||||||
|
private fun darkModeToggle() = onView(withText("Dark"))
|
||||||
|
|
||||||
|
private fun lightModeToggle() = onView(withText("Light"))
|
||||||
|
|
Loading…
Reference in New Issue