зеркало из https://github.com/mozilla/pjs.git
fix bug 371026 - reftest: double setTimeout from onload is not late enough for some tests
the fix is to provide a way for the testcase to indicate when it's finished loading. Also move the reftest self-checks into their own manifest. r=dbaron
This commit is contained in:
Родитель
dbfd44d4e3
Коммит
be0b28d6a2
|
@ -0,0 +1,7 @@
|
||||||
|
== data:text/html,<body> about:blank
|
||||||
|
== data:text/plain, about:blank
|
||||||
|
!= data:text/plain,HELLO about:blank
|
||||||
|
|
||||||
|
# these tests make sure async reftests work:
|
||||||
|
== test-async.xul test-async-ref.xul
|
||||||
|
== test-async.html test-async-ref.html
|
|
@ -0,0 +1,2 @@
|
||||||
|
<html>
|
||||||
|
<body style="background-color: green;">
|
|
@ -0,0 +1,3 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||||
|
style="background-color: green"/>
|
|
@ -0,0 +1,12 @@
|
||||||
|
<html class="reftest-wait">
|
||||||
|
<body style="background-color: red;"
|
||||||
|
onload="HandleLoad()">
|
||||||
|
<script>
|
||||||
|
function HandleLoad() {
|
||||||
|
setTimeout(function() {
|
||||||
|
document.body.style.backgroundColor = "green";
|
||||||
|
document.documentElement.className = "";
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||||
|
id="main"
|
||||||
|
class="reftest-wait"
|
||||||
|
style="background-color: red;"
|
||||||
|
onload="HandleLoad()">
|
||||||
|
<script>
|
||||||
|
function HandleLoad() {
|
||||||
|
setTimeout(function() {
|
||||||
|
document.documentElement.style.backgroundColor = "green";
|
||||||
|
document.documentElement.className = "";
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</window>
|
|
@ -3,9 +3,7 @@
|
||||||
# failing test.
|
# failing test.
|
||||||
|
|
||||||
# verify the tests work
|
# verify the tests work
|
||||||
== data:text/html,<body> about:blank
|
include reftest-sanity/reftest.list
|
||||||
== data:text/plain, about:blank
|
|
||||||
!= data:text/plain,HELLO about:blank
|
|
||||||
|
|
||||||
# bugs/
|
# bugs/
|
||||||
include bugs/reftest.list
|
include bugs/reftest.list
|
||||||
|
|
|
@ -146,7 +146,7 @@ avoided.
|
||||||
In general, the best way to achieve this is to make the test and the
|
In general, the best way to achieve this is to make the test and the
|
||||||
reference identical in as many aspects as possible. For example:
|
reference identical in as many aspects as possible. For example:
|
||||||
|
|
||||||
Good test Markup:
|
Good test markup:
|
||||||
<div style="color:green"><table><tr><td><span>green
|
<div style="color:green"><table><tr><td><span>green
|
||||||
</span></td></tr></table></div>
|
</span></td></tr></table></div>
|
||||||
|
|
||||||
|
@ -163,3 +163,24 @@ reference identical in as many aspects as possible. For example:
|
||||||
<!-- span doesn't change the positioning, so skip it -->
|
<!-- span doesn't change the positioning, so skip it -->
|
||||||
<div style="color:green"><table><tr><td>green
|
<div style="color:green"><table><tr><td>green
|
||||||
</td></tr></table></div>
|
</td></tr></table></div>
|
||||||
|
|
||||||
|
Asynchronous Tests
|
||||||
|
==================
|
||||||
|
|
||||||
|
Normally reftest takes a snapshot of the given markup's rendering right
|
||||||
|
after the load event fires for content. If your test needs to postpone
|
||||||
|
the moment the snapshot is taken, it should make sure a class
|
||||||
|
'reftest-wait' is on the root element by the moment the load event
|
||||||
|
fires. The easiest way to do this is to put it in the markup, e.g.:
|
||||||
|
<html class="reftest-wait">
|
||||||
|
|
||||||
|
When your test is ready, you should remove this class from the root
|
||||||
|
element, for example using this code:
|
||||||
|
document.documentElement.className = "";
|
||||||
|
|
||||||
|
|
||||||
|
Note that in layout tests it is often enough to trigger layout using
|
||||||
|
document.body.offsetWidth // HTML example
|
||||||
|
|
||||||
|
When possible, you should use this technique instead of making your
|
||||||
|
test async.
|
||||||
|
|
|
@ -203,16 +203,39 @@ function OnDocumentLoad(event)
|
||||||
// Ignore load events for subframes.
|
// Ignore load events for subframes.
|
||||||
return;
|
return;
|
||||||
|
|
||||||
clearTimeout(gFailureTimeout);
|
function shouldWait() {
|
||||||
// Since we can't use a bubbling-phase load listener from chrome,
|
return contentRootElement.className.split(/\s+/)
|
||||||
// this is a capturing phase listener. So do setTimeout twice, the
|
.indexOf("reftest-wait") != -1;
|
||||||
// first to get us after the onload has fired in the content, and
|
}
|
||||||
// the second to get us after any setTimeout(foo, 0) in the content.
|
|
||||||
setTimeout(setTimeout, 0, DocumentLoaded, 0);
|
var contentRootElement = gBrowser.contentDocument.documentElement;
|
||||||
|
if (shouldWait()) {
|
||||||
|
// The testcase will let us know when the test snapshot should be made.
|
||||||
|
// Register a mutation listener to know when the 'reftest-wait' class
|
||||||
|
// gets removed.
|
||||||
|
contentRootElement.addEventListener(
|
||||||
|
"DOMAttrModified",
|
||||||
|
function(event) {
|
||||||
|
if (!shouldWait()) {
|
||||||
|
contentRootElement.removeEventListener(
|
||||||
|
"DOMAttrModified",
|
||||||
|
arguments.callee,
|
||||||
|
false);
|
||||||
|
setTimeout(DocumentLoaded, 0);
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
} else {
|
||||||
|
// Since we can't use a bubbling-phase load listener from chrome,
|
||||||
|
// this is a capturing phase listener. So do setTimeout twice, the
|
||||||
|
// first to get us after the onload has fired in the content, and
|
||||||
|
// the second to get us after any setTimeout(foo, 0) in the content.
|
||||||
|
setTimeout(setTimeout, 0, DocumentLoaded, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function DocumentLoaded()
|
function DocumentLoaded()
|
||||||
{
|
{
|
||||||
|
clearTimeout(gFailureTimeout);
|
||||||
var key = IFrameToKey();
|
var key = IFrameToKey();
|
||||||
switch (gState) {
|
switch (gState) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|
Загрузка…
Ссылка в новой задаче