dom/browser-element/mochitest/browserElement_PromptCheck.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 /* Any copyright is dedicated to the public domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     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!
    11 "use strict";
    13 SimpleTest.waitForExplicitFinish();
    14 browserElementTestHelpers.setEnabledPref(true);
    15 browserElementTestHelpers.addPermission();
    17 function runTest()
    18 {
    19   var iframe = document.createElement('iframe');
    20   SpecialPowers.wrap(iframe).mozbrowser = true;
    21   document.body.appendChild(iframe);
    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     }
    36     numPrompts++;
    37     if (numPrompts == 30) {
    38       SimpleTest.finish();
    39     }
    40   });
    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 }
    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