SettingsBasicsTest.kt 7.32 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
71
        homeScreen {
        }.openThreeDotMenu {
        }.openSettings {
            verifyBasicsHeading()
            verifySearchEngineButton()
            // drill down to submenu
72
73
74
75
76
        }.openSearchSubMenu {
            verifyDefaultSearchEngineHeader()
            verifySearchEngineList()
            verifyShowSearchSuggestions()
            verifyShowSearchShortcuts()
77

78
79
80
81
            verifyShowClipboardSuggestions()
            verifySearchBrowsingHistory()
            verifySearchBookmarks()
        }.goBack {
Jeff Boek's avatar
Jeff Boek committed
82
        }.openCustomizeSubMenu {
83
84
85
            verifyThemes()
        }.goBack {
        }.openAccessibilitySubMenu {
86
            verifyAutomaticFontSizingMenuItems()
87
        }.goBack {
88
            // drill down to submenu
89
90
91
92
        }.openDefaultBrowserSubMenu {
            // verify item: set as default browser (duplicates, verify child of recyclerview)
            // Verify label: Open links in private tab
        }.goBack {
93
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
94
95
96
97
    }

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

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

129
    @Ignore("Currently failing on firebase: https://github.com/mozilla-mobile/fenix/issues/8747")
Richard Pappalardo's avatar
Richard Pappalardo committed
130
131
    @Test
    fun toggleShowVisitedSitesAndBookmarks() {
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
        // 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()
        }

Richard Pappalardo's avatar
Richard Pappalardo committed
161
162
163
164
    }

    @Test
    fun changeThemeSetting() {
165
        // Goes through the settings and changes the default search engine, then verifies it changes.
166
167
168
        homeScreen {
        }.openThreeDotMenu {
        }.openSettings {
Jeff Boek's avatar
Jeff Boek committed
169
        }.openCustomizeSubMenu {
170
171
172
173
174
175
            verifyThemes()
            selectDarkMode()
            verifyDarkThemeApplied(getUiTheme())
            selectLightMode()
            verifyLightThemeApplied(getUiTheme())
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
176
177
178
179
    }

    @Test
    fun changeAccessibiltySettings() {
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
        // 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()
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
207
208
209
210
    }

    @Test
    fun changeDefaultBrowserSetting() {
211
212
213
214
215
216
217
218
219
220
        // 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()
        }

Richard Pappalardo's avatar
Richard Pappalardo committed
221
222
    }
}