toolkit/components/prompts/test/test_bug620145.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/prompts/test/test_bug620145.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,99 @@
     1.4 +<html>
     1.5 +<head>
     1.6 +  <title>Test for Bug 620145</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 +</head>
    1.13 +<body onload="runtest()">
    1.14 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=620145">Mozilla Bug 620145</a>
    1.15 +<pre id="test">
    1.16 +</pre>
    1.17 +
    1.18 +<div id="text" style="max-width: 100px" onmouseup="openAlert()">
    1.19 +  This is a short piece of text used for testing that mouse selecting is
    1.20 +  stopped when an alert appears.
    1.21 +</div>
    1.22 +<div id="text2" style="max-width: 100px">
    1.23 +  This is another short piece of text used for testing that mouse selecting is
    1.24 +  stopped when an alert appears.
    1.25 +</div>
    1.26 +<button id="button" onmouseup="openAlert()">Button</button>
    1.27 +
    1.28 +<script class="testbody" type="text/javascript">
    1.29 +SimpleTest.waitForExplicitFinish();
    1.30 +
    1.31 +var selectionTest = false;
    1.32 +var testNum = 0;
    1.33 +
    1.34 +function hasTabModalPrompts() {
    1.35 +  var prefName = "prompts.tab_modal.enabled";
    1.36 +  var Services = SpecialPowers.Cu
    1.37 +                              .import("resource://gre/modules/Services.jsm")
    1.38 +                              .Services;
    1.39 +  return Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL &&
    1.40 +         Services.prefs.getBoolPref(prefName);
    1.41 +}
    1.42 +
    1.43 +function openAlert() {
    1.44 +  ok(true, "opening alert...");
    1.45 +  alert("hello!");
    1.46 +  ok(true, "...alert done.");
    1.47 +}
    1.48 +
    1.49 +function runtest()
    1.50 +{
    1.51 +  // The <button> in this test's HTML opens a prompt when clicked.
    1.52 +  // Here we send the events to simulate clicking it.
    1.53 +  ok(true, "starting test");
    1.54 +  isTabModal = hasTabModalPrompts();
    1.55 +  if (!isTabModal)
    1.56 +    todo(false, "Test is run with tab modal prompts disabled.");
    1.57 +  else
    1.58 +    ok(true, "Test is run with tab modal prompts enabled.");
    1.59 +  startCallbackTimer();
    1.60 +
    1.61 +  var button = $("button");
    1.62 +  dispatchMouseEvent(button, "mousedown");
    1.63 +  dispatchMouseEvent(button, "mouseup");
    1.64 +
    1.65 +  selectionTest = isTabModal;
    1.66 +
    1.67 +  startCallbackTimer();
    1.68 +
    1.69 +  var text = $("text");
    1.70 +  dispatchMouseEvent(text, "mousedown");
    1.71 +  dispatchMouseEvent(text, "mouseup");
    1.72 +
    1.73 +  SimpleTest.finish();
    1.74 +}
    1.75 +
    1.76 +function dispatchMouseEvent(target, type)
    1.77 +{
    1.78 +  var win = target.ownerDocument.defaultView;
    1.79 +  e = document.createEvent("MouseEvent");
    1.80 +  e.initEvent(type, false, false, win, 0, 1, 1, 1, 1,
    1.81 +              false, false, false, false, 0, null);
    1.82 +  var utils = SpecialPowers.getDOMWindowUtils(win);
    1.83 +  utils.dispatchDOMEventViaPresShell(target, e, true);
    1.84 +  ok(true, type + " sent to " + target.id);
    1.85 +}
    1.86 +
    1.87 +function handleDialog(ui, testNum)
    1.88 +{
    1.89 +  if (!selectionTest) {
    1.90 +    todo(false, "Selection test is disabled when tab modal prompts are not enabled.");
    1.91 +  } else {
    1.92 +    synthesizeMouse($("text"), 25, 55, { type: "mousemove" });
    1.93 +    is(window.getSelection().toString(), "", "selection not made");
    1.94 +  }
    1.95 +
    1.96 +  ok(true, "handleDialog sending mouseclick to dialog...");
    1.97 +  synthesizeMouse(ui.button0, 5, 5, { }, SpecialPowers.unwrap(ui.button0.ownerDocument.defaultView));
    1.98 +}
    1.99 +</script>
   1.100 +
   1.101 +</body>
   1.102 +</html>

mercurial