Bug 1641153 - Part 1: Add a test to ensure we won't hit the assertion for nested iframes. r=dimi
authorTim Huang <tihuang@mozilla.com>
Thu, 28 May 2020 11:39:19 +0000
changeset 596508 5a7e4520064c892fa5207deccd5bd3db747b272a
parent 596507 0cd2dde310d810f4ad858c5faf722ee858cd34a1
child 596509 b0959ede7962825fa1536ebfacb699d75a540b2d
push id13186
push userffxbld-merge
push dateMon, 01 Jun 2020 09:52:46 +0000
treeherdermozilla-beta@3e7c70a1e4a1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdimi
bugs1641153
milestone78.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 1641153 - Part 1: Add a test to ensure we won't hit the assertion for nested iframes. r=dimi Differential Revision: https://phabricator.services.mozilla.com/D77074
toolkit/components/antitracking/test/browser/antitracking_head.js
toolkit/components/antitracking/test/browser/browser_serviceWorkersWithStorageAccessGranted.js
--- a/toolkit/components/antitracking/test/browser/antitracking_head.js
+++ b/toolkit/components/antitracking/test/browser/antitracking_head.js
@@ -511,18 +511,19 @@ this.AntiTracking = {
         thirdPartyPage = TEST_3RD_PARTY_PAGE;
         thirdPartyDomainURI = Services.io.newURI(TEST_3RD_PARTY_DOMAIN);
       }
 
       // It's possible that the third-party domain has been whitelisted through
       // extraPrefs, so let's try annotating it here and adjust our blocking
       // expectations as necessary.
       if (
+        !options.dontResetExpectedBlockingNotifications &&
         options.expectedBlockingNotifications ==
-        Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER
+          Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER
       ) {
         if (
           !(await AntiTracking._isThirdPartyPageClassifiedAsTracker(
             topPage,
             thirdPartyDomainURI
           ))
         ) {
           options.expectedBlockingNotifications = 0;
--- a/toolkit/components/antitracking/test/browser/browser_serviceWorkersWithStorageAccessGranted.js
+++ b/toolkit/components/antitracking/test/browser/browser_serviceWorkersWithStorageAccessGranted.js
@@ -3,16 +3,19 @@
  *  permission manager to simulate the storage access has been granted. We would
  *  test the service worker three times. The fist time is to check the service
  *  work is allowed. The second time is to load again and check it won't hit
  *  assertion, this assertion would only be hit if we have registered a service
  *  worker, see Bug 1631234.
  *
  *  The third time is to load again but in a sandbox iframe to check it won't
  *  hit the assertion. See Bug 1637226 for details.
+ *
+ *  The fourth time is to load again in a nested iframe to check it won't hit
+ *  the assertion. See Bug 1641153 for details.
  *  */
 
 /* import-globals-from antitracking_head.js */
 
 add_task(async _ => {
   // Manually add the storage permission.
   PermissionTestUtils.add(
     TEST_DOMAIN,
@@ -108,9 +111,51 @@ add_task(async _ => {
       ["dom.serviceWorkers.testing.enabled", true],
     ],
     expectedBlockingNotifications: 0,
     runInPrivateWindow: false,
     iframeSandbox: "allow-scripts allow-same-origin",
     accessRemoval: null,
     callbackAfterRemoval: null,
   });
+
+  const NESTED_THIRD_PARTY_PAGE =
+    TEST_DOMAIN + TEST_PATH + "3rdPartyRelay.html?" + TEST_3RD_PARTY_PAGE;
+
+  AntiTracking._createTask({
+    name:
+      "Test again to check if we cannot use service worker in a nested iframe without hit the assertion.",
+    cookieBehavior: BEHAVIOR_REJECT_TRACKER,
+    allowList: false,
+    callback: async _ => {
+      await navigator.serviceWorker
+        .register("empty.js")
+        .then(
+          _ => {
+            ok(false, "ServiceWorker cannot be used in nested iframe!");
+          },
+          _ => {
+            ok(true, "ServiceWorker cannot be used in nested iframe!");
+          }
+        )
+        .catch(e => ok(false, "Promise rejected: " + e));
+    },
+    extraPrefs: [
+      ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+      ["dom.serviceWorkers.enabled", true],
+      ["dom.serviceWorkers.testing.enabled", true],
+    ],
+    expectedBlockingNotifications:
+      Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
+    // Due to the first-level iframe won't be considered as a third-party
+    // tracking iframe in this test since it is loaded with the origin of the
+    // top level. So, the test framework will reset the
+    // `expectedBlockingNotifications` to 0. However, we actually expect to see
+    // blocking notifications from the nested iframe where we do the test. So,
+    // we have to skip resetting the blocking notifications for this test.
+    dontResetExpectedBlockingNotifications: true,
+    runInPrivateWindow: false,
+    iframeSandbox: null,
+    accessRemoval: null,
+    callbackAfterRemoval: null,
+    thirdPartyPage: NESTED_THIRD_PARTY_PAGE,
+  });
 });