Bug 1463772 - [2.1] Add basic tracking protection tests. r=jchen

This commit is contained in:
Eugen Sawin 2018-05-25 00:30:55 +02:00
parent c4cfb57d29
commit 410a424061
3 changed files with 32 additions and 0 deletions

View File

@ -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>

View File

@ -33,6 +33,7 @@ open class BaseSessionTest(noErrorCollector: Boolean = false) {
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()

View File

@ -6,9 +6,11 @@ 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
@ -23,6 +25,26 @@ import org.junit.runner.RunWith
@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()