mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
For #27522: New search settings UI tests coverage
This commit is contained in:
parent
1da0d91ed9
commit
c528c371d5
@ -9,6 +9,8 @@ package org.mozilla.fenix.helpers
|
||||
import android.app.ActivityManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
@ -43,6 +45,8 @@ import androidx.test.uiautomator.UiObjectNotFoundException
|
||||
import androidx.test.uiautomator.UiScrollable
|
||||
import androidx.test.uiautomator.UiSelector
|
||||
import androidx.test.uiautomator.Until
|
||||
import java.util.Locale
|
||||
import java.util.regex.Pattern
|
||||
import junit.framework.AssertionFailedError
|
||||
import mozilla.components.browser.state.search.SearchEngine
|
||||
import mozilla.components.support.ktx.android.content.appName
|
||||
@ -63,8 +67,6 @@ import org.mozilla.fenix.helpers.idlingresource.NetworkConnectionIdlingResource
|
||||
import org.mozilla.fenix.ui.robots.BrowserRobot
|
||||
import org.mozilla.fenix.utils.IntentUtils
|
||||
import org.mozilla.gecko.util.ThreadUtils
|
||||
import java.util.Locale
|
||||
import java.util.regex.Pattern
|
||||
|
||||
object TestHelper {
|
||||
|
||||
@ -418,4 +420,14 @@ object TestHelper {
|
||||
Configuration::class.java,
|
||||
).invoke(am, config)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates clipboard data.
|
||||
*/
|
||||
fun setTextToClipBoard(context: Context, message: String) {
|
||||
val clipBoard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clipData = ClipData.newPlainText("label", message)
|
||||
|
||||
clipBoard.setPrimaryClip(clipData)
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ class BookmarksTest {
|
||||
clickClearButton()
|
||||
longClickToolbar()
|
||||
clickPasteText()
|
||||
verifyPastedToolbarText(defaultWebPage.url.toString())
|
||||
verifyTypedToolbarText(defaultWebPage.url.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ class CustomTabsTest {
|
||||
clickClearButton()
|
||||
longClickToolbar()
|
||||
clickPasteText()
|
||||
verifyPastedToolbarText(customTabPage.url.toString())
|
||||
verifyTypedToolbarText(customTabPage.url.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ class SearchTest {
|
||||
}.openThreeDotMenu {
|
||||
}.openSettings {
|
||||
}.openSearchSubMenu {
|
||||
enableShowSearchShortcuts()
|
||||
toggleShowSearchShortcuts()
|
||||
}.goBack {
|
||||
}.goBack {
|
||||
}.openSearch {
|
||||
@ -147,7 +147,7 @@ class SearchTest {
|
||||
}.openThreeDotMenu {
|
||||
}.openSettings {
|
||||
}.openSearchSubMenu {
|
||||
enableShowSearchShortcuts()
|
||||
toggleShowSearchShortcuts()
|
||||
}.goBack {
|
||||
}.goBack {
|
||||
}.openSearch {
|
||||
|
@ -12,6 +12,8 @@ import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
|
||||
import org.mozilla.fenix.helpers.SearchDispatcher
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset
|
||||
import org.mozilla.fenix.helpers.TestHelper.appContext
|
||||
import org.mozilla.fenix.helpers.TestHelper.setTextToClipBoard
|
||||
import org.mozilla.fenix.helpers.TestHelper.exitMenu
|
||||
import org.mozilla.fenix.ui.robots.homeScreen
|
||||
import org.mozilla.fenix.ui.robots.navigationToolbar
|
||||
@ -47,6 +49,11 @@ class SettingsSearchTest {
|
||||
verifySearchToolbar()
|
||||
verifyDefaultSearchEngineHeader()
|
||||
verifySearchEngineList()
|
||||
verifyShowSearchSuggestions()
|
||||
verifyShowSearchShortcuts()
|
||||
verifySearchBrowsingHistory()
|
||||
verifySearchBookmarks()
|
||||
verifyShowClipboardSuggestionsDefault()
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,7 +72,27 @@ class SettingsSearchTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Failing after compose migration. See: https://github.com/mozilla-mobile/fenix/issues/26087")
|
||||
fun toggleSearchAutocomplete() {
|
||||
homeScreen {
|
||||
}.openSearch {
|
||||
typeSearch("mo")
|
||||
verifyTypedToolbarText("monster.com")
|
||||
typeSearch("moz")
|
||||
verifyTypedToolbarText("mozilla.org")
|
||||
}.dismissSearchBar {
|
||||
}.openThreeDotMenu {
|
||||
}.openSettings {
|
||||
}.openSearchSubMenu {
|
||||
toggleAutocomplete()
|
||||
}.goBack {
|
||||
}.goBack {
|
||||
}.openSearch {
|
||||
typeSearch("moz")
|
||||
verifyTypedToolbarText("moz")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun toggleSearchBookmarksAndHistoryTest() {
|
||||
// Bookmarks 2 websites, toggles the bookmarks and history search settings off,
|
||||
// then verifies if the websites do not show in the suggestions.
|
||||
@ -93,8 +120,9 @@ class SettingsSearchTest {
|
||||
}.openSearch {
|
||||
typeSearch("test")
|
||||
expandSearchSuggestionsList()
|
||||
verifySearchEngineSuggestionResults(activityTestRule, "Test_Page_1")
|
||||
verifySearchEngineSuggestionResults(activityTestRule, "Test_Page_2")
|
||||
verifyFirefoxSuggestResults(activityTestRule, "Firefox Suggest")
|
||||
verifyFirefoxSuggestResults(activityTestRule, "Test_Page_1")
|
||||
verifyFirefoxSuggestResults(activityTestRule, "Test_Page_2")
|
||||
}.dismissSearchBar {
|
||||
}.openThreeDotMenu {
|
||||
}.openSettings {
|
||||
@ -110,6 +138,7 @@ class SettingsSearchTest {
|
||||
}.openSearch {
|
||||
typeSearch("test")
|
||||
expandSearchSuggestionsList()
|
||||
verifyNoSuggestionsAreDisplayed(activityTestRule, "Firefox Suggest")
|
||||
verifyNoSuggestionsAreDisplayed(activityTestRule, "Test_Page_1")
|
||||
verifyNoSuggestionsAreDisplayed(activityTestRule, "Test_Page_2")
|
||||
}
|
||||
@ -192,7 +221,48 @@ class SettingsSearchTest {
|
||||
}.openThreeDotMenu {
|
||||
}.openSettings {
|
||||
}.openSearchSubMenu {
|
||||
disableShowSearchSuggestions()
|
||||
toggleShowSearchSuggestions()
|
||||
}.goBack {
|
||||
}.goBack {
|
||||
}.openSearch {
|
||||
typeSearch("mozilla")
|
||||
verifyNoSuggestionsAreDisplayed(activityTestRule, "mozilla firefox")
|
||||
}
|
||||
}
|
||||
|
||||
// Tests the "Don't allow" option from private mode search suggestions onboarding dialog
|
||||
@Test
|
||||
fun blockSearchSuggestionsInPrivateModeOnboardingTest() {
|
||||
homeScreen {
|
||||
togglePrivateBrowsingModeOnOff()
|
||||
}.openSearch {
|
||||
typeSearch("mozilla")
|
||||
verifyAllowSuggestionsInPrivateModeDialog()
|
||||
denySuggestionsInPrivateMode()
|
||||
verifyNoSuggestionsAreDisplayed(activityTestRule, "mozilla firefox")
|
||||
}.dismissSearchBar {
|
||||
togglePrivateBrowsingModeOnOff()
|
||||
}.openSearch {
|
||||
typeSearch("mozilla")
|
||||
verifySearchEngineSuggestionResults(activityTestRule, "mozilla firefox")
|
||||
}
|
||||
}
|
||||
|
||||
// Tests the "Allow" option from private mode search suggestions onboarding dialog
|
||||
@Test
|
||||
fun allowSearchSuggestionsInPrivateModeOnboardingTest() {
|
||||
homeScreen {
|
||||
togglePrivateBrowsingModeOnOff()
|
||||
}.openSearch {
|
||||
typeSearch("mozilla")
|
||||
verifyAllowSuggestionsInPrivateModeDialog()
|
||||
allowSuggestionsInPrivateMode()
|
||||
verifySearchEngineSuggestionResults(activityTestRule, "mozilla firefox")
|
||||
}.dismissSearchBar {
|
||||
}.openThreeDotMenu {
|
||||
}.openSettings {
|
||||
}.openSearchSubMenu {
|
||||
toggleShowSuggestionsInPrivateSessions()
|
||||
}.goBack {
|
||||
}.goBack {
|
||||
}.openSearch {
|
||||
@ -220,4 +290,26 @@ class SettingsSearchTest {
|
||||
verifyVoiceSearchButtonVisibility(false)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun toggleShowClipboardSuggestionsTest() {
|
||||
val link = "https://www.mozilla.org/en-US/"
|
||||
setTextToClipBoard(appContext, link)
|
||||
|
||||
homeScreen {
|
||||
}.openNavigationToolbar {
|
||||
verifyClipboardSuggestionsAreDisplayed(link, true)
|
||||
}.visitLinkFromClipboard {
|
||||
}.openThreeDotMenu {
|
||||
}.openSettings {
|
||||
}.openSearchSubMenu {
|
||||
verifyShowClipboardSuggestionsDefault()
|
||||
toggleClipboardSuggestion()
|
||||
exitMenu()
|
||||
}
|
||||
homeScreen {
|
||||
}.openNavigationToolbar {
|
||||
verifyClipboardSuggestionsAreDisplayed(link, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -862,7 +862,7 @@ class SmokeTest {
|
||||
clickClearButton()
|
||||
longClickToolbar()
|
||||
clickPasteText()
|
||||
verifyPastedToolbarText("content")
|
||||
verifyTypedToolbarText("content")
|
||||
}
|
||||
}
|
||||
|
||||
@ -881,7 +881,8 @@ class SmokeTest {
|
||||
clickClearButton()
|
||||
longClickToolbar()
|
||||
clickPasteText()
|
||||
verifyPastedToolbarText("Page content: 1")
|
||||
// with Select all, some white space is copied over, so we need to include that too
|
||||
verifyTypedToolbarText(" Page content: 1 ")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,10 +28,12 @@ import androidx.test.uiautomator.UiSelector
|
||||
import androidx.test.uiautomator.Until
|
||||
import org.hamcrest.CoreMatchers.allOf
|
||||
import org.hamcrest.CoreMatchers.not
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.helpers.SessionLoadedIdlingResource
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
|
||||
import org.mozilla.fenix.helpers.TestHelper.getStringResource
|
||||
import org.mozilla.fenix.helpers.TestHelper.mDevice
|
||||
import org.mozilla.fenix.helpers.TestHelper.packageName
|
||||
@ -53,8 +55,6 @@ class NavigationToolbarRobot {
|
||||
fun verifyCloseReaderViewDetected(visible: Boolean = false) =
|
||||
assertCloseReaderViewDetected(visible)
|
||||
|
||||
fun typeSearchTerm(searchTerm: String) = awesomeBar().setText(searchTerm)
|
||||
|
||||
fun toggleReaderView() {
|
||||
mDevice.findObject(
|
||||
UiSelector()
|
||||
@ -65,6 +65,33 @@ class NavigationToolbarRobot {
|
||||
readerViewToggle().click()
|
||||
}
|
||||
|
||||
fun verifyClipboardSuggestionsAreDisplayed(link: String, shouldBeDisplayed: Boolean) {
|
||||
when (shouldBeDisplayed) {
|
||||
true -> {
|
||||
assertTrue(
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/fill_link_from_clipboard"))
|
||||
.waitForExists(waitingTime),
|
||||
)
|
||||
|
||||
assertTrue(
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/clipboard_url").text(link))
|
||||
.waitForExists(waitingTime),
|
||||
)
|
||||
}
|
||||
false -> {
|
||||
assertFalse(
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/fill_link_from_clipboard"))
|
||||
.waitForExists(waitingTime),
|
||||
)
|
||||
|
||||
assertFalse(
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/clipboard_url").text(link))
|
||||
.waitForExists(waitingTime),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Transition {
|
||||
private lateinit var sessionLoadedIdlingResource: SessionLoadedIdlingResource
|
||||
|
||||
@ -151,14 +178,12 @@ class NavigationToolbarRobot {
|
||||
}
|
||||
|
||||
fun visitLinkFromClipboard(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
||||
mDevice.waitNotNull(
|
||||
Until.findObject(By.res("org.mozilla.fenix.debug:id/mozac_browser_toolbar_clear_view")),
|
||||
waitingTime,
|
||||
)
|
||||
clearAddressBar().click()
|
||||
if (clearAddressBar().waitForExists(waitingTimeShort)) {
|
||||
clearAddressBar().click()
|
||||
}
|
||||
|
||||
mDevice.waitNotNull(
|
||||
Until.findObject(By.res("org.mozilla.fenix.debug:id/clipboard_title")),
|
||||
Until.findObject(By.res("$packageName:id/clipboard_title")),
|
||||
waitingTime,
|
||||
)
|
||||
|
||||
@ -166,7 +191,7 @@ class NavigationToolbarRobot {
|
||||
// See for mor information https://github.com/mozilla-mobile/fenix/issues/22271
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
||||
mDevice.waitNotNull(
|
||||
Until.findObject(By.res("org.mozilla.fenix.debug:id/clipboard_url")),
|
||||
Until.findObject(By.res("$packageName:id/clipboard_url")),
|
||||
waitingTime,
|
||||
)
|
||||
}
|
||||
@ -286,7 +311,9 @@ private fun threeDotButton() = onView(withId(R.id.mozac_browser_toolbar_menu))
|
||||
private fun tabTrayButton() = onView(withId(R.id.tab_button))
|
||||
private fun fillLinkButton() = onView(withId(R.id.fill_link_from_clipboard))
|
||||
private fun clearAddressBar() =
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_clear_view"))
|
||||
mDevice.findObject(
|
||||
UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_clear_view"),
|
||||
)
|
||||
private fun goBackButton() = mDevice.pressBack()
|
||||
private fun readerViewToggle() =
|
||||
onView(withParent(withId(R.id.mozac_browser_toolbar_page_actions)))
|
||||
|
@ -19,6 +19,7 @@ import androidx.compose.ui.test.onNodeWithTag
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performScrollToIndex
|
||||
import androidx.compose.ui.test.performScrollToNode
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
@ -28,10 +29,8 @@ import androidx.test.espresso.matcher.ViewMatchers
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withSubstring
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import androidx.test.uiautomator.By
|
||||
import androidx.test.uiautomator.UiScrollable
|
||||
import androidx.test.uiautomator.UiSelector
|
||||
import androidx.test.uiautomator.Until
|
||||
import org.hamcrest.CoreMatchers.allOf
|
||||
@ -41,10 +40,12 @@ import org.junit.Assert.assertTrue
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.helpers.Constants
|
||||
import org.mozilla.fenix.helpers.Constants.LONG_CLICK_DURATION
|
||||
import org.mozilla.fenix.helpers.Constants.RETRY_COUNT
|
||||
import org.mozilla.fenix.helpers.Constants.SPEECH_RECOGNITION
|
||||
import org.mozilla.fenix.helpers.SessionLoadedIdlingResource
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
|
||||
import org.mozilla.fenix.helpers.TestHelper.getStringResource
|
||||
import org.mozilla.fenix.helpers.TestHelper.isPackageInstalled
|
||||
import org.mozilla.fenix.helpers.TestHelper.mDevice
|
||||
import org.mozilla.fenix.helpers.TestHelper.packageName
|
||||
@ -94,13 +95,98 @@ class SearchRobot {
|
||||
}
|
||||
|
||||
fun verifySearchEngineButton() = assertSearchButton()
|
||||
fun verifySearchWithText() = assertSearchWithText()
|
||||
fun verifySearchEngineResults(rule: ComposeTestRule, searchSuggestion: String, searchEngineName: String) =
|
||||
assertSearchEngineResults(rule, searchSuggestion, searchEngineName)
|
||||
fun verifySearchEngineSuggestionResults(rule: ComposeTestRule, searchSuggestion: String) =
|
||||
assertSearchEngineSuggestionResults(rule, searchSuggestion)
|
||||
fun verifyNoSuggestionsAreDisplayed(rule: ComposeTestRule, searchSuggestion: String) =
|
||||
assertNoSuggestionsAreDisplayed(rule, searchSuggestion)
|
||||
|
||||
fun verifySearchEngineResults(rule: ComposeTestRule, searchSuggestion: String, searchEngineName: String) {
|
||||
rule.waitUntil(waitingTime, waitForSearchSuggestions(rule, searchSuggestion, searchEngineName))
|
||||
rule.onNodeWithText(searchSuggestion).assertIsDisplayed()
|
||||
}
|
||||
|
||||
fun verifySearchEngineSuggestionResults(rule: ComposeTestRule, searchSuggestion: String) {
|
||||
rule.waitForIdle()
|
||||
for (i in 1..RETRY_COUNT) {
|
||||
try {
|
||||
assertTrue(
|
||||
mDevice.findObject(UiSelector().textContains(searchSuggestion))
|
||||
.waitForExists(waitingTime),
|
||||
)
|
||||
break
|
||||
} catch (e: AssertionError) {
|
||||
if (i == RETRY_COUNT) {
|
||||
throw e
|
||||
} else {
|
||||
expandSearchSuggestionsList()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun verifyFirefoxSuggestResults(rule: ComposeTestRule, searchSuggestion: String) {
|
||||
rule.waitForIdle()
|
||||
for (i in 1..RETRY_COUNT) {
|
||||
try {
|
||||
rule.onNodeWithTag("mozac.awesomebar.suggestions")
|
||||
.performScrollToNode(hasText(searchSuggestion))
|
||||
.assertExists()
|
||||
break
|
||||
} catch (e: AssertionError) {
|
||||
if (i == RETRY_COUNT) {
|
||||
throw e
|
||||
} else {
|
||||
expandSearchSuggestionsList()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun verifyNoSuggestionsAreDisplayed(rule: ComposeTestRule, searchSuggestion: String) {
|
||||
rule.waitForIdle()
|
||||
|
||||
assertFalse(
|
||||
mDevice.findObject(UiSelector().textContains(searchSuggestion))
|
||||
.waitForExists(waitingTime),
|
||||
)
|
||||
}
|
||||
|
||||
fun verifyAllowSuggestionsInPrivateModeDialog() {
|
||||
assertTrue(
|
||||
mDevice.findObject(
|
||||
UiSelector().text(getStringResource(R.string.search_suggestions_onboarding_title)),
|
||||
).waitForExists(waitingTime),
|
||||
)
|
||||
assertTrue(
|
||||
mDevice.findObject(
|
||||
UiSelector().text(getStringResource(R.string.search_suggestions_onboarding_text)),
|
||||
).exists(),
|
||||
)
|
||||
assertTrue(
|
||||
mDevice.findObject(
|
||||
UiSelector().text("Learn more"),
|
||||
).exists(),
|
||||
)
|
||||
assertTrue(
|
||||
mDevice.findObject(
|
||||
UiSelector().text(getStringResource(R.string.search_suggestions_onboarding_allow_button)),
|
||||
).exists(),
|
||||
)
|
||||
assertTrue(
|
||||
mDevice.findObject(
|
||||
UiSelector().text(getStringResource(R.string.search_suggestions_onboarding_do_not_allow_button)),
|
||||
).exists(),
|
||||
)
|
||||
}
|
||||
|
||||
fun denySuggestionsInPrivateMode() {
|
||||
mDevice.findObject(
|
||||
UiSelector().text(getStringResource(R.string.search_suggestions_onboarding_do_not_allow_button)),
|
||||
).click()
|
||||
}
|
||||
|
||||
fun allowSuggestionsInPrivateMode() {
|
||||
mDevice.findObject(
|
||||
UiSelector().text(getStringResource(R.string.search_suggestions_onboarding_allow_button)),
|
||||
).click()
|
||||
}
|
||||
|
||||
fun verifySearchSettings() = assertSearchSettings()
|
||||
fun verifySearchBarEmpty() = assertSearchBarEmpty()
|
||||
|
||||
@ -226,10 +312,24 @@ class SearchRobot {
|
||||
}
|
||||
|
||||
fun expandSearchSuggestionsList() {
|
||||
onView(allOf(withId(R.id.search_wrapper))).perform(
|
||||
closeSoftKeyboard(),
|
||||
)
|
||||
awesomeBar.swipeUp(2)
|
||||
}
|
||||
|
||||
fun verifyPastedToolbarText(expectedText: String) = assertPastedToolbarText(expectedText)
|
||||
fun verifyTypedToolbarText(expectedText: String) {
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar"))
|
||||
.waitForExists(waitingTime)
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_url_view"))
|
||||
.waitForExists(waitingTime)
|
||||
onView(
|
||||
allOf(
|
||||
withText(expectedText),
|
||||
withId(R.id.mozac_browser_toolbar_edit_url_view),
|
||||
),
|
||||
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
}
|
||||
|
||||
class Transition {
|
||||
private lateinit var sessionLoadedIdlingResource: SessionLoadedIdlingResource
|
||||
@ -300,11 +400,6 @@ private fun clearButton() =
|
||||
|
||||
private fun searchWrapper() = mDevice.findObject(UiSelector().resourceId("$packageName:id/search_wrapper"))
|
||||
|
||||
private fun assertSearchEngineResults(rule: ComposeTestRule, searchSuggestion: String, searchEngineName: String) {
|
||||
rule.waitUntil(waitingTime, waitForSearchSuggestions(rule, searchSuggestion, searchEngineName))
|
||||
rule.onNodeWithText(searchSuggestion).assertIsDisplayed()
|
||||
}
|
||||
|
||||
private fun waitForSearchSuggestions(rule: ComposeTestRule, searchSuggestion: String, searchEngineName: String): () -> Boolean =
|
||||
{
|
||||
rule.waitForIdle()
|
||||
@ -313,24 +408,6 @@ private fun waitForSearchSuggestions(rule: ComposeTestRule, searchSuggestion: St
|
||||
mDevice.findObject(UiSelector().textContains(searchSuggestion)).waitForExists(waitingTime)
|
||||
}
|
||||
|
||||
private fun assertSearchEngineSuggestionResults(rule: ComposeTestRule, searchResult: String) {
|
||||
rule.waitForIdle()
|
||||
|
||||
assertTrue(
|
||||
mDevice.findObject(UiSelector().textContains(searchResult))
|
||||
.waitForExists(waitingTime),
|
||||
)
|
||||
}
|
||||
|
||||
private fun assertNoSuggestionsAreDisplayed(rule: ComposeTestRule, searchTerm: String) {
|
||||
rule.waitForIdle()
|
||||
|
||||
assertFalse(
|
||||
mDevice.findObject(UiSelector().textContains(searchTerm))
|
||||
.waitForExists(waitingTime),
|
||||
)
|
||||
}
|
||||
|
||||
private fun assertSearchView() =
|
||||
assertTrue(
|
||||
mDevice.findObject(
|
||||
@ -462,25 +539,7 @@ private fun assertDefaultSearchEngine(expectedText: String) =
|
||||
).waitForExists(waitingTime),
|
||||
)
|
||||
|
||||
private fun assertPastedToolbarText(expectedText: String) {
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar"))
|
||||
.waitForExists(waitingTime)
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_url_view"))
|
||||
.waitForExists(waitingTime)
|
||||
onView(
|
||||
allOf(
|
||||
withSubstring(expectedText),
|
||||
withId(R.id.mozac_browser_toolbar_edit_url_view),
|
||||
),
|
||||
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
}
|
||||
|
||||
private val awesomeBar =
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_edit_url_view"))
|
||||
|
||||
private val voiceSearchButton = mDevice.findObject(UiSelector().description("Voice search"))
|
||||
|
||||
private val searchSuggestionsList =
|
||||
UiScrollable(
|
||||
UiSelector().className("android.widget.ScrollView"),
|
||||
)
|
||||
|
@ -15,6 +15,7 @@ import androidx.test.espresso.matcher.ViewMatchers
|
||||
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withChild
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withClassName
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
@ -24,12 +25,16 @@ import androidx.test.uiautomator.By
|
||||
import androidx.test.uiautomator.UiSelector
|
||||
import org.hamcrest.CoreMatchers
|
||||
import org.hamcrest.Matchers.allOf
|
||||
import org.hamcrest.Matchers.endsWith
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
|
||||
import org.mozilla.fenix.helpers.TestHelper.getStringResource
|
||||
import org.mozilla.fenix.helpers.TestHelper.hasCousin
|
||||
import org.mozilla.fenix.helpers.TestHelper.mDevice
|
||||
import org.mozilla.fenix.helpers.TestHelper.packageName
|
||||
import org.mozilla.fenix.helpers.click
|
||||
import org.mozilla.fenix.helpers.isChecked
|
||||
|
||||
/**
|
||||
* Implementation of Robot Pattern for the settings search sub menu.
|
||||
@ -38,18 +43,90 @@ class SettingsSubMenuSearchRobot {
|
||||
fun verifySearchToolbar() = assertSearchToolbar()
|
||||
fun verifyDefaultSearchEngineHeader() = assertDefaultSearchEngineHeader()
|
||||
fun verifySearchEngineList() = assertSearchEngineList()
|
||||
fun verifyShowSearchSuggestions() = assertShowSearchSuggestions()
|
||||
|
||||
fun verifyShowSearchSuggestions() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText("Show search suggestions")),
|
||||
),
|
||||
)
|
||||
onView(withText("Show search suggestions"))
|
||||
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
}
|
||||
|
||||
fun verifyShowSearchShortcuts() = assertShowSearchShortcuts()
|
||||
fun verifyShowClipboardSuggestions() = assertShowClipboardSuggestions()
|
||||
fun verifySearchBrowsingHistory() = assertSearchBrowsingHistory()
|
||||
fun verifySearchBookmarks() = assertSearchBookmarks()
|
||||
|
||||
fun verifyShowClipboardSuggestionsDefault() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText(getStringResource(R.string.preferences_show_clipboard_suggestions))),
|
||||
),
|
||||
)
|
||||
onView(withText(getStringResource(R.string.preferences_show_clipboard_suggestions)))
|
||||
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
.check(matches(hasCousin(allOf(withClassName(endsWith("Switch")), isChecked(true)))))
|
||||
}
|
||||
|
||||
fun toggleClipboardSuggestion() {
|
||||
onView(withText(getStringResource(R.string.preferences_show_clipboard_suggestions)))
|
||||
.click()
|
||||
}
|
||||
|
||||
fun verifySearchBrowsingHistory() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText("Search browsing history")),
|
||||
),
|
||||
)
|
||||
searchHistoryToggle
|
||||
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
}
|
||||
|
||||
fun verifySearchBookmarks() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText("Search bookmarks")),
|
||||
),
|
||||
)
|
||||
searchBookmarksToggle
|
||||
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
}
|
||||
|
||||
fun changeDefaultSearchEngine(searchEngineName: String) =
|
||||
selectSearchEngine(searchEngineName)
|
||||
|
||||
fun disableShowSearchSuggestions() = toggleShowSearchSuggestions()
|
||||
fun toggleAutocomplete() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText(getStringResource(R.string.preferences_enable_autocomplete_urls))),
|
||||
),
|
||||
)
|
||||
|
||||
fun enableShowSearchShortcuts() = toggleShowSearchShortcuts()
|
||||
onView(withText(getStringResource(R.string.preferences_enable_autocomplete_urls)))
|
||||
.click()
|
||||
}
|
||||
|
||||
fun toggleShowSearchSuggestions() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText("Show search suggestions")),
|
||||
),
|
||||
)
|
||||
|
||||
onView(withText("Show search suggestions"))
|
||||
.perform(click())
|
||||
}
|
||||
|
||||
fun toggleShowSearchShortcuts() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText("Show search engines")),
|
||||
),
|
||||
)
|
||||
|
||||
onView(withText("Show search engines"))
|
||||
.perform(click())
|
||||
}
|
||||
|
||||
fun toggleVoiceSearch() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
@ -78,6 +155,16 @@ class SettingsSubMenuSearchRobot {
|
||||
searchBookmarksToggle.click()
|
||||
}
|
||||
|
||||
fun toggleShowSuggestionsInPrivateSessions() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText(getStringResource(R.string.preferences_show_search_suggestions_in_private))),
|
||||
),
|
||||
)
|
||||
onView(withText(getStringResource(R.string.preferences_show_search_suggestions_in_private)))
|
||||
.click()
|
||||
}
|
||||
|
||||
fun openAddSearchEngineMenu() = addSearchEngineButton().click()
|
||||
|
||||
fun verifyAddSearchEngineList() = assertAddSearchEngineList()
|
||||
@ -215,16 +302,6 @@ private fun assertSearchEngineList() {
|
||||
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
}
|
||||
|
||||
private fun assertShowSearchSuggestions() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText("Show search suggestions")),
|
||||
),
|
||||
)
|
||||
onView(withText("Show search suggestions"))
|
||||
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
}
|
||||
|
||||
private fun assertShowSearchShortcuts() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
@ -235,38 +312,8 @@ private fun assertShowSearchShortcuts() {
|
||||
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
}
|
||||
|
||||
private fun assertShowClipboardSuggestions() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText("Show clipboard suggestions")),
|
||||
),
|
||||
)
|
||||
onView(withText("Show clipboard suggestions"))
|
||||
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
}
|
||||
|
||||
private fun assertSearchBrowsingHistory() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText("Search browsing history")),
|
||||
),
|
||||
)
|
||||
searchHistoryToggle
|
||||
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
}
|
||||
|
||||
private val searchHistoryToggle = onView(withText("Search browsing history"))
|
||||
|
||||
private fun assertSearchBookmarks() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText("Search bookmarks")),
|
||||
),
|
||||
)
|
||||
searchBookmarksToggle
|
||||
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
||||
}
|
||||
|
||||
private val searchBookmarksToggle = onView(withText("Search bookmarks"))
|
||||
|
||||
private fun selectSearchEngine(searchEngine: String) {
|
||||
@ -275,28 +322,6 @@ private fun selectSearchEngine(searchEngine: String) {
|
||||
.perform(click())
|
||||
}
|
||||
|
||||
private fun toggleShowSearchSuggestions() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText("Show search suggestions")),
|
||||
),
|
||||
)
|
||||
|
||||
onView(withText("Show search suggestions"))
|
||||
.perform(click())
|
||||
}
|
||||
|
||||
private fun toggleShowSearchShortcuts() {
|
||||
onView(withId(androidx.preference.R.id.recycler_view)).perform(
|
||||
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
|
||||
hasDescendant(withText("Show search engines")),
|
||||
),
|
||||
)
|
||||
|
||||
onView(withText("Show search engines"))
|
||||
.perform(click())
|
||||
}
|
||||
|
||||
private fun goBackButton() =
|
||||
onView(CoreMatchers.allOf(withContentDescription("Navigate up")))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user