HomeScreenTest.kt 2.95 KB
Newer Older
Kevin Brosnan's avatar
Kevin Brosnan 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 androidx.test.uiautomator.UiDevice
Kevin Brosnan's avatar
Kevin Brosnan committed
8
9
10
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.helpers.HomeActivityTestRule
11
import androidx.test.platform.app.InstrumentationRegistry
12
13
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
14
import org.mozilla.fenix.helpers.ext.waitNotNull
15
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
Kevin Brosnan's avatar
Kevin Brosnan committed
16
17
18
import org.mozilla.fenix.ui.robots.homeScreen

/**
19
 *  Tests for verifying the presence of home screen and first-run homescreen elements
Kevin Brosnan's avatar
Kevin Brosnan committed
20
 *
21
22
 *  Note: For private browsing, navigation bar and tabs see separate test class
 *
Kevin Brosnan's avatar
Kevin Brosnan committed
23
24
25
26
 */

class HomeScreenTest {
    /* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.
27
28
29

    private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

Kevin Brosnan's avatar
Kevin Brosnan committed
30
31
    @get:Rule
    val activityTestRule = HomeActivityTestRule()
32

Kevin Brosnan's avatar
Kevin Brosnan committed
33
34
    @Test
    fun homeScreenItemsTest() {
35
        homeScreen { }.dismissOnboarding()
36

Kevin Brosnan's avatar
Kevin Brosnan committed
37
38
        homeScreen {
            verifyHomeScreen()
39
            verifyNavigationToolbar()
Kevin Brosnan's avatar
Kevin Brosnan committed
40
41
42
            verifyHomePrivateBrowsingButton()
            verifyHomeMenu()
            verifyHomeWordmark()
43
44
            verifyTabButton()
            verifyCollectionsHeader()
Kevin Brosnan's avatar
Kevin Brosnan committed
45
46
            verifyHomeToolbar()
            verifyHomeComponent()
47
48
49
50
51

            // Verify Top Sites
            verifyExistingTopSitesList()
            verifyExistingTopSitesTabs("Wikipedia")
            verifyExistingTopSitesTabs("Top Articles")
52
            verifyExistingTopSitesTabs("Google")
Kevin Brosnan's avatar
Kevin Brosnan committed
53
54
        }
    }
55

56
57
58
    @Test
    fun privateModeScreenItemsTest() {
        homeScreen { }.dismissOnboarding()
59
        homeScreen { }.togglePrivateBrowsingMode()
60
61
62
63
64
65
66

        homeScreen {
            verifyHomeScreen()
            verifyNavigationToolbar()
            verifyHomePrivateBrowsingButton()
            verifyHomeMenu()
            verifyHomeWordmark()
67
68
            verifyTabButton()
            verifyPrivateSessionMessage()
69
70
            verifyHomeToolbar()
            verifyHomeComponent()
71
72
73
        }.openCommonMythsLink {
            verifyUrl("common-myths-about-private-browsing")
            mDevice.pressBack()
74
75
76
77
78
        }

        homeScreen {
            // To deal with the race condition where multiple "add tab" buttons are present,
            // we need to wait until previous HomeFragment View objects are gone.
79
            mDevice.waitNotNull(Until.gone(By.text(privateSessionMessage)), waitingTime)
80
81
82
83
84
            verifyHomeScreen()
            verifyNavigationToolbar()
            verifyHomePrivateBrowsingButton()
            verifyHomeMenu()
            verifyHomeWordmark()
85
86
            verifyTabButton()
            verifyPrivateSessionMessage()
87
88
89
90
            verifyHomeToolbar()
            verifyHomeComponent()
        }
    }
Kevin Brosnan's avatar
Kevin Brosnan committed
91
}