3 const { HttpServer
} = ChromeUtils
.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
7 var httpserver
= new HttpServer();
10 // Initial request. Cached variant will have no cookie
11 { url
: "/bug468426", server
: "0", expected
: "0", cookie
: null },
13 // Cache now contains a variant with no value for cookie. If we don't
14 // set cookie we expect to receive the cached variant
15 { url
: "/bug468426", server
: "1", expected
: "0", cookie
: null },
17 // Cache still contains a variant with no value for cookie. If we
18 // set a value for cookie we expect a fresh value
19 { url
: "/bug468426", server
: "2", expected
: "2", cookie
: "c=2" },
21 // Cache now contains a variant with cookie "c=2". If the request
22 // also set cookie "c=2", we expect to receive the cached variant.
23 { url
: "/bug468426", server
: "3", expected
: "2", cookie
: "c=2" },
25 // Cache still contains a variant with cookie "c=2". When setting
26 // cookie "c=4" in the request we expect a fresh value
27 { url
: "/bug468426", server
: "4", expected
: "4", cookie
: "c=4" },
29 // Cache now contains a variant with cookie "c=4". When setting
30 // cookie "c=4" in the request we expect the cached variant
31 { url
: "/bug468426", server
: "5", expected
: "4", cookie
: "c=4" },
33 // Cache still contains a variant with cookie "c=4". When setting
34 // no cookie in the request we expect a fresh value
35 { url
: "/bug468426", server
: "6", expected
: "6", cookie
: null },
38 function setupChannel(suffix
, value
, cookie
) {
39 var chan
= NetUtil
.newChannel({
40 uri
: "http://localhost:" + httpserver
.identity
.primaryPort
+ suffix
,
41 loadUsingSystemPrincipal
: true,
43 var httpChan
= chan
.QueryInterface(Ci
.nsIHttpChannel
);
44 httpChan
.requestMethod
= "GET";
45 httpChan
.setRequestHeader("x-request", value
, false);
47 httpChan
.setRequestHeader("Cookie", cookie
, false);
52 function triggerNextTest() {
53 var channel
= setupChannel(
58 channel
.asyncOpen(new ChannelListener(checkValueAndTrigger
, null));
61 function checkValueAndTrigger(request
, data
) {
62 Assert
.equal(tests
[index
].expected
, data
);
64 if (index
< tests
.length
- 1) {
66 // This call happens in onStopRequest from the channel. Opening a new
67 // channel to the same url here is no good idea! Post it instead...
68 do_timeout(1, triggerNextTest
);
70 httpserver
.stop(do_test_finished
);
75 httpserver
.registerPathHandler("/bug468426", handler
);
78 // Clear cache and trigger the first test
79 evict_cache_entries();
85 function handler(metadata
, response
) {
88 body
= metadata
.getHeader("x-request");
90 response
.setStatusLine(metadata
.httpVersion
, 200, "Ok");
91 response
.setHeader("Content-Type", "text/plain", false);
92 response
.setHeader("Last-Modified", getDateString(-1), false);
93 response
.setHeader("Vary", "Cookie", false);
94 response
.bodyOutputStream
.write(body
, body
.length
);
97 function getDateString(yearDelta
) {
112 var days
= ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
116 days
[d
.getUTCDay()] +
120 months
[d
.getUTCMonth()] +
122 (d
.getUTCFullYear() + yearDelta
) +