Bug 1451307 - Part 3 - Add a test for showing the TP UI for iframes and unloaded documents. r=francois
☠☠ backed out by 791af1639cdd ☠ ☠
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 19 Apr 2018 22:37:49 +0200
changeset 473184 12ea607734b158dce4d70f16b858b81799c2ca11
parent 473183 7adc755a42295aedb4530fd14bbb286bc53eaee5
child 473185 9e0246c2f62f9c1e97fa9b194357e01787907213
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrancois
bugs1451307
milestone61.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 1451307 - Part 3 - Add a test for showing the TP UI for iframes and unloaded documents. r=francois MozReview-Commit-ID: FrcwyIbBTFL
browser/base/content/test/trackingUI/browser.ini
browser/base/content/test/trackingUI/browser_trackingUI_iframe.js
browser/base/content/test/trackingUI/browser_trackingUI_unloaded_documents.js
browser/base/content/test/trackingUI/trackingPage_iframe.html
browser/base/content/test/trackingUI/trackingPage_onunload.html
--- a/browser/base/content/test/trackingUI/browser.ini
+++ b/browser/base/content/test/trackingUI/browser.ini
@@ -10,9 +10,15 @@ support-files =
 [browser_trackingUI_3.js]
 [browser_trackingUI_4.js]
 [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_iframe.js]
+support-files =
+  trackingPage_iframe.html
 [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>