1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/test/test_bug369814.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,222 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=369814 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 369814</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=384014">Mozilla Bug 369814</a> 1.17 + 1.18 +<p> 1.19 + 1.20 +<pre id="test"> 1.21 +<script class="testbody" type="text/javascript"> 1.22 + 1.23 +/** Tests for Bug 369814 **/ 1.24 + 1.25 +SimpleTest.waitForExplicitFinish(); 1.26 + 1.27 +// Because child scripts won't be able to run to tell us they're done, 1.28 +// we need to just wait for them. Wait this many event loop spins before 1.29 +// checking the results. 1.30 +const gLoadEventLoopCount = 100; 1.31 + 1.32 +var gCurrentTest; 1.33 +var gTargetWindow; 1.34 +var gNumPokes; 1.35 +var gTestFrame; 1.36 + 1.37 +/** 1.38 + * Called by documents loaded from jar files to indicate that they can access 1.39 + * this document. 1.40 + */ 1.41 +function poke(description) { 1.42 + ok(false, gCurrentTest['name'] + ": got unexpected poke: " + description); 1.43 + gNumPokes++; 1.44 +} 1.45 + 1.46 +function loadEvent(window, callback) 1.47 +{ 1.48 + var fn = function() { 1.49 + window.removeEventListener("load", fn, false); 1.50 + callback(); 1.51 + }; 1.52 + window.addEventListener("load", fn, false); 1.53 +} 1.54 + 1.55 +function loadTestTarget(callback) 1.56 +{ 1.57 + gTargetWindow = window.open("http://mochi.test:8888", "bug369814target"); 1.58 + loadEvent(gTargetWindow, callback); 1.59 +} 1.60 + 1.61 +function closeTestTarget() 1.62 +{ 1.63 + gTargetWindow.close(); 1.64 + gTargetWindow = null; 1.65 +} 1.66 + 1.67 +function loadErrorTest(test) 1.68 +{ 1.69 + // Give the frame a chance to fail at loading. 1.70 + // How do detect failure to load? Error pages don't fire load 1.71 + // events. But we can load another page before the error page and 1.72 + // then use its unload handler to know when the error page is just 1.73 + // about loaded; at that point a single trip through the event loop 1.74 + // should do the trick. 1.75 + loadEvent(gTestFrame, function() { 1.76 + gTestFrame.src = test['url']; 1.77 + }); 1.78 + gTestFrame.unloading = function() { 1.79 + gTestFrame.unloading = null; 1.80 + // Go out to the event loop once so that unload processing finishes and 1.81 + // the new document is set up. 1.82 + setTimeout(function() { 1.83 + // XXX: There doesn't seem to be a reliable check for "got an error," 1.84 + // but reaching in to an error document will throw an exception 1.85 + var errorPage; 1.86 + try { 1.87 + var item = gTestFrame.contentDocument.getElementById(gCurrentTest['data-iframe']); 1.88 + errorPage = false; 1.89 + } catch (e) { 1.90 + errorPage = true; 1.91 + } 1.92 + ok(errorPage, gCurrentTest["name"] + ": should block a suspicious JAR load."); 1.93 + 1.94 + finishTest(); 1.95 + }, 0); 1.96 + } 1.97 + var unloadDetector = "data:text/html,<script>window.onunload = function() { frameElement.unloading(); }</" + "script>"; 1.98 + gTestFrame.src = unloadDetector; 1.99 +} 1.100 + 1.101 +function iframeTest(test) { 1.102 + gTestFrame.src = test['url']; 1.103 + loadEvent(gTestFrame, function() { 1.104 + finishTest(); 1.105 + }); 1.106 +} 1.107 + 1.108 + 1.109 +function hitEventLoop(func, times) { 1.110 + if (times > 0) { 1.111 + SimpleTest.executeSoon(function() { hitEventLoop(func, times-1); }); 1.112 + } else { 1.113 + SimpleTest.executeSoon(func); 1.114 + } 1.115 +} 1.116 + 1.117 +function refreshTest(test) { 1.118 + gTestFrame.src = test['url']; 1.119 + loadEvent(gTestFrame, function() { 1.120 + // Wait for the frame to try and refresh 1.121 + // XXX: a "blocked redirect" signal would be needed to get rid of 1.122 + // this timeout. 1.123 + hitEventLoop(function() { 1.124 + finishTest(); 1.125 + }, gLoadEventLoopCount); 1.126 + }); 1.127 +} 1.128 + 1.129 +function anchorTest(test) { 1.130 + loadTestTarget(function() { 1.131 + gTestFrame.src = test['url']; 1.132 + loadEvent(gTestFrame, function() { 1.133 + sendMouseEvent({type:'click'}, 'target', gTestFrame.contentWindow); 1.134 + sendMouseEvent({type:'click'}, 'notarget', gTestFrame.contentWindow); 1.135 + 1.136 + // Give the clicks a chance to load 1.137 + hitEventLoop(function() { 1.138 + closeTestTarget(); 1.139 + finishTest(); 1.140 + }, gLoadEventLoopCount); 1.141 + }); 1.142 + }); 1.143 +} 1.144 + 1.145 +var gTests = [ 1.146 + { "name" : "iframes.html loaded from non-jar type, pref disabled", 1.147 + "url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/iframes.html", 1.148 + "pref" : false, 1.149 + "pokes" : { }, 1.150 + "func" : loadErrorTest, 1.151 + }, 1.152 + { "name" : "refresh.html loaded from non-jar type, pref enabled", 1.153 + "url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/refresh.html", 1.154 + "pref" : true, 1.155 + "pokes" : { }, 1.156 + "func" : refreshTest, 1.157 + }, 1.158 + { "name" : "iframes.html loaded from non-jar type, pref enabled", 1.159 + "url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/iframes.html", 1.160 + "pref" : true, 1.161 + "pokes" : { }, 1.162 + "func" : iframeTest, 1.163 + }, 1.164 + { "name" : "anchors.html loaded from non-jar type, pref enabled", 1.165 + "url" : "jar:http://mochi.test:8888/tests/docshell/test/bug369814.zip!/anchors.html", 1.166 + "pref" : true, 1.167 + "pokes" : { }, 1.168 + "func" : anchorTest, 1.169 + }, 1.170 + { "name" : "iframes.html loaded from view-source jar type, pref disabled", 1.171 + "url" : "jar:view-source:http://mochi.test:8888/tests/docshell/test/bug369814.jar!/iframes.html", 1.172 + "pref" : false, 1.173 + "pokes" : { }, 1.174 + "func" : loadErrorTest 1.175 + }, 1.176 + { "name" : "iframes.html loaded from view-source jar type, pref enabled", 1.177 + "url" : "jar:view-source:http://mochi.test:8888/tests/docshell/test/bug369814.jar!/iframes.html", 1.178 + "pref" : true, 1.179 + "pokes" : { }, 1.180 + "func" : loadErrorTest 1.181 + }, 1.182 +]; 1.183 + 1.184 +var gNextTest = 0; 1.185 + 1.186 +function runNextTest() 1.187 +{ 1.188 + if (gNextTest < gTests.length) { 1.189 + gCurrentTest = gTests[gNextTest++]; 1.190 + gNumPokes = 0; 1.191 + 1.192 + SpecialPowers.pushPrefEnv({"set": [["network.jar.open-unsafe-types", gCurrentTest['pref']]]}, function() { 1.193 + 1.194 + // Create a new frame each time, so our restictions on loads in a 1.195 + // jar:-loaded iframe don't interfere with the test. 1.196 + if (gTestFrame) { 1.197 + document.body.removeChild(gTestFrame); 1.198 + } 1.199 + gTestFrame = document.createElement("iframe"); 1.200 + document.body.insertBefore(gTestFrame, $("test")); 1.201 + 1.202 + gCurrentTest['func'](gCurrentTest); 1.203 + }); 1.204 + } else { 1.205 + SimpleTest.finish(); 1.206 + } 1.207 +} 1.208 + 1.209 +function finishTest() 1.210 +{ 1.211 + SpecialPowers.pushPrefEnv({"set": [["network.jar.open-unsafe-types", false]]}, function() { 1.212 + if (gNumPokes == 0) { 1.213 + ok(true, gCurrentTest["name"] + ": no unexpected pokes"); 1.214 + } 1.215 + 1.216 + runNextTest(); 1.217 + }); 1.218 +} 1.219 + 1.220 +addLoadEvent(runNextTest); 1.221 + 1.222 +</script> 1.223 +</pre> 1.224 +</body> 1.225 +</html>