tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

anchor-download-aborts-previous-navigation.html (1528B)


      1 <!doctype html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <iframe id="iframe" src="/common/blank.html"></iframe>
      5 <script>
      6  promise_test(async t => {
      7    const iframe = document.getElementById("iframe");
      8    await new Promise(resolve => window.onload = resolve);
      9    const navigate_called = Promise.withResolvers();
     10    const { navigation } = iframe.contentWindow;
     11    navigation.addEventListener("navigate", e => {
     12      if (!e.downloadRequest) {
     13        e.intercept({ handler: () => new Promise(resolve => { }) });
     14        navigate_called.resolve();
     15      }
     16    });
     17    navigation.navigate("?never");
     18    await navigate_called.promise;
     19    const events = [];
     20    const { transition } = navigation;
     21    transition.committed.then(() => events.push("committed")).catch(e => events.push("commit-rejected"));
     22    transition.finished.then(() => events.push("finished")).catch(e => events.push("finish-rejected"));
     23    navigation.onnavigatesuccess = () => events.push("navigatesuccess");
     24    navigation.onnavigateerror = () => events.push("navigateerror");
     25 
     26    await Promise.resolve();
     27    let a = iframe.contentDocument.createElement("a");
     28    a.href = "?download";
     29    a.download = "";
     30    iframe.contentDocument.body.appendChild(a);
     31    a.click();
     32    await Promise.allSettled([transition.finished, transition.committed])
     33    assert_array_equals(events, ["committed", "navigateerror", "finish-rejected"]);
     34  }, "<a download> aborts previous navigations");
     35 </script>