SettingsBasicsTest.kt 6.97 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
            // drill down to submenu
73
74
75
76
77
        }.openSearchSubMenu {
            verifyDefaultSearchEngineHeader()
            verifySearchEngineList()
            verifyShowSearchSuggestions()
            verifyShowSearchShortcuts()
78

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

    @Test
    fun selectNewDefaultSearchEngine() {
95
96
97
98
99
100
101
102
103
104
        // 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
105
106
    }

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

    @Test
    fun toggleShowVisitedSitesAndBookmarks() {
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
        // 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) {
148
            mDevice.waitForIdle()
149
150
151
152
153
        }

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

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

    @Test
    fun changeAccessibiltySettings() {
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
        // 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)
193
        }.openTabDrawer {
194
195
        }.openNewTab {
        }.dismiss {
196
197
198
199
200
201
        }.openThreeDotMenu {
        }.openSettings {
        }.openAccessibilitySubMenu {
            clickFontSizingSwitch()
            verifyNewMenuItemsAreGone()
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
202
203
204
205
    }

    @Test
    fun changeDefaultBrowserSetting() {
206
207
208
209
        // 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 {
210
            verifyDefaultBrowserIsDisaled()
211
212
213
            clickDefaultBrowserSwitch()
            verifyAndroidDefaultAppsMenuAppears()
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
214
215
    }
}