content/base/test/test_bug587931.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug587931.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=587931
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 587931</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=587931">Mozilla Bug 587931</a>
    1.16 +<pre id="test">
    1.17 +<script type="application/javascript">
    1.18 +/** Test for Bug 587931 **/
    1.19 +SimpleTest.waitForExplicitFinish();
    1.20 +var afterCount = 0;
    1.21 +var lastBeforeExecute = null;
    1.22 +var expectedCurrentScriptInAfterScriptExecute = null;
    1.23 +function verifyScript(n) {
    1.24 +  var curr = document.currentScript;
    1.25 +  is(curr, document.getElementById(n), "correct script (" + n + ")");
    1.26 +  is(lastBeforeExecute, curr, "correct beforescript (" + n + ")");
    1.27 +  document.addEventListener("afterscriptexecute", function(event) {
    1.28 +    afterCount++;
    1.29 +    lastBeforeExecute = null;
    1.30 +    is(event.target, curr, "correct afterscript (" + n + ")");
    1.31 +    is(document.currentScript, expectedCurrentScriptInAfterScriptExecute,
    1.32 +       "document.currentScript in afterscriptexecute(" + n + ")");
    1.33 +    document.removeEventListener("afterscriptexecute", arguments.callee, false);
    1.34 +  }, false);
    1.35 +}
    1.36 +document.onbeforescriptexecute = function(event) {
    1.37 +  lastBeforeExecute = event.target;
    1.38 +};
    1.39 +
    1.40 +window.addEventListener("load", function() {
    1.41 +  is(afterCount, 4, "correct number of afterscriptexecute");
    1.42 +  SimpleTest.finish();
    1.43 +}, false);
    1.44 +</script>
    1.45 +</pre>
    1.46 +<!-- Test parser inserted scripts -->
    1.47 +<script id="parse-inline">
    1.48 +verifyScript("parse-inline");
    1.49 +</script>
    1.50 +<script id="parse-ext" src="data:text/plain,verifyScript('parse-ext');"></script>
    1.51 +
    1.52 +<!-- Test DOM inserted scripts -->
    1.53 +<script>
    1.54 +var s = document.createElement("script");
    1.55 +s.textContent = "verifyScript('dom-inline');";
    1.56 +s.id = "dom-inline";
    1.57 +expectedCurrentScriptInAfterScriptExecute = document.currentScript;
    1.58 +document.body.appendChild(s);
    1.59 +expectedCurrentScriptInAfterScriptExecute = null;
    1.60 +
    1.61 +s = document.createElement("script");
    1.62 +s.src = "data:text/plain,verifyScript('dom-ext');";
    1.63 +s.id = "dom-ext";
    1.64 +document.body.appendChild(s);
    1.65 +</script>
    1.66 +
    1.67 +<!-- Test cancel using beforescriptexecute -->
    1.68 +<script onbeforescriptexecute="return false;"
    1.69 +        onafterescriptexecute="window.firedAfterScriptExecuteForCancel = true;">
    1.70 +ok(false, "should have been canceled");
    1.71 +</script>
    1.72 +<script>
    1.73 +isnot(window.firedAfterScriptExecuteForCancel, true, "onafterscriptexecute executed");
    1.74 +</script>
    1.75 +
    1.76 +<!-- Test cancel using beforescriptexecute for external -->
    1.77 +<script onbeforescriptexecute="return false;"
    1.78 +        onafterescriptexecute="window.extFiredAfterScriptExecuteForCancel = true;"
    1.79 +        onload="window.extFiredLoadForCancel = true;"
    1.80 +        src="data:text/plain,ok(false, 'should have been canceled');">
    1.81 +</script>
    1.82 +<script>
    1.83 +isnot(window.extFiredAfterScriptExecuteForCancel, true, "onafterscriptexecute executed");
    1.84 +is(extFiredLoadForCancel, true, "onload executed");
    1.85 +</script>
    1.86 +
    1.87 +<!-- Test that all events fire -->
    1.88 +<script onbeforescriptexecute="window.beforeDidExecute = true;"
    1.89 +        onafterscriptexecute="window.afterDidExecute = true;"
    1.90 +        onload="window.loadDidExecute = true"
    1.91 +        onerror="window.errorDidExecute = true"
    1.92 +        src="data:text/plain,
    1.93 +is(window.beforeDidExecute, true, 'onbeforescriptexecute executed');
    1.94 +isnot(window.afterDidExecute, true, 'onafterscriptexecute executed');
    1.95 +isnot(window.loadDidExecute, true, 'onload executed');
    1.96 +isnot(window.errorDidExecute, true, 'onerror executed');
    1.97 +">
    1.98 +</script>
    1.99 +<script>
   1.100 +is(afterDidExecute, true, "onafterscriptexecute executed");
   1.101 +is(loadDidExecute, true, "onload executed");
   1.102 +isnot(window.errorDidExecute, true, "onerror executed");
   1.103 +</script>
   1.104 +</body>
   1.105 +</html>

mercurial