beforeunload-synchronous.html (920B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>beforeunload event is emitted synchronously</title> 4 <link rel="help" href="https://html.spec.whatwg.org/multipage/webappapis.html#the-event-handler-processing-algorithm"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <body> 8 <script> 9 'use strict'; 10 // "navigate a browsing context" synchronously calls "prompt to unload", which 11 // synchronously calls "dispatch an event". 12 13 async_test(function(t) { 14 var iframe = document.createElement('iframe'); 15 16 iframe.onload = t.step_func(function() { 17 var callCount = 0; 18 19 iframe.contentWindow.onbeforeunload = function() { 20 callCount += 1; 21 }; 22 23 iframe.contentWindow.location.href = '/common/blank.html'; 24 25 assert_equals(callCount, 1, 'invoked synchronously exactly once'); 26 27 t.done(); 28 }); 29 30 document.body.appendChild(iframe); 31 }); 32 </script> 33 </body>