parent
ef4366af31
commit
e717d79abd
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,85 @@
|
||||
/* 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.helpers
|
||||
|
||||
import androidx.test.uiautomator.UiObject
|
||||
import androidx.test.uiautomator.UiSelector
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
|
||||
import org.mozilla.fenix.helpers.TestHelper.mDevice
|
||||
|
||||
/**
|
||||
* Helper for querying and interacting with items based on their matchers.
|
||||
*/
|
||||
object MatcherHelper {
|
||||
|
||||
fun itemWithResId(resourceId: String) =
|
||||
mDevice.findObject(UiSelector().resourceId(resourceId))
|
||||
|
||||
fun itemContainingText(itemText: String) =
|
||||
mDevice.findObject(UiSelector().textContains(itemText))
|
||||
|
||||
fun itemWithDescription(description: String) =
|
||||
mDevice.findObject(UiSelector().descriptionContains(description))
|
||||
|
||||
fun checkedItemWithResId(resourceId: String, isChecked: Boolean) =
|
||||
mDevice.findObject(UiSelector().resourceId(resourceId).checked(isChecked))
|
||||
|
||||
fun checkedItemWithResIdAndText(resourceId: String, text: String, isChecked: Boolean) =
|
||||
mDevice.findObject(
|
||||
UiSelector()
|
||||
.resourceId(resourceId)
|
||||
.textContains(text)
|
||||
.checked(isChecked),
|
||||
)
|
||||
|
||||
fun itemWithResIdAndDescription(resourceId: String, description: String) =
|
||||
mDevice.findObject(UiSelector().resourceId(resourceId).descriptionContains(description))
|
||||
|
||||
fun itemWithResIdAndText(resourceId: String, text: String) =
|
||||
mDevice.findObject(UiSelector().resourceId(resourceId).text(text))
|
||||
|
||||
fun assertItemWithResIdExists(vararg appItems: UiObject) {
|
||||
for (appItem in appItems) {
|
||||
assertTrue(appItem.waitForExists(waitingTime))
|
||||
}
|
||||
}
|
||||
|
||||
fun assertItemContainingTextExists(vararg appItems: UiObject) {
|
||||
for (appItem in appItems) {
|
||||
assertTrue(appItem.waitForExists(waitingTime))
|
||||
}
|
||||
}
|
||||
|
||||
fun assertItemWithDescriptionExists(vararg appItems: UiObject) {
|
||||
for (appItem in appItems) {
|
||||
assertTrue(appItem.waitForExists(waitingTime))
|
||||
}
|
||||
}
|
||||
|
||||
fun assertCheckedItemWithResIdExists(vararg appItems: UiObject) {
|
||||
for (appItem in appItems) {
|
||||
assertTrue(appItem.waitForExists(waitingTime))
|
||||
}
|
||||
}
|
||||
|
||||
fun assertCheckedItemWithResIdAndTextExists(vararg appItems: UiObject) {
|
||||
for (appItem in appItems) {
|
||||
assertTrue(appItem.waitForExists(waitingTime))
|
||||
}
|
||||
}
|
||||
|
||||
fun assertItemWithResIdAndDescriptionExists(vararg appItems: UiObject) {
|
||||
for (appItem in appItems) {
|
||||
assertTrue(appItem.waitForExists(waitingTime))
|
||||
}
|
||||
}
|
||||
|
||||
fun assertItemWithResIdAndTextExists(vararg appItems: UiObject) {
|
||||
for (appItem in appItems) {
|
||||
assertTrue(appItem.waitForExists(waitingTime))
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,223 @@
|
||||
package org.mozilla.fenix.ui
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import okhttp3.mockwebserver.MockWebServer
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.customannotations.SmokeTest
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
import org.mozilla.fenix.helpers.TestHelper.verifyDarkThemeApplied
|
||||
import org.mozilla.fenix.helpers.TestHelper.verifyLightThemeApplied
|
||||
import org.mozilla.fenix.ui.robots.homeScreen
|
||||
import org.mozilla.fenix.ui.robots.navigationToolbar
|
||||
|
||||
class OnboardingTest {
|
||||
private lateinit var mDevice: UiDevice
|
||||
private lateinit var mockWebServer: MockWebServer
|
||||
private val privacyNoticeLink = "mozilla.org/en-US/privacy/firefox"
|
||||
|
||||
@get:Rule
|
||||
val activityTestRule = HomeActivityTestRule.withDefaultSettingsOverrides()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
mockWebServer = MockWebServer().apply {
|
||||
dispatcher = AndroidAssetDispatcher()
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
mockWebServer.shutdown()
|
||||
}
|
||||
|
||||
private fun getUITheme(): Boolean {
|
||||
val mode =
|
||||
activityTestRule.activity.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)
|
||||
|
||||
return when (mode) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> true // dark theme is set
|
||||
Configuration.UI_MODE_NIGHT_NO -> false // dark theme is not set, using light theme
|
||||
else -> false // default option is light theme
|
||||
}
|
||||
}
|
||||
|
||||
// Verifies the first run onboarding screen
|
||||
@SmokeTest
|
||||
@Test
|
||||
fun firstRunScreenTest() {
|
||||
homeScreen {
|
||||
verifyHomeScreenAppBarItems()
|
||||
verifyHomeScreenWelcomeItems()
|
||||
verifyChooseYourThemeCard(
|
||||
isDarkThemeChecked = false,
|
||||
isLightThemeChecked = false,
|
||||
isAutomaticThemeChecked = true,
|
||||
)
|
||||
verifyToolbarPlacementCard(isBottomChecked = true, isTopChecked = false)
|
||||
verifySignInToSyncCard()
|
||||
verifyPrivacyProtectionCard(isStandardChecked = true, isStrictChecked = false)
|
||||
verifyPrivacyNoticeCard()
|
||||
verifyStartBrowsingSection()
|
||||
verifyNavigationToolbarItems("0")
|
||||
}
|
||||
}
|
||||
|
||||
// Verifies the functionality of the onboarding Start Browsing button
|
||||
@SmokeTest
|
||||
@Test
|
||||
fun startBrowsingButtonTest() {
|
||||
homeScreen {
|
||||
verifyStartBrowsingButton()
|
||||
}.clickStartBrowsingButton {
|
||||
verifySearchView()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dismissOnboardingUsingSettingsTest() {
|
||||
homeScreen {
|
||||
verifyWelcomeHeader()
|
||||
}.openThreeDotMenu {
|
||||
}.openSettings {
|
||||
verifyGeneralHeading()
|
||||
}.goBack {
|
||||
verifyExistingTopSitesList()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dismissOnboardingUsingBookmarksTest() {
|
||||
homeScreen {
|
||||
verifyWelcomeHeader()
|
||||
}.openThreeDotMenu {
|
||||
}.openBookmarks {
|
||||
verifyBookmarksMenuView()
|
||||
navigateUp()
|
||||
}
|
||||
homeScreen {
|
||||
verifyExistingTopSitesList()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dismissOnboardingUsingHelpTest() {
|
||||
homeScreen {
|
||||
verifyWelcomeHeader()
|
||||
}.openThreeDotMenu {
|
||||
}.openHelp {
|
||||
verifyHelpUrl()
|
||||
}.goBack {
|
||||
verifyExistingTopSitesList()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun toolbarTapDoesntDismissOnboardingTest() {
|
||||
homeScreen {
|
||||
verifyWelcomeHeader()
|
||||
}.openSearch {
|
||||
verifyScanButton()
|
||||
verifySearchEngineButton()
|
||||
verifyKeyboardVisibility()
|
||||
}.dismissSearchBar {
|
||||
verifyWelcomeHeader()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dismissOnboardingWithPageLoadTest() {
|
||||
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
|
||||
|
||||
homeScreen {
|
||||
verifyWelcomeHeader()
|
||||
}
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
|
||||
}.goToHomescreen {
|
||||
verifyExistingTopSitesList()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun chooseYourThemeCardTest() {
|
||||
homeScreen {
|
||||
verifyChooseYourThemeCard(
|
||||
isDarkThemeChecked = false,
|
||||
isLightThemeChecked = false,
|
||||
isAutomaticThemeChecked = true,
|
||||
)
|
||||
clickLightThemeButton()
|
||||
verifyChooseYourThemeCard(
|
||||
isDarkThemeChecked = false,
|
||||
isLightThemeChecked = true,
|
||||
isAutomaticThemeChecked = false,
|
||||
)
|
||||
verifyLightThemeApplied(getUITheme())
|
||||
clickDarkThemeButton()
|
||||
verifyChooseYourThemeCard(
|
||||
isDarkThemeChecked = true,
|
||||
isLightThemeChecked = false,
|
||||
isAutomaticThemeChecked = false,
|
||||
)
|
||||
verifyDarkThemeApplied(getUITheme())
|
||||
clickAutomaticThemeButton()
|
||||
verifyChooseYourThemeCard(
|
||||
isDarkThemeChecked = false,
|
||||
isLightThemeChecked = false,
|
||||
isAutomaticThemeChecked = true,
|
||||
)
|
||||
verifyLightThemeApplied(getUITheme())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun pickYourToolbarPlacementCardTest() {
|
||||
homeScreen {
|
||||
verifyToolbarPlacementCard(isBottomChecked = true, isTopChecked = false)
|
||||
clickTopToolbarPlacementButton()
|
||||
verifyToolbarPosition(defaultPosition = false)
|
||||
clickBottomToolbarPlacementButton()
|
||||
verifyToolbarPosition(defaultPosition = true)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun privacyProtectionByDefaultCardTest() {
|
||||
homeScreen {
|
||||
verifyPrivacyProtectionCard(isStandardChecked = true, isStrictChecked = false)
|
||||
clickStrictTrackingProtectionButton()
|
||||
verifyPrivacyProtectionCard(isStandardChecked = false, isStrictChecked = true)
|
||||
clickStandardTrackingProtectionButton()
|
||||
verifyPrivacyProtectionCard(isStandardChecked = true, isStrictChecked = false)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun pickUpWhereYouLeftOffCardTest() {
|
||||
homeScreen {
|
||||
verifySignInToSyncCard()
|
||||
}.clickSignInButton {
|
||||
verifyTurnOnSyncMenu()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun youControlYourDataCardTest() {
|
||||
homeScreen {
|
||||
verifyPrivacyNoticeCard()
|
||||
}.clickPrivacyNoticeButton {
|
||||
verifyUrl(privacyNoticeLink)
|
||||
}.goBack {
|
||||
verifyPrivacyNoticeCard()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,252 @@
|
||||
/* 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
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
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.customannotations.SmokeTest
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.Constants.defaultTopSitesList
|
||||
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
import org.mozilla.fenix.helpers.TestHelper
|
||||
import org.mozilla.fenix.helpers.TestHelper.exitMenu
|
||||
import org.mozilla.fenix.helpers.TestHelper.getSponsoredShortcutTitle
|
||||
import org.mozilla.fenix.ui.robots.homeScreen
|
||||
|
||||
/**
|
||||
* Tests Sponsored shortcuts functionality
|
||||
*/
|
||||
|
||||
class SponsoredShortcutsTest {
|
||||
private lateinit var mDevice: UiDevice
|
||||
private lateinit var mockWebServer: MockWebServer
|
||||
private val defaultSearchEngine = "Amazon.com"
|
||||
private lateinit var sponsoredShortcutTitle: String
|
||||
private lateinit var sponsoredShortcutTitle2: String
|
||||
|
||||
@get:Rule
|
||||
val activityIntentTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides(skipOnboarding = true)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
TestHelper.appContext.settings().userOptOutOfReEngageCookieBannerDialog = true
|
||||
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
mockWebServer = MockWebServer().apply {
|
||||
dispatcher = AndroidAssetDispatcher()
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
mockWebServer.shutdown()
|
||||
}
|
||||
|
||||
// Expected for en-us defaults
|
||||
@SmokeTest
|
||||
@Test
|
||||
fun verifySponsoredShortcutsListTest() {
|
||||
homeScreen {
|
||||
defaultTopSitesList.values.forEach { value ->
|
||||
verifyExistingTopSitesTabs(value)
|
||||
}
|
||||
}.openThreeDotMenu {
|
||||
}.openCustomizeHome {
|
||||
verifySponsoredShortcutsCheckBox(true)
|
||||
clickSponsoredShortcuts()
|
||||
verifySponsoredShortcutsCheckBox(false)
|
||||
}.goBack {
|
||||
verifyNotExistingSponsoredTopSitesList()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openSponsoredShortcutTest() {
|
||||
homeScreen {
|
||||
sponsoredShortcutTitle = getSponsoredShortcutTitle(2)
|
||||
}.openSponsoredShortcut(sponsoredShortcutTitle) {
|
||||
verifyUrl(sponsoredShortcutTitle)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openSponsoredShortcutInPrivateBrowsingTest() {
|
||||
homeScreen {
|
||||
sponsoredShortcutTitle = getSponsoredShortcutTitle(2)
|
||||
}.openContextMenuOnSponsoredShortcut(sponsoredShortcutTitle) {
|
||||
}.openTopSiteInPrivateTab {
|
||||
verifyUrl(sponsoredShortcutTitle)
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("Failing, see: https://github.com/mozilla-mobile/fenix/issues/25926")
|
||||
@Test
|
||||
fun verifySponsorsAndPrivacyLinkTest() {
|
||||
homeScreen {
|
||||
sponsoredShortcutTitle = getSponsoredShortcutTitle(2)
|
||||
}.openContextMenuOnSponsoredShortcut(sponsoredShortcutTitle) {
|
||||
}.clickSponsorsAndPrivacyButton {
|
||||
verifyUrl("support.mozilla.org/en-US/kb/sponsor-privacy")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun verifySponsoredShortcutsSettingsOptionTest() {
|
||||
homeScreen {
|
||||
sponsoredShortcutTitle = getSponsoredShortcutTitle(2)
|
||||
}.openContextMenuOnSponsoredShortcut(sponsoredShortcutTitle) {
|
||||
}.clickSponsoredShortcutsSettingsButton {
|
||||
verifyHomePageView()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun verifySponsoredShortcutsDetailsTest() {
|
||||
homeScreen {
|
||||
sponsoredShortcutTitle = getSponsoredShortcutTitle(2)
|
||||
sponsoredShortcutTitle2 = getSponsoredShortcutTitle(3)
|
||||
|
||||
verifySponsoredShortcutDetails(sponsoredShortcutTitle, 2)
|
||||
verifySponsoredShortcutDetails(sponsoredShortcutTitle2, 3)
|
||||
}
|
||||
}
|
||||
|
||||
// The default search engine should not be displayed as a sponsored shortcut
|
||||
@Test
|
||||
fun defaultSearchEngineIsNotDisplayedAsSponsoredShortcutTest() {
|
||||
val sponsoredShortcutTitle = "Amazon"
|
||||
|
||||
homeScreen {
|
||||
}.openThreeDotMenu {
|
||||
}.openSettings {
|
||||
}.openSearchSubMenu {
|
||||
changeDefaultSearchEngine(defaultSearchEngine)
|
||||
}
|
||||
|
||||
exitMenu()
|
||||
|
||||
homeScreen {
|
||||
verifySponsoredShortcutDoesNotExist(sponsoredShortcutTitle, 2)
|
||||
verifySponsoredShortcutDoesNotExist(sponsoredShortcutTitle, 3)
|
||||
}
|
||||
}
|
||||
|
||||
// 1 sponsored shortcut should be displayed if there are 7 pinned top sites
|
||||
@Test
|
||||
fun verifySponsoredShortcutsListWithSevenPinnedSitesTest() {
|
||||
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
|
||||
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
|
||||
val thirdWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 3)
|
||||
val fourthWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 4)
|
||||
|
||||
homeScreen {
|
||||
sponsoredShortcutTitle = getSponsoredShortcutTitle(2)
|
||||
sponsoredShortcutTitle2 = getSponsoredShortcutTitle(3)
|
||||
|
||||
verifySponsoredShortcutDetails(sponsoredShortcutTitle, 2)
|
||||
verifySponsoredShortcutDetails(sponsoredShortcutTitle2, 3)
|
||||
}.openNavigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(firstWebPage.url) {
|
||||
verifyPageContent(firstWebPage.content)
|
||||
}.openThreeDotMenu {
|
||||
expandMenu()
|
||||
}.addToFirefoxHome {
|
||||
}.goToHomescreen {
|
||||
verifyExistingTopSitesTabs(firstWebPage.title)
|
||||
}.openNavigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(secondWebPage.url) {
|
||||
verifyPageContent(secondWebPage.content)
|
||||
}.openThreeDotMenu {
|
||||
expandMenu()
|
||||
}.addToFirefoxHome {
|
||||
}.goToHomescreen {
|
||||
verifyExistingTopSitesTabs(secondWebPage.title)
|
||||
}.openNavigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(thirdWebPage.url) {
|
||||
verifyPageContent(thirdWebPage.content)
|
||||
}.openThreeDotMenu {
|
||||
expandMenu()
|
||||
}.addToFirefoxHome {
|
||||
}.goToHomescreen {
|
||||
verifyExistingTopSitesTabs(thirdWebPage.title)
|
||||
}.openNavigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(fourthWebPage.url) {
|
||||
verifyPageContent(fourthWebPage.content)
|
||||
}.openThreeDotMenu {
|
||||
expandMenu()
|
||||
}.addToFirefoxHome {
|
||||
}.goToHomescreen {
|
||||
verifySponsoredShortcutDetails(sponsoredShortcutTitle, 2)
|
||||
verifySponsoredShortcutDoesNotExist(sponsoredShortcutTitle2, 3)
|
||||
}
|
||||
}
|
||||
|
||||
// No sponsored shortcuts should be displayed if there are 8 pinned top sites
|
||||
@Test
|
||||
fun verifySponsoredShortcutsListWithEightPinnedSitesTest() {
|
||||
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
|
||||
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
|
||||
val thirdWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 3)
|
||||
val fourthWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 4)
|
||||
val fifthWebPage = TestAssetHelper.getLoremIpsumAsset(mockWebServer)
|
||||
|
||||
homeScreen {
|
||||
sponsoredShortcutTitle = getSponsoredShortcutTitle(2)
|
||||
sponsoredShortcutTitle2 = getSponsoredShortcutTitle(3)
|
||||
|
||||
verifySponsoredShortcutDetails(sponsoredShortcutTitle, 2)
|
||||
verifySponsoredShortcutDetails(sponsoredShortcutTitle2, 3)
|
||||
}.openNavigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(firstWebPage.url) {
|
||||
verifyPageContent(firstWebPage.content)
|
||||
}.openThreeDotMenu {
|
||||
expandMenu()
|
||||
}.addToFirefoxHome {
|
||||
}.goToHomescreen {
|
||||
verifyExistingTopSitesTabs(firstWebPage.title)
|
||||
}.openNavigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(secondWebPage.url) {
|
||||
verifyPageContent(secondWebPage.content)
|
||||
}.openThreeDotMenu {
|
||||
expandMenu()
|
||||
}.addToFirefoxHome {
|
||||
}.goToHomescreen {
|
||||
verifyExistingTopSitesTabs(secondWebPage.title)
|
||||
}.openNavigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(thirdWebPage.url) {
|
||||
verifyPageContent(thirdWebPage.content)
|
||||
}.openThreeDotMenu {
|
||||
expandMenu()
|
||||
}.addToFirefoxHome {
|
||||
}.goToHomescreen {
|
||||
verifyExistingTopSitesTabs(thirdWebPage.title)
|
||||
}.openNavigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(fourthWebPage.url) {
|
||||
verifyPageContent(fourthWebPage.content)
|
||||
}.openThreeDotMenu {
|
||||
expandMenu()
|
||||
}.addToFirefoxHome {
|
||||
}.goToHomescreen {
|
||||
verifyExistingTopSitesTabs(fourthWebPage.title)
|
||||
}.openNavigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(fifthWebPage.url) {
|
||||
verifyPageContent(fifthWebPage.content)
|
||||
}.openThreeDotMenu {
|
||||
expandMenu()
|
||||
}.addToFirefoxHome {
|
||||
}.goToHomescreen {
|
||||
verifySponsoredShortcutDoesNotExist(sponsoredShortcutTitle, 2)
|
||||
verifySponsoredShortcutDoesNotExist(sponsoredShortcutTitle2, 3)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
/* 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.compose.annotation
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
|
||||
/**
|
||||
* A wrapper annotation for the two uiMode that are commonly used
|
||||
* in Compose preview functions.
|
||||
*/
|
||||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
|
||||
annotation class LightDarkPreview
|
@ -0,0 +1,60 @@
|
||||
/* 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.ext
|
||||
|
||||
import android.os.Build
|
||||
import androidx.core.app.NotificationChannelCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
|
||||
/**
|
||||
* Returns whether notifications are enabled, catches any exception that was thrown from
|
||||
* [NotificationManagerCompat.areNotificationsEnabled] and returns false.
|
||||
*/
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
fun NotificationManagerCompat.areNotificationsEnabledSafe(): Boolean {
|
||||
return try {
|
||||
areNotificationsEnabled()
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the channel does not exist or is null, this returns false.
|
||||
* If the channel exists with importance more than [NotificationManagerCompat.IMPORTANCE_NONE] and
|
||||
* notifications are enabled for the app, this returns true.
|
||||
* On <= SDK 26, this checks if notifications are enabled for the app.
|
||||
*
|
||||
* @param channelId the id of the notification channel to check.
|
||||
* @return true if the channel is enabled, false otherwise.
|
||||
*/
|
||||
fun NotificationManagerCompat.isNotificationChannelEnabled(channelId: String): Boolean {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val channel = getNotificationChannelSafe(channelId)
|
||||
if (channel == null) {
|
||||
false
|
||||
} else {
|
||||
areNotificationsEnabledSafe() && channel.importance != NotificationManagerCompat.IMPORTANCE_NONE
|
||||
}
|
||||
} else {
|
||||
areNotificationsEnabledSafe()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the notification channel with the given [channelId], or null if the channel does not
|
||||
* exist, catches any exception that was thrown by
|
||||
* [NotificationManagerCompat.getNotificationChannelCompat] and returns null.
|
||||
*
|
||||
* @param channelId the id of the notification channel to check.
|
||||
*/
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
private fun NotificationManagerCompat.getNotificationChannelSafe(channelId: String): NotificationChannelCompat? {
|
||||
return try {
|
||||
getNotificationChannelCompat(channelId)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/* 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.home.intent
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.navOptions
|
||||
import org.mozilla.fenix.NavGraphDirections
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.metrics.MetricsUtils
|
||||
import org.mozilla.fenix.ext.nav
|
||||
|
||||
/**
|
||||
* Long pressing home button should also open to the search fragment if Fenix is set as the
|
||||
* assist app
|
||||
*/
|
||||
class AssistIntentProcessor : HomeIntentProcessor {
|
||||
override fun process(intent: Intent, navController: NavController, out: Intent): Boolean {
|
||||
if (intent.action != Intent.ACTION_ASSIST) {
|
||||
return false
|
||||
}
|
||||
|
||||
val directions = NavGraphDirections.actionGlobalSearchDialog(
|
||||
sessionId = null,
|
||||
// Will follow this up with adding `ASSIST` as a search source.
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1808043
|
||||
searchAccessPoint = MetricsUtils.Source.NONE,
|
||||
)
|
||||
|
||||
val options = navOptions {
|
||||
popUpTo(R.id.homeFragment)
|
||||
}
|
||||
|
||||
navController.nav(null, directions, options)
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/* 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.onboarding
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.google.accompanist.insets.ProvideWindowInsets
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.onboarding.view.NotificationPermissionDialogScreen
|
||||
import org.mozilla.fenix.theme.FirefoxTheme
|
||||
|
||||
/**
|
||||
* Dialog displaying notification pre-permission prompt.
|
||||
*/
|
||||
class HomeNotificationPermissionDialogFragment : DialogFragment() {
|
||||
|
||||
@SuppressLint("SourceLockedOrientationActivity")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setStyle(STYLE_NO_TITLE, R.style.HomeOnboardingDialogStyle)
|
||||
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?,
|
||||
): View = ComposeView(requireContext()).apply {
|
||||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
||||
setContent {
|
||||
ProvideWindowInsets {
|
||||
FirefoxTheme {
|
||||
NotificationPermissionDialogScreen(
|
||||
onDismiss = ::onDismiss,
|
||||
grantNotificationPermission = {
|
||||
ensureMarketingChannelExists(context.applicationContext)
|
||||
onDismiss()
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onDismiss() {
|
||||
dismiss()
|
||||
context?.settings()?.isNotificationPrePermissionShown = true
|
||||
}
|
||||
}
|
@ -0,0 +1,233 @@
|
||||
/* 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.onboarding.view
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.IconButton
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.google.accompanist.insets.navigationBarsPadding
|
||||
import com.google.accompanist.insets.statusBarsPadding
|
||||
import mozilla.components.service.glean.private.NoExtras
|
||||
import org.mozilla.fenix.GleanMetrics.Onboarding
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.compose.button.PrimaryButton
|
||||
import org.mozilla.fenix.compose.button.SecondaryButton
|
||||
import org.mozilla.fenix.theme.FirefoxTheme
|
||||
|
||||
/**
|
||||
* Model containing data for the [NotificationPermissionPage].
|
||||
*
|
||||
* @param image [DrawableRes] displayed on the page.
|
||||
* @param title [StringRes] of the permission headline text.
|
||||
* @param description [StringRes] of the permission body text.
|
||||
* @param primaryButtonText [StringRes] of the primary button text.
|
||||
* @param secondaryButtonText [StringRes] of the secondary button text.
|
||||
* @param onRecordImpressionEvent Callback for recording impression event.
|
||||
*/
|
||||
private data class NotificationPermissionPageState(
|
||||
@DrawableRes val image: Int,
|
||||
@StringRes val title: Int,
|
||||
@StringRes val description: Int,
|
||||
@StringRes val primaryButtonText: Int,
|
||||
@StringRes val secondaryButtonText: Int? = null,
|
||||
val onRecordImpressionEvent: () -> Unit,
|
||||
)
|
||||
|
||||
/**
|
||||
* A screen for displaying notification pre permission prompt.
|
||||
*
|
||||
* @param onDismiss Invoked when the user clicks on the close or the negative button.
|
||||
* @param grantNotificationPermission Invoked when the user clicks on the positive button.
|
||||
*/
|
||||
@Composable
|
||||
fun NotificationPermissionDialogScreen(
|
||||
onDismiss: () -> Unit,
|
||||
grantNotificationPermission: () -> Unit,
|
||||
) {
|
||||
NotificationPermissionContent(
|
||||
notificationPermissionPageState = NotificationPageState,
|
||||
onDismiss = {
|
||||
onDismiss()
|
||||
Onboarding.notifPppCloseClick.record(NoExtras())
|
||||
},
|
||||
onPrimaryButtonClick = {
|
||||
grantNotificationPermission()
|
||||
Onboarding.notifPppPositiveBtnClick.record(NoExtras())
|
||||
},
|
||||
onSecondaryButtonClick = {
|
||||
onDismiss()
|
||||
Onboarding.notifPppNegativeBtnClick.record(NoExtras())
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NotificationPermissionContent(
|
||||
notificationPermissionPageState: NotificationPermissionPageState,
|
||||
onDismiss: () -> Unit,
|
||||
onPrimaryButtonClick: () -> Unit,
|
||||
onSecondaryButtonClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
BoxWithConstraints(Modifier.fillMaxSize()) {
|
||||
val boxWithConstraintsScope = this
|
||||
Column(
|
||||
modifier = modifier
|
||||
.background(FirefoxTheme.colors.layer1)
|
||||
.fillMaxSize()
|
||||
.padding(bottom = 32.dp)
|
||||
.statusBarsPadding()
|
||||
.navigationBarsPadding(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onDismiss,
|
||||
modifier = Modifier.align(Alignment.End),
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.mozac_ic_close),
|
||||
contentDescription = stringResource(R.string.content_description_close_button),
|
||||
tint = FirefoxTheme.colors.iconPrimary,
|
||||
)
|
||||
}
|
||||
|
||||
NotificationPermissionPage(
|
||||
pageState = notificationPermissionPageState,
|
||||
onPrimaryButtonClick = onPrimaryButtonClick,
|
||||
onSecondaryButtonClick = onSecondaryButtonClick,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
imageModifier = Modifier
|
||||
.height(boxWithConstraintsScope.maxHeight.times(IMAGE_HEIGHT_RATIO)),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A page for displaying Notification Permission Content.
|
||||
*
|
||||
* @param pageState The page content that's displayed.
|
||||
* @param onPrimaryButtonClick Invoked when the user clicks the primary button.
|
||||
* @param onSecondaryButtonClick Invoked when the user clicks the secondary button.
|
||||
* @param modifier The modifier to be applied to the Composable.
|
||||
*/
|
||||
@Composable
|
||||
private fun NotificationPermissionPage(
|
||||
pageState: NotificationPermissionPageState,
|
||||
onPrimaryButtonClick: () -> Unit,
|
||||
onSecondaryButtonClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
imageModifier: Modifier = Modifier,
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.SpaceEvenly,
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = pageState.image),
|
||||
contentDescription = null,
|
||||
modifier = imageModifier,
|
||||
)
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(
|
||||
id = pageState.title,
|
||||
formatArgs = arrayOf(stringResource(R.string.app_name)),
|
||||
),
|
||||
color = FirefoxTheme.colors.textPrimary,
|
||||
textAlign = TextAlign.Center,
|
||||
style = FirefoxTheme.typography.headline5,
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
text = stringResource(
|
||||
id = pageState.description,
|
||||
formatArgs = arrayOf(stringResource(R.string.app_name)),
|
||||
),
|
||||
color = FirefoxTheme.colors.textSecondary,
|
||||
textAlign = TextAlign.Center,
|
||||
style = FirefoxTheme.typography.body2,
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.padding(top = 16.dp),
|
||||
) {
|
||||
PrimaryButton(
|
||||
text = stringResource(id = pageState.primaryButtonText),
|
||||
onClick = onPrimaryButtonClick,
|
||||
)
|
||||
|
||||
if (pageState.secondaryButtonText != null) {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
SecondaryButton(
|
||||
text = stringResource(id = pageState.secondaryButtonText),
|
||||
onClick = onSecondaryButtonClick,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(pageState) {
|
||||
pageState.onRecordImpressionEvent()
|
||||
}
|
||||
}
|
||||
|
||||
private val NotificationPageState = NotificationPermissionPageState(
|
||||
image = R.drawable.ic_notification_permission,
|
||||
title = R.string.onboarding_home_enable_notifications_title,
|
||||
description = R.string.onboarding_home_enable_notifications_description,
|
||||
primaryButtonText = R.string.onboarding_home_enable_notifications_positive_button,
|
||||
secondaryButtonText = R.string.onboarding_home_enable_notifications_negative_button,
|
||||
onRecordImpressionEvent = { Onboarding.notifPppImpression.record(NoExtras()) },
|
||||
)
|
||||
|
||||
private const val IMAGE_HEIGHT_RATIO = 0.4f
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun NotificationPermissionScreenPreview() {
|
||||
FirefoxTheme {
|
||||
NotificationPermissionDialogScreen(
|
||||
grantNotificationPermission = {},
|
||||
onDismiss = { },
|
||||
)
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue