Bug 1463772 - [2.1] Add basic tracking protection tests. r=jchen
authorEugen Sawin <esawin@mozilla.com>
Fri, 25 May 2018 00:30:55 +0200
changeset 474594 951c7d8ee07944d45f67c9aece69f34a7b7ef772
parent 474593 410b2cbefe3ae5a7337c7cf7d864eb0df8718fe5
child 474595 4e1b975f4897db99ba92b4a6dc47025dfdb2614e
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1463772
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1463772 - [2.1] Add basic tracking protection tests. r=jchen
mobile/android/geckoview/src/androidTest/assets/www/trackers.html
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
new file mode 100644
--- /dev/null
+++ b/mobile/android/geckoview/src/androidTest/assets/www/trackers.html
@@ -0,0 +1,9 @@
+<html>
+    <head><title>Trackers</title></head>
+    <body>
+        <p>Trackers</p>
+
+        <!-- test-track-simple -->
+        <script src="https://trackertest.org/tracker.js"></script>
+    </body>
+</html>
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt
@@ -28,16 +28,17 @@ open class BaseSessionTest(noErrorCollec
         const val INVALID_URI = "http://www.test.invalid/"
         const val HELLO_HTML_PATH = "/assets/www/hello.html"
         const val HELLO2_HTML_PATH = "/assets/www/hello2.html"
         const val NEW_SESSION_HTML_PATH = "/assets/www/newSession.html"
         const val NEW_SESSION_CHILD_HTML_PATH = "/assets/www/newSession_child.html"
         const val CLICK_TO_RELOAD_HTML_PATH = "/assets/www/clickToReload.html"
         const val TITLE_CHANGE_HTML_PATH = "/assets/www/titleChange.html"
         const val DOWNLOAD_HTML_PATH = "/assets/www/download.html"
+        const val TRACKERS_PATH = "/assets/www/trackers.html"
     }
 
     @get:Rule val sessionRule = GeckoSessionTestRule()
 
     @get:Rule val errors = ErrorCollector()
 
     val mainSession get() = sessionRule.session
 
--- 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
@@ -1,33 +1,55 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 package org.mozilla.geckoview.test
 
 import org.mozilla.geckoview.GeckoResponse
 import org.mozilla.geckoview.GeckoSession
+import org.mozilla.geckoview.GeckoSession.TrackingProtectionDelegate;
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.NullDelegate
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.ReuseSession
+import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.Setting
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDevToolsAPI
 import org.mozilla.geckoview.test.util.Callbacks
 
 import android.support.test.filters.MediumTest
 import android.support.test.runner.AndroidJUnit4
 import org.hamcrest.Matchers.*
 import org.junit.Test
 import org.junit.runner.RunWith
 
 @RunWith(AndroidJUnit4::class)
 @MediumTest
 @ReuseSession(false)
 class NavigationDelegateTest : BaseSessionTest() {
 
+    @Setting(key = Setting.Key.USE_TRACKING_PROTECTION, value = "true")
+    @Test fun trackingProtectionBasic() {
+        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,
+                                          categories: Int) {
+                assertThat("Category should be set",
+                           categories,
+                           equalTo(category))
+                assertThat("URI should not be null", uri, notNullValue())
+                assertThat("URI should match", uri, endsWith("trackertest.org/tracker.js"))
+            }
+        })
+    }
+
     @Test fun load() {
         sessionRule.session.loadTestPath(HELLO_HTML_PATH)
         sessionRule.waitForPageStop()
 
         sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
             @AssertCalled(count = 1, order = [1])
             override fun onLoadRequest(session: GeckoSession, uri: String,
                                        where: Int,