SettingsBasicsTest.kt 5.93 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
import org.junit.Before
Richard Pappalardo's avatar
Richard Pappalardo committed
13
import org.junit.Ignore
14
import org.junit.Rule
Richard Pappalardo's avatar
Richard Pappalardo committed
15
16
17
import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
18
import org.mozilla.fenix.ui.robots.homeScreen
Richard Pappalardo's avatar
Richard Pappalardo committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

/**
 *  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
    val activityTestRule = HomeActivityTestRule()

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

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

47
48
49
50
51
52
53
54
55
56
    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
        }
    }

Richard Pappalardo's avatar
Richard Pappalardo committed
57
    @Test
58
    // Walks through settings menu and sub-menus to ensure all items are present
Richard Pappalardo's avatar
Richard Pappalardo committed
59
    fun settingsMenuBasicsItemsTests() {
60
61
62
63
64
65
        homeScreen {
        }.openThreeDotMenu {
        }.openSettings {
            verifyBasicsHeading()
            verifySearchEngineButton()
            // drill down to submenu
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
        }.openSearchSubMenu {
            verifyDefaultSearchEngineHeader()
            verifySearchEngineList()
            verifyShowSearchSuggestions()
            verifyShowSearchShortcuts()
            verifyShowClipboardSuggestions()
            verifySearchBrowsingHistory()
            verifySearchBookmarks()
        }.goBack {
        }.openThemeSubMenu {
            verifyThemes()
        }.goBack {
        }.openAccessibilitySubMenu {
            verifyAutomaticFontSizing()
        }.goBack {
81
            // drill down to submenu
82
83
84
85
        }.openDefaultBrowserSubMenu {
            // verify item: set as default browser (duplicates, verify child of recyclerview)
            // Verify label: Open links in private tab
        }.goBack {
86
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
    }

    @Ignore("This is a stub test, ignore for now")
    @Test
    fun selectNewDefaultSearchEngine() {
        // Open 3dot (main) menu
        // Select settings
        // Select "Search engine"
        // Choose: DuckDuckGo
        // Back arrow to Home
        // Verify DuckDuckGo icon in Navigation bar
    }

    @Ignore("This is a stub test, ignore for now")
    @Test
    fun toggleSearchSuggestions() {
        // Enter: "mozilla" in navigation bar
        // Verify more than one suggesion provided
        // Open 3dot (main) menu
        // Select settings
        // Select "Search engine"
        // Toggle 'Show search suggestions' to 'off'
        // Back arrow twice to home screen
        // Enter: "mozilla" in navigation bar
        // Verify no suggestions provided
    }

    @Ignore("This is a stub test, ignore for now")
    @Test
    fun toggleShowVisitedSitesAndBookmarks() {
        // Visit 3 static sites
        // Bookmark 2 of them
        // Open 3dot (main) menu
        // Enter navigation bar and verify visited sites appear
        // Verify bookmarks exist
        // Open 3dot (main) menu
        // Select settings
        // Select "Search engine"
        // Toggle off "Show visited sites and bookmarks"
        // Back arrow twice to home screen
        // Verify history and bookmarks are gone
    }

    @Test
    fun changeThemeSetting() {
132
133
134
135
136
137
138
139
140
141
        homeScreen {
        }.openThreeDotMenu {
        }.openSettings {
        }.openThemeSubMenu {
            verifyThemes()
            selectDarkMode()
            verifyDarkThemeApplied(getUiTheme())
            selectLightMode()
            verifyLightThemeApplied(getUiTheme())
        }
Richard Pappalardo's avatar
Richard Pappalardo committed
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
    }

    @Ignore("This is a stub test, ignore for now")
    @Test
    fun changeAccessibiltySettings() {
        // Open 3dot (main) menu
        // Select settings
        // Select Accessibility
        // Verify header:  "Automatic Font Sizing"
        // Verify description: "Font size will match your Android settings. Disable to manage font size here"
        // Verify toggle is set to 'on' by default
        // Toggle font size to off
        // Verify that new sub-menu items appear....
        // Verify header: "Font Size"
        // Verify description: "Make text on websites larger or smaller"
        // Verify slider bar exists
        // Verify slider bar default value set to 100%
        // Verify sample text "The quick brown fox..." appears 4 times
        // Move slider bar to 180%
        // Verify that text grows to 180%
        // Back error twice to home screen
        // Open static website in navigation bar
        // Verify that text is now at 180%
        // Select settings
        // Select Accessibility
        // Toggle font size back to 'off'
        // Verify that "Font Size" header, description, slider bar and sample text all disappear
    }

    @Ignore("This is a stub test, ignore for now")
    @Test
    fun changeDefaultBrowserSetting() {
        // Open 3dot (main) menu
        // Select settings
        // Verify that "Set as default browser toggle is set to 'off' (default)
        // Turn default browser toggle 'on'
        // Verify that Andrdoid "Default Apps" menu appears
    }
}