Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_bug510359.js
blob2262e0a2e6c64516546dc0adb0c698e240687a53
1 "use strict";
3 const { HttpServer } = ChromeUtils.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
5 );
7 var httpserver = new HttpServer();
8 var index = 0;
9 var tests = [
10 { url: "/bug510359", server: "0", expected: "0" },
11 { url: "/bug510359", server: "1", expected: "1" },
14 function setupChannel(suffix, value) {
15 var chan = NetUtil.newChannel({
16 uri: "http://localhost:" + httpserver.identity.primaryPort + suffix,
17 loadUsingSystemPrincipal: true,
18 });
19 var httpChan = chan.QueryInterface(Ci.nsIHttpChannel);
20 httpChan.requestMethod = "GET";
21 httpChan.setRequestHeader("x-request", value, false);
22 httpChan.setRequestHeader("Cookie", "c=" + value, false);
23 return httpChan;
26 function triggerNextTest() {
27 var channel = setupChannel(tests[index].url, tests[index].server);
28 channel.asyncOpen(new ChannelListener(checkValueAndTrigger, null));
31 function checkValueAndTrigger(request, data) {
32 Assert.equal(tests[index].expected, data);
34 if (index < tests.length - 1) {
35 index++;
36 triggerNextTest();
37 } else {
38 httpserver.stop(do_test_finished);
42 function run_test() {
43 httpserver.registerPathHandler("/bug510359", handler);
44 httpserver.start(-1);
46 // clear cache
47 evict_cache_entries();
49 triggerNextTest();
51 do_test_pending();
54 function handler(metadata, response) {
55 try {
56 metadata.getHeader("If-Modified-Since");
57 response.setStatusLine(metadata.httpVersion, 500, "Failed");
58 var msg = "Client should not set If-Modified-Since header";
59 response.bodyOutputStream.write(msg, msg.length);
60 } catch (ex) {
61 response.setStatusLine(metadata.httpVersion, 200, "Ok");
62 response.setHeader("Content-Type", "text/plain", false);
63 response.setHeader("Last-Modified", getDateString(-1), false);
64 response.setHeader("Vary", "Cookie", false);
65 var body = metadata.getHeader("x-request");
66 response.bodyOutputStream.write(body, body.length);
70 function getDateString(yearDelta) {
71 var months = [
72 "Jan",
73 "Feb",
74 "Mar",
75 "Apr",
76 "May",
77 "Jun",
78 "Jul",
79 "Aug",
80 "Sep",
81 "Oct",
82 "Nov",
83 "Dec",
85 var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
87 var d = new Date();
88 return (
89 days[d.getUTCDay()] +
90 ", " +
91 d.getUTCDate() +
92 " " +
93 months[d.getUTCMonth()] +
94 " " +
95 (d.getUTCFullYear() + yearDelta) +
96 " " +
97 d.getUTCHours() +
98 ":" +
99 d.getUTCMinutes() +
100 ":" +
101 d.getUTCSeconds() +
102 " UTC"