зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1513647 - MutableBlobStorage should be used in eCouldBeInTemporaryFile mode for fetch(), r=smaug
This commit is contained in:
Родитель
038eae013b
Коммит
1472148116
|
@ -838,6 +838,15 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext) {
|
|||
|
||||
response = new InternalResponse(responseStatus, statusText);
|
||||
|
||||
UniquePtr<mozilla::ipc::PrincipalInfo> principalInfo(
|
||||
new mozilla::ipc::PrincipalInfo());
|
||||
nsresult rv = PrincipalToPrincipalInfo(mPrincipal, principalInfo.get());
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
response->SetPrincipalInfo(std::move(principalInfo));
|
||||
|
||||
response->Headers()->FillResponseHeaders(httpChannel);
|
||||
|
||||
// If Content-Encoding or Transfer-Encoding headers are set, then the actual
|
||||
|
|
|
@ -508,16 +508,22 @@ bool MutableBlobStorage::MaybeCreateTemporaryFile(
|
|||
RefPtr<MutableBlobStorage> self = this;
|
||||
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
|
||||
"MutableBlobStorage::MaybeCreateTemporaryFile",
|
||||
[self]() { self->MaybeCreateTemporaryFileOnMainThread(); });
|
||||
EventTarget()->Dispatch(r.forget(), NS_DISPATCH_SYNC);
|
||||
return !!mActor;
|
||||
[self]() {
|
||||
MutexAutoLock lock(self->mMutex);
|
||||
self->MaybeCreateTemporaryFileOnMainThread(lock);
|
||||
if (!self->mActor) {
|
||||
self->ErrorPropagated(NS_ERROR_FAILURE);
|
||||
}
|
||||
});
|
||||
EventTarget()->Dispatch(r.forget(), NS_DISPATCH_NORMAL);
|
||||
return true;
|
||||
}
|
||||
|
||||
MaybeCreateTemporaryFileOnMainThread();
|
||||
MaybeCreateTemporaryFileOnMainThread(aProofOfLock);
|
||||
return !!mActor;
|
||||
}
|
||||
|
||||
void MutableBlobStorage::MaybeCreateTemporaryFileOnMainThread() {
|
||||
void MutableBlobStorage::MaybeCreateTemporaryFileOnMainThread(const MutexAutoLock& aProofOfLock) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!mActor);
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ class MutableBlobStorage final {
|
|||
uint64_t aSize) const;
|
||||
|
||||
bool MaybeCreateTemporaryFile(const MutexAutoLock& aProofOfLock);
|
||||
void MaybeCreateTemporaryFileOnMainThread();
|
||||
void MaybeCreateTemporaryFileOnMainThread(const MutexAutoLock& aProofOfLock);
|
||||
|
||||
MOZ_MUST_USE nsresult
|
||||
DispatchToIOThread(already_AddRefed<nsIRunnable> aRunnable);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var data = new Array(256).join("1234567890ABCDEF");
|
||||
|
||||
function test_basic() {
|
||||
info("Simple test");
|
||||
function test_fetch_basic() {
|
||||
info("Simple fetch test");
|
||||
|
||||
fetch("/tests/dom/xhr/tests/temporaryFileBlob.sjs",
|
||||
{ method: "POST", body: data })
|
||||
|
@ -10,6 +10,9 @@ function test_basic() {
|
|||
}).then(blob => {
|
||||
ok(blob instanceof Blob, "We have a blob!");
|
||||
is(blob.size, data.length, "Data length matches");
|
||||
if ("SpecialPowers" in self) {
|
||||
is(SpecialPowers.wrap(blob).blobImplType, "StreamBlobImpl", "We have a blob stored into a stream file");
|
||||
}
|
||||
|
||||
var fr = new FileReader();
|
||||
fr.readAsText(blob);
|
||||
|
@ -20,7 +23,53 @@ function test_basic() {
|
|||
});
|
||||
}
|
||||
|
||||
function test_worker() {
|
||||
function test_fetch_worker() {
|
||||
info("fetch in workers");
|
||||
var w = new Worker('worker_temporaryFileBlob.js');
|
||||
w.onmessage = function(e) {
|
||||
if (e.data.type == 'info') {
|
||||
info(e.data.msg);
|
||||
} else if (e.data.type == 'check') {
|
||||
ok(e.data.what, e.data.msg);
|
||||
} else if (e.data.type == 'finish') {
|
||||
next();
|
||||
} else {
|
||||
ok(false, 'Something wrong happened');
|
||||
}
|
||||
}
|
||||
|
||||
w.postMessage('fetch');
|
||||
}
|
||||
|
||||
function test_xhr_basic() {
|
||||
info("Simple XHR test");
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.responseType = "blob";
|
||||
xhr.open("POST", "/tests/dom/xhr/tests/temporaryFileBlob.sjs");
|
||||
xhr.send(data);
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4) {
|
||||
let blob = xhr.response;
|
||||
|
||||
ok(blob instanceof Blob, "We have a blob!");
|
||||
is(blob.size, data.length, "Data length matches");
|
||||
if ("SpecialPowers" in self) {
|
||||
is(SpecialPowers.wrap(blob).blobImplType, "StreamBlobImpl", "We have a blob stored into a stream file");
|
||||
}
|
||||
|
||||
var fr = new FileReader();
|
||||
fr.readAsText(blob);
|
||||
fr.onload = function() {
|
||||
is(fr.result, data, "Data content matches");
|
||||
next();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function test_xhr_worker() {
|
||||
info("XHR in workers");
|
||||
var w = new Worker('worker_temporaryFileBlob.js');
|
||||
w.onmessage = function(e) {
|
||||
|
@ -35,5 +84,5 @@ function test_worker() {
|
|||
}
|
||||
}
|
||||
|
||||
w.postMessage(42);
|
||||
w.postMessage('xhr');
|
||||
}
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
|
||||
var tests = [
|
||||
// from common_temporaryFileBlob.js:
|
||||
test_basic,
|
||||
test_worker,
|
||||
test_fetch_basic,
|
||||
test_fetch_worker,
|
||||
test_xhr_basic,
|
||||
test_xhr_worker,
|
||||
];
|
||||
|
||||
function next() {
|
||||
|
|
|
@ -17,5 +17,9 @@ function next() {
|
|||
}
|
||||
|
||||
onmessage = function(e) {
|
||||
test_basic();
|
||||
if (e == 'xhr') {
|
||||
test_xhr_basic();
|
||||
} else {
|
||||
test_fetch_basic();
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче