Bug 1451307 - Part 3 - Add a test for showing the TP UI for iframes and unloaded documents. r=francois
☠☠ backed out by 76f35d0ecaa6 ☠ ☠
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 19 Apr 2018 22:37:49 +0200
changeset 469063 be0a9b78c2242fcc4eb2545d7fe5b58fecd250e7
parent 469062 13e58d5887d8b8dae297577abe1d15edf254cd44
child 469064 bb0bb35465d9161f35e06f677df2956afea254a4
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [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>