Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=341604 |
michael@0 | 5 | Implement HTML5 sandbox attribute for IFRAMEs |
michael@0 | 6 | --> |
michael@0 | 7 | <head> |
michael@0 | 8 | <meta charset="utf-8"> |
michael@0 | 9 | <title>Test for Bug 341604 - navigation</title> |
michael@0 | 10 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 11 | <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 12 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 13 | </head> |
michael@0 | 14 | <script type="application/javascript"> |
michael@0 | 15 | /** Test for Bug 341604 - Implement HTML5 sandbox attribute for IFRAMEs **/ |
michael@0 | 16 | /** Navigation tests Part 2**/ |
michael@0 | 17 | |
michael@0 | 18 | SimpleTest.expectAssertions(0); |
michael@0 | 19 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 20 | // a postMessage handler that is used by sandboxed iframes without |
michael@0 | 21 | // 'allow-same-origin'/other windows to communicate pass/fail back to this main page. |
michael@0 | 22 | // it expects to be called with an object like {ok: true/false, desc: |
michael@0 | 23 | // <description of the test> which it then forwards to ok() |
michael@0 | 24 | window.addEventListener("message", receiveMessage, false); |
michael@0 | 25 | |
michael@0 | 26 | var testPassesReceived = 0; |
michael@0 | 27 | |
michael@0 | 28 | function receiveMessage(event) { |
michael@0 | 29 | switch (event.data.type) { |
michael@0 | 30 | case "attempted": |
michael@0 | 31 | testAttempted(); |
michael@0 | 32 | break; |
michael@0 | 33 | case "ok": |
michael@0 | 34 | ok_wrapper(event.data.ok, event.data.desc, event.data.addToAttempted); |
michael@0 | 35 | break; |
michael@0 | 36 | default: |
michael@0 | 37 | // allow for old style message |
michael@0 | 38 | if (event.data.ok != undefined) { |
michael@0 | 39 | ok_wrapper(event.data.ok, event.data.desc, event.data.addToAttempted); |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | // Open windows for tests to attempt to navigate later. |
michael@0 | 45 | var windowsToClose = new Array(); |
michael@0 | 46 | windowsToClose.push(window.open("about:blank", "window_to_navigate")); |
michael@0 | 47 | windowsToClose.push(window.open("about:blank", "window_to_navigate2")); |
michael@0 | 48 | var iframesWithWindowsToClose = new Array(); |
michael@0 | 49 | |
michael@0 | 50 | var attemptedTests = 0; |
michael@0 | 51 | var passedTests = 0; |
michael@0 | 52 | var totalTestsToPass = 12; |
michael@0 | 53 | var totalTestsToAttempt = 15; |
michael@0 | 54 | |
michael@0 | 55 | function ok_wrapper(result, desc, addToAttempted = true) { |
michael@0 | 56 | ok(result, desc); |
michael@0 | 57 | |
michael@0 | 58 | if (result) { |
michael@0 | 59 | passedTests++; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | if (addToAttempted) { |
michael@0 | 63 | testAttempted(); |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | // Added so that tests that don't register unless they fail, |
michael@0 | 68 | // can at least notify that they've attempted to run. |
michael@0 | 69 | function testAttempted() { |
michael@0 | 70 | attemptedTests++; |
michael@0 | 71 | if (attemptedTests == totalTestsToAttempt) { |
michael@0 | 72 | // Make sure all tests have had a chance to complete. |
michael@0 | 73 | setTimeout(function() {finish();}, 1000); |
michael@0 | 74 | } |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | var finishCalled = false; |
michael@0 | 78 | |
michael@0 | 79 | function finish() { |
michael@0 | 80 | if (!finishCalled) { |
michael@0 | 81 | finishCalled = true; |
michael@0 | 82 | is(passedTests, totalTestsToPass, "There are " + totalTestsToPass + " navigation tests that should pass"); |
michael@0 | 83 | |
michael@0 | 84 | for (var i = 0; i < windowsToClose.length; i++) { |
michael@0 | 85 | windowsToClose[i].close(); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | SimpleTest.finish(); |
michael@0 | 89 | } |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | function checkTestsFinished() { |
michael@0 | 93 | // If our own finish() has not been called, probably failed due to a timeout, so close remaining windows. |
michael@0 | 94 | if (!finishCalled) { |
michael@0 | 95 | for (var i = 0; i < windowsToClose.length; i++) { |
michael@0 | 96 | windowsToClose[i].close(); |
michael@0 | 97 | } |
michael@0 | 98 | } |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | function doTest() { |
michael@0 | 102 | // fails if bad |
michael@0 | 103 | // 14) iframe with sandbox='allow-same-origin allow-scripts allow-top-navigation' should not |
michael@0 | 104 | // be able to navigate another window (opened by another browsing context) using its name. |
michael@0 | 105 | // file_iframe_sandbox_d_if14.html in if_14 attempts to navigate "window_to_navigate", |
michael@0 | 106 | // which has been opened in preparation. |
michael@0 | 107 | |
michael@0 | 108 | // fails if bad |
michael@0 | 109 | // 15) iframe with sandbox='allow-scripts' should not be able to navigate top using its |
michael@0 | 110 | // real name (instead of _top) as allow-top-navigation is not specified. |
michael@0 | 111 | // file_iframe_sandbox_e_if7.html contains file_iframe_sandbox_e_if8.html, which |
michael@0 | 112 | // attempts to navigate top by name. |
michael@0 | 113 | windowsToClose.push(window.open("file_iframe_sandbox_e_if7.html")); |
michael@0 | 114 | |
michael@0 | 115 | // fails if bad |
michael@0 | 116 | // 16) iframe with sandbox='allow-same-origin allow-scripts allow-top-navigation' should not |
michael@0 | 117 | // be able to use its parent's name (instead of _parent) to navigate it, when it is not top. |
michael@0 | 118 | // (Note: this would apply to other ancestors that are not top as well.) |
michael@0 | 119 | // file_iframe_sandbox_d_if15.html in if_15 contains file_iframe_sandbox_d_if16.html, which |
michael@0 | 120 | // tries to navigate if_15 by its name (if_parent). |
michael@0 | 121 | |
michael@0 | 122 | // passes if good, fails if bad |
michael@0 | 123 | // 17) A sandboxed iframe is allowed to navigate itself using window.open(). |
michael@0 | 124 | // (Done by file_iframe_sandbox_d_if17.html which has 'allow-scripts' and navigates to |
michael@0 | 125 | // file_iframe_sandbox_navigation_pass.html). |
michael@0 | 126 | |
michael@0 | 127 | // passes if good, fails if bad |
michael@0 | 128 | // 18) A sandboxed iframe is allowed to navigate its children with window.open(), even if |
michael@0 | 129 | // they are sandboxed. (Done by file_iframe_sandbox_d_if18.html which has 'allow-scripts', |
michael@0 | 130 | // it navigates a child iframe to file_iframe_sandbox_navigation_pass.html). |
michael@0 | 131 | |
michael@0 | 132 | // passes if good, fails if bad |
michael@0 | 133 | // 19) A sandboxed iframe is not allowed to navigate its ancestor with window.open(). |
michael@0 | 134 | // (Done by file_iframe_sandbox_d_if20.html contained within file_iframe_sandbox_d_if19.html, |
michael@0 | 135 | // it attempts to navigate file_iframe_sandbox_d_if19.html to file_iframe_sandbox_navigation_fail.html). |
michael@0 | 136 | |
michael@0 | 137 | // passes if good, fails if bad |
michael@0 | 138 | // 20) iframe with sandbox='allow-same-origin allow-scripts allow-top-navigation' should not |
michael@0 | 139 | // be able to navigate another window (opened by another browsing context) using window.open(..., "<name>"). |
michael@0 | 140 | // file_iframe_sandbox_d_if14.html in if_14 attempts to navigate "window_to_navigate2", |
michael@0 | 141 | // which has been opened in preparation, using window.open(..., "window_to_navigate2"). |
michael@0 | 142 | |
michael@0 | 143 | // passes if good, fails if bad |
michael@0 | 144 | // 21) iframe with sandbox='allow-same-origin allow-scripts allow-top-navigation' should not |
michael@0 | 145 | // be able to use its parent's name (not _parent) to navigate it using window.open(), when it is not top. |
michael@0 | 146 | // (Note: this would apply to other ancestors that are not top as well.) |
michael@0 | 147 | // file_iframe_sandbox_d_if21.html in if_21 contains file_iframe_sandbox_d_if22.html, which |
michael@0 | 148 | // tries to navigate if_21 by its name (if_parent2). |
michael@0 | 149 | |
michael@0 | 150 | // passes if good, fails if bad |
michael@0 | 151 | // 22) iframe with sandbox='allow-top-navigation allow-scripts' can navigate top with window.open(). |
michael@0 | 152 | // file_iframe_sandbox_e_if9.html contains file_iframe_sandbox_e_if11.html which navigates top. |
michael@0 | 153 | window.open("file_iframe_sandbox_e_if9.html"); |
michael@0 | 154 | |
michael@0 | 155 | // passes if good, fails if bad |
michael@0 | 156 | // 23) iframe with sandbox='allow-top-navigation allow-scripts' nested inside an iframe with |
michael@0 | 157 | // 'allow-top-navigation allow-scripts' can navigate top, with window.open(). |
michael@0 | 158 | // file_iframe_sandbox_e_if10.html contains file_iframe_sandbox_e_if9.html which contains |
michael@0 | 159 | // file_iframe_sandbox_e_if11.html which navigates top. |
michael@0 | 160 | window.open("file_iframe_sandbox_e_if10.html"); |
michael@0 | 161 | |
michael@0 | 162 | // passes if good, fails if bad |
michael@0 | 163 | // 24) iframe with sandbox='allow-scripts' can NOT navigate top with window.open(). |
michael@0 | 164 | // file_iframe_sandbox_e_if12.html contains file_iframe_sandbox_e_if14.html which navigates top. |
michael@0 | 165 | window.open("file_iframe_sandbox_e_if12.html"); |
michael@0 | 166 | |
michael@0 | 167 | // passes if good, fails if bad |
michael@0 | 168 | // 25) iframe with sandbox='allow-scripts' nested inside an iframe with |
michael@0 | 169 | // 'allow-top-navigation allow-scripts' can NOT navigate top, with window.open(..., "_top"). |
michael@0 | 170 | // file_iframe_sandbox_e_if13.html contains file_iframe_sandbox_e_if12.html which contains |
michael@0 | 171 | // file_iframe_sandbox_e_if14.html which navigates top. |
michael@0 | 172 | window.open("file_iframe_sandbox_e_if13.html"); |
michael@0 | 173 | |
michael@0 | 174 | // passes if good, fails if bad |
michael@0 | 175 | // 26) iframe with sandbox='allow-scripts' should not be able to navigate top using its real name |
michael@0 | 176 | // (not with _top e.g. window.open(..., "topname")) as allow-top-navigation is not specified. |
michael@0 | 177 | // file_iframe_sandbox_e_if15.html contains file_iframe_sandbox_e_if16.html, which |
michael@0 | 178 | // attempts to navigate top by name using window.open(). |
michael@0 | 179 | window.open("file_iframe_sandbox_e_if15.html"); |
michael@0 | 180 | |
michael@0 | 181 | // passes if good |
michael@0 | 182 | // 27) iframe with sandbox='allow-scripts allow-popups' should be able to |
michael@0 | 183 | // navigate a window, that it has opened, using it's name. |
michael@0 | 184 | // file_iframe_sandbox_d_if23.html in if_23 opens a window and then attempts |
michael@0 | 185 | // to navigate it using it's name in the target of an anchor. |
michael@0 | 186 | iframesWithWindowsToClose.push("if_23"); |
michael@0 | 187 | |
michael@0 | 188 | // passes if good, fails if bad |
michael@0 | 189 | // 28) iframe with sandbox='allow-scripts allow-popups' should be able to |
michael@0 | 190 | // navigate a window, that it has opened, using window.open(..., "<name>"). |
michael@0 | 191 | // file_iframe_sandbox_d_if23.html in if_23 opens a window and then attempts |
michael@0 | 192 | // to navigate it using it's name in the target of window.open(). |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | addLoadEvent(doTest); |
michael@0 | 196 | </script> |
michael@0 | 197 | <body onunload="checkTestsFinished()"> |
michael@0 | 198 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=341604">Mozilla Bug 341604</a> - Implement HTML5 sandbox attribute for IFRAMEs |
michael@0 | 199 | <p id="display"></p> |
michael@0 | 200 | <div id="content"> |
michael@0 | 201 | <iframe sandbox="allow-same-origin allow-scripts allow-top-navigation" id="if_14" src="file_iframe_sandbox_d_if14.html" height="10" width="10"></iframe> |
michael@0 | 202 | <iframe id="if_15" name="if_parent" src="file_iframe_sandbox_d_if15.html" height="10" width="10"></iframe> |
michael@0 | 203 | <iframe sandbox="allow-scripts" id="if_17" src="file_iframe_sandbox_d_if17.html" height="10" width="10"></iframe> |
michael@0 | 204 | <iframe sandbox="allow-scripts" id="if_18" src="file_iframe_sandbox_d_if18.html" height="10" width="10"></iframe> |
michael@0 | 205 | <iframe sandbox="allow-scripts" id="if_19" src="file_iframe_sandbox_d_if19.html" height="10" width="10"></iframe> |
michael@0 | 206 | <iframe id="if_21" name="if_parent2" src="file_iframe_sandbox_d_if21.html" height="10" width="10"></iframe> |
michael@0 | 207 | <iframe sandbox="allow-scripts allow-popups" id="if_23" src="file_iframe_sandbox_d_if23.html" height="10" width="10"></iframe> |
michael@0 | 208 | </div> |
michael@0 | 209 | </body> |
michael@0 | 210 | </html> |