pull/600/head
AndiAJ 2 years ago committed by mergify[bot]
parent 916200a3dd
commit 3ee2d3a7c6

@ -55,6 +55,74 @@ class SettingsHomepageTest {
featureSettingsHelper.resetAllFeatureFlags() featureSettingsHelper.resetAllFeatureFlags()
} }
@Test
fun verifyHomepageSettingsTest() {
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openHomepageSubMenu {
verifyHomePageView()
}
}
@Test
fun verifyShortcutOptionTest() {
// en-US defaults
val defaultTopSites = arrayOf(
"Top Articles",
"Wikipedia",
"Google",
)
homeScreen {
defaultTopSites.forEach { item ->
verifyExistingTopSitesTabs(item)
}
}.openThreeDotMenu {
}.openCustomizeHome {
clickShortcutsButton()
}.goBack {
defaultTopSites.forEach { item ->
verifyNotExistingTopSitesList(item)
}
}
}
@Test
fun verifyRecentlyVisitedOptionTest() {
featureSettingsHelper.setRecentTabsFeatureEnabled(false)
val genericURL = getGenericAsset(mockWebServer, 1)
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
}.goToHomescreen {
verifyRecentlyVisitedSectionIsDisplayed()
}.openThreeDotMenu {
}.openCustomizeHome {
clickRecentlyVisited()
}.goBack {
verifyRecentlyVisitedSectionIsNotDisplayed()
}
}
@Test
fun verifyPocketOptionTest() {
featureSettingsHelper.setRecentTabsFeatureEnabled(false)
featureSettingsHelper.setRecentlyVisitedFeatureEnabled(false)
val genericURL = getGenericAsset(mockWebServer, 1)
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
}.goToHomescreen {
verifyPocketSectionIsDisplayed()
}.openThreeDotMenu {
}.openCustomizeHome {
clickPocketButton()
}.goBack {
verifyPocketSectionIsNotDisplayed()
}
}
@SmokeTest @SmokeTest
@Test @Test
fun jumpBackInOptionTest() { fun jumpBackInOptionTest() {

@ -37,7 +37,6 @@ import mozilla.components.browser.state.state.searchEngines
import org.hamcrest.CoreMatchers.allOf import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.CoreMatchers.instanceOf import org.hamcrest.CoreMatchers.instanceOf
import org.hamcrest.CoreMatchers.not
import org.hamcrest.Matchers import org.hamcrest.Matchers
import org.junit.Assert import org.junit.Assert
import org.junit.Assert.assertFalse import org.junit.Assert.assertFalse
@ -56,7 +55,6 @@ import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText
import org.mozilla.fenix.helpers.click import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.helpers.ext.waitNotNull import org.mozilla.fenix.helpers.ext.waitNotNull
import org.mozilla.fenix.helpers.matchers.hasItem
import org.mozilla.fenix.helpers.withBitmapDrawable import org.mozilla.fenix.helpers.withBitmapDrawable
import org.mozilla.fenix.ui.util.STRING_ONBOARDING_ACCOUNT_SIGN_IN_HEADER import org.mozilla.fenix.ui.util.STRING_ONBOARDING_ACCOUNT_SIGN_IN_HEADER
import org.mozilla.fenix.ui.util.STRING_ONBOARDING_TOOLBAR_PLACEMENT_HEADER import org.mozilla.fenix.ui.util.STRING_ONBOARDING_TOOLBAR_PLACEMENT_HEADER
@ -145,8 +143,12 @@ class HomeScreenRobot {
fun verifyJumpBackInSectionIsDisplayed() = assertJumpBackInSectionIsDisplayed() fun verifyJumpBackInSectionIsDisplayed() = assertJumpBackInSectionIsDisplayed()
fun verifyJumpBackInSectionIsNotDisplayed() = assertJumpBackInSectionIsNotDisplayed() fun verifyJumpBackInSectionIsNotDisplayed() = assertJumpBackInSectionIsNotDisplayed()
fun verifyRecentlyVisitedSectionIsDisplayed() = assertRecentlyVisitedSectionIsDisplayed()
fun verifyRecentlyVisitedSectionIsNotDisplayed() = assertRecentlyVisitedSectionIsNotDisplayed()
fun verifyRecentBookmarksSectionIsDisplayed() = assertRecentBookmarksSectionIsDisplayed() fun verifyRecentBookmarksSectionIsDisplayed() = assertRecentBookmarksSectionIsDisplayed()
fun verifyRecentBookmarksSectionIsNotDisplayed() = assertRecentBookmarksSectionIsNotDisplayed() fun verifyRecentBookmarksSectionIsNotDisplayed() = assertRecentBookmarksSectionIsNotDisplayed()
fun verifyPocketSectionIsDisplayed() = assertPocketSectionIsDisplayed()
fun verifyPocketSectionIsNotDisplayed() = assertPocketSectionIsNotDisplayed()
fun verifyRecentlyVisitedSearchGroupDisplayed(shouldBeDisplayed: Boolean, searchTerm: String, groupSize: Int) { fun verifyRecentlyVisitedSearchGroupDisplayed(shouldBeDisplayed: Boolean, searchTerm: String, groupSize: Int) {
// checks if the search group exists in the Recently visited section // checks if the search group exists in the Recently visited section
@ -820,11 +822,15 @@ private fun assertSponsoredShortcutTitle(sponsoredShortcutTitle: String, positio
} }
private fun assertNotExistingTopSitesList(title: String) { private fun assertNotExistingTopSitesList(title: String) {
mDevice.findObject(UiSelector().text(title)) mDevice.findObject(UiSelector().text(title)).waitUntilGone(waitingTime)
.waitUntilGone(waitingTime)
onView(allOf(withId(R.id.top_sites_list))) assertFalse(
.check(matches(not(hasItem(hasDescendant(withText(title)))))) mDevice.findObject(
UiSelector()
.resourceId("$packageName:id/top_site_title")
.textContains(title),
).waitForExists(waitingTime),
)
} }
private fun assertSponsoredTopSitesNotDisplayed() { private fun assertSponsoredTopSitesNotDisplayed() {
@ -852,12 +858,20 @@ private fun assertJumpBackInSectionIsDisplayed() = assertTrue(jumpBackInSection(
private fun assertJumpBackInSectionIsNotDisplayed() = assertFalse(jumpBackInSection().waitForExists(waitingTimeShort)) private fun assertJumpBackInSectionIsNotDisplayed() = assertFalse(jumpBackInSection().waitForExists(waitingTimeShort))
private fun assertRecentlyVisitedSectionIsDisplayed() = assertTrue(recentlyVisitedSection().waitForExists(waitingTime))
private fun assertRecentlyVisitedSectionIsNotDisplayed() = assertFalse(recentlyVisitedSection().waitForExists(waitingTime))
private fun assertRecentBookmarksSectionIsDisplayed() = private fun assertRecentBookmarksSectionIsDisplayed() =
assertTrue(recentBookmarksSection().waitForExists(waitingTime)) assertTrue(recentBookmarksSection().waitForExists(waitingTime))
private fun assertRecentBookmarksSectionIsNotDisplayed() = private fun assertRecentBookmarksSectionIsNotDisplayed() =
assertFalse(recentBookmarksSection().waitForExists(waitingTimeShort)) assertFalse(recentBookmarksSection().waitForExists(waitingTimeShort))
private fun assertPocketSectionIsDisplayed() = assertTrue(pocketSection().waitForExists(waitingTime))
private fun assertPocketSectionIsNotDisplayed() = assertFalse(pocketSection().waitForExists(waitingTime))
private fun privateBrowsingButton() = onView(withId(R.id.privateBrowsingButton)) private fun privateBrowsingButton() = onView(withId(R.id.privateBrowsingButton))
private fun saveTabsToCollectionButton() = onView(withId(R.id.add_tabs_to_collections_button)) private fun saveTabsToCollectionButton() = onView(withId(R.id.add_tabs_to_collections_button))
@ -867,9 +881,15 @@ private fun tabsCounter() = onView(withId(R.id.tab_button))
private fun jumpBackInSection() = private fun jumpBackInSection() =
mDevice.findObject(UiSelector().textContains(getStringResource(R.string.recent_tabs_header))) mDevice.findObject(UiSelector().textContains(getStringResource(R.string.recent_tabs_header)))
private fun recentlyVisitedSection() =
mDevice.findObject(UiSelector().textContains(getStringResource(R.string.history_metadata_header_2)))
private fun recentBookmarksSection() = private fun recentBookmarksSection() =
mDevice.findObject(UiSelector().textContains(getStringResource(R.string.recently_saved_title))) mDevice.findObject(UiSelector().textContains(getStringResource(R.string.recently_saved_title)))
private fun pocketSection() =
mDevice.findObject(UiSelector().textContains(getStringResource(R.string.pocket_stories_header_1)))
private fun startBrowsingButton(): UiObject { private fun startBrowsingButton(): UiObject {
val startBrowsingButton = mDevice.findObject(UiSelector().resourceId("$packageName:id/finish_button")) val startBrowsingButton = mDevice.findObject(UiSelector().resourceId("$packageName:id/finish_button"))
homeScreenList() homeScreenList()

@ -6,22 +6,24 @@ package org.mozilla.fenix.ui.robots
import androidx.test.espresso.Espresso.onView import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.Visibility import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.hasSibling import androidx.test.espresso.matcher.ViewMatchers.hasSibling
import androidx.test.espresso.matcher.ViewMatchers.isChecked import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.isNotChecked import androidx.test.espresso.matcher.ViewMatchers.isNotChecked
import androidx.test.espresso.matcher.ViewMatchers.withChild
import androidx.test.espresso.matcher.ViewMatchers.withClassName import androidx.test.espresso.matcher.ViewMatchers.withClassName
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.UiSelector import androidx.test.uiautomator.UiSelector
import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.allOf import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.endsWith import org.hamcrest.Matchers
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestHelper.mDevice import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.click import org.mozilla.fenix.helpers.click
@ -30,25 +32,46 @@ import org.mozilla.fenix.helpers.click
*/ */
class SettingsSubMenuHomepageRobot { class SettingsSubMenuHomepageRobot {
fun verifyHomePageView() { fun verifyHomePageView(
assertMostVisitedTopSitesButton() shortcutsSwitchEnabled: Boolean = true,
sponsoredShortcutsCheckBox: Boolean = true,
jumpBackInSwitchEnabled: Boolean = true,
recentBookmarksSwitchEnabled: Boolean = true,
recentlyVisitedSwitchEnabled: Boolean = true,
pocketSwitchEnabled: Boolean = true,
sponsoredStoriesCheckBox: Boolean = true,
) {
assertShortcutsButton()
assertShortcutsSwitchState(shortcutsSwitchEnabled)
assertSponsoredShortcutsButton()
assertSponsoredShortcutsCheckBox(sponsoredShortcutsCheckBox)
assertJumpBackInButton() assertJumpBackInButton()
assertJumpBackInSwitchState(jumpBackInSwitchEnabled)
assertRecentBookmarksButton() assertRecentBookmarksButton()
assertRecentSearchesButton() assertRecentBookmarksSwitchState(recentBookmarksSwitchEnabled)
assertRecentlyVisitedButton()
assertRecentlyVisitedSwitchState(recentlyVisitedSwitchEnabled)
assertPocketButton() assertPocketButton()
assertPocketSwitchState(pocketSwitchEnabled)
assertSponsoredStoriesButton()
assertSponsoredStoriesCheckBox(sponsoredStoriesCheckBox)
assertOpeningScreenHeading() assertOpeningScreenHeading()
assertHomepageButton() assertHomepageButton()
assertLastTabButton() assertLastTabButton()
assertHomepageAfterFourHoursButton() assertHomepageAfterFourHoursButton()
} }
fun clickSponsoredShortcuts() = sponsoredShortcuts().click() fun clickShortcutsButton() = shortcutsButton().click()
fun clickSponsoredShortcuts() = sponsoredShortcutsButton().click()
fun clickJumpBackInButton() = jumpBackInButton().click() fun clickJumpBackInButton() = jumpBackInButton().click()
fun clickRecentlyVisited() = recentlyVisitedButton().click()
fun clickRecentBookmarksButton() = recentBookmarksButton().click() fun clickRecentBookmarksButton() = recentBookmarksButton().click()
fun clickRecentSearchesButton() = recentSearchesButton().click() fun clickRecentSearchesButton() = recentlyVisitedButton().click()
fun clickPocketButton() = pocketButton().click() fun clickPocketButton() = pocketButton().click()
@ -69,37 +92,7 @@ class SettingsSubMenuHomepageRobot {
).waitForExists(waitingTimeShort), ).waitForExists(waitingTimeShort),
) )
fun verifySponsoredShortcutsCheckBox(checked: Boolean) { fun verifySponsoredShortcutsCheckBox(checked: Boolean) = assertSponsoredShortcutsCheckBox(checked)
if (checked) {
sponsoredShortcuts()
.check(
matches(
hasSibling(
withChild(
allOf(
withClassName(endsWith("CheckBox")),
isChecked(),
),
),
),
),
)
} else {
sponsoredShortcuts()
.check(
matches(
hasSibling(
withChild(
allOf(
withClassName(endsWith("CheckBox")),
isNotChecked(),
),
),
),
),
)
}
}
class Transition { class Transition {
@ -121,10 +114,10 @@ class SettingsSubMenuHomepageRobot {
} }
} }
private fun mostVisitedTopSitesButton() = private fun shortcutsButton() =
onView(allOf(withText(R.string.top_sites_toggle_top_recent_sites_4))) onView(allOf(withText(R.string.top_sites_toggle_top_recent_sites_4)))
private fun sponsoredShortcuts() = private fun sponsoredShortcutsButton() =
onView(allOf(withText(R.string.customize_toggle_contile))) onView(allOf(withText(R.string.customize_toggle_contile)))
private fun jumpBackInButton() = private fun jumpBackInButton() =
@ -133,12 +126,15 @@ private fun jumpBackInButton() =
private fun recentBookmarksButton() = private fun recentBookmarksButton() =
onView(allOf(withText(R.string.customize_toggle_recent_bookmarks))) onView(allOf(withText(R.string.customize_toggle_recent_bookmarks)))
private fun recentSearchesButton() = private fun recentlyVisitedButton() =
onView(allOf(withText(R.string.customize_toggle_recently_visited))) onView(allOf(withText(R.string.customize_toggle_recently_visited)))
private fun pocketButton() = private fun pocketButton() =
onView(allOf(withText(R.string.customize_toggle_pocket))) onView(allOf(withText(R.string.customize_toggle_pocket)))
private fun sponsoredStoriesButton() =
onView(allOf(withText(R.string.customize_toggle_pocket_sponsored)))
private fun openingScreenHeading() = onView(withText(R.string.preferences_opening_screen)) private fun openingScreenHeading() = onView(withText(R.string.preferences_opening_screen))
private fun homepageButton() = private fun homepageButton() =
@ -170,16 +166,20 @@ private fun homepageAfterFourHoursButton() =
private fun goBackButton() = onView(allOf(withContentDescription(R.string.action_bar_up_description))) private fun goBackButton() = onView(allOf(withContentDescription(R.string.action_bar_up_description)))
private fun assertMostVisitedTopSitesButton() = private fun assertShortcutsButton() =
mostVisitedTopSitesButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) shortcutsButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertSponsoredShortcutsButton() =
sponsoredShortcutsButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertJumpBackInButton() = private fun assertJumpBackInButton() =
jumpBackInButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) jumpBackInButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertRecentBookmarksButton() = private fun assertRecentBookmarksButton() =
recentBookmarksButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) recentBookmarksButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertRecentSearchesButton() = private fun assertRecentlyVisitedButton() =
recentSearchesButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) recentlyVisitedButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertPocketButton() = private fun assertPocketButton() =
pocketButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) pocketButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertSponsoredStoriesButton() =
sponsoredStoriesButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertOpeningScreenHeading() = private fun assertOpeningScreenHeading() =
openingScreenHeading().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) openingScreenHeading().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertHomepageButton() = private fun assertHomepageButton() =
@ -189,4 +189,208 @@ private fun assertLastTabButton() =
private fun assertHomepageAfterFourHoursButton() = private fun assertHomepageAfterFourHoursButton() =
homepageAfterFourHoursButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE))) homepageAfterFourHoursButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
fun assertShortcutsSwitchState(enabled: Boolean) {
if (enabled) {
shortcutsButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isChecked(),
),
),
),
)
} else {
shortcutsButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isNotChecked(),
),
),
),
)
}
}
fun assertSponsoredShortcutsCheckBox(checked: Boolean) {
if (checked) {
sponsoredShortcutsButton()
.check(
matches(
hasSibling(
ViewMatchers.withChild(
allOf(
withClassName(CoreMatchers.endsWith("CheckBox")),
isChecked(),
),
),
),
),
)
} else {
sponsoredShortcutsButton()
.check(
matches(
hasSibling(
ViewMatchers.withChild(
allOf(
withClassName(CoreMatchers.endsWith("CheckBox")),
isNotChecked(),
),
),
),
),
)
}
}
fun assertJumpBackInSwitchState(enabled: Boolean) {
if (enabled) {
jumpBackInButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isChecked(),
),
),
),
)
} else {
jumpBackInButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isNotChecked(),
),
),
),
)
}
}
fun assertRecentBookmarksSwitchState(enabled: Boolean) {
if (enabled) {
recentBookmarksButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isChecked(),
),
),
),
)
} else {
recentBookmarksButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isNotChecked(),
),
),
),
)
}
}
fun assertRecentlyVisitedSwitchState(enabled: Boolean) {
if (enabled) {
recentlyVisitedButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isChecked(),
),
),
),
)
} else {
recentlyVisitedButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isNotChecked(),
),
),
),
)
}
}
fun assertPocketSwitchState(enabled: Boolean) {
if (enabled) {
pocketButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isChecked(),
),
),
),
)
} else {
pocketButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isNotChecked(),
),
),
),
)
}
}
fun assertSponsoredStoriesCheckBox(checked: Boolean) {
if (checked) {
sponsoredStoriesButton()
.check(
matches(
hasSibling(
ViewMatchers.withChild(
allOf(
withClassName(CoreMatchers.endsWith("CheckBox")),
isChecked(),
),
),
),
),
)
} else {
sponsoredStoriesButton()
.check(
matches(
hasSibling(
ViewMatchers.withChild(
allOf(
withClassName(CoreMatchers.endsWith("CheckBox")),
isNotChecked(),
),
),
),
),
)
}
}
private val wallpapersMenuButton = onView(withText("Wallpapers")) private val wallpapersMenuButton = onView(withText("Wallpapers"))

Loading…
Cancel
Save