9 var h2Port
= Services
.env
.get("MOZHTTP2_PORT");
10 Assert
.notEqual(h2Port
, null);
11 Assert
.notEqual(h2Port
, "");
13 // Set to allow the cert presented by our H2 server
15 prefs
= Services
.prefs
;
17 http2pref
= prefs
.getBoolPref("network.http.http2.enabled");
18 rcwnpref
= prefs
.getBoolPref("network.http.rcwn.enabled");
20 prefs
.setBoolPref("network.http.http2.enabled", true);
22 "network.dns.localDomains",
23 "foo.example.com, bar.example.com"
25 // Disable rcwn to make cache behavior deterministic.
26 prefs
.setBoolPref("network.http.rcwn.enabled", false);
28 // The moz-http2 cert is for foo.example.com and is signed by http2-ca.pem
29 // so add that cert to the trust list as a signing cert. // the foo.example.com domain name.
30 let certdb
= Cc
["@mozilla.org/security/x509certdb;1"].getService(
33 addCertFromFile(certdb
, "http2-ca.pem", "CTu,u,u");
35 origin
= "https://foo.example.com:" + h2Port
;
36 dump("origin - " + origin
+ "\n");
40 function resetPrefs() {
41 prefs
.setBoolPref("network.http.http2.enabled", http2pref
);
42 prefs
.setBoolPref("network.http.rcwn.enabled", rcwnpref
);
43 prefs
.clearUserPref("network.dns.localDomains");
46 function makeChan(path
) {
47 return NetUtil
.newChannel({
49 loadUsingSystemPrincipal
: true,
50 }).QueryInterface(Ci
.nsIHttpChannel
);
54 var expectPass
= true;
55 var expectConditional
= false;
57 var Listener = function () {};
58 Listener
.prototype = {
59 onStartRequest
: function testOnStartRequest(request
) {
60 Assert
.ok(request
instanceof Ci
.nsIHttpChannel
);
63 if (!Components
.isSuccessCode(request
.status
)) {
65 "Channel should have a success code! (" + request
.status
+ ")"
68 Assert
.equal(request
.responseStatus
, 200);
70 Assert
.equal(Components
.isSuccessCode(request
.status
), false);
74 onDataAvailable
: function testOnDataAvailable(request
, stream
, off
, cnt
) {
75 read_stream(stream
, cnt
);
78 onStopRequest
: function testOnStopRequest(request
) {
79 if (expectConditional
) {
80 Assert
.equal(request
.getResponseHeader("x-conditional"), "true");
83 Assert
.notEqual(request
.getResponseHeader("x-conditional"), "true");
93 function testsDone() {
99 dump("execute doTest1 - resource without immutable. initial request\n");
101 expectConditional
= false;
102 var chan
= makeChan("/immutable-test-without-attribute");
103 var listener
= new Listener();
105 chan
.asyncOpen(listener
);
109 dump("execute doTest2 - resource without immutable. reload\n");
111 expectConditional
= true;
112 var chan
= makeChan("/immutable-test-without-attribute");
113 var listener
= new Listener();
115 chan
.loadFlags
= Ci
.nsIRequest
.VALIDATE_ALWAYS
;
116 chan
.asyncOpen(listener
);
120 dump("execute doTest3 - resource without immutable. shift reload\n");
122 expectConditional
= false;
123 var chan
= makeChan("/immutable-test-without-attribute");
124 var listener
= new Listener();
126 chan
.loadFlags
= Ci
.nsIRequest
.LOAD_BYPASS_CACHE
;
127 chan
.asyncOpen(listener
);
131 dump("execute doTest4 - resource with immutable. initial request\n");
133 expectConditional
= false;
134 var chan
= makeChan("/immutable-test-with-attribute");
135 var listener
= new Listener();
137 chan
.asyncOpen(listener
);
141 dump("execute doTest5 - resource with immutable. reload\n");
143 expectConditional
= false;
144 var chan
= makeChan("/immutable-test-with-attribute");
145 var listener
= new Listener();
147 chan
.loadFlags
= Ci
.nsIRequest
.VALIDATE_ALWAYS
;
148 chan
.asyncOpen(listener
);
152 dump("execute doTest6 - resource with immutable. shift reload\n");
154 expectConditional
= false;
155 var chan
= makeChan("/immutable-test-with-attribute");
156 var listener
= new Listener();
158 chan
.loadFlags
= Ci
.nsIRequest
.LOAD_BYPASS_CACHE
;
159 chan
.asyncOpen(listener
);
163 dump("execute doTest7 - expired resource with immutable. initial request\n");
165 expectConditional
= false;
166 var chan
= makeChan("/immutable-test-expired-with-Expires-header");
167 var listener
= new Listener();
169 chan
.asyncOpen(listener
);
173 dump("execute doTest8 - expired resource with immutable. reload\n");
175 expectConditional
= true;
176 var chan
= makeChan("/immutable-test-expired-with-Expires-header");
177 var listener
= new Listener();
179 chan
.loadFlags
= Ci
.nsIRequest
.VALIDATE_ALWAYS
;
180 chan
.asyncOpen(listener
);
185 "execute doTest9 - expired resource with immutable cache extension and Last modified header. initial request\n"
188 expectConditional
= false;
189 var chan
= makeChan("/immutable-test-expired-with-last-modified-header");
190 var listener
= new Listener();
192 chan
.asyncOpen(listener
);
195 function doTest10() {
197 "execute doTest10 - expired resource with immutable cache extension and Last modified heder. reload\n"
200 expectConditional
= true;
201 var chan
= makeChan("/immutable-test-expired-with-last-modified-header");
202 var listener
= new Listener();
203 nextTest
= testsDone
;
204 chan
.loadFlags
= Ci
.nsIRequest
.VALIDATE_ALWAYS
;
205 chan
.asyncOpen(listener
);