Wed, 31 Dec 2014 06:09:35 +0100
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 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 != "newTop") { |
michael@0 | 20 | ok(false, "event.data: got '" + event.data + "', expected 'newTop'"); |
michael@0 | 21 | } |
michael@0 | 22 | ok(!testCase.shouldBeBlocked, testCase.desc, "top navigation was NOT blocked"); |
michael@0 | 23 | runNextTest(); |
michael@0 | 24 | }; |
michael@0 | 25 | try { |
michael@0 | 26 | SpecialPowers.wrap(testWin[testCase.iframeName]).eval(testCase.script); |
michael@0 | 27 | } catch(e) { |
michael@0 | 28 | ok(testCase.shouldBeBlocked, testCase.desc, SpecialPowers.wrap(e).message); |
michael@0 | 29 | runNextTest(); |
michael@0 | 30 | } |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | var testCaseIndex = -1; |
michael@0 | 34 | testCases = [ |
michael@0 | 35 | { |
michael@0 | 36 | desc: "Test 1: top.location.replace should be blocked when sandboxed without allow-top-navigation", |
michael@0 | 37 | script: "top.location.replace('file_top_navigation_by_location.html')", |
michael@0 | 38 | iframeName: "if1", |
michael@0 | 39 | shouldBeBlocked: true |
michael@0 | 40 | }, |
michael@0 | 41 | { |
michael@0 | 42 | desc: "Test 2: top.location.assign should be blocked when sandboxed without allow-top-navigation", |
michael@0 | 43 | script: "top.location.assign('file_top_navigation_by_location.html')", |
michael@0 | 44 | iframeName: "if1", |
michael@0 | 45 | shouldBeBlocked: true |
michael@0 | 46 | }, |
michael@0 | 47 | { |
michael@0 | 48 | desc: "Test 3: top.location.href should be blocked when sandboxed without allow-top-navigation", |
michael@0 | 49 | script: "top.location.href = 'file_top_navigation_by_location.html'", |
michael@0 | 50 | iframeName: "if1", |
michael@0 | 51 | shouldBeBlocked: true |
michael@0 | 52 | }, |
michael@0 | 53 | { |
michael@0 | 54 | desc: "Test 4: top.location.pathname should be blocked when sandboxed without allow-top-navigation", |
michael@0 | 55 | script: "top.location.pathname = top.location.pathname", |
michael@0 | 56 | iframeName: "if1", |
michael@0 | 57 | shouldBeBlocked: true |
michael@0 | 58 | }, |
michael@0 | 59 | { |
michael@0 | 60 | desc: "Test 5: top.location should be blocked when sandboxed without allow-top-navigation", |
michael@0 | 61 | script: "top.location = 'file_top_navigation_by_location.html'", |
michael@0 | 62 | iframeName: "if1", |
michael@0 | 63 | shouldBeBlocked: true |
michael@0 | 64 | }, |
michael@0 | 65 | { |
michael@0 | 66 | desc: "Test 6: top.location.hash should be blocked when sandboxed without allow-top-navigation", |
michael@0 | 67 | script: "top.location.hash = 'wibble'", |
michael@0 | 68 | iframeName: "if1", |
michael@0 | 69 | shouldBeBlocked: true |
michael@0 | 70 | }, |
michael@0 | 71 | { |
michael@0 | 72 | desc: "Test 7: top.location.replace should NOT be blocked when sandboxed with allow-same-origin allow-top-navigation", |
michael@0 | 73 | script: "top.location.replace('file_top_navigation_by_location.html')", |
michael@0 | 74 | iframeName: "if2", |
michael@0 | 75 | shouldBeBlocked: false |
michael@0 | 76 | }, |
michael@0 | 77 | { |
michael@0 | 78 | desc: "Test 8: top.location.assign should NOT be blocked when sandboxed with allow-same-origin allow-top-navigation", |
michael@0 | 79 | script: "top.location.assign('file_top_navigation_by_location.html')", |
michael@0 | 80 | iframeName: "if2", |
michael@0 | 81 | shouldBeBlocked: false |
michael@0 | 82 | }, |
michael@0 | 83 | { |
michael@0 | 84 | desc: "Test 9: top.location.href should NOT be blocked when sandboxed with allow-same-origin allow-top-navigation", |
michael@0 | 85 | script: "top.location.href = 'file_top_navigation_by_location.html'", |
michael@0 | 86 | iframeName: "if2", |
michael@0 | 87 | shouldBeBlocked: false |
michael@0 | 88 | }, |
michael@0 | 89 | { |
michael@0 | 90 | desc: "Test 10: top.location.pathname should NOT be blocked when sandboxed with allow-same-origin allow-top-navigation", |
michael@0 | 91 | script: "top.location.pathname = top.location.pathname", |
michael@0 | 92 | iframeName: "if2", |
michael@0 | 93 | shouldBeBlocked: false |
michael@0 | 94 | }, |
michael@0 | 95 | { |
michael@0 | 96 | desc: "Test 11: top.location should NOT be blocked when sandboxed with allow-same-origin allow-top-navigation", |
michael@0 | 97 | script: "top.location = 'file_top_navigation_by_location.html'", |
michael@0 | 98 | iframeName: "if2", |
michael@0 | 99 | shouldBeBlocked: false |
michael@0 | 100 | }, |
michael@0 | 101 | { |
michael@0 | 102 | desc: "Test 12: top.location.hash should NOT be blocked when sandboxed with allow-same-origin allow-top-navigation", |
michael@0 | 103 | script: "top.location.hash = 'wibble'", |
michael@0 | 104 | iframeName: "if2", |
michael@0 | 105 | shouldBeBlocked: false |
michael@0 | 106 | }, |
michael@0 | 107 | { |
michael@0 | 108 | desc: "Test 13: top.location.replace should NOT be blocked when sandboxed with allow-top-navigation, but without allow-same-origin", |
michael@0 | 109 | script: "top.location.replace('file_top_navigation_by_location.html')", |
michael@0 | 110 | iframeName: "if3", |
michael@0 | 111 | shouldBeBlocked: false |
michael@0 | 112 | }, |
michael@0 | 113 | { |
michael@0 | 114 | desc: "Test 14: top.location.assign should be blocked when sandboxed with allow-top-navigation, but without allow-same-origin", |
michael@0 | 115 | script: "top.location.assign('file_top_navigation_by_location.html')", |
michael@0 | 116 | iframeName: "if3", |
michael@0 | 117 | shouldBeBlocked: true |
michael@0 | 118 | }, |
michael@0 | 119 | { |
michael@0 | 120 | desc: "Test 15: top.location.href should NOT be blocked when sandboxed with allow-top-navigation, but without allow-same-origin", |
michael@0 | 121 | script: "top.location.href = 'file_top_navigation_by_location.html'", |
michael@0 | 122 | iframeName: "if3", |
michael@0 | 123 | shouldBeBlocked: false |
michael@0 | 124 | }, |
michael@0 | 125 | { |
michael@0 | 126 | desc: "Test 16: top.location.pathname should be blocked when sandboxed with allow-top-navigation, but without allow-same-origin", |
michael@0 | 127 | script: "top.location.pathname = top.location.pathname", |
michael@0 | 128 | iframeName: "if3", |
michael@0 | 129 | shouldBeBlocked: true |
michael@0 | 130 | }, |
michael@0 | 131 | { |
michael@0 | 132 | desc: "Test 17: top.location should NOT be blocked when sandboxed with allow-top-navigation, but without allow-same-origin", |
michael@0 | 133 | script: "top.location = 'file_top_navigation_by_location.html'", |
michael@0 | 134 | iframeName: "if3", |
michael@0 | 135 | shouldBeBlocked: false |
michael@0 | 136 | }, |
michael@0 | 137 | { |
michael@0 | 138 | desc: "Test 18: top.location.hash should be blocked when sandboxed with allow-top-navigation, but without allow-same-origin", |
michael@0 | 139 | script: "top.location.hash = 'wibble'", |
michael@0 | 140 | iframeName: "if3", |
michael@0 | 141 | shouldBeBlocked: true |
michael@0 | 142 | } |
michael@0 | 143 | ]; |
michael@0 | 144 | |
michael@0 | 145 | function runNextTest() { |
michael@0 | 146 | ++testCaseIndex; |
michael@0 | 147 | if (testCaseIndex == testCases.length) { |
michael@0 | 148 | testWin.close(); |
michael@0 | 149 | SimpleTest.finish(); |
michael@0 | 150 | return; |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | runScriptNavigationTest(testCases[testCaseIndex]); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | window.onmessage = runNextTest; |
michael@0 | 157 | testWin = window.open("file_top_navigation_by_location.html", "newTop"); |
michael@0 | 158 | </script> |
michael@0 | 159 | </head> |
michael@0 | 160 | <body> |
michael@0 | 161 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=785310">Mozilla Bug 785310</a> |
michael@0 | 162 | <p id="display"></p> |
michael@0 | 163 | <div id="content"> |
michael@0 | 164 | Tests for Bug 785310 |
michael@0 | 165 | </div> |
michael@0 | 166 | </body> |
michael@0 | 167 | </html> |