toolkit/components/prompts/test/test_bug625187.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <html>
     2 <head>
     3   <title>Test for Bug 625187</title>
     4   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
     5   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
     7   <script type="text/javascript" src="prompt_common.js"></script>
     8   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
     9 <!--
    10    - Any copyright is dedicated to the Public Domain.
    11    - http://creativecommons.org/publicdomain/zero/1.0/
    12    -
    13    - Contributor(s):
    14    -   Mihai Sucan <mihai.sucan@gmail.com>
    15    -->
    16 </head>
    17 <body onload="runtest()">
    18 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=625187">Mozilla Bug 625187</a>
    20 <p><button onclick="alert('hello world')">Button</button></p>
    22 <iframe id="iframe_diff_origin" src="http://example.com/tests/toolkit/components/prompts/test/bug625187_iframe.html"></iframe>
    24 <iframe id="iframe_same_origin" src="bug625187_iframe.html"></iframe>
    26 <pre id="test"></pre>
    28 <script class="testbody" type="text/javascript">
    29 SimpleTest.waitForExplicitFinish();
    31 var testNum = 0;
    32 var dialogNum = 0;
    34 function hasTabModalPrompts() {
    35   var prefName = "prompts.tab_modal.enabled";
    36   var Services = SpecialPowers.Cu.import("resource://gre/modules/Services.jsm").Services;
    37   return Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL &&
    38          Services.prefs.getBoolPref(prefName);
    39 }
    41 function runtest()
    42 {
    43   isTabModal = hasTabModalPrompts();
    45   // This test depends on tab modal prompts being enabled.
    46   if (!isTabModal) {
    47     todo(false, "Test disabled when tab modal prompts are not enabled.");
    48     SimpleTest.finish();
    49     return;
    50   }
    52   startCallbackTimer();
    54   var button = document.querySelector("button");
    55   dispatchMouseEvent(button, "click");
    57   startCallbackTimer();
    59   var iframe = document.getElementById("iframe_diff_origin");
    60   button = SpecialPowers.wrap(iframe.contentWindow).document.getElementById("btn1");
    61   dispatchMouseEvent(button, "click");
    63   startCallbackTimer();
    65   iframe = document.getElementById("iframe_same_origin");
    66   button = iframe.contentWindow.document.getElementById("btn1");
    67   dispatchMouseEvent(button, "click");
    69   startCallbackTimer();
    71   button = iframe.contentWindow.document.getElementById("btn2");
    72   dispatchMouseEvent(button, "click");
    74   SimpleTest.finish();
    75 }
    77 function handleDialog(ui)
    78 {
    79   dialogNum++;
    80   if (dialogNum == 1 || dialogNum == 3 || dialogNum == 4)
    81     is(ui.infoTitle.getAttribute("hidden"), "true",
    82        "dialog #" + dialogNum + ": the tabprompt infoTitle element is hidden");
    83   else if (dialogNum == 2)
    84     ok(!ui.infoTitle.hasAttribute("hidden"),
    85        "dialog #" + dialogNum + ": the tabprompt infoTitle element is not hidden");
    87   synthesizeMouse(ui.button0, 2, 2, {}, SpecialPowers.unwrap(ui.button0.ownerDocument.defaultView));
    88 }
    90 function dispatchMouseEvent(target, type)
    91 {
    92   var win = SpecialPowers.unwrap(target.ownerDocument.defaultView);
    93   var e = document.createEvent("MouseEvent");
    94   e.initEvent(type, false, false, win, 0, 1, 1, 1, 1,
    95               false, false, false, false, 0, null);
    96   var utils = SpecialPowers.getDOMWindowUtils(win);
    97   utils.dispatchDOMEventViaPresShell(SpecialPowers.unwrap(target), e, true);
    98 }
    99 </script>
   100 </body>
   101 </html>

mercurial