SettingsBasicsTest.kt 7.27 KB
Newer Older
Richard Pappalardo's avatar
Richard Pappalardo committed
1 2 3 4 5 6
/* 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

7
import android.content.res.Configuration
Richard Pappalardo's avatar
Richard Pappalardo committed
8 9 10 11
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
12 13
import org.junit.Before
import org.junit.Rule
Richard Pappalardo's avatar
Richard Pappalardo committed
14
import org.junit.Test
15 16
import org.junit.Ignore
import org.mozilla.fenix.FenixApplication
Richard Pappalardo's avatar
Richard Pappalardo committed
17
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
18 19 20 21
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
22
import org.mozilla.fenix.ui.robots.homeScreen
23
import org.mozilla.fenix.ui.robots.navigationToolbar
Richard Pappalardo's avatar
Richard Pappalardo committed
24 25 26 27 28 29 30 31 32 33 34 35 36

/**
 *  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
37
    val activityIntentTestRule = HomeActivityIntentTestRule()
Richard Pappalardo's avatar
Richard Pappalardo committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51

    @Before
    fun setUp() {
        mockWebServer = MockWebServer().apply {
            setDispatcher(AndroidAssetDispatcher())
            start()
        }
    }

    @After
    fun tearDown() {
        mockWebServer.shutdown()
    }

52
    private fun getUiTheme(): Boolean {
53 54
        val mode =
            activityIntentTestRule.activity.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)
55 56 57 58 59 60 61 62

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

Richard Pappalardo's avatar
Richard Pappalardo committed
63
    @Test
64
    // Walks through settings menu and sub-menus to ensure all items are present
Richard Pappalardo's avatar
Richard Pappalardo committed
65
    fun settingsMenuBasicsItemsTests() {
66 67 68 69 70
        homeScreen {
        }.openThreeDotMenu {
        }.openSettings {
            verifyBasicsHeading()
            verifySearchEngineButton()
71
            verifyDefaultBrowserItem()
72
            verifyCloseTabsItem()
73
            // drill down to submenu
74 75 76 77 78
        }.openSearchSubMenu {
            verifyDefaultSearchEngineHeader()
            verifySearchEngineList()
            verifyShowSearchSuggestions()
            verifyShowSearchShortcuts()
79

80 81 82 83
            verifyShowClipboardSuggestions()
            verifySearchBrowsingHistory()
            verifySearchBookmarks()
        }.goBack {
Jeff Boek's avatar
Jeff Boek committed
84
        }.openCustomizeSubMenu {
85 86 87
            verifyThemes()
        }.goBack {
        }.openAccessibilitySubMenu {
88
            verifyAutomaticFontSizingMenuItems()
89
        }.goBack {
90 91
            // drill down to submenu
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
92 93 94 95
    }

    @Test
    fun selectNewDefaultSearchEngine() {
96 97 98 99 100 101 102 103 104 105
        // 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")
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
106 107
    }

108
    @Ignore("This test works locally, fails on firebase. https://github.com/mozilla-mobile/fenix/issues/8174")
Richard Pappalardo's avatar
Richard Pappalardo committed
109 110
    @Test
    fun toggleSearchSuggestions() {
111 112 113 114 115 116 117 118 119 120 121 122 123 124
        // 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")
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
125 126 127 128
    }

    @Test
    fun toggleShowVisitedSitesAndBookmarks() {
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
        // 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) {
        }.openThreeDotMenu {
            clickAddBookmarkButton()
        }

        navigationToolbar {
        }.enterURLAndEnterToBrowser(page2.url) {
        }.openThreeDotMenu {
            clickAddBookmarkButton()
        }

        navigationToolbar {
        }.enterURLAndEnterToBrowser(page3.url) {
149
            mDevice.waitForIdle()
150 151 152 153 154
        }

        navigationToolbar {
            verifyNoHistoryBookmarks()
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
155 156 157 158
    }

    @Test
    fun changeThemeSetting() {
159
        // Goes through the settings and changes the default search engine, then verifies it changes.
160 161 162
        homeScreen {
        }.openThreeDotMenu {
        }.openSettings {
Jeff Boek's avatar
Jeff Boek committed
163
        }.openCustomizeSubMenu {
164 165 166 167 168 169
            verifyThemes()
            selectDarkMode()
            verifyDarkThemeApplied(getUiTheme())
            selectLightMode()
            verifyLightThemeApplied(getUiTheme())
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
170 171
    }

172 173 174 175 176 177 178 179 180 181 182
    @Test
    fun changeCloseTabsSetting() {
        // Goes through the settings and verified the close tabs setting options.
        homeScreen {
        }.openThreeDotMenu {
        }.openSettings {
        }.openCloseTabsSubMenu {
            verifyOptions()
        }
    }

Richard Pappalardo's avatar
Richard Pappalardo committed
183 184
    @Test
    fun changeAccessibiltySettings() {
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
        // 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)
205
        }.openTabDrawer {
206 207
        }.openNewTab {
        }.dismiss {
208 209 210 211 212 213
        }.openThreeDotMenu {
        }.openSettings {
        }.openAccessibilitySubMenu {
            clickFontSizingSwitch()
            verifyNewMenuItemsAreGone()
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
214 215 216 217
    }

    @Test
    fun changeDefaultBrowserSetting() {
218 219 220 221
        // 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 {
222
            verifyDefaultBrowserIsDisaled()
223 224 225
            clickDefaultBrowserSwitch()
            verifyAndroidDefaultAppsMenuAppears()
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
226 227
    }
}