Bug 1451307 - Part 3 - Add a test for showing the TP UI for iframes and unloaded documents. r=francois
MozReview-Commit-ID: FrcwyIbBTFL
--- a/browser/base/content/test/trackingUI/browser.ini
+++ b/browser/base/content/test/trackingUI/browser.ini
@@ -10,12 +10,18 @@ support-files =
[browser_trackingUI_5.js]
[browser_trackingUI_6.js]
support-files =
file_trackingUI_6.html
file_trackingUI_6.js
file_trackingUI_6.js^headers^
[browser_trackingUI_appMenu.js]
[browser_trackingUI_appMenu_toggle.js]
+[browser_trackingUI_iframe.js]
+support-files =
+ trackingPage_iframe.html
[browser_trackingUI_open_preferences.js]
[browser_trackingUI_reload_hint.js]
[browser_trackingUI_state.js]
[browser_trackingUI_telemetry.js]
+[browser_trackingUI_unloaded_documents.js]
+support-files =
+ trackingPage_onunload.html
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_iframe.js
@@ -0,0 +1,29 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+const URL = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.org") + "trackingPage_iframe.html";
+
+/**
+ * Tests that sites that only contain trackers in iframes still
+ * get the tracking protection UI.
+ */
+
+add_task(async function test_iframe() {
+ await UrlClassifierTestUtils.addTestTrackers();
+
+ await SpecialPowers.pushPrefEnv({ set: [[PREF, true]] });
+
+ await BrowserTestUtils.withNewTab(URL, async function(browser) {
+ var TrackingProtection = browser.ownerGlobal.TrackingProtection;
+ ok(TrackingProtection, "got TP object");
+ ok(TrackingProtection.enabled, "TP is enabled");
+
+ is(TrackingProtection.content.getAttribute("state"), "blocked-tracking-content",
+ 'content: state="blocked-tracking-content"');
+ is(TrackingProtection.icon.getAttribute("state"), "blocked-tracking-content",
+ 'icon: state="blocked-tracking-content"');
+ is(TrackingProtection.icon.getAttribute("tooltiptext"),
+ gNavigatorBundle.getString("trackingProtection.icon.activeTooltip"), "correct tooltip");
+ });
+
+ UrlClassifierTestUtils.cleanupTestTrackers();
+});
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_unloaded_documents.js
@@ -0,0 +1,33 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+const URL = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.org") + "trackingPage_onunload.html";
+
+/**
+ * Tests that visiting a new page while a request to a tracker is still
+ * in flight (such as when it was triggered on unload) does not cause
+ * the tracking UI to appear.
+ */
+
+add_task(async function test_onunload() {
+ await UrlClassifierTestUtils.addTestTrackers();
+
+ await SpecialPowers.pushPrefEnv({ set: [[PREF, true]] });
+
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
+ let browser = tab.linkedBrowser;
+
+ let loaded = BrowserTestUtils.browserLoaded(browser, false, "http://example.com/");
+ await BrowserTestUtils.loadURI(browser, "http://example.com/");
+ await loaded;
+ var TrackingProtection = browser.ownerGlobal.TrackingProtection;
+ ok(TrackingProtection, "got TP object");
+ ok(TrackingProtection.enabled, "TP is enabled");
+
+ ok(!TrackingProtection.container.hidden, "The container is visible");
+ ok(!TrackingProtection.content.hasAttribute("state"), "content: no state");
+ ok(!TrackingProtection.icon.hasAttribute("state"), "icon: no state");
+ ok(!TrackingProtection.icon.hasAttribute("tooltiptext"), "icon: no tooltip");
+
+ BrowserTestUtils.removeTab(tab);
+ UrlClassifierTestUtils.cleanupTestTrackers();
+});
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/trackingUI/trackingPage_iframe.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML>
+<!-- Any copyright is dedicated to the Public Domain.
+ - http://creativecommons.org/publicdomain/zero/1.0/ -->
+<html dir="ltr" xml:lang="en-US" lang="en-US">
+ <head>
+ <meta charset="utf8">
+ </head>
+ <body>
+ <iframe src="http://example.com/browser/browser/base/content/test/trackingUI/trackingPage.html"></iframe>
+ </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/trackingUI/trackingPage_onunload.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<!-- Any copyright is dedicated to the Public Domain.
+ - http://creativecommons.org/publicdomain/zero/1.0/ -->
+<html dir="ltr" xml:lang="en-US" lang="en-US">
+ <head>
+ <meta charset="utf8">
+ <script>
+ window.onunload = function() {
+ var img = new Image();
+ img.src = "http://tracking.example.com/";
+ document.body.appendChild(img);
+ };
+ </script>
+ </head>
+ <body>
+ Testing tracking requests onunload.
+ </body>
+</html>