Bug 1486061 - [1.1] Add GeckoView safe browsing tests. r=snorp
authorEugen Sawin <esawin@mozilla.com>
Fri, 24 Aug 2018 19:19:35 +0200
changeset 486925 b3439a7f9f2771424d2dab0e5f5c260e3a3872f4
parent 486924 3c8df5d50089a3e4d03a31d57e6a7fdbcfbd871f
child 486926 d4f56bcc389645e34612ebcee616520132fbdc6a
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewerssnorp
bugs1486061
milestone64.0a1
Bug 1486061 - [1.1] Add GeckoView safe browsing tests. r=snorp
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
@@ -164,17 +164,17 @@ class NavigationDelegateTest : BaseSessi
             "https://expired.badssl.com/"
         }
         testLoadExpectError(uri,
                 GeckoSession.NavigationDelegate.ERROR_CATEGORY_SECURITY,
                 GeckoSession.NavigationDelegate.ERROR_SECURITY_BAD_CERT);
     }
 
     @Setting(key = Setting.Key.USE_TRACKING_PROTECTION, value = "true")
-    @Test fun trackingProtectionBasic() {
+    @Test fun trackingProtection() {
         val category = TrackingProtectionDelegate.CATEGORY_TEST;
         sessionRule.runtime.settings.trackingProtectionCategories = category
         sessionRule.session.loadTestPath(TRACKERS_PATH)
 
         sessionRule.waitUntilCalled(
                 object : Callbacks.TrackingProtectionDelegate {
             @AssertCalled(count = 1)
             override fun onTrackerBlocked(session: GeckoSession, uri: String,
@@ -229,16 +229,112 @@ class NavigationDelegateTest : BaseSessi
                 assertThat("Where should not be null", where, notNullValue())
                 assertThat("Where should match", where,
                         equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT))
                 return null
             }
         })
     }
 
+    @Test fun safebrowsingPhishing() {
+        val phishingUri = "https://www.itisatrap.org/firefox/its-a-trap.html"
+
+        sessionRule.runtime.settings.blockPhishing = true
+
+        testLoadExpectError(phishingUri,
+                        GeckoSession.NavigationDelegate.ERROR_CATEGORY_SAFEBROWSING,
+                        GeckoSession.NavigationDelegate.ERROR_SAFEBROWSING_PHISHING_URI)
+
+        sessionRule.runtime.settings.blockPhishing = false
+
+        sessionRule.session.loadUri(phishingUri)
+        sessionRule.session.waitForPageStop()
+
+        sessionRule.forCallbacksDuringWait(
+                object : Callbacks.NavigationDelegate {
+            @AssertCalled(false)
+            override fun onLoadError(session: GeckoSession, uri: String?,
+                                     category: Int, error: Int): GeckoResult<String>? {
+                return null
+            }
+        })
+    }
+
+    @Test fun safebrowsingMalware() {
+        val malwareUri = "https://www.itisatrap.org/firefox/its-an-attack.html"
+
+        sessionRule.runtime.settings.blockMalware = true
+
+        testLoadExpectError(malwareUri,
+                        GeckoSession.NavigationDelegate.ERROR_CATEGORY_SAFEBROWSING,
+                        GeckoSession.NavigationDelegate.ERROR_SAFEBROWSING_MALWARE_URI)
+
+        sessionRule.runtime.settings.blockMalware = false
+
+        sessionRule.session.loadUri(malwareUri)
+        sessionRule.session.waitForPageStop()
+
+        sessionRule.forCallbacksDuringWait(
+                object : Callbacks.NavigationDelegate {
+            @AssertCalled(false)
+            override fun onLoadError(session: GeckoSession, uri: String?,
+                                     category: Int, error: Int): GeckoResult<String>? {
+                return null
+            }
+        })
+    }
+
+    @Test fun safebrowsingUnwanted() {
+        val unwantedUri = "https://www.itisatrap.org/firefox/unwanted.html"
+
+        sessionRule.runtime.settings.blockMalware = true
+
+        testLoadExpectError(unwantedUri,
+                        GeckoSession.NavigationDelegate.ERROR_CATEGORY_SAFEBROWSING,
+                        GeckoSession.NavigationDelegate.ERROR_SAFEBROWSING_UNWANTED_URI)
+
+        sessionRule.runtime.settings.blockMalware = false
+
+        sessionRule.session.loadUri(unwantedUri)
+        sessionRule.session.waitForPageStop()
+
+        sessionRule.forCallbacksDuringWait(
+                object : Callbacks.NavigationDelegate {
+            @AssertCalled(false)
+            override fun onLoadError(session: GeckoSession, uri: String?,
+                                     category: Int, error: Int): GeckoResult<String>? {
+                return null
+            }
+        })
+    }
+
+    @Test fun safebrowsingHarmful() {
+        val harmfulUri = "https://www.itisatrap.org/firefox/harmful.html"
+
+        sessionRule.runtime.settings.blockMalware = true
+
+        testLoadExpectError(harmfulUri,
+                        GeckoSession.NavigationDelegate.ERROR_CATEGORY_SAFEBROWSING,
+                        GeckoSession.NavigationDelegate.ERROR_SAFEBROWSING_HARMFUL_URI)
+
+        sessionRule.runtime.settings.blockMalware = false
+
+        sessionRule.session.loadUri(harmfulUri)
+        sessionRule.session.waitForPageStop()
+
+        sessionRule.forCallbacksDuringWait(
+                object : Callbacks.NavigationDelegate {
+            @AssertCalled(false)
+            override fun onLoadError(session: GeckoSession, uri: String?,
+                                     category: Int, error: Int): GeckoResult<String>? {
+                return null
+            }
+        })
+    }
+
     @WithDevToolsAPI
     @Test fun desktopMode() {
         sessionRule.session.loadUri("https://example.com")
         sessionRule.waitForPageStop()
 
         val userAgentJs = "window.navigator.userAgent"
         val mobileSubStr = "Mobile"
         val desktopSubStr = "X11"