dom/browser-element/mochitest/browserElement_PromptCheck.js

changeset 2
7e26c7da4463
equal deleted inserted replaced
-1:000000000000 0:0298d3ad8022
1 /* Any copyright is dedicated to the public domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 // Test that alertCheck (i.e., alert with the opportunity to opt out of future
5 // alerts), promptCheck, and confirmCheck work. We do this by spamming
6 // alerts/prompts/confirms from inside an <iframe mozbrowser>.
7 //
8 // At the moment, we treat alertCheck/promptCheck/confirmCheck just like a
9 // normal alert. But it's different to nsIPrompt!
10
11 "use strict";
12
13 SimpleTest.waitForExplicitFinish();
14 browserElementTestHelpers.setEnabledPref(true);
15 browserElementTestHelpers.addPermission();
16
17 function runTest()
18 {
19 var iframe = document.createElement('iframe');
20 SpecialPowers.wrap(iframe).mozbrowser = true;
21 document.body.appendChild(iframe);
22
23 var numPrompts = 0;
24 iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
25 is(e.detail.message, numPrompts, "prompt message");
26 if (numPrompts / 10 < 1) {
27 is(e.detail.promptType, 'alert');
28 }
29 else if (numPrompts / 10 < 2) {
30 is(e.detail.promptType, 'confirm');
31 }
32 else {
33 is(e.detail.promptType, 'prompt');
34 }
35
36 numPrompts++;
37 if (numPrompts == 30) {
38 SimpleTest.finish();
39 }
40 });
41
42 iframe.src =
43 'data:text/html,<html><body><script>\
44 addEventListener("load", function() { \
45 setTimeout(function() { \
46 var i = 0; \
47 for (; i < 10; i++) { alert(i); } \
48 for (; i < 20; i++) { confirm(i); } \
49 for (; i < 30; i++) { prompt(i); } \
50 }); \
51 }); \
52 </scr' + 'ipt></body></html>';
53 }
54
55 // The test harness sets dom.successive_dialog_time_limit to 0 for some bizarre
56 // reason. That's not normal usage, and it keeps us from testing alertCheck!
57 addEventListener('testready', function() {
58 SpecialPowers.pushPrefEnv({'set': [['dom.successive_dialog_time_limit', 10]]}, runTest);
59 });

mercurial