Revision control
Copy as Markdown
/* 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
package org.mozilla.focus.activity
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.focus.R
import org.mozilla.focus.activity.robots.homeScreen
import org.mozilla.focus.activity.robots.searchScreen
import org.mozilla.focus.helpers.FeatureSettingsHelper
import org.mozilla.focus.helpers.MainActivityFirstrunTestRule
import org.mozilla.focus.helpers.MockWebServerHelper
import org.mozilla.focus.helpers.TestHelper.exitToTop
import org.mozilla.focus.helpers.TestHelper.getStringResource
import org.mozilla.focus.testAnnotations.SmokeTest
// These tests verify the Safe Browsing feature by visiting unsafe URLs and checking they are blocked
class SafeBrowsingTest {
private lateinit var webServer: MockWebServer
private val malwareWarning = getStringResource(R.string.mozac_browser_errorpages_safe_browsing_malware_uri_title)
private val phishingWarning = getStringResource(R.string.mozac_browser_errorpages_safe_phishing_uri_title)
private val unwantedSoftwareWarning =
getStringResource(R.string.mozac_browser_errorpages_safe_browsing_unwanted_uri_title)
private val harmfulSiteWarning = getStringResource(R.string.mozac_browser_errorpages_safe_harmful_uri_title)
private val tryAgainButton = getStringResource(R.string.mozac_browser_errorpages_page_refresh)
private val featureSettingsHelper = FeatureSettingsHelper()
@get: Rule
val mActivityTestRule = MainActivityFirstrunTestRule(showFirstRun = false)
@Before
fun setUp() {
featureSettingsHelper.setCfrForTrackingProtectionEnabled(false)
featureSettingsHelper.setSearchWidgetDialogEnabled(false)
webServer = MockWebServer().apply {
dispatcher = MockWebServerHelper.AndroidAssetDispatcher()
start()
}
}
@After
fun tearDown() {
webServer.shutdown()
featureSettingsHelper.resetAllFeatureFlags()
}
@SmokeTest
@Test
fun blockMalwarePageTest() {
searchScreen {
}.loadPage(malwareURl) {
verifyPageContent(malwareWarning)
verifyPageContent(tryAgainButton)
}
}
@SmokeTest
@Test
fun blockPhishingPageTest() {
searchScreen {
}.loadPage(phishingURl) {
verifyPageContent(phishingWarning)
verifyPageContent(tryAgainButton)
}
}
@SmokeTest
@Test
fun blockUnwantedSoftwarePageTest() {
searchScreen {
}.loadPage(unwantedURl) {
verifyPageContent(unwantedSoftwareWarning)
verifyPageContent(tryAgainButton)
}
}
@SmokeTest
@Test
fun blockHarmfulPageTest() {
searchScreen {
}.loadPage(harmfulURl) {
verifyPageContent(harmfulSiteWarning)
verifyPageContent(tryAgainButton)
}
}
@SmokeTest
@Test
fun unblockSafeBrowsingTest() {
homeScreen {
}.openMainMenu {
}.openSettings {
}.openPrivacySettingsMenu {
switchSafeBrowsingToggle()
exitToTop()
}
searchScreen {
}.loadPage(malwareURl) {
verifyPageContent("It’s an Attack!")
}
}
@SmokeTest
@Test
fun verifyPageSecurityIconAndInfo() {
searchScreen {
}.loadPage(safePageUrl) {
verifyPageContent("Lets test!")
verifySiteTrackingProtectionIconShown()
}.openSiteSecurityInfoSheet {
verifySiteConnectionInfoIsSecure(true)
}.closeSecurityInfoSheet {
}.clearBrowsingData {}
searchScreen {
}.loadPage(insecurePageUrl) {
verifyPageURL(insecurePageUrl)
verifySiteSecurityIndicatorShown()
}.openSiteSecurityInfoSheet {
verifySiteConnectionInfoIsSecure(false)
}.closeSecurityInfoSheet { }
}
}