summaryrefslogtreecommitdiff
path: root/toolkit/components/prompts/test/test_bug620145.html
blob: bb4470259dd3c4afe3a9f58b49424baafa6f7a10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<html>
<head>
  <title>Test for Bug 620145</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="prompt_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=620145">Mozilla Bug 620145</a>
<pre id="test">
</pre>

<div id="text" style="max-width: 100px" onmouseup="openAlert()">
  This is a short piece of text used for testing that mouse selecting is
  stopped when an alert appears.
</div>
<div id="text2" style="max-width: 100px">
  This is another short piece of text used for testing that mouse selecting is
  stopped when an alert appears.
</div>
<button id="button" onmouseup="openAlert()">Button</button>

<script class="testbody" type="text/javascript">
var selectionTest = false;

function openAlert() {
  info("opening alert...");
  alert("hello!");
  info("...alert done.");
}

add_task(function* runTest() {
  var state, action;
  // The <button> in this test's HTML opens a prompt when clicked.
  // Here we send the events to simulate clicking it.
  info("isTabModal? " + isTabModal);
  selectionTest = isTabModal;

  state = {
    msg         : "hello!",
    iconClass   : "alert-icon",
    titleHidden : true,
    textHidden  : true,
    passHidden  : true,
    checkHidden : true,
    textValue   : "",
    passValue   : "",
    checkMsg    : "",
    checked     : false,
    focused     : "button0",
    defButton   : "button0",
  };
  action = {
    buttonClick: "ok",
  };

  promptDone = handlePrompt(state, action);

  var button = $("button");
  dispatchMouseEvent(button, "mousedown");
  dispatchMouseEvent(button, "mouseup");
  // alert appears at this point, to be closed by the chrome script.

  yield promptDone;
  checkSelection();

  // using same state and action.
  promptDone = handlePrompt(state, action);

  var text = $("text");
  dispatchMouseEvent(text, "mousedown");
  dispatchMouseEvent(text, "mouseup");
  // alert appears at this point, to be closed by the chrome script.

  yield promptDone;
  checkSelection();
});

function dispatchMouseEvent(target, type)
{
  var win = target.ownerDocument.defaultView;
  e = document.createEvent("MouseEvent");
  e.initEvent(type, false, false, win, 0, 1, 1, 1, 1,
              false, false, false, false, 0, null);
  var utils = SpecialPowers.getDOMWindowUtils(win);
  utils.dispatchDOMEventViaPresShell(target, e, true);
  ok(true, type + " sent to " + target.id);
}

function checkSelection()
{
  if (!selectionTest) {
    todo(false, "Selection test is disabled when tab modal prompts are not enabled.");
  } else {
    synthesizeMouse($("text"), 25, 55, { type: "mousemove" });
    is(window.getSelection().toString(), "", "selection not made");
  }
}
</script>

</body>
</html>