content/base/test/test_bug372964.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

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=372964
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 372964</title>
michael@0 8 <script type="text/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=372964">Mozilla Bug 372964</a>
michael@0 13 <p id="display"></p>
michael@0 14 <div id="content" style="display: none">
michael@0 15
michael@0 16 </div>
michael@0 17 <pre id="test">
michael@0 18 <script class="testbody" type="text/javascript">
michael@0 19
michael@0 20 /** Test for Bug 372964 **/
michael@0 21
michael@0 22 var expectedEventType = "";
michael@0 23 var shouldBeTrusted = false;
michael@0 24 var eventHandlerCallCount = 0;
michael@0 25
michael@0 26 function eventHandler(evt) {
michael@0 27 ++eventHandlerCallCount;
michael@0 28 is(evt.type, expectedEventType, "Wrong event type");
michael@0 29 is(evt.isTrusted, shouldBeTrusted, "Wrong .isTrusted");
michael@0 30 }
michael@0 31
michael@0 32 function test(trusted, type, removeAddedListener, removeSetListener, allowUntrusted) {
michael@0 33 if (trusted) {
michael@0 34 var x1 = SpecialPowers.wrap(new XMLHttpRequest());
michael@0 35 } else {
michael@0 36 x1 = new XMLHttpRequest();
michael@0 37 }
michael@0 38
michael@0 39 var handlerCount = 0;
michael@0 40 if (trusted || allowUntrusted || allowUntrusted == undefined) {
michael@0 41 ++handlerCount;
michael@0 42 }
michael@0 43
michael@0 44 if (allowUntrusted == undefined) {
michael@0 45 // Test .addEventListener with 3 parameters.
michael@0 46 x1.addEventListener(type, eventHandler, false);
michael@0 47 } else {
michael@0 48 // Test .addEventListener with 4 parameters.
michael@0 49 x1.addEventListener(type, eventHandler, false, allowUntrusted);
michael@0 50 }
michael@0 51
michael@0 52 if (("on" + type) in x1) {
michael@0 53 ++handlerCount;
michael@0 54 x1["on" + type] = eventHandler;
michael@0 55 }
michael@0 56
michael@0 57 if (removeAddedListener) {
michael@0 58 x1.removeEventListener(type, eventHandler, false);
michael@0 59 if (trusted || allowUntrusted || allowUntrusted == undefined) {
michael@0 60 --handlerCount;
michael@0 61 }
michael@0 62 }
michael@0 63
michael@0 64 if (removeSetListener) {
michael@0 65 if (("on" + type) in x1) {
michael@0 66 --handlerCount;
michael@0 67 x1["on" + type] = null;
michael@0 68 }
michael@0 69 }
michael@0 70
michael@0 71 var e1 = document.createEvent("Events");
michael@0 72 e1.initEvent(type, true, true);
michael@0 73 expectedEventType = type;
michael@0 74 shouldBeTrusted = trusted;
michael@0 75 var ecc = eventHandlerCallCount;
michael@0 76 x1.dispatchEvent(e1);
michael@0 77 is(eventHandlerCallCount, ecc + handlerCount,
michael@0 78 "Wrong number event handler calls. (1)");
michael@0 79
michael@0 80 e1 = document.createEvent("Events");
michael@0 81 e1.initEvent(type, true, true);
michael@0 82 expectedEventType = type;
michael@0 83 // Set trusted since open() may cause events to be sent.
michael@0 84 shouldBeTrusted = true;
michael@0 85 x1.open("GET", window.location);
michael@0 86 x1.abort(); // This should not remove event listeners.
michael@0 87 ecc = eventHandlerCallCount;
michael@0 88 shouldBeTrusted = trusted;
michael@0 89 x1.dispatchEvent(e1);
michael@0 90 is(eventHandlerCallCount, ecc + handlerCount,
michael@0 91 "Wrong number event handler calls. (2)");
michael@0 92
michael@0 93 e1 = document.createEvent("Events");
michael@0 94 e1.initEvent(type, true, true);
michael@0 95 expectedEventType = type;
michael@0 96 // Set trusted since open()/send() may cause events to be sent.
michael@0 97 shouldBeTrusted = true;
michael@0 98 x1.open("GET", window.location);
michael@0 99 x1.send("");
michael@0 100 x1.abort(); // This should not remove event listeners!
michael@0 101 ecc = eventHandlerCallCount;
michael@0 102 shouldBeTrusted = trusted;
michael@0 103 x1.dispatchEvent(e1);
michael@0 104 is(eventHandlerCallCount, ecc + handlerCount,
michael@0 105 "Wrong number event handler calls. (3)");
michael@0 106 }
michael@0 107
michael@0 108 var events =
michael@0 109 ["load", "error", "progress", "readystatechange", "foo"];
michael@0 110
michael@0 111 do {
michael@0 112 var e = events.shift();
michael@0 113 test(false, e, false, false);
michael@0 114 test(false, e, false, true);
michael@0 115 test(false, e, true, false);
michael@0 116 test(false, e, true, true);
michael@0 117 test(true, e, false, false);
michael@0 118 test(true, e, false, true);
michael@0 119 test(true, e, true, false);
michael@0 120 test(true, e, true, true);
michael@0 121
michael@0 122 test(false, e, false, false, false);
michael@0 123 test(false, e, false, false, true);
michael@0 124 test(false, e, false, true, false);
michael@0 125 test(false, e, false, true, true);
michael@0 126 test(false, e, true, false, false);
michael@0 127 test(false, e, true, false, true);
michael@0 128 test(false, e, true, true, false);
michael@0 129 test(false, e, true, true, true);
michael@0 130 test(true, e, false, false, false);
michael@0 131 test(true, e, false, false, true);
michael@0 132 test(true, e, false, true, false);
michael@0 133 test(true, e, false, true, true);
michael@0 134 test(true, e, true, false, false);
michael@0 135 test(true, e, true, false, true);
michael@0 136 test(true, e, true, true, false);
michael@0 137 test(true, e, true, true, true);
michael@0 138 } while(events.length);
michael@0 139
michael@0 140 </script>
michael@0 141 </pre>
michael@0 142 </body>
michael@0 143 </html>
michael@0 144

mercurial