reload-state-and-info.html (2040B)
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 navState1 = { key: "value" }; 9 const navState2 = { key2: "value2" }; 10 const navInfo = { infoKey: "infoValue" }; 11 i.contentWindow.navigation.navigate("#1", { state: navState1 }).committed.then(t.step_func(() => { 12 // Make sure that state setting worked 13 assert_equals(i.contentWindow.navigation.currentEntry.getState().key, "value", "initial state setup"); 14 assert_not_equals(i.contentWindow.navigation.currentEntry.getState(), navState1); 15 16 let start_url = i.contentWindow.location.href; 17 let start_key = i.contentWindow.navigation.currentEntry.key; 18 let start_id = i.contentWindow.navigation.currentEntry.id; 19 let onnavigate_called = false; 20 let promise_settled = false; 21 i.contentWindow.navigation.onnavigate = t.step_func(e => { 22 e.intercept(); 23 onnavigate_called = true; 24 assert_equals(e.info, navInfo); 25 assert_equals(e.navigationType, "reload"); 26 assert_equals(e.destination.getState().key2, "value2", "navigate event for the reload()"); 27 assert_not_equals(e.destination.getState(), navState2); 28 }); 29 i.contentWindow.navigation.reload({ info: navInfo, state: navState2 }).committed.then(t.step_func_done(() => { 30 assert_true(onnavigate_called); 31 assert_equals(i.contentWindow.location.href, start_url); 32 assert_equals(i.contentWindow.navigation.currentEntry.key, start_key); 33 assert_equals(i.contentWindow.navigation.currentEntry.id, start_id); 34 assert_equals(i.contentWindow.navigation.currentEntry.getState().key2, "value2", "currentEntry.getState() after the reload"); 35 assert_not_equals(i.contentWindow.navigation.currentEntry.getState(), navState2); 36 })); 37 })); 38 }); 39 }, "reload() variant with info and new state"); 40 </script>