wpt / html / user-activation / traverse-to-pushed-entry.https.html?store

Open test on wpt.live | wpt.fyi

Runs: Chrome 160.0.8195.0 (wpt@1ab8957e4, 2026-12-01) | Firefox 163.0a1 (wpt@1ab8957e4, 2026-12-01) | Safari 257 preview (wpt@1ab8957e4, 2026-12-01) | Ladybird 1.0-fe766 (wpt@c2d91acbf, 2026-12-02) | Servo Servo 0.8 (wpt@75c11f957, 2026-12-01) | Blitz af350c0af (wpt@705f393a6, 2026-12-02)

ChromeFirefoxSafariLadybirdServoBlitz
Total0/10/10/10/10/1NOT RUN
SubtestChromeFirefoxSafariLadybirdServoBlitz
User activation propagation across a traversal to an entry that is not the one its document was last shown forPRECONDITION_FAILEDPRECONDITION_FAILEDPRECONDITION_FAILEDPRECONDITION_FAILEDFAIL—

/html/user-activation/traverse-to-pushed-entry.https.html

<!DOCTYPE html>
<meta name="variant" content="?store">
<meta name="variant" content="?no-store">
<title>User activation propagation across a traversal to an entry that is not the one its document was last shown for</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step">
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/common/utils.js"></script>
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="resources/utils.js"></script>

<body>
  <p>Non-zero-sized body to allow clicks.</p>
</body>

<script>
  'use strict';

  let uuid1 = token();
  let uuid2 = token();

  // Only the "store" variant lands on an entry that is not the one its document
  // was last shown for: the document comes back from the back/forward cache
  // with the pushed entry as its latest one. The "no-store" variant recreates
  // it, which leaves it with no latest entry at all, and is worth running
  // because the entry records the same thing either way. The test is "https"
  // because that is where a no-store response keeps a page out of the cache.
  const noStore = location.search === "?no-store";
  let opened = originSameOrigin + executorPath + uuid1 +
               (noStore ? "&pipe=header(Cache-Control,no-store)" : "");
  let navigated_to = originSameOrigin + executorPath + uuid2;

  promise_test(async test => {
    // Open a new window, push a second entry for its document, and navigate
    // away. Traversing past the pushed entry then lands on an entry that is not
    // the one its document was last shown for, which is what the carry-over
    // conditions have to be read from.
    let w;
    document.body.onclick = () => {
      w = window.open(opened);
    };

    await test_driver.click(document.body);
    assert_true(!!w, "A window is opened");
    // Close the window at the end of the test, so that a later test in the same
    // session cannot click a window this one left behind.
    test.add_cleanup(() => w && w.close());

    const first = new RemoteContext(uuid1);
    const second = new RemoteContext(uuid2);

    // Check that the new window does not have user activation initially.
    {
      const result = await first.execute_script(getUserActivationStateWhenShown);
      assertUserActivationState(result, false, false, "after window opened");
    }

    // Push a second entry for the first document, and navigate the window to a
    // second same-origin document.
    await first.execute_script(url => {
      history.pushState(null, "", location.href + "&pushed=1");
      prepareNavigation(() => {
        location.href = url;
      });
    }, [navigated_to]);

    // Wait for the second document to be shown.
    await second.execute_script(async () => {
      await window.pageShowPromise;
    });

    // Confirm that the second document gets user activation after a click.
    await test_driver.click(w.document.documentElement);
    {
      const result = await second.execute_script(getUserActivationState);
      assertUserActivationState(result, true, true, "after window clicked");
    }

    // Traverse past the pushed entry, back to the entry the first document was
    // originally shown for.
    await second.execute_script(() => {
      prepareNavigation(() => {
        history.go(-2);
      });
    });

    // Confirm that the first document got the sticky user activation carried
    // over.
    {
      const [url, state] = await first.execute_script(async () => {
        await window.pageShowPromise;
        return [location.href,
                [navigator.userActivation.isActive,
                 navigator.userActivation.hasBeenActive]];
      });
      assert_false(url.includes("pushed=1"), "Traversed past the pushed entry");

      if (noStore) {
        await assert_not_bfcached(first);
      } else {
        await assert_bfcached(first);
      }

      assertUserActivationState(state, false, true, "after traversing back");
    }
}, "User activation propagation across a traversal to an entry that is not " +
   "the one its document was last shown for");
</script>