toolkit/components/prompts/test/test_bug625187.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/prompts/test/test_bug625187.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     1.4 +<html>
     1.5 +<head>
     1.6 +  <title>Test for Bug 625187</title>
     1.7 +  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.10 +  <script type="text/javascript" src="prompt_common.js"></script>
    1.11 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
    1.12 +<!--
    1.13 +   - Any copyright is dedicated to the Public Domain.
    1.14 +   - http://creativecommons.org/publicdomain/zero/1.0/
    1.15 +   -
    1.16 +   - Contributor(s):
    1.17 +   -   Mihai Sucan <mihai.sucan@gmail.com>
    1.18 +   -->
    1.19 +</head>
    1.20 +<body onload="runtest()">
    1.21 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=625187">Mozilla Bug 625187</a>
    1.22 +
    1.23 +<p><button onclick="alert('hello world')">Button</button></p>
    1.24 +
    1.25 +<iframe id="iframe_diff_origin" src="http://example.com/tests/toolkit/components/prompts/test/bug625187_iframe.html"></iframe>
    1.26 +
    1.27 +<iframe id="iframe_same_origin" src="bug625187_iframe.html"></iframe>
    1.28 +
    1.29 +<pre id="test"></pre>
    1.30 +
    1.31 +<script class="testbody" type="text/javascript">
    1.32 +SimpleTest.waitForExplicitFinish();
    1.33 +
    1.34 +var testNum = 0;
    1.35 +var dialogNum = 0;
    1.36 +
    1.37 +function hasTabModalPrompts() {
    1.38 +  var prefName = "prompts.tab_modal.enabled";
    1.39 +  var Services = SpecialPowers.Cu.import("resource://gre/modules/Services.jsm").Services;
    1.40 +  return Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL &&
    1.41 +         Services.prefs.getBoolPref(prefName);
    1.42 +}
    1.43 +
    1.44 +function runtest()
    1.45 +{
    1.46 +  isTabModal = hasTabModalPrompts();
    1.47 +
    1.48 +  // This test depends on tab modal prompts being enabled.
    1.49 +  if (!isTabModal) {
    1.50 +    todo(false, "Test disabled when tab modal prompts are not enabled.");
    1.51 +    SimpleTest.finish();
    1.52 +    return;
    1.53 +  }
    1.54 +
    1.55 +  startCallbackTimer();
    1.56 +
    1.57 +  var button = document.querySelector("button");
    1.58 +  dispatchMouseEvent(button, "click");
    1.59 +
    1.60 +  startCallbackTimer();
    1.61 +
    1.62 +  var iframe = document.getElementById("iframe_diff_origin");
    1.63 +  button = SpecialPowers.wrap(iframe.contentWindow).document.getElementById("btn1");
    1.64 +  dispatchMouseEvent(button, "click");
    1.65 +
    1.66 +  startCallbackTimer();
    1.67 +
    1.68 +  iframe = document.getElementById("iframe_same_origin");
    1.69 +  button = iframe.contentWindow.document.getElementById("btn1");
    1.70 +  dispatchMouseEvent(button, "click");
    1.71 +
    1.72 +  startCallbackTimer();
    1.73 +
    1.74 +  button = iframe.contentWindow.document.getElementById("btn2");
    1.75 +  dispatchMouseEvent(button, "click");
    1.76 +
    1.77 +  SimpleTest.finish();
    1.78 +}
    1.79 +
    1.80 +function handleDialog(ui)
    1.81 +{
    1.82 +  dialogNum++;
    1.83 +  if (dialogNum == 1 || dialogNum == 3 || dialogNum == 4)
    1.84 +    is(ui.infoTitle.getAttribute("hidden"), "true",
    1.85 +       "dialog #" + dialogNum + ": the tabprompt infoTitle element is hidden");
    1.86 +  else if (dialogNum == 2)
    1.87 +    ok(!ui.infoTitle.hasAttribute("hidden"),
    1.88 +       "dialog #" + dialogNum + ": the tabprompt infoTitle element is not hidden");
    1.89 +
    1.90 +  synthesizeMouse(ui.button0, 2, 2, {}, SpecialPowers.unwrap(ui.button0.ownerDocument.defaultView));
    1.91 +}
    1.92 +
    1.93 +function dispatchMouseEvent(target, type)
    1.94 +{
    1.95 +  var win = SpecialPowers.unwrap(target.ownerDocument.defaultView);
    1.96 +  var e = document.createEvent("MouseEvent");
    1.97 +  e.initEvent(type, false, false, win, 0, 1, 1, 1, 1,
    1.98 +              false, false, false, false, 0, null);
    1.99 +  var utils = SpecialPowers.getDOMWindowUtils(win);
   1.100 +  utils.dispatchDOMEventViaPresShell(SpecialPowers.unwrap(target), e, true);
   1.101 +}
   1.102 +</script>
   1.103 +</body>
   1.104 +</html>

mercurial