mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-06 14:44:26 +00:00
Bug 313646 - synchronous XMLHttpRequest does not fire readystatechange event, r=sicking, a=sicking
This commit is contained in:
parent
f69f6db1c8
commit
3a2339d1ee
@ -2633,12 +2633,6 @@ nsXMLHttpRequest::Send(nsIVariant *aBody)
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Now that we've successfully opened the channel, we can change state. Note
|
||||
// that this needs to come after the AsyncOpen() and rv check, because this
|
||||
// can run script that would try to restart this request, and that could end
|
||||
// up doing our AsyncOpen on a null channel if the reentered AsyncOpen fails.
|
||||
ChangeState(XML_HTTP_REQUEST_SENT);
|
||||
|
||||
// If we're synchronous, spin an event loop here and wait
|
||||
if (!(mState & XML_HTTP_REQUEST_ASYNC)) {
|
||||
mState |= XML_HTTP_REQUEST_SYNCLOOPING;
|
||||
@ -2661,6 +2655,9 @@ nsXMLHttpRequest::Send(nsIVariant *aBody)
|
||||
}
|
||||
}
|
||||
|
||||
ChangeState(XML_HTTP_REQUEST_SENT);
|
||||
// Note, calling ChangeState may have cleared
|
||||
// XML_HTTP_REQUEST_SYNCLOOPING flag.
|
||||
nsIThread *thread = NS_GetCurrentThread();
|
||||
while (mState & XML_HTTP_REQUEST_SYNCLOOPING) {
|
||||
if (!NS_ProcessNextEvent(thread)) {
|
||||
@ -2677,6 +2674,11 @@ nsXMLHttpRequest::Send(nsIVariant *aBody)
|
||||
NS_DispatchToCurrentThread(resumeTimeoutRunnable);
|
||||
}
|
||||
} else {
|
||||
// Now that we've successfully opened the channel, we can change state. Note
|
||||
// that this needs to come after the AsyncOpen() and rv check, because this
|
||||
// can run script that would try to restart this request, and that could end
|
||||
// up doing our AsyncOpen on a null channel if the reentered AsyncOpen fails.
|
||||
ChangeState(XML_HTTP_REQUEST_SENT);
|
||||
if (!mUploadComplete &&
|
||||
HasListenersFor(NS_LITERAL_STRING(UPLOADPROGRESS_STR)) ||
|
||||
(mUpload && mUpload->HasListenersFor(NS_LITERAL_STRING(PROGRESS_STR)))) {
|
||||
@ -2993,9 +2995,11 @@ nsXMLHttpRequest::ChangeState(PRUint32 aState, PRBool aBroadcast)
|
||||
mProgressNotifier->Cancel();
|
||||
}
|
||||
|
||||
if ((mState & XML_HTTP_REQUEST_ASYNC) &&
|
||||
(aState & XML_HTTP_REQUEST_LOADSTATES) && // Broadcast load states only
|
||||
aBroadcast) {
|
||||
if ((aState & XML_HTTP_REQUEST_LOADSTATES) && // Broadcast load states only
|
||||
aBroadcast &&
|
||||
(mState & XML_HTTP_REQUEST_ASYNC ||
|
||||
aState & XML_HTTP_REQUEST_OPENED ||
|
||||
aState & XML_HTTP_REQUEST_COMPLETED)) {
|
||||
nsCOMPtr<nsIDOMEvent> event;
|
||||
rv = CreateReadystatechangeEvent(getter_AddRefs(event));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -310,6 +310,8 @@ _TEST_FILES2 = \
|
||||
file_xhtmlserializer_2_latin1.xhtml \
|
||||
test_bug500937.html \
|
||||
test_htmlcopyencoder.html \
|
||||
test_bug313646.html \
|
||||
bug313646.txt \
|
||||
test_htmlcopyencoder.xhtml \
|
||||
test_bug270145.xhtml \
|
||||
test_elementTraversal.html \
|
||||
|
1
content/base/test/bug313646.txt
Normal file
1
content/base/test/bug313646.txt
Normal file
@ -0,0 +1 @@
|
||||
Nothing to see here. Just need to request this file via XHR.
|
63
content/base/test/test_bug313646.html
Normal file
63
content/base/test/test_bug313646.html
Normal file
@ -0,0 +1,63 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=313646
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 313646</title>
|
||||
<script type="text/javascript" src="/MochiKit/packed.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=313646">Mozilla Bug 313646</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
/** Test for Bug 313646 **/
|
||||
|
||||
// content/base/test/bug313646.txt
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var count1 = 0;
|
||||
var count2 = 0;
|
||||
var count3 = 0;
|
||||
var count4 = 0;
|
||||
var innerXHRDone = 0;
|
||||
var req = new XMLHttpRequest();
|
||||
req.onreadystatechange = function(evt) {
|
||||
++window["count" + evt.target.readyState];
|
||||
|
||||
// Do something a bit evil, start a new sync XHR in
|
||||
// readyStateChange listener.
|
||||
var innerXHR = new XMLHttpRequest();
|
||||
innerXHR.onreadystatechange = function(e) {
|
||||
if (e.target.readyState == 4) {
|
||||
++innerXHRDone;
|
||||
}
|
||||
}
|
||||
innerXHR.open("GET","bug313646.txt", false);
|
||||
innerXHR.send();
|
||||
}
|
||||
|
||||
// make the synchronous request
|
||||
req.open("GET","bug313646.txt", false);
|
||||
req.send();
|
||||
|
||||
ok(count1, "XMLHttpRequest wasn't in state 1");
|
||||
is(count2, 0, "XMLHttpRequest shouldn't have been in state 2");
|
||||
is(count3, 0, "XMLHttpRequest shouldn't have been in state 3");
|
||||
ok(count4, "XMLHttpRequest wasn't in state 4");
|
||||
is(innerXHRDone, 2, "There should have been 2 inner XHRs.");
|
||||
|
||||
SimpleTest.finish();
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user