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