2019-08-16 00:48:05 +02:00
/ * This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ui
2019-11-13 17:52:41 +01:00
import android.content.res.Configuration
2019-08-16 00:48:05 +02:00
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
2019-11-13 17:52:41 +01:00
import org.junit.Before
import org.junit.Rule
2019-08-16 00:48:05 +02:00
import org.junit.Test
2020-02-06 21:58:47 +01:00
import org.junit.Ignore
import org.mozilla.fenix.FenixApplication
2019-08-16 00:48:05 +02:00
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
2020-02-06 21:58:47 +01:00
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset
import org.mozilla.fenix.helpers.TestAssetHelper.getLoremIpsumAsset
import org.mozilla.fenix.ui.robots.checkTextSizeOnWebsite
2019-10-03 18:30:55 +02:00
import org.mozilla.fenix.ui.robots.homeScreen
2020-02-06 21:58:47 +01:00
import org.mozilla.fenix.ui.robots.navigationToolbar
2019-08-16 00:48:05 +02:00
/ * *
* Tests for verifying the main three dot menu options
*
* /
class SettingsBasicsTest {
/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.
private val mDevice = UiDevice . getInstance ( InstrumentationRegistry . getInstrumentation ( ) )
private lateinit var mockWebServer : MockWebServer
@get : Rule
2020-02-06 21:58:47 +01:00
val activityIntentTestRule = HomeActivityIntentTestRule ( )
2019-08-16 00:48:05 +02:00
@Before
fun setUp ( ) {
mockWebServer = MockWebServer ( ) . apply {
setDispatcher ( AndroidAssetDispatcher ( ) )
start ( )
}
}
@After
fun tearDown ( ) {
mockWebServer . shutdown ( )
}
2019-11-13 17:52:41 +01:00
private fun getUiTheme ( ) : Boolean {
2020-02-06 21:58:47 +01:00
val mode =
activityIntentTestRule . activity . resources ?. configuration ?. uiMode ?. and ( Configuration . UI _MODE _NIGHT _MASK )
2019-11-13 17:52:41 +01:00
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
}
}
2019-08-16 00:48:05 +02:00
@Test
2019-10-03 18:30:55 +02:00
// Walks through settings menu and sub-menus to ensure all items are present
2019-08-16 00:48:05 +02:00
fun settingsMenuBasicsItemsTests ( ) {
2019-10-03 18:30:55 +02:00
homeScreen {
} . openThreeDotMenu {
} . openSettings {
verifyBasicsHeading ( )
verifySearchEngineButton ( )
// drill down to submenu
2019-11-20 07:37:17 +01:00
} . openSearchSubMenu {
verifyDefaultSearchEngineHeader ( )
verifySearchEngineList ( )
verifyShowSearchSuggestions ( )
verifyShowSearchShortcuts ( )
2020-02-06 21:58:47 +01:00
2019-11-20 07:37:17 +01:00
verifyShowClipboardSuggestions ( )
verifySearchBrowsingHistory ( )
verifySearchBookmarks ( )
} . goBack {
2020-02-12 01:17:30 +01:00
} . openCustomizeSubMenu {
2019-11-20 07:37:17 +01:00
verifyThemes ( )
} . goBack {
} . openAccessibilitySubMenu {
2020-02-06 21:58:47 +01:00
verifyAutomaticFontSizingMenuItems ( )
2019-11-20 07:37:17 +01:00
} . goBack {
2019-10-03 18:30:55 +02:00
// drill down to submenu
2019-11-20 07:37:17 +01:00
} . openDefaultBrowserSubMenu {
// verify item: set as default browser (duplicates, verify child of recyclerview)
// Verify label: Open links in private tab
} . goBack {
2019-10-03 18:30:55 +02:00
}
2019-08-16 00:48:05 +02:00
}
@Test
fun selectNewDefaultSearchEngine ( ) {
2020-02-06 21:58:47 +01:00
// Goes through the settings and changes the default search engine, then verifies it has changed.
homeScreen {
} . openThreeDotMenu {
} . openSettings {
} . openSearchSubMenu {
changeDefaultSearchEngine ( " DuckDuckGo " )
} . goBack {
} . goBack {
verifyDefaultSearchEngine ( " DuckDuckGo " )
}
2019-08-16 00:48:05 +02:00
}
2020-02-06 21:58:47 +01:00
@Ignore ( " This test works locally, fails on firebase. https://github.com/mozilla-mobile/fenix/issues/8174 " )
2019-08-16 00:48:05 +02:00
@Test
fun toggleSearchSuggestions ( ) {
2020-02-06 21:58:47 +01:00
// Goes through the settings and changes the search suggestion toggle, then verifies it changes.
homeScreen {
} . openNavigationToolbar {
verifySearchSuggestionsAreMoreThan ( 1 , " mozilla " )
} . goBack {
} . openThreeDotMenu {
} . openSettings {
} . openSearchSubMenu {
disableShowSearchSuggestions ( )
} . goBack {
} . goBack {
} . openNavigationToolbar {
verifySearchSuggestionsAreEqualTo ( 0 , " mozilla " )
}
2019-08-16 00:48:05 +02:00
}
@Test
fun toggleShowVisitedSitesAndBookmarks ( ) {
2020-02-06 21:58:47 +01:00
// Bookmarks a few websites, toggles the history and bookmarks setting to off, then verifies if the visited and bookmarked websites do not show in the suggestions.
val page1 = getGenericAsset ( mockWebServer , 1 )
val page2 = getGenericAsset ( mockWebServer , 2 )
val page3 = getGenericAsset ( mockWebServer , 3 )
homeScreen {
} . openNavigationToolbar {
} . enterURLAndEnterToBrowser ( page1 . url ) {
verifyPageContent ( page1 . content )
} . openThreeDotMenu {
clickAddBookmarkButton ( )
}
navigationToolbar {
} . enterURLAndEnterToBrowser ( page2 . url ) {
verifyPageContent ( page2 . content )
} . openThreeDotMenu {
clickAddBookmarkButton ( )
}
navigationToolbar {
} . enterURLAndEnterToBrowser ( page3 . url ) {
verifyPageContent ( page3 . content )
}
navigationToolbar {
verifyNoHistoryBookmarks ( )
}
2019-08-16 00:48:05 +02:00
}
@Test
fun changeThemeSetting ( ) {
2020-02-06 21:58:47 +01:00
// Goes through the settings and changes the default search engine, then verifies it changes.
2019-11-13 17:52:41 +01:00
homeScreen {
} . openThreeDotMenu {
} . openSettings {
2020-02-12 01:17:30 +01:00
} . openCustomizeSubMenu {
2019-11-13 17:52:41 +01:00
verifyThemes ( )
selectDarkMode ( )
verifyDarkThemeApplied ( getUiTheme ( ) )
selectLightMode ( )
verifyLightThemeApplied ( getUiTheme ( ) )
}
2019-08-16 00:48:05 +02:00
}
@Test
fun changeAccessibiltySettings ( ) {
2020-02-06 21:58:47 +01:00
// Goes through the settings and changes the default text on a webpage, then verifies if the text has changed.
val fenixApp = activityIntentTestRule . activity . applicationContext as FenixApplication
val webpage = getLoremIpsumAsset ( mockWebServer ) . url
// This value will represent the text size percentage the webpage will scale to. The default value is 100%.
val textSizePercentage = 180
homeScreen {
} . openThreeDotMenu {
} . openSettings {
} . openAccessibilitySubMenu {
clickFontSizingSwitch ( )
verifyNewMenuItems ( )
changeTextSizeSlider ( textSizePercentage )
verifyTextSizePercentage ( textSizePercentage )
} . goBack {
} . goBack {
} . openNavigationToolbar {
} . enterURLAndEnterToBrowser ( webpage ) {
checkTextSizeOnWebsite ( textSizePercentage , fenixApp . components )
} . openHomeScreen {
} . openThreeDotMenu {
} . openSettings {
} . openAccessibilitySubMenu {
clickFontSizingSwitch ( )
verifyNewMenuItemsAreGone ( )
}
2019-08-16 00:48:05 +02:00
}
@Test
fun changeDefaultBrowserSetting ( ) {
2020-02-06 21:58:47 +01:00
// Opens settings and toggles the default browser setting to on. The device settings open and allows the user to set a default browser.
homeScreen {
} . openThreeDotMenu {
} . openSettings {
} . openDefaultBrowserSubMenu {
verifyDefaultBrowserIsDisabled ( )
clickDefaultBrowserSwitch ( )
verifyAndroidDefaultAppsMenuAppears ( )
}
2019-08-16 00:48:05 +02:00
}
}