Commit 6001a77e authored by Tim Huang's avatar Tim Huang
Browse files

Bug 1641153 - Part 1: Add a test to ensure we won't hit the assertion for nested iframes. r=dimi

parent 9a0799b9
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -516,6 +516,7 @@ this.AntiTracking = {
      // extraPrefs, so let's try annotating it here and adjust our blocking
      // extraPrefs, so let's try annotating it here and adjust our blocking
      // expectations as necessary.
      // expectations as necessary.
      if (
      if (
        !options.dontResetExpectedBlockingNotifications &&
        options.expectedBlockingNotifications ==
        options.expectedBlockingNotifications ==
          Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER
          Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER
      ) {
      ) {
+45 −0
Original line number Original line Diff line number Diff line
@@ -8,6 +8,9 @@
 *
 *
 *  The third time is to load again but in a sandbox iframe to check it won't
 *  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.
 *  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 */
/* import-globals-from antitracking_head.js */
@@ -113,4 +116,46 @@ add_task(async _ => {
    accessRemoval: null,
    accessRemoval: null,
    callbackAfterRemoval: 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,
  });
});
});