hashchange-same-fragment-does-not-fire.html (989B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>hashchange is not fired when setting the same fragment</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 7 <script> 8 promise_test(async t => { 9 t.add_cleanup(() => history.replaceState(null, "", location.pathname + location.search)); 10 11 const first = new Promise(resolve => addEventListener("hashchange", resolve, { once: true })); 12 location.hash = "#foo"; 13 await first; 14 15 const secondHashchange = new Promise(resolve => { 16 addEventListener("hashchange", () => resolve("fired"), { once: true }); 17 }); 18 const timeout = new Promise(resolve => t.step_timeout(() => resolve("timeout"), 100)); 19 20 location.hash = "#foo"; 21 22 const result = await Promise.race([secondHashchange, timeout]); 23 assert_equals(result, "timeout", "hashchange must not fire when fragment does not change"); 24 }, "Setting the same location.hash twice must not fire hashchange the second time"); 25 </script>