Bug 1126819 - Part 1: Respect the RequestInit.cache member in Request's constructor; r=nsm

This commit is contained in:
Ehsan Akhgari 2015-03-22 13:13:18 -04:00
Родитель 253e96f2ca
Коммит 3ae4ca6b18
2 изменённых файлов: 12 добавлений и 0 удалений

Просмотреть файл

@ -82,6 +82,7 @@ Request::Constructor(const GlobalObject& aGlobal,
RequestMode fallbackMode = RequestMode::EndGuard_;
RequestCredentials fallbackCredentials = RequestCredentials::EndGuard_;
RequestCache fallbackCache = RequestCache::EndGuard_;
if (aInput.IsUSVString()) {
nsString input;
input.Assign(aInput.GetAsUSVString());
@ -127,6 +128,7 @@ Request::Constructor(const GlobalObject& aGlobal,
request->SetURL(NS_ConvertUTF16toUTF8(requestURL));
fallbackMode = RequestMode::Cors;
fallbackCredentials = RequestCredentials::Omit;
fallbackCache = RequestCache::Default;
}
// CORS-with-forced-preflight is not publicly exposed and should not be
@ -152,6 +154,12 @@ Request::Constructor(const GlobalObject& aGlobal,
request->SetCredentialsMode(credentials);
}
RequestCache cache = aInit.mCache.WasPassed() ?
aInit.mCache.Value() : fallbackCache;
if (cache != RequestCache::EndGuard_) {
request->SetCacheMode(cache);
}
// Request constructor step 14.
if (aInit.mMethod.WasPassed()) {
nsAutoCString method(aInit.mMethod.Value());

Просмотреть файл

@ -7,6 +7,7 @@ function testDefaultCtor() {
is(req.referrer, "about:client", "Default referrer is `client` which serializes to about:client.");
is(req.mode, "cors", "Request mode for string input is cors");
is(req.credentials, "omit", "Default Request credentials is omit");
is(req.cache, "default", "Default Request cache is default");
var req = new Request(req);
is(req.method, "GET", "Default Request method is GET");
@ -16,6 +17,7 @@ function testDefaultCtor() {
is(req.referrer, "about:client", "Default referrer is `client` which serializes to about:client.");
is(req.mode, "cors", "Request mode string input is cors");
is(req.credentials, "omit", "Default Request credentials is omit");
is(req.cache, "default", "Default Request cache is default");
}
function testClone() {
@ -25,6 +27,7 @@ function testClone() {
body: "Sample body",
mode: "same-origin",
credentials: "same-origin",
cache: "no-store",
});
var clone = orig.clone();
ok(clone.method === "POST", "Request method is POST");
@ -39,6 +42,7 @@ function testClone() {
ok(clone.referrer === "about:client", "Default referrer is `client` which serializes to about:client.");
ok(clone.mode === "same-origin", "Request mode is same-origin");
ok(clone.credentials === "same-origin", "Default credentials is same-origin");
ok(clone.cache === "no-store", "Default cache is no-store");
ok(!orig.bodyUsed, "Original body is not consumed.");
ok(!clone.bodyUsed, "Clone body is not consumed.");