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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<window title="Native mouse event tests"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
<script class="testbody" type="application/javascript">
<![CDATA[
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const NSEventTypeMouseMoved = 5;
var gLeftWindow, gRightWindow, gBrowserElement;
var gExpectedEvents = [];
function moveMouseTo(x, y, andThen) {
var utils = gLeftWindow.windowUtils;
utils.sendNativeMouseEvent(x, y, NSEventTypeMouseMoved, 0, gLeftWindow.documentElement);
SimpleTest.executeSoon(andThen);
}
function openWindows() {
gLeftWindow = window.browsingContext.topChromeWindow
.open('empty_window.xhtml', '_blank', 'chrome,screenX=50,screenY=50,width=200,height=200');
SimpleTest.waitForFocus(function () {
gRightWindow = window.browsingContext.topChromeWindow
.open('empty_window.xhtml', '', 'chrome,screenX=300,screenY=50,width=200,height=200');
SimpleTest.waitForFocus(attachBrowserToLeftWindow, gRightWindow);
}, gLeftWindow);
}
function attachBrowserToLeftWindow() {
gBrowserElement = gLeftWindow.document.createXULElement("browser");
gBrowserElement.setAttribute("type", "content");
gBrowserElement.setAttribute("src", "file_bug596600.html");
gBrowserElement.style.width = "100px";
gBrowserElement.style.height = "100px";
gBrowserElement.style.margin = "50px";
gLeftWindow.document.documentElement.appendChild(gBrowserElement);
gBrowserElement.addEventListener("load", function (e) {
test1();
}, { capture: true, once: true });
}
function test1() {
// gRightWindow is active, gLeftWindow is inactive.
moveMouseTo(0, 0, function () {
var expectMouseOver = false, expectMouseOut = false;
function mouseOverListener(e) {
ok(expectMouseOver, "Got expected mouseover at " + e.screenX + ", " + e.screenY);
expectMouseOver = false;
}
function mouseOutListener(e) {
ok(expectMouseOut, "Got expected mouseout at " + e.screenX + ", " + e.screenY);
expectMouseOut = false;
}
gLeftWindow.addEventListener("mouseover", mouseOverListener);
gLeftWindow.addEventListener("mouseout", mouseOutListener);
// Move into the left window
expectMouseOver = true;
moveMouseTo(80, 80, function () {
ok(!expectMouseOver, "Should have got mouseover event");
// Move over the browser
expectMouseOut = true;
moveMouseTo(150, 150, function () {
ok (!expectMouseOut, "Should have got mouseout event");
gLeftWindow.removeEventListener("mouseover", mouseOverListener);
gLeftWindow.removeEventListener("mouseout", mouseOutListener);
test2();
});
});
});
}
function test2() {
// Make the browser cover the whole window.
gBrowserElement.style.margin = "0";
gBrowserElement.style.width = gBrowserElement.style.height = "200px";
// Add a box to the browser at the left edge.
var doc = gBrowserElement.contentDocument;
var box = doc.createElement("div");
box.setAttribute("id", "box");
box.style.position = "absolute";
box.style.left = "0";
box.style.top = "50px";
box.style.width = "100px";
box.style.height = "100px";
box.style.backgroundColor = "green";
doc.body.appendChild(box);
ok(!box.matches(":hover"), "Box shouldn't be hovered (since the mouse isn't over it and since it's in a non-clickthrough browser in a background window)");
// A function to waitForFocus and then wait for synthetic mouse
// events to happen. Note that those happen off the refresh driver,
// and happen after animation frame requests.
function changeFocusAndAwaitSyntheticMouse(callback, winToFocus,
elementToWatchForMouseEventOn) {
function mouseWatcher() {
elementToWatchForMouseEventOn.removeEventListener("mouseover",
mouseWatcher);
elementToWatchForMouseEventOn.removeEventListener("mouseout",
mouseWatcher);
SimpleTest.executeSoon(callback);
}
elementToWatchForMouseEventOn.addEventListener("mouseover",
mouseWatcher);
elementToWatchForMouseEventOn.addEventListener("mouseout",
mouseWatcher);
// Just pass a dummy function to waitForFocus; the mouseout/over listener
// will actually handle things for us.
SimpleTest.waitForFocus(function() {}, winToFocus);
}
// Move the mouse over the box.
moveMouseTo(100, 150, function () {
ok(!box.matches(":hover"), "Box shouldn't be hovered (since it's in a non-clickthrough browser in a background window)");
// Activate the left window.
changeFocusAndAwaitSyntheticMouse(function () {
ok(gBrowserElement.matches(":hover"), "browser should be hovered");
ok(box.matches(":hover"), "Box should be hovered");
// De-activate the window (by activating the right window).
changeFocusAndAwaitSyntheticMouse(function () {
ok(!gBrowserElement.matches(":hover"), "browser shouldn't be hovered");
ok(!box.matches(":hover"), "Box shouldn't be hovered");
// Re-activate it.
changeFocusAndAwaitSyntheticMouse(function () {
ok(gBrowserElement.matches(":hover"), "browser should be hovered");
ok(box.matches(":hover"), "Box should be hovered");
// Unhover box and browser by moving the mouse outside the window.
moveMouseTo(0, 150, function () {
ok(!gBrowserElement.matches(":hover"), "browser shouldn't be hovered");
ok(!box.matches(":hover"), "box shouldn't be hovered");
finalize();
});
}, gLeftWindow, box);
}, gRightWindow, box);
}, gLeftWindow, box);
});
}
function finalize() {
gRightWindow.close();
gLeftWindow.close();
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(openWindows);
]]>
</script>
</window>
|