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=61098 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 61098</title> |
michael@0 | 8 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 10 | <script type="application/javascript" src="/tests/SimpleTest/MockObjects.js"></script> |
michael@0 | 11 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 12 | </head> |
michael@0 | 13 | <body onload="runtests();"> |
michael@0 | 14 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=61098">Mozilla Bug 61098</a> |
michael@0 | 15 | <p id="display"> |
michael@0 | 16 | </p> |
michael@0 | 17 | <div id="content" style="display: none"> |
michael@0 | 18 | </div> |
michael@0 | 19 | <pre id="test"> |
michael@0 | 20 | </pre> |
michael@0 | 21 | <script class="testbody" type="text/javascript"> |
michael@0 | 22 | /** Test for Bug 61098 **/ |
michael@0 | 23 | |
michael@0 | 24 | SimpleTest.expectAssertions(8); |
michael@0 | 25 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 26 | |
michael@0 | 27 | var mockPromptServiceRegisterer, mockPromptFactoryRegisterer; |
michael@0 | 28 | |
michael@0 | 29 | var promptState; |
michael@0 | 30 | |
michael@0 | 31 | function registerMockPromptService() |
michael@0 | 32 | { |
michael@0 | 33 | netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); |
michael@0 | 34 | var XPCOMUtils = SpecialPowers.Cu.import("resource://gre/modules/XPCOMUtils.jsm").XPCOMUtils; |
michael@0 | 35 | var Ci = SpecialPowers.Ci; |
michael@0 | 36 | |
michael@0 | 37 | function MockPrompt(aDOMWindow) { |
michael@0 | 38 | this.domWindow = aDOMWindow; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | MockPrompt.prototype = { |
michael@0 | 42 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIPrompt]), |
michael@0 | 43 | |
michael@0 | 44 | domWindow : null, |
michael@0 | 45 | |
michael@0 | 46 | _toggleModalState: function() |
michael@0 | 47 | { |
michael@0 | 48 | // The real prompt service puts the window into a modal state |
michael@0 | 49 | // immediately before showing a modal prompt, and leaves the modal state |
michael@0 | 50 | // when the prompt is dismissed by the user. This mock prompt doesn't |
michael@0 | 51 | // show anything to the user, so we only need to enter and immediately |
michael@0 | 52 | // leave the modal state -- this is done to trigger the necessary |
michael@0 | 53 | // accounting for triggering the "stop showing more prompts" code for |
michael@0 | 54 | // abusive pages. |
michael@0 | 55 | var winUtils = SpecialPowers.getDOMWindowUtils(this.domWindow); |
michael@0 | 56 | winUtils.enterModalState(); |
michael@0 | 57 | winUtils.leaveModalState(); |
michael@0 | 58 | }, |
michael@0 | 59 | |
michael@0 | 60 | alert: function(aDialogTitle, aText) |
michael@0 | 61 | { |
michael@0 | 62 | this._toggleModalState(); |
michael@0 | 63 | promptState = {method: "alert", |
michael@0 | 64 | parent: this.domWindow, |
michael@0 | 65 | title: aDialogTitle, |
michael@0 | 66 | msg: aText |
michael@0 | 67 | }; |
michael@0 | 68 | }, |
michael@0 | 69 | |
michael@0 | 70 | alertCheck: function(aDialogTitle, aText, aCheckMsg, aCheckState) |
michael@0 | 71 | { |
michael@0 | 72 | this._toggleModalState(); |
michael@0 | 73 | promptState = {method: "alertCheck", |
michael@0 | 74 | parent: this.domWindow, |
michael@0 | 75 | title: aDialogTitle, |
michael@0 | 76 | msg: aText, |
michael@0 | 77 | checkMsg: aCheckMsg, |
michael@0 | 78 | checkState: aCheckState |
michael@0 | 79 | }; |
michael@0 | 80 | |
michael@0 | 81 | SpecialPowers.wrap(aCheckState).value = true; |
michael@0 | 82 | }, |
michael@0 | 83 | |
michael@0 | 84 | confirm: function(aDialogTitle, aText) |
michael@0 | 85 | { |
michael@0 | 86 | this._toggleModalState(); |
michael@0 | 87 | promptState = {method: "confirm", |
michael@0 | 88 | parent: this.domWindow, |
michael@0 | 89 | title: aDialogTitle, |
michael@0 | 90 | msg: aText |
michael@0 | 91 | }; |
michael@0 | 92 | |
michael@0 | 93 | return true; |
michael@0 | 94 | }, |
michael@0 | 95 | |
michael@0 | 96 | confirmCheck: function(aDialogTitle, aText, aCheckMsg, aCheckState) |
michael@0 | 97 | { |
michael@0 | 98 | this._toggleModalState(); |
michael@0 | 99 | promptState = {method: "confirmCheck", |
michael@0 | 100 | parent: this.domWindow, |
michael@0 | 101 | title: aDialogTitle, |
michael@0 | 102 | msg: aText, |
michael@0 | 103 | checkMsg: aCheckMsg, |
michael@0 | 104 | checkState: aCheckState |
michael@0 | 105 | }; |
michael@0 | 106 | |
michael@0 | 107 | SpecialPowers.wrap(aCheckState).value = true; |
michael@0 | 108 | |
michael@0 | 109 | return true; |
michael@0 | 110 | }, |
michael@0 | 111 | |
michael@0 | 112 | confirmEx: function(aDialogTitle, aText, aButtonFlags, |
michael@0 | 113 | aButton0Title, aButton1Title, aButton2Title, |
michael@0 | 114 | aCheckMsg, aCheckState) |
michael@0 | 115 | { |
michael@0 | 116 | this._toggleModalState(); |
michael@0 | 117 | promptState = {method: "confirmCheck", |
michael@0 | 118 | parent: this.domWindow, |
michael@0 | 119 | title: aDialogTitle, |
michael@0 | 120 | msg: aText, |
michael@0 | 121 | checkMsg: aCheckMsg, |
michael@0 | 122 | checkState: aCheckState |
michael@0 | 123 | }; |
michael@0 | 124 | |
michael@0 | 125 | if (aCheckMsg != null) |
michael@0 | 126 | SpecialPowers.wrap(aCheckState).value = true; |
michael@0 | 127 | |
michael@0 | 128 | return 0; |
michael@0 | 129 | }, |
michael@0 | 130 | |
michael@0 | 131 | prompt: function(aDialogTitle, aText, aValue, aCheckMsg, |
michael@0 | 132 | aCheckState) |
michael@0 | 133 | { |
michael@0 | 134 | this._toggleModalState(); |
michael@0 | 135 | promptState = {method: "prompt", |
michael@0 | 136 | parent: this.domWindow, |
michael@0 | 137 | title: aDialogTitle, |
michael@0 | 138 | msg: aText, |
michael@0 | 139 | checkMsg: aCheckMsg, |
michael@0 | 140 | checkState: aCheckState |
michael@0 | 141 | }; |
michael@0 | 142 | |
michael@0 | 143 | if (aCheckMsg != null) |
michael@0 | 144 | SpecialPowers.wrap(aCheckState).value = true; |
michael@0 | 145 | |
michael@0 | 146 | return true; |
michael@0 | 147 | }, |
michael@0 | 148 | }; |
michael@0 | 149 | |
michael@0 | 150 | |
michael@0 | 151 | // Override the prompt service with our own so that we can test |
michael@0 | 152 | // modal dialogs |
michael@0 | 153 | |
michael@0 | 154 | function MockPromptService() |
michael@0 | 155 | { |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | MockPromptService.prototype = { |
michael@0 | 159 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIPromptFactory, Ci.nsIPromptService]), |
michael@0 | 160 | |
michael@0 | 161 | getPrompt: function(aDOMWindow, aIID) |
michael@0 | 162 | { |
michael@0 | 163 | return new MockPrompt(aDOMWindow); |
michael@0 | 164 | }, |
michael@0 | 165 | |
michael@0 | 166 | alert: function(aParent, aDialogTitle, aText) |
michael@0 | 167 | { |
michael@0 | 168 | var prompt = new MockPrompt(aParent); |
michael@0 | 169 | return prompt.alert(aDialogTitle, aText); |
michael@0 | 170 | }, |
michael@0 | 171 | |
michael@0 | 172 | alertCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState) |
michael@0 | 173 | { |
michael@0 | 174 | var prompt = new MockPrompt(aParent); |
michael@0 | 175 | return prompt.alertCheck(aDialogTitle, aText, aCheckMsg, aCheckState); |
michael@0 | 176 | }, |
michael@0 | 177 | |
michael@0 | 178 | confirm: function(aParent, aDialogTitle, aText) |
michael@0 | 179 | { |
michael@0 | 180 | var prompt = new MockPrompt(aParent); |
michael@0 | 181 | return prompt.confirm(aDialogTitle, aText); |
michael@0 | 182 | }, |
michael@0 | 183 | |
michael@0 | 184 | confirmCheck: function(aParent, aDialogTitle, aText, aCheckMsg, |
michael@0 | 185 | aCheckState) |
michael@0 | 186 | { |
michael@0 | 187 | var prompt = new MockPrompt(aParent); |
michael@0 | 188 | return prompt.confirmCheck(aDialogTitle, aText, aCheckMsg, aCheckState); |
michael@0 | 189 | }, |
michael@0 | 190 | |
michael@0 | 191 | confirmEx: function(aParent, aDialogTitle, aText, aButtonFlags, |
michael@0 | 192 | aButton0Title, aButton1Title, aButton2Title, |
michael@0 | 193 | aCheckMsg, aCheckState) |
michael@0 | 194 | { |
michael@0 | 195 | var prompt = new MockPrompt(aParent); |
michael@0 | 196 | return prompt.confirmEx(aDialogTitle, aText, aButtonFlags, |
michael@0 | 197 | aButton0Title, aButton1Title, aButton2Title, |
michael@0 | 198 | aCheckMsg, aCheckState); |
michael@0 | 199 | }, |
michael@0 | 200 | |
michael@0 | 201 | prompt: function(aParent, aDialogTitle, aText, aValue, aCheckMsg, |
michael@0 | 202 | aCheckState) |
michael@0 | 203 | { |
michael@0 | 204 | var prompt = new MockPrompt(aParent); |
michael@0 | 205 | return prompt.prompt(aDialogTitle, aText, aValue, aCheckMsg, aCheckState); |
michael@0 | 206 | }, |
michael@0 | 207 | |
michael@0 | 208 | }; |
michael@0 | 209 | |
michael@0 | 210 | mockPromptServiceRegisterer = |
michael@0 | 211 | new MockObjectRegisterer("@mozilla.org/embedcomp/prompt-service;1", |
michael@0 | 212 | MockPromptService); |
michael@0 | 213 | mockPromptFactoryRegisterer = |
michael@0 | 214 | new MockObjectRegisterer("@mozilla.org/prompter;1", |
michael@0 | 215 | MockPromptService); |
michael@0 | 216 | |
michael@0 | 217 | mockPromptServiceRegisterer.register(); |
michael@0 | 218 | mockPromptFactoryRegisterer.register(); |
michael@0 | 219 | }; |
michael@0 | 220 | |
michael@0 | 221 | function enableDialogLoopBlocking() |
michael@0 | 222 | { |
michael@0 | 223 | var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"]. |
michael@0 | 224 | getService(SpecialPowers.Ci.nsIPrefBranch); |
michael@0 | 225 | |
michael@0 | 226 | prefs.setIntPref("dom.successive_dialog_time_limit", 3); |
michael@0 | 227 | } |
michael@0 | 228 | |
michael@0 | 229 | function resetDialogLoopBlocking() |
michael@0 | 230 | { |
michael@0 | 231 | var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"]. |
michael@0 | 232 | getService(SpecialPowers.Ci.nsIPrefBranch); |
michael@0 | 233 | |
michael@0 | 234 | prefs.setIntPref("dom.successive_dialog_time_limit", 0); |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | var expectedState; |
michael@0 | 238 | |
michael@0 | 239 | function runtests() |
michael@0 | 240 | { |
michael@0 | 241 | registerMockPromptService(); |
michael@0 | 242 | enableDialogLoopBlocking(); |
michael@0 | 243 | |
michael@0 | 244 | // Test that alert() works normally and then gets blocked on the |
michael@0 | 245 | // second call. |
michael@0 | 246 | w = window.open(); |
michael@0 | 247 | w.alert("alert message 1"); |
michael@0 | 248 | is (promptState.method, "alert", "Wrong prompt method called"); |
michael@0 | 249 | is (promptState.parent, w, "Wrong alert parent"); |
michael@0 | 250 | is (promptState.msg, "alert message 1", "Wrong alert message"); |
michael@0 | 251 | promptState = void(0); |
michael@0 | 252 | |
michael@0 | 253 | w.alert("alert message 2"); |
michael@0 | 254 | is (promptState.method, "alertCheck", "Wrong prompt method called"); |
michael@0 | 255 | is (promptState.parent, w, "Wrong alert parent"); |
michael@0 | 256 | is (promptState.msg, "alert message 2", "Wrong alert message"); |
michael@0 | 257 | promptState = void(0); |
michael@0 | 258 | |
michael@0 | 259 | try { |
michael@0 | 260 | w.alert("alert message 3"); |
michael@0 | 261 | } catch(e) { |
michael@0 | 262 | is(e.name, "NS_ERROR_NOT_AVAILABLE", "Wrong exception"); |
michael@0 | 263 | } |
michael@0 | 264 | |
michael@0 | 265 | is (promptState, void(0), "Wrong prompt state after blocked alert()"); |
michael@0 | 266 | |
michael@0 | 267 | w.close(); |
michael@0 | 268 | |
michael@0 | 269 | // Test that confirm() works normally and then gets blocked on the |
michael@0 | 270 | // second call. |
michael@0 | 271 | w = window.open(); |
michael@0 | 272 | w.confirm("confirm message 1"); |
michael@0 | 273 | is (promptState.method, "confirm", "Wrong prompt method called"); |
michael@0 | 274 | is (promptState.parent, w, "Wrong confirm parent"); |
michael@0 | 275 | is (promptState.msg, "confirm message 1", "Wrong confirm message"); |
michael@0 | 276 | promptState = void(0); |
michael@0 | 277 | |
michael@0 | 278 | w.confirm("confirm message 2"); |
michael@0 | 279 | is (promptState.method, "confirmCheck", "Wrong prompt method called"); |
michael@0 | 280 | is (promptState.parent, w, "Wrong confirm parent"); |
michael@0 | 281 | is (promptState.msg, "confirm message 2", "Wrong confirm message"); |
michael@0 | 282 | promptState = void(0); |
michael@0 | 283 | |
michael@0 | 284 | try { |
michael@0 | 285 | w.confirm("confirm message 3"); |
michael@0 | 286 | } catch(e) { |
michael@0 | 287 | is(e.name, "NS_ERROR_NOT_AVAILABLE", "Wrong exception"); |
michael@0 | 288 | } |
michael@0 | 289 | |
michael@0 | 290 | is (promptState, void(0), "Wrong prompt state after blocked confirm()"); |
michael@0 | 291 | |
michael@0 | 292 | w.close(); |
michael@0 | 293 | |
michael@0 | 294 | // Test that prompt() works normally and then gets blocked on the |
michael@0 | 295 | // second call. |
michael@0 | 296 | w = window.open(); |
michael@0 | 297 | w.prompt("prompt message 1"); |
michael@0 | 298 | is (promptState.method, "prompt", "Wrong prompt method called"); |
michael@0 | 299 | is (promptState.parent, w, "Wrong prompt parent"); |
michael@0 | 300 | is (promptState.msg, "prompt message 1", "Wrong prompt message"); |
michael@0 | 301 | is (promptState.checkMsg, null, "Wrong dialog value"); |
michael@0 | 302 | promptState = void(0); |
michael@0 | 303 | |
michael@0 | 304 | w.prompt("prompt message 2"); |
michael@0 | 305 | is (promptState.method, "prompt", "Wrong prompt method called"); |
michael@0 | 306 | is (promptState.parent, w, "Wrong prompt parent"); |
michael@0 | 307 | is (promptState.msg, "prompt message 2", "Wrong prompt message"); |
michael@0 | 308 | is (promptState.checkMsg, "Prevent this page from creating additional dialogs", "Wrong dialog value"); |
michael@0 | 309 | promptState = void(0); |
michael@0 | 310 | |
michael@0 | 311 | try { |
michael@0 | 312 | w.prompt("prompt message 3"); |
michael@0 | 313 | } catch(e) { |
michael@0 | 314 | is(e.name, "NS_ERROR_NOT_AVAILABLE", "Wrong exception"); |
michael@0 | 315 | } |
michael@0 | 316 | |
michael@0 | 317 | is (promptState, void(0), "Wrong prompt state after blocked prompt()"); |
michael@0 | 318 | |
michael@0 | 319 | w.close(); |
michael@0 | 320 | |
michael@0 | 321 | // Test that showModalDialog() works normally and then gets blocked |
michael@0 | 322 | // on the second call. |
michael@0 | 323 | w = window.open(); |
michael@0 | 324 | w.showModalDialog("data:text/html,%3Cscript>window.close();%3C/script>") |
michael@0 | 325 | is (promptState, void(0), "Wrong prompt state"); |
michael@0 | 326 | |
michael@0 | 327 | // Test that showModalDialog() works normally and then gets blocked |
michael@0 | 328 | // on the second call. |
michael@0 | 329 | try { |
michael@0 | 330 | w.showModalDialog("data:text/html,%3Cscript>window.close();%3C/script>") |
michael@0 | 331 | } catch(e) { |
michael@0 | 332 | is(e.name, "NS_ERROR_NOT_AVAILABLE", "Wrong exception"); |
michael@0 | 333 | } |
michael@0 | 334 | is (promptState.method, "confirm", "Wrong prompt method called"); |
michael@0 | 335 | is (promptState.parent, w, "Wrong confirm parent"); |
michael@0 | 336 | is (promptState.msg, "Prevent this page from creating additional dialogs", |
michael@0 | 337 | "Wrong confirm message"); |
michael@0 | 338 | promptState = void(0); |
michael@0 | 339 | |
michael@0 | 340 | w.close(); |
michael@0 | 341 | |
michael@0 | 342 | resetDialogLoopBlocking(); |
michael@0 | 343 | |
michael@0 | 344 | mockPromptFactoryRegisterer.unregister(); |
michael@0 | 345 | mockPromptServiceRegisterer.unregister(); |
michael@0 | 346 | |
michael@0 | 347 | SimpleTest.finish(); |
michael@0 | 348 | } |
michael@0 | 349 | |
michael@0 | 350 | </script> |
michael@0 | 351 | </body> |
michael@0 | 352 | </html> |