tor-browser

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

reload-state-undefined.html (2043B)


      1 <!doctype html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <iframe id="i" src="/common/blank.html"></iframe>
      5 <script>
      6 async_test(t => {
      7  window.onload = t.step_func(() => {
      8    const navState = { key: "value" };
      9    const navInfo = { infoKey: "infoValue" };
     10    i.contentWindow.navigation.navigate("#1", { state: navState }).committed.then(t.step_func(() => {
     11      // Make sure that state setting worked
     12      assert_equals(i.contentWindow.navigation.currentEntry.getState().key, "value");
     13      assert_not_equals(i.contentWindow.navigation.currentEntry.getState(), navState);
     14 
     15      let start_url = i.contentWindow.location.href;
     16      let start_key = i.contentWindow.navigation.currentEntry.key;
     17      let start_id = i.contentWindow.navigation.currentEntry.id;
     18      let onnavigate_called = false;
     19      let promise_settled = false;
     20      i.contentWindow.navigation.onnavigate = t.step_func(e => {
     21        e.intercept();
     22        onnavigate_called = true;
     23        assert_equals(e.info, navInfo);
     24        assert_equals(e.navigationType, "reload");
     25        assert_equals(e.destination.getState().key, "value", "destination.getState()");
     26        assert_not_equals(e.destination.getState(), navState);
     27      });
     28      i.contentWindow.navigation.reload({ info: navInfo, state: undefined }).committed.then(t.step_func_done(() => {
     29        assert_true(onnavigate_called);
     30        assert_equals(i.contentWindow.location.href, start_url);
     31        assert_equals(i.contentWindow.navigation.currentEntry.key, start_key);
     32        assert_equals(i.contentWindow.navigation.currentEntry.id, start_id);
     33        assert_equals(i.contentWindow.navigation.currentEntry.getState().key, "value", "destination.getState()");
     34        assert_not_equals(i.contentWindow.navigation.currentEntry.getState(), navState);
     35      }));
     36    }));
     37  });
     38 }, "reload() variant with info and state: undefined counts the same as not present (because of Web IDL dictionary semantics), so preserves the state");
     39 </script>