зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1278777 - XHR in workers should support the setting of responseType before calling open(), r=bkelly
This commit is contained in:
Родитель
d1ad4b0dc8
Коммит
c177c5e05d
|
@ -760,6 +760,7 @@ class OpenRunnable final : public WorkerThreadProxySyncRunnable
|
|||
bool mBackgroundRequest;
|
||||
bool mWithCredentials;
|
||||
uint32_t mTimeout;
|
||||
XMLHttpRequestResponseType mResponseType;
|
||||
|
||||
public:
|
||||
OpenRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
|
||||
|
@ -767,11 +768,12 @@ public:
|
|||
const Optional<nsAString>& aUser,
|
||||
const Optional<nsAString>& aPassword,
|
||||
bool aBackgroundRequest, bool aWithCredentials,
|
||||
uint32_t aTimeout)
|
||||
uint32_t aTimeout, XMLHttpRequestResponseType aResponseType)
|
||||
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy),
|
||||
mMethod(aMethod),
|
||||
mURL(aURL), mBackgroundRequest(aBackgroundRequest),
|
||||
mWithCredentials(aWithCredentials), mTimeout(aTimeout)
|
||||
mWithCredentials(aWithCredentials), mTimeout(aTimeout),
|
||||
mResponseType(aResponseType)
|
||||
{
|
||||
if (aUser.WasPassed()) {
|
||||
mUserStr = aUser.Value();
|
||||
|
@ -1464,7 +1466,12 @@ OpenRunnable::MainThreadRunInternal()
|
|||
return rv2.StealNSResult();
|
||||
}
|
||||
|
||||
return mProxy->mXHR->SetResponseType(NS_LITERAL_STRING("text"));
|
||||
mProxy->mXHR->SetResponseType(mResponseType, rv2);
|
||||
if (rv2.Failed()) {
|
||||
return rv2.StealNSResult();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1902,7 +1909,7 @@ XMLHttpRequest::Open(const nsACString& aMethod, const nsAString& aUrl,
|
|||
RefPtr<OpenRunnable> runnable =
|
||||
new OpenRunnable(mWorkerPrivate, mProxy, aMethod, aUrl, aUser, aPassword,
|
||||
mBackgroundRequest, mWithCredentials,
|
||||
mTimeout);
|
||||
mTimeout, mResponseType);
|
||||
|
||||
++mProxy->mOpenCount;
|
||||
runnable->Dispatch(aRv);
|
||||
|
@ -2343,19 +2350,26 @@ XMLHttpRequest::SetResponseType(XMLHttpRequestResponseType aResponseType,
|
|||
return;
|
||||
}
|
||||
|
||||
if (!mProxy || (SendInProgress() &&
|
||||
(mProxy->mSeenLoadStart ||
|
||||
mStateData.mReadyState > nsIXMLHttpRequest::OPENED))) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
// "document" is fine for the main thread but not for a worker. Short-circuit
|
||||
// that here.
|
||||
if (aResponseType == XMLHttpRequestResponseType::Document) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mProxy) {
|
||||
// Open() has not been called yet. We store the responseType and we will use
|
||||
// it later in Open().
|
||||
mResponseType = aResponseType;
|
||||
return;
|
||||
}
|
||||
|
||||
if (SendInProgress() &&
|
||||
(mProxy->mSeenLoadStart ||
|
||||
mStateData.mReadyState > nsIXMLHttpRequest::OPENED)) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
nsString responseType;
|
||||
ConvertResponseTypeToString(aResponseType, responseType);
|
||||
|
||||
|
|
|
@ -125,6 +125,7 @@ support-files =
|
|||
fileapi_chromeScript.js
|
||||
importScripts_3rdParty_worker.js
|
||||
xhr_cors_redirect.sjs
|
||||
worker_bug1278777.js
|
||||
!/dom/base/test/file_XHRResponseURL.js
|
||||
!/dom/base/test/file_XHRResponseURL.sjs
|
||||
!/dom/base/test/file_XHRResponseURL.text
|
||||
|
@ -272,3 +273,4 @@ skip-if = (os == "win") || (os == "mac") || toolkit == 'android' #bug 798220
|
|||
[test_sharedWorker_lifetime.html]
|
||||
[test_fileReader.html]
|
||||
[test_navigator_workers_hardwareConcurrency.html]
|
||||
[test_bug1278777.html]
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1278777
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 1278777</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=1278777">Mozilla Bug 1278777</a>
|
||||
<script type="application/javascript">
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var worker = new Worker('worker_bug1278777.js');
|
||||
worker.onerror = function() {
|
||||
ok(false, "We should not see any error.");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
worker.onmessage = function(e) {
|
||||
ok(e.data, "Everything seems ok.");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,9 @@
|
|||
var xhr = new XMLHttpRequest();
|
||||
xhr.responseType = 'blob';
|
||||
xhr.open('GET', 'worker_bug1278777.js');
|
||||
|
||||
xhr.onload = function() {
|
||||
postMessage(xhr.response instanceof Blob);
|
||||
}
|
||||
|
||||
xhr.send();
|
|
@ -100,28 +100,6 @@ onmessage = function(event) {
|
|||
var exception;
|
||||
|
||||
xhr = new XMLHttpRequest();
|
||||
try {
|
||||
xhr.responseType = "arraybuffer";
|
||||
}
|
||||
catch(e) {
|
||||
exception = e;
|
||||
}
|
||||
|
||||
if (!exception) {
|
||||
throw new Error("Failed to throw when setting responseType before " +
|
||||
"calling open()");
|
||||
}
|
||||
|
||||
if (exception.name != "InvalidStateError") {
|
||||
throw new Error("Unexpected error when setting responseType before " +
|
||||
"calling open()");
|
||||
}
|
||||
|
||||
if (exception.code != DOMException.INVALID_STATE_ERR) {
|
||||
throw new Error("Unexpected error code when setting responseType before " +
|
||||
"calling open()");
|
||||
}
|
||||
|
||||
xhr.open("GET", url);
|
||||
xhr.responseType = "text";
|
||||
xhr.onload = function(event) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче