Bug 1360473 - Add tests for network requests cookie-related filter options. r=Honza

MozReview-Commit-ID: 36VyUnR3aGD

--HG--
extra : rebase_source : ae2ced87c8f542810913918395a420ec9e8dc321
This commit is contained in:
Vangelis Katsikaros 2017-05-07 12:36:35 +03:00
Родитель 4b035dd340
Коммит b777047482
2 изменённых файлов: 65 добавлений и 19 удалений

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

@ -8,6 +8,8 @@
*/
const REQUESTS = [
{ url: "sjs_content-type-test-server.sjs?fmt=html&res=undefined&text=Sample" },
{ url: "sjs_content-type-test-server.sjs?fmt=html&res=undefined&text=Sample" +
"&cookies=1" },
{ url: "sjs_content-type-test-server.sjs?fmt=css&text=sample" },
{ url: "sjs_content-type-test-server.sjs?fmt=js&text=sample" },
{ url: "sjs_content-type-test-server.sjs?fmt=font" },
@ -29,6 +31,17 @@ const EXPECTED_REQUESTS = [
fullMimeType: "text/html; charset=utf-8"
}
},
{
method: "GET",
url: CONTENT_TYPE_SJS + "?fmt=html",
data: {
fuzzyUrl: true,
status: 200,
statusText: "OK",
type: "html",
fullMimeType: "text/html; charset=utf-8"
}
},
{
method: "GET",
url: CONTENT_TYPE_SJS + "?fmt=css",
@ -125,67 +138,91 @@ add_task(function* () {
info("Starting test... ");
let waitNetwork = waitForNetworkEvents(monitor, 8);
let waitNetwork = waitForNetworkEvents(monitor, REQUESTS.length);
loadCommonFrameScript();
yield performRequestsInContent(REQUESTS);
yield waitNetwork;
// Test running flag once requests finish running
setFreetextFilter("is:running");
testContents([0, 0, 0, 0, 0, 0, 0, 0]);
testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
// Test cached flag
setFreetextFilter("is:from-cache");
testContents([0, 0, 0, 0, 0, 0, 0, 1]);
testContents([0, 0, 0, 0, 0, 0, 0, 0, 1]);
setFreetextFilter("is:cached");
testContents([0, 0, 0, 0, 0, 0, 0, 1]);
testContents([0, 0, 0, 0, 0, 0, 0, 0, 1]);
// Test negative cached flag
setFreetextFilter("-is:from-cache");
testContents([1, 1, 1, 1, 1, 1, 1, 0]);
testContents([1, 1, 1, 1, 1, 1, 1, 1, 0]);
setFreetextFilter("-is:cached");
testContents([1, 1, 1, 1, 1, 1, 1, 0]);
testContents([1, 1, 1, 1, 1, 1, 1, 1, 0]);
// Test status-code flag
setFreetextFilter("status-code:200");
testContents([1, 1, 1, 1, 1, 1, 1, 0]);
testContents([1, 1, 1, 1, 1, 1, 1, 1, 0]);
// Test status-code negative flag
setFreetextFilter("-status-code:200");
testContents([0, 0, 0, 0, 0, 0, 0, 1]);
testContents([0, 0, 0, 0, 0, 0, 0, 0, 1]);
// Test mime-type flag
setFreetextFilter("mime-type:HtmL");
testContents([1, 0, 0, 0, 0, 0, 0, 0]);
testContents([1, 1, 0, 0, 0, 0, 0, 0, 0]);
// Test mime-type negative flag
setFreetextFilter("-mime-type:HtmL");
testContents([0, 1, 1, 1, 1, 1, 1, 1]);
testContents([0, 0, 1, 1, 1, 1, 1, 1, 1]);
// Test method flag
setFreetextFilter("method:get");
testContents([1, 1, 1, 1, 1, 1, 1, 1]);
testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
// Test unmatched method flag
setFreetextFilter("method:post");
testContents([0, 0, 0, 0, 0, 0, 0, 0]);
testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
// Test scheme flag (all requests are http)
setFreetextFilter("scheme:http");
testContents([1, 1, 1, 1, 1, 1, 1, 1]);
testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
setFreetextFilter("scheme:https");
testContents([0, 0, 0, 0, 0, 0, 0, 0]);
// Test mixing flags
setFreetextFilter("-mime-type:HtmL status-code:200");
testContents([0, 1, 1, 1, 1, 1, 1, 0]);
testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
// Test regex filter
setFreetextFilter("regexp:content.*?Sam");
testContents([1, 0, 0, 0, 0, 0, 0, 0]);
testContents([1, 1, 0, 0, 0, 0, 0, 0, 0]);
// Test set-cookie-name flag
setFreetextFilter("set-cookie-name:name2");
testContents([0, 1, 0, 0, 0, 0, 0, 0, 0]);
setFreetextFilter("set-cookie-name:not-existing");
testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
// Test set-cookie-value flag
setFreetextFilter("set-cookie-value:value2");
testContents([0, 1, 0, 0, 0, 0, 0, 0, 0]);
setFreetextFilter("set-cookie-value:not-existing");
testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
// Test set-cookie-domain flag
setFreetextFilter("set-cookie-domain:.example.com");
testContents([0, 1, 0, 0, 0, 0, 0, 0, 0]);
setFreetextFilter("set-cookie-domain:.foo.example.com");
testContents([0, 1, 0, 0, 0, 0, 0, 0, 0]);
setFreetextFilter("set-cookie-domain:.not-existing.example.com");
testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
// Test mixing flags
setFreetextFilter("-mime-type:HtmL status-code:200");
testContents([0, 0, 1, 1, 1, 1, 1, 1, 0]);
yield teardown(monitor);

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

@ -36,6 +36,7 @@ function handleRequest(request, response) {
let params = request.queryString.split("&");
let format = (params.filter((s) => s.includes("fmt="))[0] || "").split("=")[1];
let status = (params.filter((s) => s.includes("sts="))[0] || "").split("=")[1] || 200;
let cookies = (params.filter((s) => s.includes("cookies="))[0] || "").split("=")[1] || 0;
let cachedCount = 0;
let cacheExpire = 60; // seconds
@ -56,6 +57,13 @@ function handleRequest(request, response) {
cachedCount++;
}
function setCookieHeaders() {
if (cookies) {
response.setHeader("Set-Cookie", "name1=value1; Domain=.foo.example.com", true);
response.setHeader("Set-Cookie", "name2=value2; Domain=.example.com", true);
}
}
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(() => {
// to avoid garbage collection
@ -82,6 +90,7 @@ function handleRequest(request, response) {
response.setStatusLine(request.httpVersion, status, "OK");
response.setHeader("Content-Type", "text/html; charset=utf-8", false);
setCacheHeaders();
setCookieHeaders();
response.write(content || "<p>Hello HTML!</p>");
response.finish();
break;