mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] Add UI tests for deep links
This commit is contained in:
parent
dc588ca0ae
commit
83ed39ed5c
147
app/src/androidTest/java/org/mozilla/fenix/ui/DeepLinkTest.kt
Normal file
147
app/src/androidTest/java/org/mozilla/fenix/ui/DeepLinkTest.kt
Normal file
@ -0,0 +1,147 @@
|
||||
/* 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.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
import org.mozilla.fenix.ui.robots.DeepLinkRobot
|
||||
|
||||
/**
|
||||
* Tests for verifying basic functionality of deep links
|
||||
* - fenix://home
|
||||
* - fenix://open
|
||||
* - fenix://settings_notifications — take the user to the notification settings page
|
||||
* - fenix://settings_privacy — take the user to the privacy settings page.
|
||||
* - fenix://settings_search_engine — take the user to the search engine page, to set the default search engine.
|
||||
* - fenix://home_collections — take the user to the home screen to see the list of collections.
|
||||
* - fenix://home_history — take the user to the history list.
|
||||
* - fenix://home_bookmarks — take the user to the bookmarks list
|
||||
* - fenix://settings_logins — take the user to the settings page to do with logins (not the saved logins).
|
||||
**/
|
||||
class DeepLinkTest {
|
||||
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
private lateinit var mockWebServer: MockWebServer
|
||||
|
||||
private val robot = DeepLinkRobot()
|
||||
|
||||
@get:Rule
|
||||
val activityIntentTestRule = HomeActivityIntentTestRule()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
mockWebServer = MockWebServer().apply {
|
||||
setDispatcher(AndroidAssetDispatcher())
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
mockWebServer.shutdown()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openHomeScreen() {
|
||||
robot.openHomeScreen {
|
||||
verifyHomeComponent()
|
||||
}
|
||||
robot.openSettings { /* move away from the home screen */ }
|
||||
robot.openHomeScreen {
|
||||
verifyHomeComponent()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openURL() {
|
||||
val genericURL =
|
||||
TestAssetHelper.getGenericAsset(mockWebServer, 1)
|
||||
robot.openURL(genericURL.url.toString()) {
|
||||
verifyUrl(genericURL.url.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openBookmarks() {
|
||||
robot.openBookmarks {
|
||||
// verify we can see headings.
|
||||
verifyFolderTitle("Desktop Bookmarks")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openHistory() {
|
||||
robot.openHistory {
|
||||
verifyHistoryMenuView()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openCollections() {
|
||||
robot.openHomeScreen { /* do nothing */ }.dismissOnboarding()
|
||||
robot.openCollections {
|
||||
verifyCollectionsHeader()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openSettings() {
|
||||
robot.openSettings {
|
||||
verifyBasicsHeading()
|
||||
verifyAdvancedHeading()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openSettingsLogins() {
|
||||
robot.openSettingsLogins {
|
||||
verifyDefaultView()
|
||||
verifyDefaultValueSyncLogins()
|
||||
verifyDefaultValueAutofillLogins()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openSettingsPrivacy() {
|
||||
robot.openSettingsPrivacy {
|
||||
verifyPrivacyHeading()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openSettingsTrackingProtection() {
|
||||
robot.openSettingsTrackingProtection {
|
||||
verifyEnhancedTrackingProtectionHeader()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openSettingsSearchEngine() {
|
||||
robot.openSettingsSearchEngine {
|
||||
verifyDefaultSearchEngineHeader()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openSettingsNotifications() {
|
||||
robot.openSettingsNotification {
|
||||
verifyNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun openMakeDefaultBrowser() {
|
||||
robot.openMakeDefaultBrowser {
|
||||
verifyMakeDefaultBrowser()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/* 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.robots
|
||||
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.ext.application
|
||||
|
||||
class DeepLinkRobot {
|
||||
private fun openDeepLink(url: String) {
|
||||
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val intent = Intent().apply {
|
||||
action = Intent.ACTION_VIEW
|
||||
data = Uri.parse(url)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
component =
|
||||
ComponentName(context.application.packageName, HomeActivity::class.java.name)
|
||||
addCategory(Intent.CATEGORY_BROWSABLE)
|
||||
}
|
||||
try {
|
||||
context.startActivity(intent)
|
||||
} catch (ex: ActivityNotFoundException) {
|
||||
intent.setPackage(null)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
fun openURL(url: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
||||
val deepLink = Uri.parse("fenix://open")
|
||||
.buildUpon()
|
||||
.appendQueryParameter("url", url)
|
||||
.build()
|
||||
.toString()
|
||||
openDeepLink(deepLink)
|
||||
return browserScreen(interact)
|
||||
}
|
||||
|
||||
fun openHomeScreen(interact: HomeScreenRobot.() -> Unit) =
|
||||
openDeepLink("fenix://home").run { homeScreen(interact) }
|
||||
|
||||
fun openBookmarks(interact: BookmarksRobot.() -> Unit) =
|
||||
openDeepLink("fenix://home_bookmarks").run { bookmarksMenu(interact) }
|
||||
|
||||
fun openHistory(interact: HistoryRobot.() -> Unit) =
|
||||
openDeepLink("fenix://home_history").run { historyMenu(interact) }
|
||||
|
||||
fun openCollections(interact: HomeScreenRobot.() -> Unit) =
|
||||
openDeepLink("fenix://home_collections").run { homeScreen(interact) }
|
||||
|
||||
fun openSettings(interact: SettingsRobot.() -> Unit) =
|
||||
openDeepLink("fenix://settings").run { settings(interact) }
|
||||
|
||||
fun openSettingsPrivacy(interact: SettingsRobot.() -> Unit) =
|
||||
openDeepLink("fenix://settings_privacy").run { settings(interact) }
|
||||
|
||||
fun openSettingsLogins(interact: SettingsSubMenuLoginsAndPasswordRobot.() -> Unit) =
|
||||
openDeepLink("fenix://settings_logins").run { settingsSubMenuLoginsAndPassword(interact) }
|
||||
|
||||
fun openSettingsTrackingProtection(interact: SettingsSubMenuEnhancedTrackingProtectionRobot.() -> Unit) =
|
||||
openDeepLink("fenix://settings_tracking_protection").run {
|
||||
settingsSubMenuEnhancedTrackingProtection(interact)
|
||||
}
|
||||
|
||||
fun openSettingsSearchEngine(interact: SettingsSubMenuSearchRobot.() -> Unit) =
|
||||
openDeepLink("fenix://settings_search_engine").run {
|
||||
SettingsSubMenuSearchRobot().interact()
|
||||
SettingsSubMenuSearchRobot.Transition()
|
||||
}
|
||||
|
||||
fun openSettingsNotification(interact: SystemSettingsRobot.() -> Unit) =
|
||||
openDeepLink("fenix://settings_notifications").run { systemSettings(interact) }
|
||||
|
||||
fun openMakeDefaultBrowser(interact: SystemSettingsRobot.() -> Unit) =
|
||||
openDeepLink("fenix://make_default_browser").run { systemSettings(interact) }
|
||||
}
|
||||
|
||||
private fun settings(interact: SettingsRobot.() -> Unit) =
|
||||
SettingsRobot().interact().run { SettingsRobot.Transition() }
|
@ -0,0 +1,27 @@
|
||||
/* 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.robots
|
||||
|
||||
import androidx.test.espresso.intent.Intents
|
||||
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
|
||||
|
||||
class SystemSettingsRobot {
|
||||
fun verifyNotifications() {
|
||||
Intents.intended(hasAction("android.settings.APP_NOTIFICATION_SETTINGS"))
|
||||
}
|
||||
|
||||
fun verifyMakeDefaultBrowser() {
|
||||
Intents.intended(hasAction(SettingsRobot.DEFAULT_APPS_SETTINGS_ACTION))
|
||||
}
|
||||
|
||||
class Transition {
|
||||
// Difficult to know where this will go
|
||||
}
|
||||
}
|
||||
|
||||
fun systemSettings(interact: SystemSettingsRobot.() -> Unit): SystemSettingsRobot.Transition {
|
||||
SystemSettingsRobot().interact()
|
||||
return SystemSettingsRobot.Transition()
|
||||
}
|
Loading…
Reference in New Issue
Block a user