tor-browser

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

browser_unloaddialogs.js (1799B)


      1 var testUrls = [
      2  "data:text/html,<script>" +
      3    "function handle(evt) {" +
      4    "evt.target.removeEventListener(evt.type, handle, true);" +
      5    "try { alert('This should NOT appear'); } catch(e) { }" +
      6    "}" +
      7    "window.addEventListener('pagehide', handle, true);" +
      8    "window.addEventListener('beforeunload', handle, true);" +
      9    "window.addEventListener('unload', handle, true);" +
     10    "</script><body>Testing alert during pagehide/beforeunload/unload</body>",
     11  "data:text/html,<script>" +
     12    "function handle(evt) {" +
     13    "evt.target.removeEventListener(evt.type, handle, true);" +
     14    "try { prompt('This should NOT appear'); } catch(e) { }" +
     15    "}" +
     16    "window.addEventListener('pagehide', handle, true);" +
     17    "window.addEventListener('beforeunload', handle, true);" +
     18    "window.addEventListener('unload', handle, true);" +
     19    "</script><body>Testing prompt during pagehide/beforeunload/unload</body>",
     20  "data:text/html,<script>" +
     21    "function handle(evt) {" +
     22    "evt.target.removeEventListener(evt.type, handle, true);" +
     23    "try { confirm('This should NOT appear'); } catch(e) { }" +
     24    "}" +
     25    "window.addEventListener('pagehide', handle, true);" +
     26    "window.addEventListener('beforeunload', handle, true);" +
     27    "window.addEventListener('unload', handle, true);" +
     28    "</script><body>Testing confirm during pagehide/beforeunload/unload</body>",
     29 ];
     30 
     31 add_task(async function () {
     32  for (let url of testUrls) {
     33    let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
     34    ok(true, "Loaded page " + url);
     35    // Wait one turn of the event loop before closing, so everything settles.
     36    await new Promise(resolve => setTimeout(resolve, 0));
     37    BrowserTestUtils.removeTab(tab);
     38    ok(true, "Closed page " + url + " without timeout");
     39  }
     40 });