docshell/test/test_bug369814.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=369814
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 369814</title>
michael@0 8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=384014">Mozilla Bug 369814</a>
michael@0 14
michael@0 15 <p>
michael@0 16
michael@0 17 <pre id="test">
michael@0 18 <script class="testbody" type="text/javascript">
michael@0 19
michael@0 20 /** Tests for Bug 369814 **/
michael@0 21
michael@0 22 SimpleTest.waitForExplicitFinish();
michael@0 23
michael@0 24 // Because child scripts won't be able to run to tell us they're done,
michael@0 25 // we need to just wait for them. Wait this many event loop spins before
michael@0 26 // checking the results.
michael@0 27 const gLoadEventLoopCount = 100;
michael@0 28
michael@0 29 var gCurrentTest;
michael@0 30 var gTargetWindow;
michael@0 31 var gNumPokes;
michael@0 32 var gTestFrame;
michael@0 33
michael@0 34 /**
michael@0 35 * Called by documents loaded from jar files to indicate that they can access
michael@0 36 * this document.
michael@0 37 */
michael@0 38 function poke(description) {
michael@0 39 ok(false, gCurrentTest['name'] + ": got unexpected poke: " + description);
michael@0 40 gNumPokes++;
michael@0 41 }
michael@0 42
michael@0 43 function loadEvent(window, callback)
michael@0 44 {
michael@0 45 var fn = function() {
michael@0 46 window.removeEventListener("load", fn, false);
michael@0 47 callback();
michael@0 48 };
michael@0 49 window.addEventListener("load", fn, false);
michael@0 50 }
michael@0 51
michael@0 52 function loadTestTarget(callback)
michael@0 53 {
michael@0 54 gTargetWindow = window.open("http://mochi.test:8888", "bug369814target");
michael@0 55 loadEvent(gTargetWindow, callback);
michael@0 56 }
michael@0 57
michael@0 58 function closeTestTarget()
michael@0 59 {
michael@0 60 gTargetWindow.close();
michael@0 61 gTargetWindow = null;
michael@0 62 }
michael@0 63
michael@0 64 function loadErrorTest(test)
michael@0 65 {
michael@0 66 // Give the frame a chance to fail at loading.
michael@0 67 // How do detect failure to load? Error pages don't fire load
michael@0 68 // events. But we can load another page before the error page and
michael@0 69 // then use its unload handler to know when the error page is just
michael@0 70 // about loaded; at that point a single trip through the event loop
michael@0 71 // should do the trick.
michael@0 72 loadEvent(gTestFrame, function() {
michael@0 73 gTestFrame.src = test['url'];
michael@0 74 });
michael@0 75 gTestFrame.unloading = function() {
michael@0 76 gTestFrame.unloading = null;
michael@0 77 // Go out to the event loop once so that unload processing finishes and
michael@0 78 // the new document is set up.
michael@0 79 setTimeout(function() {
michael@0 80 // XXX: There doesn't seem to be a reliable check for "got an error,"
michael@0 81 // but reaching in to an error document will throw an exception
michael@0 82 var errorPage;
michael@0 83 try {
michael@0 84 var item = gTestFrame.contentDocument.getElementById(gCurrentTest['data-iframe']);
michael@0 85 errorPage = false;
michael@0 86 } catch (e) {
michael@0 87 errorPage = true;
michael@0 88 }
michael@0 89 ok(errorPage, gCurrentTest["name"] + ": should block a suspicious JAR load.");
michael@0 90
michael@0 91 finishTest();
michael@0 92 }, 0);
michael@0 93 }
michael@0 94 var unloadDetector = "data:text/html,<script>window.onunload = function() { frameElement.unloading(); }</" + "script>";
michael@0 95 gTestFrame.src = unloadDetector;
michael@0 96 }
michael@0 97
michael@0 98 function iframeTest(test) {
michael@0 99 gTestFrame.src = test['url'];
michael@0 100 loadEvent(gTestFrame, function() {
michael@0 101 finishTest();
michael@0 102 });
michael@0 103 }
michael@0 104
michael@0 105
michael@0 106 function hitEventLoop(func, times) {
michael@0 107 if (times > 0) {
michael@0 108 SimpleTest.executeSoon(function() { hitEventLoop(func, times-1); });
michael@0 109 } else {
michael@0 110 SimpleTest.executeSoon(func);
michael@0 111 }
michael@0 112 }
michael@0 113
michael@0 114 function refreshTest(test) {
michael@0 115 gTestFrame.src = test['url'];
michael@0 116 loadEvent(gTestFrame, function() {
michael@0 117 // Wait for the frame to try and refresh
michael@0 118 // XXX: a "blocked redirect" signal would be needed to get rid of
michael@0 119 // this timeout.
michael@0 120 hitEventLoop(function() {
michael@0 121 finishTest();
michael@0 122 }, gLoadEventLoopCount);
michael@0 123 });
michael@0 124 }
michael@0 125
michael@0 126 function anchorTest(test) {
michael@0 127 loadTestTarget(function() {
michael@0 128 gTestFrame.src = test['url'];
michael@0 129 loadEvent(gTestFrame, function() {
michael@0 130 sendMouseEvent({type:'click'}, 'target', gTestFrame.contentWindow);
michael@0 131 sendMouseEvent({type:'click'}, 'notarget', gTestFrame.contentWindow);
michael@0 132
michael@0 133 // Give the clicks a chance to load
michael@0 134 hitEventLoop(function() {
michael@0 135 closeTestTarget();
michael@0 136 finishTest();
michael@0 137 }, gLoadEventLoopCount);
michael@0 138 });
michael@0 139 });
michael@0 140 }
michael@0 141
michael@0 142 var gTests = [
michael@0 143 { "name" : "iframes.html loaded from non-jar type, pref disabled",
michael@0 144 "url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/iframes.html",
michael@0 145 "pref" : false,
michael@0 146 "pokes" : { },
michael@0 147 "func" : loadErrorTest,
michael@0 148 },
michael@0 149 { "name" : "refresh.html loaded from non-jar type, pref enabled",
michael@0 150 "url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/refresh.html",
michael@0 151 "pref" : true,
michael@0 152 "pokes" : { },
michael@0 153 "func" : refreshTest,
michael@0 154 },
michael@0 155 { "name" : "iframes.html loaded from non-jar type, pref enabled",
michael@0 156 "url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/iframes.html",
michael@0 157 "pref" : true,
michael@0 158 "pokes" : { },
michael@0 159 "func" : iframeTest,
michael@0 160 },
michael@0 161 { "name" : "anchors.html loaded from non-jar type, pref enabled",
michael@0 162 "url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/anchors.html",
michael@0 163 "pref" : true,
michael@0 164 "pokes" : { },
michael@0 165 "func" : anchorTest,
michael@0 166 },
michael@0 167 { "name" : "iframes.html loaded from view-source jar type, pref disabled",
michael@0 168 "url" : "jar:view-source:http://mochi.test:8888/tests/docshell/test/bug369814.jar!/iframes.html",
michael@0 169 "pref" : false,
michael@0 170 "pokes" : { },
michael@0 171 "func" : loadErrorTest
michael@0 172 },
michael@0 173 { "name" : "iframes.html loaded from view-source jar type, pref enabled",
michael@0 174 "url" : "jar:view-source:http://mochi.test:8888/tests/docshell/test/bug369814.jar!/iframes.html",
michael@0 175 "pref" : true,
michael@0 176 "pokes" : { },
michael@0 177 "func" : loadErrorTest
michael@0 178 },
michael@0 179 ];
michael@0 180
michael@0 181 var gNextTest = 0;
michael@0 182
michael@0 183 function runNextTest()
michael@0 184 {
michael@0 185 if (gNextTest < gTests.length) {
michael@0 186 gCurrentTest = gTests[gNextTest++];
michael@0 187 gNumPokes = 0;
michael@0 188
michael@0 189 SpecialPowers.pushPrefEnv({"set": [["network.jar.open-unsafe-types", gCurrentTest['pref']]]}, function() {
michael@0 190
michael@0 191 // Create a new frame each time, so our restictions on loads in a
michael@0 192 // jar:-loaded iframe don't interfere with the test.
michael@0 193 if (gTestFrame) {
michael@0 194 document.body.removeChild(gTestFrame);
michael@0 195 }
michael@0 196 gTestFrame = document.createElement("iframe");
michael@0 197 document.body.insertBefore(gTestFrame, $("test"));
michael@0 198
michael@0 199 gCurrentTest['func'](gCurrentTest);
michael@0 200 });
michael@0 201 } else {
michael@0 202 SimpleTest.finish();
michael@0 203 }
michael@0 204 }
michael@0 205
michael@0 206 function finishTest()
michael@0 207 {
michael@0 208 SpecialPowers.pushPrefEnv({"set": [["network.jar.open-unsafe-types", false]]}, function() {
michael@0 209 if (gNumPokes == 0) {
michael@0 210 ok(true, gCurrentTest["name"] + ": no unexpected pokes");
michael@0 211 }
michael@0 212
michael@0 213 runNextTest();
michael@0 214 });
michael@0 215 }
michael@0 216
michael@0 217 addLoadEvent(runNextTest);
michael@0 218
michael@0 219 </script>
michael@0 220 </pre>
michael@0 221 </body>
michael@0 222 </html>

mercurial