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
169
170
171
172
173
174
175
176
177
178
179
180
181
|
<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=450930
-->
<head>
<title>Test for Bug 450930 (MozAfterPaint)</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="runNext()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450930">Mozilla Bug 450930</a>
<div id="display">
<div id="d" style="width:400px; height:200px;"></div>
<iframe id="iframe" style="width:400px; height:200px;"
src="data:text/html,<div id='d'><span style='margin-left:3px;'>Hello</span>
</div><div style='margin-top:500px' id='d2'>
<span style='margin-left:3px;'>Goodbye</span></div>"></iframe>
<svg:svg style="width:410px; height:210px;" id="svg">
<svg:foreignObject width="100%" height="100%">
<iframe id="iframe2" style="width:400px; height:200px;"
src="data:text/html,<div id='d'><span style='margin-left:3px;'>Hello</span>
</div><div style='margin-top:500px' id='d2'>
<span style='margin-left:3px;'>Goodbye</span></div>"></iframe>
</svg:foreignObject>
</svg:svg>
</div>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript"><![CDATA[
function flash(doc, name) {
var d = doc.getElementById(name);
d.style.backgroundColor = d.style.backgroundColor == "blue" ? "yellow" : "blue";
// Now flush out style changes in that document, since our event listeners
// seem to assume that things will work that way.
d.getBoundingClientRect();
}
function le(v1, v2, s) {
window.opener.ok(v1 <= v2, s + " (" + v1 + "," + v2 + ")");
}
function checkContains(r1, r2, s) {
le(Math.round(r1.left), Math.round(r2.left), "Left edges out" + s);
le(Math.round(r2.right), Math.round(r1.right), "Right edges out" + s);
le(Math.round(r1.top), Math.round(r2.top), "Top edges out" + s);
le(Math.round(r2.bottom), Math.round(r1.bottom), "Bottom edges out" + s);
}
function isRect(r1, r2) {
return (Math.abs(r1.left - r2.left) <= 1 ||
Math.abs(r1.right - r2.right) <= 1 ||
Math.abs(r1.top - r2.top) <= 1 ||
Math.abs(r1.bottom - r2.bottom) <= 1);
}
function isRectInList(r, list) {
for (var i = 0; i < list.length; ++i) {
if (isRect(r, list[i]))
return true;
}
return false;
}
function doesRectContain(r1, r2) {
return Math.floor(r1.left) <= r2.left && r2.right <= Math.ceil(r1.right) &&
Math.floor(r1.top) <= r2.top && r2.bottom <= Math.ceil(r1.bottom);
}
function rectToString(r) {
return "(" + r.left + "," + r.top + "," + r.right + "," + r.bottom + ")";
}
function doesRectContainListElement(r, list) {
dump("Incoming rect: " + rectToString(r) + "\n");
for (var i = 0; i < list.length; ++i) {
dump("List rect " + i + ": " + rectToString(list[i]));
if (doesRectContain(r, list[i])) {
dump(" FOUND\n");
return true;
}
dump("\n");
}
dump("NOT FOUND\n");
return false;
}
function checkGotSubdoc(list, container) {
var r = container.getBoundingClientRect();
return doesRectContainListElement(r, list);
}
function runTest1() {
// test basic functionality
var iterations = 0;
var foundExactRect = false;
function listener(event) {
var r = SpecialPowers.wrap(event).boundingClientRect;
var bounds = document.getElementById('d').getBoundingClientRect();
checkContains(r, bounds, "");
if (isRectInList(bounds, SpecialPowers.wrap(event).clientRects)) {
foundExactRect = true;
}
window.removeEventListener("MozAfterPaint", listener);
++iterations;
if (iterations < 4) {
setTimeout(triggerPaint, 100);
} else {
window.opener.ok(foundExactRect, "Found exact rect");
runNext();
}
}
function triggerPaint() {
window.addEventListener("MozAfterPaint", listener);
flash(document, 'd');
window.opener.ok(true, "trigger test1 paint");
}
triggerPaint();
}
function runTest2(frameID, containerID) {
// test reporting of painting in subdocuments
var fired = 0;
var gotSubdocPrivileged = false;
var iframe = document.getElementById(frameID);
var container = document.getElementById(containerID);
function listener(event) {
if (checkGotSubdoc(SpecialPowers.wrap(event).clientRects, container))
gotSubdocPrivileged = true;
if (SpecialPowers.wrap(event).clientRects.length > 0) {
if (++fired == 1)
setTimeout(check, 100);
}
}
function check() {
window.opener.is(fired, 1, "Wrong event count (" + frameID + ")");
window.opener.ok(gotSubdocPrivileged, "Didn't get subdoc invalidation while we were privileged (" + frameID + ")");
window.removeEventListener("MozAfterPaint", listener);
runNext();
}
function triggerPaint() {
window.addEventListener("MozAfterPaint", listener);
document.body.offsetTop;
flash(iframe.contentDocument, 'd');
}
triggerPaint();
}
var test = 0;
var tests = [runTest1,
function() { runTest2("iframe", "iframe") },
function() { runTest2("iframe2", "svg") }];
function runNext() {
if (SpecialPowers.DOMWindowUtils.isMozAfterPaintPending) {
// Wait until there are no pending paints before trying to run tests
setTimeout(runNext, 100);
return;
}
if (test < tests.length) {
++test;
tests[test - 1]();
} else {
window.opener.finishTests();
}
}
]]></script>
</pre>
</body>
</html>
|