Bug 1505571 - Tests of localStorage access immediatelly after a user-interaction, r=ehsan
☠☠ backed out by 29ff944efa40 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 19 Nov 2018 19:16:24 +0100
changeset 503526 88af3329ee16b19450f0c4638d4fb39019cdf928
parent 503525 be17a8b7aefa08d2ab6e7967314747073c087512
child 503527 838dfe679fddff427f3e8b8ded6e356437c6110e
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1505571
milestone65.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 1505571 - Tests of localStorage access immediatelly after a user-interaction, r=ehsan
toolkit/components/antitracking/test/browser/browser.ini
toolkit/components/antitracking/test/browser/browser_localStorageEvents.js
toolkit/components/antitracking/test/browser/localStorage.html
--- a/toolkit/components/antitracking/test/browser/browser.ini
+++ b/toolkit/components/antitracking/test/browser/browser.ini
@@ -55,11 +55,13 @@ skip-if = serviceworker_e10s
 [browser_storageAccessPromiseResolveHandlerUserInteraction.js]
 [browser_storageAccessRemovalNavigateSubframe.js]
 skip-if = serviceworker_e10s
 [browser_storageAccessSandboxed.js]
 skip-if = serviceworker_e10s
 [browser_storageAccessWithHeuristics.js]
 [browser_allowPermissionForTracker.js]
 [browser_denyPermissionForTracker.js]
+[browser_localStorageEvents.js]
+support-files = localStorage.html
 [browser_partitionedLocalStorage.js]
 [browser_partitionedLocalStorage_events.js]
 support-files = localStorageEvents.html
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/browser_localStorageEvents.js
@@ -0,0 +1,81 @@
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+add_task(async function() {
+  info("Starting subResources test");
+
+  await SpecialPowers.flushPrefEnv();
+  await SpecialPowers.pushPrefEnv({"set": [
+    ["dom.storage_access.enabled", true],
+    ["browser.contentblocking.allowlist.annotations.enabled", true],
+    ["browser.contentblocking.allowlist.storage.enabled", true],
+    ["browser.fastblock.enabled", false],
+    ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
+    ["privacy.trackingprotection.enabled", false],
+    ["privacy.trackingprotection.pbmode.enabled", false],
+    ["privacy.trackingprotection.annotate_channels", true],
+  ]});
+
+  await UrlClassifierTestUtils.addTestTrackers();
+});
+
+add_task(async function testLocalStorageEventPropagation() {
+  info("Creating a new tab");
+  let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
+  gBrowser.selectedTab = tab;
+
+  let browser = gBrowser.getBrowserForTab(tab);
+  await BrowserTestUtils.browserLoaded(browser);
+
+  info("Loading tracking scripts");
+  await ContentTask.spawn(browser, {
+                                     page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorage.html",
+                                   }, async obj => {
+    info("Creating tracker iframe");
+
+    let ifr = content.document.createElement("iframe");
+    ifr.src = obj.page;
+
+    await new content.Promise(resolve => {
+      ifr.onload = function() {
+        resolve();
+      };
+      content.document.body.appendChild(ifr);
+    });
+
+    info("LocalStorage should be blocked.");
+    await new content.Promise(resolve => {
+      content.addEventListener("message", e => {
+        if (e.data.type == "test") {
+          is(e.data.status, false, "LocalStorage blocked");
+        } else {
+          ok(false, "Unknown message");
+        }
+        resolve();
+      }, {once: true});
+      ifr.contentWindow.postMessage("test", "*");
+    });
+
+    info("Let's open the popup");
+    await new content.Promise(resolve => {
+      content.addEventListener("message", e => {
+        if (e.data.type == "test") {
+          is(e.data.status, true, "LocalStorage unblocked");
+        } else {
+          ok(false, "Unknown message");
+        }
+        resolve();
+      }, {once: true});
+      ifr.contentWindow.postMessage("open", "*");
+    });
+  });
+
+  info("Removing the tab");
+  BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function() {
+  info("Cleaning up.");
+  await new Promise(resolve => {
+    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
+  });
+});
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/localStorage.html
@@ -0,0 +1,45 @@
+<h1>Here a tracker!</h1>
+<script>
+
+if (window.opener) {
+  SpecialPowers.wrap(document).userInteractionForTesting();
+  localStorage.foo = "opener" + Math.random();
+  window.close();
+}
+
+if (parent) {
+  window.onmessage = e => {
+    if (e.data == "test") {
+      let status;
+      try {
+        localStorage.foo = "value" + Math.random();
+        status = true;
+      } catch (e) {
+        status = false;
+      }
+
+      parent.postMessage({type: "test", status }, "*");
+      return;
+    }
+
+    if (e.data == "open") {
+      window.open("localStorage.html");
+    }
+  };
+
+  window.addEventListener("storage", e => {
+    let fromOpener = localStorage.foo.startsWith("opener");
+
+    let status;
+    try {
+      localStorage.foo = "value" + Math.random();
+      status = true;
+    } catch (e) {
+      status = false;
+    }
+
+    parent.postMessage({type: "test", status: status && fromOpener }, "*");
+  });
+}
+
+</script>