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=545812 |
michael@0 | 5 | |
michael@0 | 6 | Test DOM full-screen API. |
michael@0 | 7 | |
michael@0 | 8 | --> |
michael@0 | 9 | <head> |
michael@0 | 10 | <title>Test for Bug 545812</title> |
michael@0 | 11 | <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 12 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 13 | <script type="application/javascript" src="file_fullscreen-utils.js"></script> |
michael@0 | 14 | <style> |
michael@0 | 15 | body { |
michael@0 | 16 | background-color: black; |
michael@0 | 17 | } |
michael@0 | 18 | </style> |
michael@0 | 19 | </head> |
michael@0 | 20 | <body> |
michael@0 | 21 | <script type="application/javascript"> |
michael@0 | 22 | |
michael@0 | 23 | /** Test for Bug 545812 **/ |
michael@0 | 24 | |
michael@0 | 25 | function ok(condition, msg) { |
michael@0 | 26 | opener.ok(condition, "[fullscreen] " + msg); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function is(a, b, msg) { |
michael@0 | 30 | opener.is(a, b, "[fullscreen] " + msg); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | /* |
michael@0 | 34 | <html> |
michael@0 | 35 | <body onload='document.body.mozRequestFullScreen();'> |
michael@0 | 36 | <iframe id='inner-frame'></iframe> |
michael@0 | 37 | </body> |
michael@0 | 38 | </html> |
michael@0 | 39 | */ |
michael@0 | 40 | var iframeContents = "data:text/html;charset=utf-8,<html><body onload%3D'parent.SimpleTest.waitForFocus(function(){document.body.mozRequestFullScreen();});'><iframe id%3D'inner-frame'><%2Fiframe><%2Fbody><%2Fhtml>"; |
michael@0 | 41 | |
michael@0 | 42 | var iframe = null; |
michael@0 | 43 | var outOfDocElement = null; |
michael@0 | 44 | var inDocElement = null; |
michael@0 | 45 | var container = null; |
michael@0 | 46 | var button = null; |
michael@0 | 47 | |
michael@0 | 48 | |
michael@0 | 49 | function sendMouseClick(element) { |
michael@0 | 50 | synthesizeMouseAtCenter(element, {}); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | function setRequireTrustedContext(value) { |
michael@0 | 54 | opener.SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", value); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function fullScreenElement() { |
michael@0 | 58 | return document.getElementById('full-screen-element'); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function enter1(event) { |
michael@0 | 62 | ok(document.mozFullScreen, "1. Should be in full-screen mode (first time)"); |
michael@0 | 63 | is(event.target, document, "2. Event target should be full-screen document #1"); |
michael@0 | 64 | is(document.mozFullScreenElement, fullScreenElement(), "3. Full-screen element should be div element."); |
michael@0 | 65 | ok(document.mozFullScreenElement.mozMatchesSelector(":-moz-full-screen"), "4. FSE should match :-moz-full-screen"); |
michael@0 | 66 | var fse = fullScreenElement(); |
michael@0 | 67 | addFullscreenChangeContinuation("exit", exit1); |
michael@0 | 68 | fse.parentNode.removeChild(fse); |
michael@0 | 69 | is(document.mozFullScreenElement, null, "5. Full-screen element should be null after removing."); |
michael@0 | 70 | ok(!document.mozFullScreen, "6. Should have left full-screen mode when we remove full-screen element"); |
michael@0 | 71 | document.body.appendChild(fse); |
michael@0 | 72 | ok(!document.mozFullScreen, "7. Should not return to full-screen mode when re-adding former FSE"); |
michael@0 | 73 | is(document.mozFullScreenElement, null, "8. Full-screen element should still be null after re-adding former FSE."); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function exit1(event) { |
michael@0 | 77 | ok(!document.mozFullScreen, "9. Should have left full-screen mode (first time)"); |
michael@0 | 78 | is(event.target, document, "10. Event target should be full-screen document #2"); |
michael@0 | 79 | is(document.mozFullScreenElement, null, "11. Full-screen element should be null."); |
michael@0 | 80 | iframe = document.createElement("iframe"); |
michael@0 | 81 | iframe.allowFullscreen = true; |
michael@0 | 82 | addFullscreenChangeContinuation("enter", enter2); |
michael@0 | 83 | document.body.appendChild(iframe); |
michael@0 | 84 | iframe.src = iframeContents; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function enter2(event) { |
michael@0 | 88 | ok(document.mozFullScreen, "12. Should be back in full-screen mode (second time)"); |
michael@0 | 89 | is(event.target, document, "13. Event target should be full-screen document #3"); |
michael@0 | 90 | is(document.mozFullScreenElement, iframe, "14. Full-screen element should be iframe element."); |
michael@0 | 91 | is(iframe.contentDocument.mozFullScreenElement, iframe.contentDocument.body, "15. Full-screen element in subframe should be body"); |
michael@0 | 92 | |
michael@0 | 93 | // The iframe's body is full-screen. Cancel full-screen in the subdocument to return |
michael@0 | 94 | // the full-screen element to the previous full-screen element. This causes |
michael@0 | 95 | // a fullscreenchange event. |
michael@0 | 96 | addFullscreenChangeContinuation("exit", exit2); |
michael@0 | 97 | document.mozCancelFullScreen(); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | function exit2(event) { |
michael@0 | 101 | ok(!document.mozFullScreen, "16. Should have left full-screen when canceling fullscreen in ancestor document."); |
michael@0 | 102 | is(document.mozFullScreenElement, null, "17. Full-screen element should have rolled back."); |
michael@0 | 103 | is(iframe.contentDocument.mozFullScreenElement, null, "18. Full-screen element in subframe should be null"); |
michael@0 | 104 | |
michael@0 | 105 | addFullscreenChangeContinuation("enter", enter3); |
michael@0 | 106 | fullScreenElement().mozRequestFullScreen(); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | function enter3(event) { |
michael@0 | 110 | ok(document.mozFullScreen, "19. Should be back in full-screen mode (second time)"); |
michael@0 | 111 | is(event.target, document, "20. Event target should be full-screen document #3"); |
michael@0 | 112 | is(document.mozFullScreenElement, fullScreenElement(), "21. Full-screen element should be div."); |
michael@0 | 113 | |
michael@0 | 114 | // Transplant the FSE into subdoc. Should exit full-screen. |
michael@0 | 115 | addFullscreenChangeContinuation("exit", exit3); |
michael@0 | 116 | var _innerFrame = iframe.contentDocument.getElementById("inner-frame"); |
michael@0 | 117 | var fse = fullScreenElement(); |
michael@0 | 118 | _innerFrame.contentDocument.body.appendChild(fse); |
michael@0 | 119 | ok(!document.mozFullScreen, "22. Should exit full-screen after transplanting FSE"); |
michael@0 | 120 | is(document.mozFullScreenElement, null, "23. Full-screen element transplanted, should be null."); |
michael@0 | 121 | is(iframe.contentDocument.mozFullScreenElement, null, "24. Full-screen element in outer frame should be null."); |
michael@0 | 122 | is(_innerFrame.contentDocument.mozFullScreenElement, null, "25. Full-screen element in inner frame should be null."); |
michael@0 | 123 | ok(!iframe.contentDocument.mozFullScreen, "26. Outer frame should not acquire full-screen status."); |
michael@0 | 124 | ok(!_innerFrame.contentDocument.mozFullScreen, "27. Inner frame should not acquire full-screen status."); |
michael@0 | 125 | |
michael@0 | 126 | document.body.appendChild(fse); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | function exit3(event) { |
michael@0 | 130 | ok(!document.mozFullScreen, "28. Should be back in non-full-screen mode (second time)"); |
michael@0 | 131 | is(event.target, document, "29. Event target should be full-screen document #4"); |
michael@0 | 132 | is(document.mozFullScreenElement, null, "30. Full-screen element should be null."); |
michael@0 | 133 | document.body.removeChild(iframe); |
michael@0 | 134 | iframe = null; |
michael@0 | 135 | |
michael@0 | 136 | // Do a request out of document. It should be denied. |
michael@0 | 137 | // Continue test in the following mozfullscreenerror handler. |
michael@0 | 138 | outOfDocElement = document.createElement("div"); |
michael@0 | 139 | addFullscreenErrorContinuation(error1); |
michael@0 | 140 | outOfDocElement.mozRequestFullScreen(); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | function error1(event) { |
michael@0 | 144 | ok(!document.mozFullScreen, "31. Requests for full-screen from not-in-doc elements should fail."); |
michael@0 | 145 | container = document.createElement("div"); |
michael@0 | 146 | inDocElement = document.createElement("div"); |
michael@0 | 147 | container.appendChild(inDocElement); |
michael@0 | 148 | fullScreenElement().appendChild(container); |
michael@0 | 149 | |
michael@0 | 150 | addFullscreenChangeContinuation("enter", enter4); |
michael@0 | 151 | inDocElement.mozRequestFullScreen(); |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | function enter4(event) { |
michael@0 | 155 | ok(document.mozFullScreen, "32. Should still be in full-screen mode (third time)"); |
michael@0 | 156 | is(event.target, document, "33. Event target should be full-screen document #5"); |
michael@0 | 157 | is(document.mozFullScreenElement, inDocElement, "35. FSE should be inDocElement."); |
michael@0 | 158 | |
michael@0 | 159 | var n = container; |
michael@0 | 160 | do { |
michael@0 | 161 | ok(n.mozMatchesSelector(":-moz-full-screen-ancestor"), "Ancestor " + n + " should match :-moz-full-screen-ancestor") |
michael@0 | 162 | n = n.parentNode; |
michael@0 | 163 | } while (n && n.mozMatchesSelector); |
michael@0 | 164 | |
michael@0 | 165 | // Remove full-screen ancestor element from document, verify it stops being reported as current FSE. |
michael@0 | 166 | addFullscreenChangeContinuation("exit", exit4); |
michael@0 | 167 | container.parentNode.removeChild(container); |
michael@0 | 168 | ok(!document.mozFullScreen, "36. Should exit full-screen mode after removing full-screen element ancestor from document"); |
michael@0 | 169 | is(document.mozFullScreenElement, null, "37. Should not have a full-screen element again."); |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | function exit4(event) { |
michael@0 | 173 | ok(!document.mozFullScreen, "38. Should be back in non-full-screen mode (third time)"); |
michael@0 | 174 | setRequireTrustedContext(true); |
michael@0 | 175 | |
michael@0 | 176 | addFullscreenErrorContinuation(error2); |
michael@0 | 177 | fullScreenElement().mozRequestFullScreen(); |
michael@0 | 178 | } |
michael@0 | 179 | |
michael@0 | 180 | function error2(event) { |
michael@0 | 181 | ok(!document.mozFullScreen, "Should still be in normal mode, because calling context isn't trusted."); |
michael@0 | 182 | button = document.createElement("button"); |
michael@0 | 183 | button.onclick = function(){fullScreenElement().mozRequestFullScreen();} |
michael@0 | 184 | fullScreenElement().appendChild(button); |
michael@0 | 185 | addFullscreenChangeContinuation("enter", enter5); |
michael@0 | 186 | sendMouseClick(button); |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | function enter5(event) { |
michael@0 | 190 | ok(document.mozFullScreen, "Moved to full-screen after mouse click"); |
michael@0 | 191 | addFullscreenChangeContinuation("exit", exit5); |
michael@0 | 192 | document.mozCancelFullScreen(); |
michael@0 | 193 | ok(!document.mozFullScreen, "Should have left full-screen mode."); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | function exit5(event) { |
michael@0 | 197 | ok(!document.mozFullScreen, "Should have left full-screen mode (last time)."); |
michael@0 | 198 | setRequireTrustedContext(false); |
michael@0 | 199 | |
michael@0 | 200 | SpecialPowers.setBoolPref("full-screen-api.enabled", false); |
michael@0 | 201 | is(document.mozFullScreenEnabled, false, "document.mozFullScreenEnabled should be false if full-screen-api.enabled is false"); |
michael@0 | 202 | |
michael@0 | 203 | addFullscreenErrorContinuation(error3); |
michael@0 | 204 | fullScreenElement().mozRequestFullScreen(); |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | function error3(event) { |
michael@0 | 208 | ok(!document.mozFullScreen, "Should still be in normal mode, because pref is not enabled."); |
michael@0 | 209 | |
michael@0 | 210 | SpecialPowers.setBoolPref("full-screen-api.enabled", true); |
michael@0 | 211 | is(document.mozFullScreenEnabled, true, "document.mozFullScreenEnabled should be true if full-screen-api.enabled is true"); |
michael@0 | 212 | |
michael@0 | 213 | opener.nextTest(); |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | function begin() { |
michael@0 | 217 | addFullscreenChangeContinuation("enter", enter1); |
michael@0 | 218 | fullScreenElement().mozRequestFullScreen(); |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | </script> |
michael@0 | 222 | </pre> |
michael@0 | 223 | <div id="full-screen-element"></div> |
michael@0 | 224 | </body> |
michael@0 | 225 | </html> |