1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/browser-element/mochitest/browserElement_PromptCheck.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +/* Any copyright is dedicated to the public domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Test that alertCheck (i.e., alert with the opportunity to opt out of future 1.8 +// alerts), promptCheck, and confirmCheck work. We do this by spamming 1.9 +// alerts/prompts/confirms from inside an <iframe mozbrowser>. 1.10 +// 1.11 +// At the moment, we treat alertCheck/promptCheck/confirmCheck just like a 1.12 +// normal alert. But it's different to nsIPrompt! 1.13 + 1.14 +"use strict"; 1.15 + 1.16 +SimpleTest.waitForExplicitFinish(); 1.17 +browserElementTestHelpers.setEnabledPref(true); 1.18 +browserElementTestHelpers.addPermission(); 1.19 + 1.20 +function runTest() 1.21 +{ 1.22 + var iframe = document.createElement('iframe'); 1.23 + SpecialPowers.wrap(iframe).mozbrowser = true; 1.24 + document.body.appendChild(iframe); 1.25 + 1.26 + var numPrompts = 0; 1.27 + iframe.addEventListener('mozbrowsershowmodalprompt', function(e) { 1.28 + is(e.detail.message, numPrompts, "prompt message"); 1.29 + if (numPrompts / 10 < 1) { 1.30 + is(e.detail.promptType, 'alert'); 1.31 + } 1.32 + else if (numPrompts / 10 < 2) { 1.33 + is(e.detail.promptType, 'confirm'); 1.34 + } 1.35 + else { 1.36 + is(e.detail.promptType, 'prompt'); 1.37 + } 1.38 + 1.39 + numPrompts++; 1.40 + if (numPrompts == 30) { 1.41 + SimpleTest.finish(); 1.42 + } 1.43 + }); 1.44 + 1.45 + iframe.src = 1.46 + 'data:text/html,<html><body><script>\ 1.47 + addEventListener("load", function() { \ 1.48 + setTimeout(function() { \ 1.49 + var i = 0; \ 1.50 + for (; i < 10; i++) { alert(i); } \ 1.51 + for (; i < 20; i++) { confirm(i); } \ 1.52 + for (; i < 30; i++) { prompt(i); } \ 1.53 + }); \ 1.54 + }); \ 1.55 + </scr' + 'ipt></body></html>'; 1.56 +} 1.57 + 1.58 +// The test harness sets dom.successive_dialog_time_limit to 0 for some bizarre 1.59 +// reason. That's not normal usage, and it keeps us from testing alertCheck! 1.60 +addEventListener('testready', function() { 1.61 + SpecialPowers.pushPrefEnv({'set': [['dom.successive_dialog_time_limit', 10]]}, runTest); 1.62 +});