docshell/test/iframesandbox/test_top_navigation_by_location_exotic.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=785310
michael@0 5 html5 sandboxed iframe should not be able to perform top navigation with scripts allowed
michael@0 6 -->
michael@0 7 <head>
michael@0 8 <meta charset="utf-8">
michael@0 9 <title>Test for Bug 785310 - iframe sandbox top navigation by location via exotic means tests</title>
michael@0 10 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 12 <script>
michael@0 13 SimpleTest.waitForExplicitFinish();
michael@0 14
michael@0 15 var testWin;
michael@0 16
michael@0 17 function runScriptNavigationTest(testCase) {
michael@0 18 window.onmessage = function(event) {
michael@0 19 if (event.data.name != 'newWindow') {
michael@0 20 ok(false, "event.data.name: got '" + event.data.name + "', expected 'newWindow'");
michael@0 21 }
michael@0 22 var diag = "top navigation was " + (event.data.blocked ? "" : "NOT ") + "blocked";
michael@0 23 ok((testCase.shouldBeBlocked == event.data.blocked), testCase.desc, diag);
michael@0 24 runNextTest();
michael@0 25 };
michael@0 26 try {
michael@0 27 testWin[testCase.iframeName].eval(testCase.script);
michael@0 28 } catch(e) {
michael@0 29 ok(testCase.shouldBeBlocked, testCase.desc, e.message);
michael@0 30 runNextTest();
michael@0 31 }
michael@0 32 }
michael@0 33
michael@0 34 var testCaseIndex = -1;
michael@0 35 testCases = [
michael@0 36 {
michael@0 37 desc: "Test 1: location.replace.call(top.location, ...) should be blocked when sandboxed without allow-top-navigation",
michael@0 38 script: "location.replace.call(top.location, 'file_top_navigation_by_location_exotic.html')",
michael@0 39 iframeName: "if1",
michael@0 40 shouldBeBlocked: true
michael@0 41 },
michael@0 42 {
michael@0 43 desc: "Test 2: location.replace.bind(top.location, ...) should be blocked when sandboxed without allow-top-navigation",
michael@0 44 script: "location.replace.bind(top.location, 'file_top_navigation_by_location_exotic.html')()",
michael@0 45 iframeName: "if1",
michael@0 46 shouldBeBlocked: true
michael@0 47 },
michael@0 48 {
michael@0 49 desc: "Test 3: Function.bind.call(location.replace, top.location, ...) should be blocked when sandboxed without allow-top-navigation",
michael@0 50 script: "Function.bind.call(location.replace, top.location, 'file_top_navigation_by_location_exotic.html')()",
michael@0 51 iframeName: "if1",
michael@0 52 shouldBeBlocked: true
michael@0 53 },
michael@0 54 {
michael@0 55 desc: "Test 4: location.replace.call(top.location, ...) should NOT be blocked when sandboxed with allow-top-navigation",
michael@0 56 script: "location.replace.call(top.location, 'file_top_navigation_by_location_exotic.html')",
michael@0 57 iframeName: "if2",
michael@0 58 shouldBeBlocked: false
michael@0 59 },
michael@0 60 {
michael@0 61 desc: "Test 5: location.replace.bind(top.location, ...) should NOT be blocked when sandboxed with allow-top-navigation",
michael@0 62 script: "location.replace.bind(top.location, 'file_top_navigation_by_location_exotic.html')()",
michael@0 63 iframeName: "if2",
michael@0 64 shouldBeBlocked: false
michael@0 65 },
michael@0 66 {
michael@0 67 desc: "Test 6: Function.bind.call(location.replace, top.location, ...) should NOT be blocked when sandboxed with allow-top-navigation",
michael@0 68 script: "Function.bind.call(location.replace, top.location, 'file_top_navigation_by_location_exotic.html')()",
michael@0 69 iframeName: "if2",
michael@0 70 shouldBeBlocked: false
michael@0 71 },
michael@0 72 {
michael@0 73 desc: "Test 7: top.location.href, via setTimeout, should be blocked when sandboxed without allow-top-navigation",
michael@0 74 script: "setTimeout(function() { try { top.location.href = 'file_top_navigation_by_location_exotic.html' } catch (e) { top.onBlock() } }, 0)",
michael@0 75 iframeName: "if1",
michael@0 76 shouldBeBlocked: true
michael@0 77 },
michael@0 78 {
michael@0 79 desc: "Test 8: top.location.href, via setTimeout, should NOT be blocked when sandboxed with allow-top-navigation",
michael@0 80 script: "setTimeout(function() { try { top.location.href = 'file_top_navigation_by_location_exotic.html' } catch(e) { top.onBlock() } }, 0)",
michael@0 81 iframeName: "if2",
michael@0 82 shouldBeBlocked: false
michael@0 83 },
michael@0 84 {
michael@0 85 desc: "Test 9: top.location.href, via eval, should be blocked when sandboxed without allow-top-navigation",
michael@0 86 script: "eval('top.location.href = \"file_top_navigation_by_location_exotic.html\"')",
michael@0 87 iframeName: "if1",
michael@0 88 shouldBeBlocked: true
michael@0 89 },
michael@0 90 {
michael@0 91 desc: "Test 10: top.location.href, via eval, should NOT be blocked when sandboxed with allow-top-navigation",
michael@0 92 script: "eval('top.location.href = \"file_top_navigation_by_location_exotic.html\"')",
michael@0 93 iframeName: "if2",
michael@0 94 shouldBeBlocked: false
michael@0 95 },
michael@0 96 {
michael@0 97 desc: "Test 11: top.location.href, via anonymous function, should be blocked when sandboxed without allow-top-navigation",
michael@0 98 script: "(function() { top.location.href = 'file_top_navigation_by_location_exotic.html' })()",
michael@0 99 iframeName: "if1",
michael@0 100 shouldBeBlocked: true
michael@0 101 },
michael@0 102 {
michael@0 103 desc: "Test 12: top.location.href, via anonymous function, should NOT be blocked when sandboxed with allow-top-navigation",
michael@0 104 script: "(function() { top.location.href = 'file_top_navigation_by_location_exotic.html' })()",
michael@0 105 iframeName: "if2",
michael@0 106 shouldBeBlocked: false
michael@0 107 },
michael@0 108 {
michael@0 109 desc: "Test 13: top.location.href, via function inserted in top, should be blocked when sandboxed without allow-top-navigation",
michael@0 110 script: "top.doTest = function() { top.location.href = 'file_top_navigation_by_location_exotic.html' }; top.doTest();",
michael@0 111 iframeName: "if1",
michael@0 112 shouldBeBlocked: true
michael@0 113 },
michael@0 114 {
michael@0 115 desc: "Test 14: top.location.href, via function inserted in top, should NOT be blocked when sandboxed with allow-top-navigation",
michael@0 116 script: "top.doTest = function() { top.location.href = 'file_top_navigation_by_location_exotic.html' }; top.doTest();",
michael@0 117 iframeName: "if2",
michael@0 118 shouldBeBlocked: false
michael@0 119 },
michael@0 120 {
michael@0 121 desc: "Test 15: top.location.href, via function inserted in us by top, should NOT be blocked when sandboxed without allow-top-navigation",
michael@0 122 script: "top.eval('window[\"if1\"].doTest = function() { top.location.href = \"file_top_navigation_by_location_exotic.html\" };'), doTest();",
michael@0 123 iframeName: "if1",
michael@0 124 shouldBeBlocked: false
michael@0 125 },
michael@0 126 {
michael@0 127 desc: "Test 16: top.location.href, via function inserted in top, should NOT be blocked when sandboxed with allow-top-navigation",
michael@0 128 script: "top.eval('window[\"if2\"].doTest = function() { top.location.href = \"file_top_navigation_by_location_exotic.html\" };'), doTest();",
michael@0 129 iframeName: "if2",
michael@0 130 shouldBeBlocked: false
michael@0 131 },
michael@0 132 {
michael@0 133 desc: "Test 17: top.location.href, via function in top, should NOT be blocked when sandboxed without allow-top-navigation",
michael@0 134 script: "top.setOwnHref()",
michael@0 135 iframeName: "if1",
michael@0 136 shouldBeBlocked: false
michael@0 137 },
michael@0 138 {
michael@0 139 desc: "Test 18: top.location.href, via function in top, should NOT be blocked when sandboxed with allow-top-navigation",
michael@0 140 script: "top.setOwnHref()",
michael@0 141 iframeName: "if2",
michael@0 142 shouldBeBlocked: false
michael@0 143 },
michael@0 144 {
michael@0 145 desc: "Test 19: top.location.href, via eval in top, should NOT be blocked when sandboxed without allow-top-navigation",
michael@0 146 script: "top.eval('location.href = \"file_top_navigation_by_location_exotic.html\"')",
michael@0 147 iframeName: "if1",
michael@0 148 shouldBeBlocked: false
michael@0 149 },
michael@0 150 {
michael@0 151 desc: "Test 20: top.location.href, via eval in top, should NOT be blocked when sandboxed with allow-top-navigation",
michael@0 152 script: "top.eval('location.href = \"file_top_navigation_by_location_exotic.html\"')",
michael@0 153 iframeName: "if2",
michael@0 154 shouldBeBlocked: false
michael@0 155 },
michael@0 156 {
michael@0 157 desc: "Test 21: top.location.href, via eval in top calling us, should be blocked when sandboxed without allow-top-navigation",
michael@0 158 script: "function doTest() { top.location.href = 'file_top_navigation_by_location_exotic.html' } top.eval('window[\"if1\"].doTest()');",
michael@0 159 iframeName: "if1",
michael@0 160 shouldBeBlocked: true
michael@0 161 },
michael@0 162 {
michael@0 163 desc: "Test 22: top.location.href, via eval in top calling us, should NOT be blocked when sandboxed with allow-top-navigation",
michael@0 164 script: "function doTest() { top.location.href = 'file_top_navigation_by_location_exotic.html' } top.eval('window[\"if2\"].doTest()');",
michael@0 165 iframeName: "if2",
michael@0 166 shouldBeBlocked: false
michael@0 167 },
michael@0 168 {
michael@0 169 desc: "Test 23: top.location.href, via function bound to top, should be blocked when sandboxed without allow-top-navigation",
michael@0 170 script: "(function() { top.location.href = 'file_top_navigation_by_location_exotic.html' }).bind(top)();",
michael@0 171 iframeName: "if1",
michael@0 172 shouldBeBlocked: true
michael@0 173 },
michael@0 174 {
michael@0 175 desc: "Test 24: top.location.href, via function bound to top, should NOT be blocked when sandboxed with allow-top-navigation",
michael@0 176 script: "(function() { top.location.href = 'file_top_navigation_by_location_exotic.html' }).bind(top)();",
michael@0 177 iframeName: "if2",
michael@0 178 shouldBeBlocked: false
michael@0 179 }
michael@0 180 ];
michael@0 181
michael@0 182 function runNextTest() {
michael@0 183 ++testCaseIndex;
michael@0 184 if (testCaseIndex == testCases.length) {
michael@0 185 testWin.close();
michael@0 186 SimpleTest.finish();
michael@0 187 return;
michael@0 188 }
michael@0 189
michael@0 190 runScriptNavigationTest(testCases[testCaseIndex]);
michael@0 191 }
michael@0 192
michael@0 193 window.onmessage = runNextTest;
michael@0 194 testWin = window.open('file_top_navigation_by_location_exotic.html', "newWindow");
michael@0 195 </script>
michael@0 196 </head>
michael@0 197 <body>
michael@0 198 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=785310">Mozilla Bug 785310</a>
michael@0 199 <p id="display"></p>
michael@0 200 <div id="content">
michael@0 201 Tests for Bug 785310
michael@0 202 </div>
michael@0 203 </body>
michael@0 204 </html>

mercurial