Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Added UI tests for the Submenu About settings. #6161

Merged
merged 1 commit into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ dependencies {

androidTestImplementation Deps.androidx_test_core
androidTestImplementation Deps.espresso_idling_resources
androidTestImplementation Deps.espresso_intents

androidTestImplementation Deps.tools_test_runner
androidTestImplementation Deps.tools_test_rules
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.mozilla.fenix.helpers

object Constants {

object PackageName {
const val GOOGLE_PLAY_SERVICES = "com.android.vending"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.mozilla.fenix.helpers

import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.rule.ActivityTestRule
import org.mozilla.fenix.HomeActivity

Expand All @@ -16,3 +17,14 @@ import org.mozilla.fenix.HomeActivity

class HomeActivityTestRule(initialTouchMode: Boolean = false, launchActivity: Boolean = true) :
ActivityTestRule<HomeActivity>(HomeActivity::class.java, initialTouchMode, launchActivity)

/**
* A [org.junit.Rule] to handle shared test set up for tests on [HomeActivity]. This adds
* functionality for using the Espresso-intents api, and extends from ActivityTestRule.
*
* @param initialTouchMode See [IntentsTestRule]
* @param launchActivity See [IntentsTestRule]
*/

class HomeActivityIntentTestRule(initialTouchMode: Boolean = false, launchActivity: Boolean = true) :
IntentsTestRule<HomeActivity>(HomeActivity::class.java, initialTouchMode, launchActivity)
43 changes: 16 additions & 27 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SettingsAboutTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import okhttp3.mockwebserver.MockWebServer
import org.junit.Rule
import org.junit.Before
import org.junit.After
import org.junit.Ignore
import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.ui.robots.clickRateButtonGooglePlay
import org.mozilla.fenix.ui.robots.homeScreen

/**
Expand All @@ -28,7 +28,7 @@ class SettingsAboutTest {
private lateinit var mockWebServer: MockWebServer

@get:Rule
val activityTestRule = HomeActivityTestRule()
val activityIntentTestRule = HomeActivityIntentTestRule()

@Before
fun setUp() {
Expand Down Expand Up @@ -58,35 +58,24 @@ class SettingsAboutTest {
}

// ABOUT
@Ignore("This is a stub test, ignore for now")
@Test
fun verifyHelpRedirect() {
// Open 3dot (main) menu
// Select settings
// Click on "Help"
// Verify redirect to: https://support.mozilla.org/
}

@Ignore("This is a stub test, ignore for now")
@Test
fun verifyRateOnGooglePlayRedirect() {
// Open 3dot (main) menu
// Select settings
// Click on "Rate on Google Play"
// Verify Android "Open with Google Play Store" sub menu
homeScreen {
}.openThreeDotMenu {
}.openSettings {
clickRateButtonGooglePlay()
verifyGooglePlayRedirect()
}

}

@Ignore("This is a stub test, ignore for now")
@Test
fun verifyAboutFirefoxPreview() {
// Open 3dot (main) menu
// Select settings
// Click on "Verify About Firefox Preview"
// Verify about page contains....
// Build #
// Version #
// "Firefox Preview is produced by Mozilla"
// Day, Date, timestamp
// "Open source libraries we use"
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openAboutFirefoxPreview {
verifyAboutFirefoxPreview()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,23 @@ class BrowserRobot {
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}

fun verifyHelpUrl() {
fun verifyUrl(redirectUrl: String) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
val redirectUrl = "https://support.mozilla.org/"
mDevice.waitNotNull(Until.findObject(By.res("org.mozilla.fenix.debug:id/mozac_browser_toolbar_url_view")),
TestAssetHelper.waitingTime)
mDevice.waitNotNull(Until.findObject(By.res("org.mozilla.fenix.debug:id/mozac_browser_toolbar_url_view")), TestAssetHelper.waitingTime)
onView(withId(R.id.mozac_browser_toolbar_url_view))
.check(matches(withText(containsString(redirectUrl))))
}

fun verifyHelpUrl() {
verifyUrl("https://support.mozilla.org/")
}

fun verifyWhatsNewURL() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
val redirectUrl = "https://support.mozilla.org/"
mDevice.waitNotNull(Until.findObject(By.res("org.mozilla.fenix.debug:id/mozac_browser_toolbar_url_view")),
TestAssetHelper.waitingTime)
onView(withId(R.id.mozac_browser_toolbar_url_view))
.check(matches(withText(containsString(redirectUrl))))
verifyUrl("https://support.mozilla.org/")
}

fun verifyRateOnGooglePlayURL() {
verifyUrl("https://play.google.com/store/apps/details?id=org.mozilla.fenix")
}

/* Asserts that the text within DOM element with ID="testContent" has the given text, i.e.
Expand Down Expand Up @@ -132,6 +133,7 @@ fun browserScreen(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
}

private fun dismissOnboardingButton() = onView(withId(R.id.close_onboarding))

fun dismissTrackingOnboarding() {
mDevice.wait(Until.findObject(By.res("close_onboarding")), TestAssetHelper.waitingTime)
dismissOnboardingButton().click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.Until
Expand Down Expand Up @@ -131,15 +132,13 @@ class HomeScreenRobot {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

fun openThreeDotMenu(interact: ThreeDotMenuMainRobot.() -> Unit): ThreeDotMenuMainRobot.Transition {
mDevice.waitForIdle()
threeDotButton().perform(click())

ThreeDotMenuMainRobot().interact()
return ThreeDotMenuMainRobot.Transition()
}

fun openSearch(interact: SearchRobot.() -> Unit): SearchRobot.Transition {
mDevice.waitForIdle()
navigationToolbar().perform(click())

SearchRobot().interact()
Expand All @@ -160,7 +159,6 @@ class HomeScreenRobot {
}

fun openTabsListThreeDotMenu(interact: ThreeDotMenuMainRobot.() -> Unit): ThreeDotMenuMainRobot.Transition {
mDevice.waitForIdle()
tabsListThreeDotButton().perform(click())

ThreeDotMenuMainRobot().interact()
Expand All @@ -177,12 +175,12 @@ fun homeScreen(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

private fun navigationToolbar() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Search or enter address")))
onView(CoreMatchers.allOf(withText("Search or enter address")))

private fun closeTabButton() = onView(withId(R.id.close_tab_button))

private fun assertNavigationToolbar() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Search or enter address")))
onView(CoreMatchers.allOf(withText("Search or enter address")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertHomeScreen() = onView(ViewMatchers.withResourceName("homeLayout"))
Expand All @@ -202,95 +200,94 @@ private fun assertHomeToolbar() = onView(ViewMatchers.withResourceName("toolbar"
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertOpenTabsHeader() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Open tabs")))
onView(CoreMatchers.allOf(withText("Open tabs")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertAddTabButton() =
onView(CoreMatchers.allOf(ViewMatchers.withId(R.id.add_tab_button), isDisplayed()))
onView(CoreMatchers.allOf(withId(R.id.add_tab_button), isDisplayed()))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertNoTabsOpenedHeader() =
onView(CoreMatchers.allOf(ViewMatchers.withText("No open tabs")))
onView(CoreMatchers.allOf(withText("No open tabs")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertNoTabsOpenedText() {
onView(CoreMatchers.allOf(ViewMatchers.withText("Your open tabs will be shown here.")))
onView(CoreMatchers.allOf(withText("Your open tabs will be shown here.")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

private fun assertCollectionsHeader() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Collections")))
onView(CoreMatchers.allOf(withText("Collections")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertNoCollectionsHeader() =
onView(CoreMatchers.allOf(ViewMatchers.withText("No collections")))
onView(CoreMatchers.allOf(withText("No collections")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertNoCollectionsText() =
onView(
CoreMatchers.allOf(
ViewMatchers
.withText("Collect the things that matter to you. To start, save open tabs to a new collection.")
withText("Collect the things that matter to you. To start, save open tabs to a new collection.")
)
)
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertHomeComponent() = onView(ViewMatchers.withResourceName("home_component"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun threeDotButton() = onView(allOf(ViewMatchers.withId(R.id.menuButton)))
private fun threeDotButton() = onView(allOf(withId(R.id.menuButton)))

// First Run elements
private fun assertWelcomeHeader() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Welcome to Firefox Preview!")))
onView(CoreMatchers.allOf(withText("Welcome to Firefox Preview!")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertGetTheMostHeader() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Get the most out of Firefox Preview.")))
onView(CoreMatchers.allOf(withText("Get the most out of Firefox Preview.")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertAccountsSignInButton() =
onView(ViewMatchers.withResourceName("turn_on_sync_button"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertGetToKnowHeader() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Get to know Firefox Preview")))
onView(CoreMatchers.allOf(withText("Get to know Firefox Preview")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertChooseThemeHeader() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Choose your theme")))
onView(CoreMatchers.allOf(withText("Choose your theme")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertChooseThemeText() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Try dark theme: easier on your battery and your eyes.")))
onView(CoreMatchers.allOf(withText("Try dark theme: easier on your battery and your eyes.")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertLightThemeToggle() =
onView(ViewMatchers.withResourceName("theme_light_radio_button"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertLightThemeDescription() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Light theme")))
onView(CoreMatchers.allOf(withText("Light theme")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertDarkThemeToggle() =
onView(ViewMatchers.withResourceName("theme_dark_radio_button"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertDarkThemeDescription() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Dark theme")))
onView(CoreMatchers.allOf(withText("Dark theme")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertAutomaticThemeToggle() =
onView(ViewMatchers.withResourceName("theme_automatic_radio_button"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertAutomaticThemeDescription() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Automatic")))
onView(CoreMatchers.allOf(withText("Automatic")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertProtectYourselfHeader() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Protect yourself")))
onView(CoreMatchers.allOf(withText("Protect yourself")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertTrackingProtectionToggle() = onView(
Expand All @@ -301,7 +298,7 @@ private fun assertTrackingProtectionToggle() = onView(
private fun assertProtectYourselfText() {
onView(
CoreMatchers.allOf(
ViewMatchers.withText(
withText(
"Firefox Preview blocks ad trackers that follow you around the web."
)
)
Expand All @@ -310,33 +307,33 @@ private fun assertProtectYourselfText() {
}

private fun assertBrowsePrivatelyHeader() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Browse privately")))
onView(CoreMatchers.allOf(withText("Browse privately")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertBrowsePrivatelyText() =
onView(CoreMatchers.allOf(ViewMatchers.withText(containsString("private browsing is just a tap away."))))
onView(CoreMatchers.allOf(withText(containsString("private browsing is just a tap away."))))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertYourPrivacyHeader() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Your privacy")))
onView(CoreMatchers.allOf(withText("Your privacy")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertYourPrivacyText() =
onView(CoreMatchers.allOf(ViewMatchers.withText(
onView(CoreMatchers.allOf(withText(
"We’ve designed Firefox Preview to give you control over what you share online and what you share with us.")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertPrivacyNoticeButton() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Read our privacy notice")))
onView(CoreMatchers.allOf(withText("Read our privacy notice")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertStartBrowsingButton() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Start browsing")))
onView(CoreMatchers.allOf(withText("Start browsing")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

// Private mode elements
private fun assertPrivateSessionHeader() =
onView(CoreMatchers.allOf(ViewMatchers.withText("Private tabs")))
onView(CoreMatchers.allOf(withText("Private tabs")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

const val PRIVATE_SESSION_MESSAGE = "Firefox Preview clears your search and browsing history " +
Expand All @@ -345,27 +342,27 @@ const val PRIVATE_SESSION_MESSAGE = "Firefox Preview clears your search and brow
"who uses this device."

private fun assertPrivateSessionMessage(visible: Boolean) =
onView(CoreMatchers.allOf(ViewMatchers.withText(PRIVATE_SESSION_MESSAGE)))
onView(CoreMatchers.allOf(withText(PRIVATE_SESSION_MESSAGE)))
.check(
if (visible) matches(withEffectiveVisibility(Visibility.VISIBLE)) else doesNotExist()
)

private fun assertShareTabsButton(visible: Boolean) =
onView(CoreMatchers.allOf(ViewMatchers.withId(R.id.share_tabs_button), isDisplayed()))
onView(CoreMatchers.allOf(withId(R.id.share_tabs_button), isDisplayed()))
.check(matches(withEffectiveVisibility(visibleOrGone(visible))))

private fun assertCloseTabsButton(visible: Boolean) =
onView(CoreMatchers.allOf(ViewMatchers.withId(R.id.close_tab_button), isDisplayed()))
onView(CoreMatchers.allOf(withId(R.id.close_tab_button), isDisplayed()))
.check(matches(withEffectiveVisibility(visibleOrGone(visible))))

private fun visibleOrGone(visibility: Boolean) = if (visibility) Visibility.VISIBLE else Visibility.GONE

private fun assertExistingTabList() =
onView(CoreMatchers.allOf(ViewMatchers.withId(R.id.item_tab)))
onView(CoreMatchers.allOf(withId(R.id.item_tab)))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun tabsListThreeDotButton() = onView(allOf(ViewMatchers.withId(R.id.tabs_overflow_button)))
private fun tabsListThreeDotButton() = onView(allOf(withId(R.id.tabs_overflow_button)))

private fun collectionThreeDotButton() = onView(allOf(ViewMatchers.withId(R.id.collection_overflow_button)))
private fun collectionThreeDotButton() = onView(allOf(withId(R.id.collection_overflow_button)))

private fun collectionNameTextField() = onView(allOf(ViewMatchers.withResourceName("name_collection_edittext")))
Loading