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

Commit

Permalink
Added UI tests for the basic settings menu
Browse files Browse the repository at this point in the history
  • Loading branch information
KMaragh committed Jan 13, 2020
1 parent 399df17 commit 7cfd4f0
Show file tree
Hide file tree
Showing 12 changed files with 618 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

package org.mozilla.fenix.helpers

import android.graphics.Bitmap
import android.view.View
import org.hamcrest.CoreMatchers.not
import org.hamcrest.Matcher
import org.mozilla.fenix.helpers.matchers.BitmapDrawableMatcher
import androidx.test.espresso.matcher.ViewMatchers.isChecked as espressoIsChecked
import androidx.test.espresso.matcher.ViewMatchers.isEnabled as espressoIsEnabled
import androidx.test.espresso.matcher.ViewMatchers.isSelected as espressoIsSelected
Expand All @@ -30,3 +32,5 @@ private fun maybeInvertMatcher(matcher: Matcher<View>, useUnmodifiedMatcher: Boo
useUnmodifiedMatcher -> matcher
else -> not(matcher)
}

fun withBitmapDrawable(bitmap: Bitmap, name: String): Matcher<View>? = BitmapDrawableMatcher(bitmap, name)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.mozilla.fenix.helpers.assertions

import android.view.View
import androidx.test.espresso.ViewAssertion
import mozilla.components.browser.awesomebar.BrowserAwesomeBar

class AwesomeBarAssertion {
companion object {
fun suggestionsAreGreaterThan(minimumSuggestions: Int): ViewAssertion {
return ViewAssertion { view, noViewFoundException ->
if (noViewFoundException != null) throw noViewFoundException

val suggestionsCount = getSuggestionCountFromView(view)

if (suggestionsCount <= minimumSuggestions)
throw AssertionError("The suggestion count is less than or equal to the minimum suggestions")
}
}

fun suggestionsAreEqualTo(expectedItemCount: Int): ViewAssertion {
return ViewAssertion { view, noViewFoundException ->
if (noViewFoundException != null) throw noViewFoundException

val suggestionsCount = getSuggestionCountFromView(view)

if (suggestionsCount != expectedItemCount)
throw AssertionError("The expected item count is $expectedItemCount, and the suggestions count within the AwesomeBar is $suggestionsCount")
}
}

private fun getSuggestionCountFromView(view: View): Int {
return (view as BrowserAwesomeBar).adapter?.itemCount
?: throw AssertionError("This view is not of type BrowserAwesomeBar")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.mozilla.fenix.helpers.matchers

import android.graphics.Bitmap
import android.view.View
import android.widget.ImageView
import androidx.test.espresso.matcher.BoundedMatcher
import org.hamcrest.Description
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.StateListDrawable
import android.graphics.drawable.Drawable

class BitmapDrawableMatcher(private val bitmap: Bitmap, private val name: String) :
BoundedMatcher<View, ImageView>(ImageView::class.java) {

override fun describeTo(description: Description?) {
description?.appendText("has image drawable resource $name")
}

override fun matchesSafely(item: ImageView): Boolean {
return sameBitmap(item.drawable, bitmap)
}

private fun sameBitmap(drawable: Drawable?, otherBitmap: Bitmap): Boolean {
var currentDrawable = drawable ?: return false

if (currentDrawable is StateListDrawable) {
currentDrawable = currentDrawable.current
}
if (currentDrawable is BitmapDrawable) {
val bitmap = currentDrawable.bitmap
return bitmap.sameAs(otherBitmap)
}
return false
}
}
8 changes: 4 additions & 4 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class SearchTest {
homeScreen {
}.openSearch {
verifySearchWithText()
clickDuckDuckGoEngineButton()
clickSearchEngineButton("DuckDuckGo")
typeSearch("mozilla")
verifyDuckDuckGoResults()
clickDuckDuckGoResult()
verifyDuckDuckGoURL()
verifySearchEngineResults("DuckDuckGo")
clickSearchEngineResult("DuckDuckGo")
verifySearchEngineURL("DuckDuckGo")
}
}

Expand Down
165 changes: 102 additions & 63 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import androidx.test.uiautomator.UiDevice
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.FenixApplication
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
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
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar

/**
* Tests for verifying the main three dot menu options
Expand All @@ -29,7 +33,7 @@ class SettingsBasicsTest {
private lateinit var mockWebServer: MockWebServer

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

@Before
fun setUp() {
Expand All @@ -45,7 +49,8 @@ class SettingsBasicsTest {
}

private fun getUiTheme(): Boolean {
val mode = activityTestRule.activity.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)
val mode =
activityIntentTestRule.activity.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)

return when (mode) {
Configuration.UI_MODE_NIGHT_YES -> true // dark theme is set
Expand All @@ -68,6 +73,7 @@ class SettingsBasicsTest {
verifySearchEngineList()
verifyShowSearchSuggestions()
verifyShowSearchShortcuts()

verifyShowClipboardSuggestions()
verifySearchBrowsingHistory()
verifySearchBookmarks()
Expand All @@ -76,7 +82,7 @@ class SettingsBasicsTest {
verifyThemes()
}.goBack {
}.openAccessibilitySubMenu {
verifyAutomaticFontSizing()
verifyAutomaticFontSizingMenuItems()
}.goBack {
// drill down to submenu
}.openDefaultBrowserSubMenu {
Expand All @@ -86,49 +92,74 @@ class SettingsBasicsTest {
}
}

@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
// 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")
}
}

@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
// 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")
}
}

@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
// 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()
}

}

@Test
fun changeThemeSetting() {
// Goes through the settings and changes the default search engine, then verifies it changes.
homeScreen {
}.openThreeDotMenu {
}.openSettings {
Expand All @@ -141,40 +172,48 @@ class SettingsBasicsTest {
}
}

@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
// 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()
}
}

@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
// 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()
}

}
}
Loading

0 comments on commit 7cfd4f0

Please sign in to comment.