Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=587931 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 587931</title> |
michael@0 | 8 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=587931">Mozilla Bug 587931</a> |
michael@0 | 13 | <pre id="test"> |
michael@0 | 14 | <script type="application/javascript"> |
michael@0 | 15 | /** Test for Bug 587931 **/ |
michael@0 | 16 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 17 | var afterCount = 0; |
michael@0 | 18 | var lastBeforeExecute = null; |
michael@0 | 19 | var expectedCurrentScriptInAfterScriptExecute = null; |
michael@0 | 20 | function verifyScript(n) { |
michael@0 | 21 | var curr = document.currentScript; |
michael@0 | 22 | is(curr, document.getElementById(n), "correct script (" + n + ")"); |
michael@0 | 23 | is(lastBeforeExecute, curr, "correct beforescript (" + n + ")"); |
michael@0 | 24 | document.addEventListener("afterscriptexecute", function(event) { |
michael@0 | 25 | afterCount++; |
michael@0 | 26 | lastBeforeExecute = null; |
michael@0 | 27 | is(event.target, curr, "correct afterscript (" + n + ")"); |
michael@0 | 28 | is(document.currentScript, expectedCurrentScriptInAfterScriptExecute, |
michael@0 | 29 | "document.currentScript in afterscriptexecute(" + n + ")"); |
michael@0 | 30 | document.removeEventListener("afterscriptexecute", arguments.callee, false); |
michael@0 | 31 | }, false); |
michael@0 | 32 | } |
michael@0 | 33 | document.onbeforescriptexecute = function(event) { |
michael@0 | 34 | lastBeforeExecute = event.target; |
michael@0 | 35 | }; |
michael@0 | 36 | |
michael@0 | 37 | window.addEventListener("load", function() { |
michael@0 | 38 | is(afterCount, 4, "correct number of afterscriptexecute"); |
michael@0 | 39 | SimpleTest.finish(); |
michael@0 | 40 | }, false); |
michael@0 | 41 | </script> |
michael@0 | 42 | </pre> |
michael@0 | 43 | <!-- Test parser inserted scripts --> |
michael@0 | 44 | <script id="parse-inline"> |
michael@0 | 45 | verifyScript("parse-inline"); |
michael@0 | 46 | </script> |
michael@0 | 47 | <script id="parse-ext" src="data:text/plain,verifyScript('parse-ext');"></script> |
michael@0 | 48 | |
michael@0 | 49 | <!-- Test DOM inserted scripts --> |
michael@0 | 50 | <script> |
michael@0 | 51 | var s = document.createElement("script"); |
michael@0 | 52 | s.textContent = "verifyScript('dom-inline');"; |
michael@0 | 53 | s.id = "dom-inline"; |
michael@0 | 54 | expectedCurrentScriptInAfterScriptExecute = document.currentScript; |
michael@0 | 55 | document.body.appendChild(s); |
michael@0 | 56 | expectedCurrentScriptInAfterScriptExecute = null; |
michael@0 | 57 | |
michael@0 | 58 | s = document.createElement("script"); |
michael@0 | 59 | s.src = "data:text/plain,verifyScript('dom-ext');"; |
michael@0 | 60 | s.id = "dom-ext"; |
michael@0 | 61 | document.body.appendChild(s); |
michael@0 | 62 | </script> |
michael@0 | 63 | |
michael@0 | 64 | <!-- Test cancel using beforescriptexecute --> |
michael@0 | 65 | <script onbeforescriptexecute="return false;" |
michael@0 | 66 | onafterescriptexecute="window.firedAfterScriptExecuteForCancel = true;"> |
michael@0 | 67 | ok(false, "should have been canceled"); |
michael@0 | 68 | </script> |
michael@0 | 69 | <script> |
michael@0 | 70 | isnot(window.firedAfterScriptExecuteForCancel, true, "onafterscriptexecute executed"); |
michael@0 | 71 | </script> |
michael@0 | 72 | |
michael@0 | 73 | <!-- Test cancel using beforescriptexecute for external --> |
michael@0 | 74 | <script onbeforescriptexecute="return false;" |
michael@0 | 75 | onafterescriptexecute="window.extFiredAfterScriptExecuteForCancel = true;" |
michael@0 | 76 | onload="window.extFiredLoadForCancel = true;" |
michael@0 | 77 | src="data:text/plain,ok(false, 'should have been canceled');"> |
michael@0 | 78 | </script> |
michael@0 | 79 | <script> |
michael@0 | 80 | isnot(window.extFiredAfterScriptExecuteForCancel, true, "onafterscriptexecute executed"); |
michael@0 | 81 | is(extFiredLoadForCancel, true, "onload executed"); |
michael@0 | 82 | </script> |
michael@0 | 83 | |
michael@0 | 84 | <!-- Test that all events fire --> |
michael@0 | 85 | <script onbeforescriptexecute="window.beforeDidExecute = true;" |
michael@0 | 86 | onafterscriptexecute="window.afterDidExecute = true;" |
michael@0 | 87 | onload="window.loadDidExecute = true" |
michael@0 | 88 | onerror="window.errorDidExecute = true" |
michael@0 | 89 | src="data:text/plain, |
michael@0 | 90 | is(window.beforeDidExecute, true, 'onbeforescriptexecute executed'); |
michael@0 | 91 | isnot(window.afterDidExecute, true, 'onafterscriptexecute executed'); |
michael@0 | 92 | isnot(window.loadDidExecute, true, 'onload executed'); |
michael@0 | 93 | isnot(window.errorDidExecute, true, 'onerror executed'); |
michael@0 | 94 | "> |
michael@0 | 95 | </script> |
michael@0 | 96 | <script> |
michael@0 | 97 | is(afterDidExecute, true, "onafterscriptexecute executed"); |
michael@0 | 98 | is(loadDidExecute, true, "onload executed"); |
michael@0 | 99 | isnot(window.errorDidExecute, true, "onerror executed"); |
michael@0 | 100 | </script> |
michael@0 | 101 | </body> |
michael@0 | 102 | </html> |