зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1605854 - Remove uneval/toSource from CORS tests. r=baku
Differential Revision: https://phabricator.services.mozilla.com/D58374 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
37de21b36d
Коммит
188c9b376a
|
@ -1,5 +1,4 @@
|
|||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
|
||||
|
||||
function handleRequest(request, response)
|
||||
{
|
||||
|
@ -25,7 +24,7 @@ function handleRequest(request, response)
|
|||
// Send response
|
||||
|
||||
secData =
|
||||
eval(getState("test/dom/security/test_CrossSiteXHR_cache:secData"));
|
||||
JSON.parse(getState("test/dom/security/test_CrossSiteXHR_cache:secData"));
|
||||
|
||||
if (secData.allowOrigin)
|
||||
response.setHeader("Access-Control-Allow-Origin", secData.allowOrigin);
|
||||
|
|
|
@ -16,7 +16,7 @@ window.addEventListener("message", function(e) {
|
|||
|
||||
sendData = null;
|
||||
|
||||
req = eval(e.data);
|
||||
req = JSON.parse(e.data);
|
||||
var res = {
|
||||
didFail: false,
|
||||
events: [],
|
||||
|
@ -110,7 +110,7 @@ window.addEventListener("message", function(e) {
|
|||
});
|
||||
|
||||
function post(e, res) {
|
||||
e.source.postMessage(res.toSource(), "http://mochi.test:8888");
|
||||
e.source.postMessage(JSON.stringify(res), "http://mochi.test:8888");
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
|
@ -6,7 +6,7 @@ window.addEventListener("message", function(e) {\n\
|
|||
\n\
|
||||
sendData = null;\n\
|
||||
\n\
|
||||
req = eval(e.data);\n\
|
||||
req = JSON.parse(e.data);\n\
|
||||
var res = {\n\
|
||||
didFail: false,\n\
|
||||
events: [],\n\
|
||||
|
@ -81,7 +81,7 @@ window.addEventListener("message", function(e) {\n\
|
|||
}, false);\n\
|
||||
\n\
|
||||
function post(e, res) {\n\
|
||||
e.source.postMessage(res.toSource(), "*");\n\
|
||||
e.source.postMessage(JSON.stringify(res), "*");\n\
|
||||
}\n\
|
||||
function trimString(stringValue) {\n\
|
||||
return stringValue.replace("/^\s+|\s+$/g","");\n\
|
||||
|
|
|
@ -25,7 +25,7 @@ function handleRequest(request, response)
|
|||
|
||||
if (query.hop) {
|
||||
query.hop = parseInt(query.hop, 10);
|
||||
hops = eval(query.hops);
|
||||
hops = JSON.parse(query.hops);
|
||||
var curHop = hops[query.hop - 1];
|
||||
query.allowOrigin = curHop.allowOrigin;
|
||||
query.allowHeaders = curHop.allowHeaders;
|
||||
|
@ -50,7 +50,7 @@ function handleRequest(request, response)
|
|||
}
|
||||
|
||||
if (!isPreflight && "headers" in query) {
|
||||
headers = eval(query.headers);
|
||||
headers = JSON.parse(query.headers);
|
||||
for(headerName in headers) {
|
||||
// Content-Type is changed if there was a body
|
||||
if (!(headerName == "Content-Type" && body) &&
|
||||
|
@ -142,7 +142,7 @@ function handleRequest(request, response)
|
|||
}
|
||||
else {
|
||||
if (query.responseHeaders) {
|
||||
let responseHeaders = eval(query.responseHeaders);
|
||||
let responseHeaders = JSON.parse(query.responseHeaders);
|
||||
for (let responseHeader in responseHeaders) {
|
||||
response.setHeader(responseHeader, responseHeaders[responseHeader]);
|
||||
}
|
||||
|
|
|
@ -61,9 +61,9 @@ function* runTest() {
|
|||
method: test.method
|
||||
};
|
||||
|
||||
loaderWindow.postMessage(req.toSource(), origin);
|
||||
loaderWindow.postMessage(JSON.stringify(req), origin);
|
||||
number_of_tests++;
|
||||
eval(yield);
|
||||
yield;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -663,7 +663,7 @@ function* runTest() {
|
|||
"application/x-www-form-urlencoded"]
|
||||
.includes(test.headers[name].toLowerCase()));
|
||||
}
|
||||
req.url += "&headers=" + escape(test.headers.toSource());
|
||||
req.url += "&headers=" + escape(JSON.stringify(test.headers));
|
||||
reqHeaders =
|
||||
escape(Object.keys(test.headers)
|
||||
.filter(isUnsafeHeader)
|
||||
|
@ -685,14 +685,14 @@ function* runTest() {
|
|||
if (test.preflightStatus)
|
||||
req.url += "&preflightStatus=" + test.preflightStatus;
|
||||
if (test.responseHeaders)
|
||||
req.url += "&responseHeaders=" + escape(test.responseHeaders.toSource());
|
||||
req.url += "&responseHeaders=" + escape(JSON.stringify(test.responseHeaders));
|
||||
if (test.exposeHeaders)
|
||||
req.url += "&exposeHeaders=" + escape(test.exposeHeaders);
|
||||
if (test.preflightBody)
|
||||
req.url += "&preflightBody=" + escape(test.preflightBody);
|
||||
|
||||
loaderWindow.postMessage(req.toSource(), origin);
|
||||
res = eval(yield);
|
||||
loaderWindow.postMessage(JSON.stringify(req), origin);
|
||||
res = JSON.parse(yield);
|
||||
}
|
||||
|
||||
// Test cookie behavior
|
||||
|
@ -795,9 +795,9 @@ function* runTest() {
|
|||
if ("allowMethods" in test)
|
||||
req.url += "&allowMethods=" + escape(test.allowMethods);
|
||||
|
||||
loaderWindow.postMessage(req.toSource(), origin);
|
||||
loaderWindow.postMessage(JSON.stringify(req), origin);
|
||||
|
||||
res = eval(yield);
|
||||
res = JSON.parse(yield);
|
||||
}
|
||||
|
||||
// Make sure to clear cookies to avoid affecting other tests
|
||||
|
@ -1285,7 +1285,7 @@ function* runTest() {
|
|||
for (test of tests) {
|
||||
req = {
|
||||
url: test.hops[0].server + basePath + "hop=1&hops=" +
|
||||
escape(test.hops.toSource()),
|
||||
escape(JSON.stringify(test.hops)),
|
||||
method: test.method,
|
||||
headers: test.headers,
|
||||
body: test.body,
|
||||
|
@ -1297,9 +1297,9 @@ function* runTest() {
|
|||
req.url += "&body=" + escape(test.body);
|
||||
}
|
||||
|
||||
loaderWindow.postMessage(req.toSource(), origin);
|
||||
loaderWindow.postMessage(JSON.stringify(req), origin);
|
||||
|
||||
res = eval(yield);
|
||||
res = JSON.parse(yield);
|
||||
}
|
||||
|
||||
document.location.href += "#finished";
|
||||
|
|
|
@ -25,8 +25,7 @@ var gen;
|
|||
function initTest() {
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
// Allow all cookies, then do the actual test initialization
|
||||
SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 0],
|
||||
["security.allow_eval_with_system_principal", true]]},
|
||||
SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 0]]},
|
||||
initTestCallback);
|
||||
}
|
||||
|
||||
|
@ -670,7 +669,7 @@ function* runTest() {
|
|||
"application/x-www-form-urlencoded"]
|
||||
.includes(test.headers[name].toLowerCase()));
|
||||
}
|
||||
req.url += "&headers=" + escape(test.headers.toSource());
|
||||
req.url += "&headers=" + escape(JSON.stringify(test.headers));
|
||||
reqHeaders =
|
||||
escape(Object.keys(test.headers)
|
||||
.filter(isUnsafeHeader)
|
||||
|
@ -692,86 +691,86 @@ function* runTest() {
|
|||
if (test.preflightStatus)
|
||||
req.url += "&preflightStatus=" + test.preflightStatus;
|
||||
if (test.responseHeaders)
|
||||
req.url += "&responseHeaders=" + escape(test.responseHeaders.toSource());
|
||||
req.url += "&responseHeaders=" + escape(JSON.stringify(test.responseHeaders));
|
||||
if (test.exposeHeaders)
|
||||
req.url += "&exposeHeaders=" + escape(test.exposeHeaders);
|
||||
if (test.preflightBody)
|
||||
req.url += "&preflightBody=" + escape(test.preflightBody);
|
||||
|
||||
loaderWindow.postMessage(req.toSource(), origin);
|
||||
res = eval(yield);
|
||||
loaderWindow.postMessage(JSON.stringify(req), origin);
|
||||
res = JSON.parse(yield);
|
||||
|
||||
if (test.pass) {
|
||||
is(res.didFail, false,
|
||||
"shouldn't have failed in test for " + test.toSource());
|
||||
"shouldn't have failed in test for " + JSON.stringify(test));
|
||||
if (test.status) {
|
||||
is(res.status, test.status, "wrong status in test for " + test.toSource());
|
||||
is(res.statusText, test.statusMessage, "wrong status text for " + test.toSource());
|
||||
is(res.status, test.status, "wrong status in test for " + JSON.stringify(test));
|
||||
is(res.statusText, test.statusMessage, "wrong status text for " + JSON.stringify(test));
|
||||
}
|
||||
else {
|
||||
is(res.status, 200, "wrong status in test for " + test.toSource());
|
||||
is(res.statusText, "OK", "wrong status text for " + test.toSource());
|
||||
is(res.status, 200, "wrong status in test for " + JSON.stringify(test));
|
||||
is(res.statusText, "OK", "wrong status text for " + JSON.stringify(test));
|
||||
}
|
||||
if (test.method !== "HEAD") {
|
||||
is(res.responseXML, "<res>hello pass</res>",
|
||||
"wrong responseXML in test for " + test.toSource());
|
||||
"wrong responseXML in test for " + JSON.stringify(test));
|
||||
is(res.responseText, "<res>hello pass</res>\n",
|
||||
"wrong responseText in test for " + test.toSource());
|
||||
"wrong responseText in test for " + JSON.stringify(test));
|
||||
is(res.events.join(","),
|
||||
"opening,rs1,sending,loadstart,rs2,rs3,rs4,load,loadend",
|
||||
"wrong responseText in test for " + test.toSource());
|
||||
"wrong responseText in test for " + JSON.stringify(test));
|
||||
}
|
||||
else {
|
||||
is(res.responseXML, null,
|
||||
"wrong responseXML in test for " + test.toSource());
|
||||
"wrong responseXML in test for " + JSON.stringify(test));
|
||||
is(res.responseText, "",
|
||||
"wrong responseText in test for " + test.toSource());
|
||||
"wrong responseText in test for " + JSON.stringify(test));
|
||||
is(res.events.join(","),
|
||||
"opening,rs1,sending,loadstart,rs2,rs4,load,loadend",
|
||||
"wrong responseText in test for " + test.toSource());
|
||||
"wrong responseText in test for " + JSON.stringify(test));
|
||||
}
|
||||
if (test.responseHeaders) {
|
||||
for (header in test.responseHeaders) {
|
||||
if (!test.expectedResponseHeaders.includes(header)) {
|
||||
is(res.responseHeaders[header], null,
|
||||
"|xhr.getResponseHeader()|wrong response header (" + header + ") in test for " +
|
||||
test.toSource());
|
||||
JSON.stringify(test));
|
||||
is(res.allResponseHeaders[header], undefined,
|
||||
"|xhr.getAllResponseHeaderss()|wrong response header (" + header + ") in test for " +
|
||||
test.toSource());
|
||||
JSON.stringify(test));
|
||||
}
|
||||
else {
|
||||
is(res.responseHeaders[header], test.responseHeaders[header],
|
||||
"|xhr.getResponseHeader()|wrong response header (" + header + ") in test for " +
|
||||
test.toSource());
|
||||
JSON.stringify(test));
|
||||
is(res.allResponseHeaders[header.toLowerCase()], test.responseHeaders[header],
|
||||
"|xhr.getAllResponseHeaderss()|wrong response header (" + header + ") in test for " +
|
||||
test.toSource());
|
||||
JSON.stringify(test));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
is(res.didFail, true,
|
||||
"should have failed in test for " + test.toSource());
|
||||
is(res.status, 0, "wrong status in test for " + test.toSource());
|
||||
is(res.statusText, "", "wrong status text for " + test.toSource());
|
||||
"should have failed in test for " + JSON.stringify(test));
|
||||
is(res.status, 0, "wrong status in test for " + JSON.stringify(test));
|
||||
is(res.statusText, "", "wrong status text for " + JSON.stringify(test));
|
||||
is(res.responseXML, null,
|
||||
"wrong responseXML in test for " + test.toSource());
|
||||
"wrong responseXML in test for " + JSON.stringify(test));
|
||||
is(res.responseText, "",
|
||||
"wrong responseText in test for " + test.toSource());
|
||||
"wrong responseText in test for " + JSON.stringify(test));
|
||||
if (!res.sendThrew) {
|
||||
is(res.events.join(","),
|
||||
"opening,rs1,sending,loadstart,rs4,error,loadend",
|
||||
"wrong events in test for " + test.toSource());
|
||||
"wrong events in test for " + JSON.stringify(test));
|
||||
}
|
||||
is(res.progressEvents, 0,
|
||||
"wrong events in test for " + test.toSource());
|
||||
"wrong events in test for " + JSON.stringify(test));
|
||||
if (test.responseHeaders) {
|
||||
for (header in test.responseHeaders) {
|
||||
is(res.responseHeaders[header], null,
|
||||
"wrong response header (" + header + ") in test for " +
|
||||
test.toSource());
|
||||
JSON.stringify(test));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -877,36 +876,36 @@ function* runTest() {
|
|||
if ("allowMethods" in test)
|
||||
req.url += "&allowMethods=" + escape(test.allowMethods);
|
||||
|
||||
loaderWindow.postMessage(req.toSource(), origin);
|
||||
loaderWindow.postMessage(JSON.stringify(req), origin);
|
||||
|
||||
res = eval(yield);
|
||||
res = JSON.parse(yield);
|
||||
if (test.pass) {
|
||||
is(res.didFail, false,
|
||||
"shouldn't have failed in test for " + test.toSource());
|
||||
is(res.status, 200, "wrong status in test for " + test.toSource());
|
||||
is(res.statusText, "OK", "wrong status text for " + test.toSource());
|
||||
"shouldn't have failed in test for " + JSON.stringify(test));
|
||||
is(res.status, 200, "wrong status in test for " + JSON.stringify(test));
|
||||
is(res.statusText, "OK", "wrong status text for " + JSON.stringify(test));
|
||||
is(res.responseXML, "<res>hello pass</res>",
|
||||
"wrong responseXML in test for " + test.toSource());
|
||||
"wrong responseXML in test for " + JSON.stringify(test));
|
||||
is(res.responseText, "<res>hello pass</res>\n",
|
||||
"wrong responseText in test for " + test.toSource());
|
||||
"wrong responseText in test for " + JSON.stringify(test));
|
||||
is(res.events.join(","),
|
||||
"opening,rs1,sending,loadstart,rs2,rs3,rs4,load,loadend",
|
||||
"wrong responseText in test for " + test.toSource());
|
||||
"wrong responseText in test for " + JSON.stringify(test));
|
||||
}
|
||||
else {
|
||||
is(res.didFail, true,
|
||||
"should have failed in test for " + test.toSource());
|
||||
is(res.status, 0, "wrong status in test for " + test.toSource());
|
||||
is(res.statusText, "", "wrong status text for " + test.toSource());
|
||||
"should have failed in test for " + JSON.stringify(test));
|
||||
is(res.status, 0, "wrong status in test for " + JSON.stringify(test));
|
||||
is(res.statusText, "", "wrong status text for " + JSON.stringify(test));
|
||||
is(res.responseXML, null,
|
||||
"wrong responseXML in test for " + test.toSource());
|
||||
"wrong responseXML in test for " + JSON.stringify(test));
|
||||
is(res.responseText, "",
|
||||
"wrong responseText in test for " + test.toSource());
|
||||
"wrong responseText in test for " + JSON.stringify(test));
|
||||
is(res.events.join(","),
|
||||
"opening,rs1,sending,loadstart,rs4,error,loadend",
|
||||
"wrong events in test for " + test.toSource());
|
||||
"wrong events in test for " + JSON.stringify(test));
|
||||
is(res.progressEvents, 0,
|
||||
"wrong events in test for " + test.toSource());
|
||||
"wrong events in test for " + JSON.stringify(test));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1431,7 +1430,7 @@ function* runTest() {
|
|||
for (test of tests) {
|
||||
req = {
|
||||
url: test.hops[0].server + basePath + "hop=1&hops=" +
|
||||
escape(test.hops.toSource()),
|
||||
escape(JSON.stringify(test.hops)),
|
||||
method: test.method,
|
||||
headers: test.headers,
|
||||
body: test.body,
|
||||
|
@ -1443,36 +1442,36 @@ function* runTest() {
|
|||
req.url += "&body=" + escape(test.body);
|
||||
}
|
||||
|
||||
loaderWindow.postMessage(req.toSource(), origin);
|
||||
loaderWindow.postMessage(JSON.stringify(req), origin);
|
||||
|
||||
res = eval(yield);
|
||||
res = JSON.parse(yield);
|
||||
if (test.pass) {
|
||||
is(res.didFail, false,
|
||||
"shouldn't have failed in test for " + test.toSource());
|
||||
is(res.status, 200, "wrong status in test for " + test.toSource());
|
||||
is(res.statusText, "OK", "wrong status text for " + test.toSource());
|
||||
"shouldn't have failed in test for " + JSON.stringify(test));
|
||||
is(res.status, 200, "wrong status in test for " + JSON.stringify(test));
|
||||
is(res.statusText, "OK", "wrong status text for " + JSON.stringify(test));
|
||||
is(res.responseXML, "<res>hello pass</res>",
|
||||
"wrong responseXML in test for " + test.toSource());
|
||||
"wrong responseXML in test for " + JSON.stringify(test));
|
||||
is(res.responseText, "<res>hello pass</res>\n",
|
||||
"wrong responseText in test for " + test.toSource());
|
||||
"wrong responseText in test for " + JSON.stringify(test));
|
||||
is(res.events.join(","),
|
||||
"opening,rs1,sending,loadstart,rs2,rs3,rs4,load,loadend",
|
||||
"wrong responseText in test for " + test.toSource());
|
||||
"wrong responseText in test for " + JSON.stringify(test));
|
||||
}
|
||||
else {
|
||||
is(res.didFail, true,
|
||||
"should have failed in test for " + test.toSource());
|
||||
is(res.status, 0, "wrong status in test for " + test.toSource());
|
||||
is(res.statusText, "", "wrong status text for " + test.toSource());
|
||||
"should have failed in test for " + JSON.stringify(test));
|
||||
is(res.status, 0, "wrong status in test for " + JSON.stringify(test));
|
||||
is(res.statusText, "", "wrong status text for " + JSON.stringify(test));
|
||||
is(res.responseXML, null,
|
||||
"wrong responseXML in test for " + test.toSource());
|
||||
"wrong responseXML in test for " + JSON.stringify(test));
|
||||
is(res.responseText, "",
|
||||
"wrong responseText in test for " + test.toSource());
|
||||
"wrong responseText in test for " + JSON.stringify(test));
|
||||
is(res.events.join(","),
|
||||
"opening,rs1,sending,loadstart,rs4,error,loadend",
|
||||
"wrong events in test for " + test.toSource());
|
||||
"wrong events in test for " + JSON.stringify(test));
|
||||
is(res.progressEvents, 0,
|
||||
"wrong progressevents in test for " + test.toSource());
|
||||
"wrong progressevents in test for " + JSON.stringify(test));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,6 @@ let gen;
|
|||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.requestFlakyTimeout("This test needs to generate artificial pauses, hence it uses timeouts. There is no way around it, unfortunately. :(");
|
||||
|
||||
SpecialPowers.pushPrefEnv({"set": [["security.allow_eval_with_system_principal",
|
||||
true]]});
|
||||
|
||||
window.addEventListener("message", function(e) {
|
||||
gen.next(e.data);
|
||||
});
|
||||
|
@ -541,16 +538,16 @@ function* runTest() {
|
|||
cacheTime: test.cacheTime,
|
||||
withCred: test.withCred };
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", setStateURL + escape(sec.toSource()), true);
|
||||
xhr.open("POST", setStateURL + escape(JSON.stringify(sec)), true);
|
||||
xhr.onloadend = function() { gen.next(); }
|
||||
xhr.send();
|
||||
yield undefined;
|
||||
|
||||
loaderWindow.postMessage(req.toSource(), origin);
|
||||
loaderWindow.postMessage(JSON.stringify(req), origin);
|
||||
|
||||
res = eval(yield);
|
||||
res = JSON.parse(yield);
|
||||
|
||||
testName = test.toSource() + " (index " + tests.indexOf(test) + ")";
|
||||
testName = JSON.stringify(test) + " (index " + tests.indexOf(test) + ")";
|
||||
|
||||
if (test.pass) {
|
||||
is(res.didFail, false,
|
||||
|
|
|
@ -118,9 +118,9 @@ function* runTest() {
|
|||
"&origin=" + escape(origin),
|
||||
method: "GET",
|
||||
};
|
||||
loaderWindow.postMessage(req.toSource(), isNullOrigin ? "*" : origin);
|
||||
loaderWindow.postMessage(JSON.stringify(req), isNullOrigin ? "*" : origin);
|
||||
|
||||
res = eval(yield);
|
||||
res = JSON.parse(yield);
|
||||
is(res.didFail, false, "shouldn't have failed for " + allowOrigin);
|
||||
is(res.status, 200, "wrong status for " + allowOrigin);
|
||||
is(res.statusText, "OK", "wrong status text for " + allowOrigin);
|
||||
|
@ -139,9 +139,9 @@ function* runTest() {
|
|||
url: baseURL + "allowOrigin=" + escape(allowOrigin),
|
||||
method: "GET",
|
||||
};
|
||||
loaderWindow.postMessage(req.toSource(), isNullOrigin ? "*" : origin);
|
||||
loaderWindow.postMessage(JSON.stringify(req), isNullOrigin ? "*" : origin);
|
||||
|
||||
res = eval(yield);
|
||||
res = JSON.parse(yield);
|
||||
is(res.didFail, true, "should have failed for " + allowOrigin);
|
||||
is(res.responseText, "", "should have no text for " + allowOrigin);
|
||||
is(res.status, 0, "should have no status for " + allowOrigin);
|
||||
|
|
|
@ -164,14 +164,14 @@ function testSameOriginCredentials() {
|
|||
}
|
||||
|
||||
function testResponse(res, test) {
|
||||
ok(test.pass, "Expected test to pass " + test.toSource());
|
||||
is(res.status, 200, "wrong status in test for " + test.toSource());
|
||||
is(res.statusText, "OK", "wrong status text for " + test.toSource());
|
||||
ok(test.pass, "Expected test to pass " + JSON.stringify(test));
|
||||
is(res.status, 200, "wrong status in test for " + JSON.stringify(test));
|
||||
is(res.statusText, "OK", "wrong status text for " + JSON.stringify(test));
|
||||
return res.text().then(function(v) {
|
||||
is(
|
||||
v,
|
||||
"<res>hello pass</res>\n",
|
||||
"wrong text in test for " + test.toSource()
|
||||
"wrong text in test for " + JSON.stringify(test)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -191,8 +191,8 @@ function testSameOriginCredentials() {
|
|||
});
|
||||
},
|
||||
function(e) {
|
||||
ok(!test.pass, "Expected test to fail " + test.toSource());
|
||||
ok(e instanceof TypeError, "Test should fail " + test.toSource());
|
||||
ok(!test.pass, "Expected test to fail " + JSON.stringify(test));
|
||||
ok(e instanceof TypeError, "Test should fail " + JSON.stringify(test));
|
||||
if (i < tests.length - 1) {
|
||||
runATest(tests, i + 1);
|
||||
} else {
|
||||
|
@ -804,7 +804,7 @@ function testModeCors() {
|
|||
].includes(test.headers[name].toLowerCase()))
|
||||
);
|
||||
}
|
||||
req.url += "&headers=" + escape(test.headers.toSource());
|
||||
req.url += "&headers=" + escape(JSON.stringify(test.headers));
|
||||
reqHeaders = escape(
|
||||
Object.keys(test.headers)
|
||||
.filter(isUnsafeHeader)
|
||||
|
@ -831,7 +831,8 @@ function testModeCors() {
|
|||
req.url += "&preflightStatus=" + test.preflightStatus;
|
||||
}
|
||||
if (test.responseHeaders) {
|
||||
req.url += "&responseHeaders=" + escape(test.responseHeaders.toSource());
|
||||
req.url +=
|
||||
"&responseHeaders=" + escape(JSON.stringify(test.responseHeaders));
|
||||
}
|
||||
if (test.exposeHeaders) {
|
||||
req.url += "&exposeHeaders=" + escape(test.exposeHeaders);
|
||||
|
@ -856,28 +857,28 @@ function testModeCors() {
|
|||
return fetch(request);
|
||||
})
|
||||
.then(function(res) {
|
||||
ok(test.pass, "Expected test to pass for " + test.toSource());
|
||||
ok(test.pass, "Expected test to pass for " + JSON.stringify(test));
|
||||
if (test.status) {
|
||||
is(
|
||||
res.status,
|
||||
test.status,
|
||||
"wrong status in test for " + test.toSource()
|
||||
"wrong status in test for " + JSON.stringify(test)
|
||||
);
|
||||
is(
|
||||
res.statusText,
|
||||
test.statusMessage,
|
||||
"wrong status text for " + test.toSource()
|
||||
"wrong status text for " + JSON.stringify(test)
|
||||
);
|
||||
} else {
|
||||
is(
|
||||
res.status,
|
||||
200,
|
||||
"wrong status in test for " + test.toSource()
|
||||
"wrong status in test for " + JSON.stringify(test)
|
||||
);
|
||||
is(
|
||||
res.statusText,
|
||||
"OK",
|
||||
"wrong status text for " + test.toSource()
|
||||
"wrong status text for " + JSON.stringify(test)
|
||||
);
|
||||
}
|
||||
if (test.responseHeaders) {
|
||||
|
@ -889,7 +890,7 @@ function testModeCors() {
|
|||
"|Headers.has()|wrong response header (" +
|
||||
header +
|
||||
") in test for " +
|
||||
test.toSource()
|
||||
JSON.stringify(test)
|
||||
);
|
||||
} else {
|
||||
is(
|
||||
|
@ -898,7 +899,7 @@ function testModeCors() {
|
|||
"|Headers.get()|wrong response header (" +
|
||||
header +
|
||||
") in test for " +
|
||||
test.toSource()
|
||||
JSON.stringify(test)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -911,21 +912,21 @@ function testModeCors() {
|
|||
is(
|
||||
v,
|
||||
"<res>hello pass</res>\n",
|
||||
"wrong responseText in test for " + test.toSource()
|
||||
"wrong responseText in test for " + JSON.stringify(test)
|
||||
);
|
||||
} else {
|
||||
is(
|
||||
v,
|
||||
"",
|
||||
"wrong responseText in HEAD test for " + test.toSource()
|
||||
"wrong responseText in HEAD test for " + JSON.stringify(test)
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch(function(e) {
|
||||
ok(!test.pass, "Expected test failure for " + test.toSource());
|
||||
ok(!test.pass, "Expected test failure for " + JSON.stringify(test));
|
||||
ok(
|
||||
e instanceof TypeError,
|
||||
"Exception should be TypeError for " + test.toSource()
|
||||
"Exception should be TypeError for " + JSON.stringify(test)
|
||||
);
|
||||
});
|
||||
})(test)
|
||||
|
@ -1112,7 +1113,7 @@ function testCrossOriginCredentials() {
|
|||
test.hops[0].server +
|
||||
corsServerPath +
|
||||
"hop=1&hops=" +
|
||||
escape(test.hops.toSource());
|
||||
escape(JSON.stringify(test.hops));
|
||||
} else {
|
||||
url = baseURL + "allowOrigin=" + escape(test.origin || origin);
|
||||
}
|
||||
|
@ -1152,14 +1153,14 @@ function testCrossOriginCredentials() {
|
|||
}
|
||||
|
||||
function testResponse(res, test) {
|
||||
ok(test.pass, "Expected test to pass for " + test.toSource());
|
||||
is(res.status, 200, "wrong status in test for " + test.toSource());
|
||||
is(res.statusText, "OK", "wrong status text for " + test.toSource());
|
||||
ok(test.pass, "Expected test to pass for " + JSON.stringify(test));
|
||||
is(res.status, 200, "wrong status in test for " + JSON.stringify(test));
|
||||
is(res.statusText, "OK", "wrong status text for " + JSON.stringify(test));
|
||||
return res.text().then(function(v) {
|
||||
is(
|
||||
v,
|
||||
"<res>hello pass</res>\n",
|
||||
"wrong text in test for " + test.toSource()
|
||||
"wrong text in test for " + JSON.stringify(test)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -1178,10 +1179,10 @@ function testCrossOriginCredentials() {
|
|||
});
|
||||
},
|
||||
function(e) {
|
||||
ok(!test.pass, "Expected test failure for " + test.toSource());
|
||||
ok(!test.pass, "Expected test failure for " + JSON.stringify(test));
|
||||
ok(
|
||||
e instanceof TypeError,
|
||||
"Exception should be TypeError for " + test.toSource()
|
||||
"Exception should be TypeError for " + JSON.stringify(test)
|
||||
);
|
||||
if (i < tests.length - 1) {
|
||||
runATest(tests, i + 1);
|
||||
|
@ -1270,7 +1271,7 @@ function testModeNoCorsCredentials() {
|
|||
}
|
||||
|
||||
function testResponse(res, test) {
|
||||
is(res.type, "opaque", "wrong response type for " + test.toSource());
|
||||
is(res.type, "opaque", "wrong response type for " + JSON.stringify(test));
|
||||
|
||||
// Get unfiltered response
|
||||
var chromeResponse = SpecialPowers.wrap(res);
|
||||
|
@ -1280,14 +1281,14 @@ function testModeNoCorsCredentials() {
|
|||
is(
|
||||
unfiltered.status,
|
||||
status,
|
||||
"wrong status in test for " + test.toSource()
|
||||
"wrong status in test for " + JSON.stringify(test)
|
||||
);
|
||||
return unfiltered.text().then(function(v) {
|
||||
if (status === 200) {
|
||||
is(
|
||||
v,
|
||||
"<res>hello pass</res>\n",
|
||||
"wrong text in test for " + test.toSource()
|
||||
"wrong text in test for " + JSON.stringify(test)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -1312,8 +1313,8 @@ function testModeNoCorsCredentials() {
|
|||
});
|
||||
},
|
||||
function(e) {
|
||||
ok(!test.pass, "Expected test to fail " + test.toSource());
|
||||
ok(e instanceof TypeError, "Test should fail " + test.toSource());
|
||||
ok(!test.pass, "Expected test to fail " + JSON.stringify(test));
|
||||
ok(e instanceof TypeError, "Test should fail " + JSON.stringify(test));
|
||||
if (i < tests.length - 1) {
|
||||
runATest(tests, i + 1);
|
||||
} else {
|
||||
|
@ -1619,14 +1620,14 @@ function testCORSRedirects() {
|
|||
test.hops[0].server +
|
||||
corsServerPath +
|
||||
"hop=1&hops=" +
|
||||
escape(test.hops.toSource()),
|
||||
escape(JSON.stringify(test.hops)),
|
||||
method: test.method,
|
||||
headers: test.headers,
|
||||
body: test.body,
|
||||
};
|
||||
|
||||
if (test.headers) {
|
||||
req.url += "&headers=" + escape(test.headers.toSource());
|
||||
req.url += "&headers=" + escape(JSON.stringify(test.headers));
|
||||
}
|
||||
|
||||
if (test.pass) {
|
||||
|
@ -1644,14 +1645,22 @@ function testCORSRedirects() {
|
|||
(function(request, test) {
|
||||
return fetch(request).then(
|
||||
function(res) {
|
||||
ok(test.pass, "Expected test to pass for " + test.toSource());
|
||||
is(res.status, 200, "wrong status in test for " + test.toSource());
|
||||
ok(test.pass, "Expected test to pass for " + JSON.stringify(test));
|
||||
is(
|
||||
res.status,
|
||||
200,
|
||||
"wrong status in test for " + JSON.stringify(test)
|
||||
);
|
||||
is(
|
||||
res.statusText,
|
||||
"OK",
|
||||
"wrong status text for " + test.toSource()
|
||||
"wrong status text for " + JSON.stringify(test)
|
||||
);
|
||||
is(
|
||||
res.type,
|
||||
"cors",
|
||||
"wrong response type for " + JSON.stringify(test)
|
||||
);
|
||||
is(res.type, "cors", "wrong response type for " + test.toSource());
|
||||
var reqHost = new URL(req.url).host;
|
||||
// If there is a service worker present, the redirections will be
|
||||
// transparent, assuming that the original request is to the current
|
||||
|
@ -1675,15 +1684,15 @@ function testCORSRedirects() {
|
|||
is(
|
||||
v,
|
||||
"<res>hello pass</res>\n",
|
||||
"wrong responseText in test for " + test.toSource()
|
||||
"wrong responseText in test for " + JSON.stringify(test)
|
||||
);
|
||||
});
|
||||
},
|
||||
function(e) {
|
||||
ok(!test.pass, "Expected test failure for " + test.toSource());
|
||||
ok(!test.pass, "Expected test failure for " + JSON.stringify(test));
|
||||
ok(
|
||||
e instanceof TypeError,
|
||||
"Exception should be TypeError for " + test.toSource()
|
||||
"Exception should be TypeError for " + JSON.stringify(test)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
@ -1740,14 +1749,14 @@ function testNoCORSRedirects() {
|
|||
test.hops[0].server +
|
||||
corsServerPath +
|
||||
"hop=1&hops=" +
|
||||
escape(test.hops.toSource()),
|
||||
escape(JSON.stringify(test.hops)),
|
||||
method: test.method,
|
||||
headers: test.headers,
|
||||
body: test.body,
|
||||
};
|
||||
|
||||
if (test.headers) {
|
||||
req.url += "&headers=" + escape(test.headers.toSource());
|
||||
req.url += "&headers=" + escape(JSON.stringify(test.headers));
|
||||
}
|
||||
|
||||
if (test.pass) {
|
||||
|
@ -1773,31 +1782,45 @@ function testNoCORSRedirects() {
|
|||
})
|
||||
.then(
|
||||
function(res) {
|
||||
ok(test.pass, "Expected test to pass for " + test.toSource());
|
||||
ok(
|
||||
test.pass,
|
||||
"Expected test to pass for " + JSON.stringify(test)
|
||||
);
|
||||
// All requests are cross-origin no-cors, we should always have
|
||||
// an opaque response here. All values on the opaque response
|
||||
// should be hidden.
|
||||
is(
|
||||
res.type,
|
||||
"opaque",
|
||||
"wrong response type for " + test.toSource()
|
||||
"wrong response type for " + JSON.stringify(test)
|
||||
);
|
||||
is(
|
||||
res.status,
|
||||
0,
|
||||
"wrong status in test for " + JSON.stringify(test)
|
||||
);
|
||||
is(res.status, 0, "wrong status in test for " + test.toSource());
|
||||
is(
|
||||
res.statusText,
|
||||
"",
|
||||
"wrong status text for " + test.toSource()
|
||||
"wrong status text for " + JSON.stringify(test)
|
||||
);
|
||||
is(res.url, "", "wrong response url for " + test.toSource());
|
||||
is(res.url, "", "wrong response url for " + JSON.stringify(test));
|
||||
return res.text().then(function(v) {
|
||||
is(v, "", "wrong responseText in test for " + test.toSource());
|
||||
is(
|
||||
v,
|
||||
"",
|
||||
"wrong responseText in test for " + JSON.stringify(test)
|
||||
);
|
||||
});
|
||||
},
|
||||
function(e) {
|
||||
ok(!test.pass, "Expected test failure for " + test.toSource());
|
||||
ok(
|
||||
!test.pass,
|
||||
"Expected test failure for " + JSON.stringify(test)
|
||||
);
|
||||
ok(
|
||||
e instanceof TypeError,
|
||||
"Exception should be TypeError for " + test.toSource()
|
||||
"Exception should be TypeError for " + JSON.stringify(test)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
@ -1820,7 +1843,7 @@ function testReferrer() {
|
|||
Referer: referrer,
|
||||
};
|
||||
return fetch(
|
||||
corsServerPath + "headers=" + encodeURIComponent(dict.toSource())
|
||||
corsServerPath + "headers=" + encodeURIComponent(JSON.stringify(dict))
|
||||
).then(
|
||||
function(res) {
|
||||
is(res.status, 200, "expected correct referrer header to be sent");
|
||||
|
|
Загрузка…
Ссылка в новой задаче