2011-01-25 03:23:08 +03:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=608030
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for MozAfterPaint pref Bug 608030</title>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=608030">Mozilla Bug 608030</a>
|
|
|
|
<div id="display" style="width: 10em; height: 5em; background-color: red"></div>
|
|
|
|
<pre id="test">
|
|
|
|
<script type="application/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 608030 **/
|
|
|
|
|
|
|
|
function get_pref()
|
|
|
|
{
|
2011-04-20 16:52:18 +04:00
|
|
|
return SpecialPowers.getBoolPref("dom.send_after_paint_to_content");
|
2011-01-25 03:23:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function set_pref(val)
|
|
|
|
{
|
2011-04-20 16:52:18 +04:00
|
|
|
SpecialPowers.setBoolPref("dom.send_after_paint_to_content", val);
|
2011-01-25 03:23:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
window.addEventListener("load", step0, false);
|
|
|
|
|
|
|
|
is(get_pref(), true, "pref defaults to true in mochitest harness");
|
|
|
|
|
|
|
|
function print_rect(rect) {
|
|
|
|
return "(top=" + rect.top + ",left=" + rect.left + ",width=" + rect.width + ",height=" + rect.height + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_event(event) {
|
|
|
|
var res = "boundingClientRect=" + print_rect(event.boundingClientRect);
|
|
|
|
var rects = event.clientRects;
|
|
|
|
for (var i = 0; i < rects.length; ++i) {
|
|
|
|
res += " clientRects[" + i + "]=" + print_rect(rects[i]);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
function step0(event) {
|
|
|
|
// Wait until we get the MozAfterPaint following the load event
|
|
|
|
// before starting.
|
2012-08-29 09:48:13 +04:00
|
|
|
ok(true, "loaded");
|
2011-01-25 03:23:08 +03:00
|
|
|
window.addEventListener("MozAfterPaint", step1, false);
|
2011-05-23 04:25:56 +04:00
|
|
|
|
|
|
|
// Ensure a MozAfterPaint event is fired
|
|
|
|
div.style.backgroundColor = "yellow";
|
2011-01-25 03:23:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var start;
|
|
|
|
var div = document.getElementById("display");
|
|
|
|
|
|
|
|
function step1(event)
|
|
|
|
{
|
2011-05-23 04:25:56 +04:00
|
|
|
ok(true, "step1 reached: " + print_event(event));
|
2011-01-25 03:23:08 +03:00
|
|
|
window.removeEventListener("MozAfterPaint", step1, false);
|
|
|
|
|
|
|
|
start = Date.now();
|
|
|
|
|
|
|
|
window.addEventListener("MozAfterPaint", step2, false);
|
|
|
|
|
|
|
|
div.style.backgroundColor = "blue";
|
|
|
|
}
|
|
|
|
|
|
|
|
function step2(event)
|
|
|
|
{
|
2011-05-23 04:25:56 +04:00
|
|
|
ok(true, "step2 reached: " + print_event(event));
|
2011-01-25 03:23:08 +03:00
|
|
|
window.removeEventListener("MozAfterPaint", step2, false);
|
|
|
|
|
|
|
|
var end = Date.now();
|
|
|
|
var timeout = 3 * Math.max(end - start, 300);
|
|
|
|
|
|
|
|
ok(true, "got MozAfterPaint (timeout for next step is " + timeout + "ms)");
|
|
|
|
|
|
|
|
// Set the pref for our second test
|
|
|
|
set_pref(false);
|
|
|
|
|
|
|
|
// When there was previously another page in our window, we seem to
|
|
|
|
// get duplicate events, simultaneously, so we need to register our
|
|
|
|
// next listener after a zero timeout.
|
|
|
|
setTimeout(step3, 0, timeout);
|
|
|
|
}
|
2011-05-23 04:25:56 +04:00
|
|
|
function step3(timeout)
|
|
|
|
{
|
|
|
|
ok(true, "step3 reached");
|
2011-01-25 03:23:08 +03:00
|
|
|
window.addEventListener("MozAfterPaint", failstep, false);
|
|
|
|
|
|
|
|
div.style.backgroundColor = "fuchsia";
|
|
|
|
|
|
|
|
setTimeout(step4, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
function failstep(event)
|
|
|
|
{
|
2011-05-23 04:25:56 +04:00
|
|
|
ok(true, "failstep reached: " + print_event(event));
|
2011-01-25 03:23:08 +03:00
|
|
|
ok(false, "got MozAfterPaint when we should not have");
|
|
|
|
}
|
|
|
|
|
|
|
|
function step4()
|
|
|
|
{
|
2011-05-23 04:25:56 +04:00
|
|
|
ok(true, "step4 reached"); // If we didn't get the failure in failstep,
|
|
|
|
// then we passed.
|
2011-01-25 03:23:08 +03:00
|
|
|
|
2011-05-23 04:25:56 +04:00
|
|
|
window.removeEventListener("MozAfterPaint", failstep, false);
|
2011-01-25 03:23:08 +03:00
|
|
|
|
|
|
|
// Set the pref back in its initial state.
|
|
|
|
set_pref(true);
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|