browser/base/content/test/general/browser_unloaddialogs.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_unloaddialogs.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,73 @@
     1.4 +var testUrls =
     1.5 +  [
     1.6 +    "data:text/html,<script>" +
     1.7 +      "function handle(evt) {" +
     1.8 +        "evt.target.removeEventListener(evt.type, handle, true);" +
     1.9 +        "try { alert('This should NOT appear'); } catch(e) { }" +
    1.10 +      "}" +
    1.11 +      "window.addEventListener('pagehide', handle, true);" +
    1.12 +      "window.addEventListener('beforeunload', handle, true);" +
    1.13 +      "window.addEventListener('unload', handle, true);" +
    1.14 +      "</script><body>Testing alert during pagehide/beforeunload/unload</body>",
    1.15 +    "data:text/html,<script>" +
    1.16 +      "function handle(evt) {" +
    1.17 +        "evt.target.removeEventListener(evt.type, handle, true);" +
    1.18 +        "try { prompt('This should NOT appear'); } catch(e) { }" +
    1.19 +      "}" +
    1.20 +      "window.addEventListener('pagehide', handle, true);" +
    1.21 +      "window.addEventListener('beforeunload', handle, true);" +
    1.22 +      "window.addEventListener('unload', handle, true);" +
    1.23 +      "</script><body>Testing prompt during pagehide/beforeunload/unload</body>",
    1.24 +    "data:text/html,<script>" +
    1.25 +      "function handle(evt) {" +
    1.26 +        "evt.target.removeEventListener(evt.type, handle, true);" +
    1.27 +        "try { confirm('This should NOT appear'); } catch(e) { }" +
    1.28 +      "}" +
    1.29 +      "window.addEventListener('pagehide', handle, true);" +
    1.30 +      "window.addEventListener('beforeunload', handle, true);" +
    1.31 +      "window.addEventListener('unload', handle, true);" +
    1.32 +      "</script><body>Testing confirm during pagehide/beforeunload/unload</body>",
    1.33 +  ];
    1.34 +var testsDone = 0;
    1.35 +
    1.36 +function test()
    1.37 +{
    1.38 +  waitForExplicitFinish();
    1.39 +  runTest();
    1.40 +}
    1.41 +
    1.42 +function runTest()
    1.43 +{
    1.44 +  whenNewTabLoaded(window, function() {
    1.45 +    gBrowser.selectedBrowser.addEventListener("load", onLoad, true);
    1.46 +    executeSoon(function() {
    1.47 +      info("Loading page with pagehide, beforeunload, and unload handlers that attempt to create dialogs");
    1.48 +      gBrowser.selectedBrowser.loadURI(testUrls[testsDone]);
    1.49 +    });
    1.50 +  });
    1.51 +}
    1.52 +
    1.53 +function onLoad(event)
    1.54 +{
    1.55 +  info("Page loaded");
    1.56 +
    1.57 +  event.target.removeEventListener("load", onLoad, true);
    1.58 +  gBrowser.selectedBrowser.addEventListener("unload", done, true);
    1.59 +
    1.60 +  executeSoon(function () {
    1.61 +    info("Closing page");
    1.62 +    gBrowser.removeCurrentTab();
    1.63 +  });
    1.64 +}
    1.65 +
    1.66 +function done() {
    1.67 +  ok(true, "Page closed (hopefully) without timeout");
    1.68 +
    1.69 +  testsDone++;
    1.70 +  if (testsDone == testUrls.length) {
    1.71 +    finish();
    1.72 +    return;
    1.73 +  }
    1.74 +
    1.75 +  executeSoon(runTest);
    1.76 +}

mercurial