Bug 445330, document.loaded XML documents fire onload before DOMContentLoaded, r+sr=bz

This commit is contained in:
Olli Pettay 2008-07-19 18:20:22 +03:00
parent 668332d867
commit ed5c851afb
5 changed files with 71 additions and 6 deletions

View File

@ -3431,10 +3431,14 @@ nsDocument::EndLoad()
NS_DOCUMENT_NOTIFY_OBSERVERS(EndLoad, (this));
nsRefPtr<nsIRunnable> ev =
new nsRunnableMethod<nsDocument>(this,
&nsDocument::DispatchContentLoadedEvents);
NS_DispatchToCurrentThread(ev);
if (!mSynchronousDOMContentLoaded) {
nsRefPtr<nsIRunnable> ev =
new nsRunnableMethod<nsDocument>(this,
&nsDocument::DispatchContentLoadedEvents);
NS_DispatchToCurrentThread(ev);
} else {
DispatchContentLoadedEvents();
}
}
void

View File

@ -940,6 +940,8 @@ protected:
PRPackedBool mDelayFrameLoaderInitialization:1;
PRPackedBool mSynchronousDOMContentLoaded:1;
PRUint8 mXMLDeclarationBits;
PRUint8 mDefaultElementType;

View File

@ -542,7 +542,10 @@ nsXMLDocument::EndLoad()
mChannelIsPending = PR_FALSE;
mLoopingForSyncLoad = PR_FALSE;
if (mLoadedAsData || mLoadedAsInteractiveData) {
mSynchronousDOMContentLoaded = (mLoadedAsData || mLoadedAsInteractiveData);
nsDocument::EndLoad();
if (mSynchronousDOMContentLoaded) {
mSynchronousDOMContentLoaded = PR_FALSE;
// Generate a document load event for the case when an XML
// document was loaded as pure data without any presentation
// attached to it.
@ -550,7 +553,6 @@ nsXMLDocument::EndLoad()
nsEventDispatcher::Dispatch(static_cast<nsIDocument*>(this), nsnull,
&event);
}
nsDocument::EndLoad();
}
// nsIDOMNode interface

View File

@ -49,6 +49,7 @@ _TEST_FILES = test_bug232004.xhtml \
test_bug355213.xhtml \
test_bug392338.html \
test_bug399502.xhtml \
test_bug445330.html \
test_viewport.xhtml \
$(NULL)

View File

@ -0,0 +1,56 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=445330
-->
<head>
<title>Test for Bug 445330</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/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=445330">Mozilla Bug 445330</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 445330 **/
var loadCounter = 0;
var dclCounter = 0;
function runTest() {
var doc = document.implementation.createDocument("", "", null);
doc.onload = function(evt) {
++loadCounter;
ok(dclCounter == 1, "DOMContentLoaded should have fired.");
if (loadCounter == 1 && dclCounter == 1) {
SimpleTest.finish();
}
};
doc.addEventListener("DOMContentLoaded",
function (evt) {
++dclCounter;
ok(loadCounter == 0, "load event shouldn't have fired.");
if (loadCounter == 1 && dclCounter == 1) {
SimpleTest.finish();
}
},
true);
doc.load("");
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(runTest);
</script>
</pre>
</body>
</html>