3 const { HttpServer
} = ChromeUtils
.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
8 function contentHandler(metadata
, response
) {
9 response
.setHeader("Content-Type", "text/plain");
15 response
.bodyOutputStream
.write(body
, body
.length
);
18 ChromeUtils
.defineLazyGetter(this, "uri", function () {
19 return "http://localhost:" + httpserver
.identity
.primaryPort
;
22 var httpserver
= null;
26 httpserver
= new HttpServer();
27 httpserver
.registerPathHandler("/test", contentHandler
);
30 add_test(test_first_response
);
31 add_test(test_inhibit_caching
);
36 // Makes a regular request
37 function test_first_response() {
38 var chan
= NetUtil
.newChannel({
40 loadUsingSystemPrincipal
: true,
42 chan
.asyncOpen(new ChannelListener(check_first_response
, null));
45 // Checks that we got the appropriate response
46 function check_first_response(request
, buffer
) {
47 request
.QueryInterface(Ci
.nsIHttpChannel
);
48 Assert
.equal(request
.responseStatus
, 200);
49 Assert
.equal(buffer
, "first");
50 // Open the cache entry to check its contents
54 Ci
.nsICacheStorage
.OPEN_READONLY
,
60 // Checks that the cache entry has the correct contents
61 function cache_entry_callback(status
, entry
) {
62 equal(status
, Cr
.NS_OK
);
63 var inputStream
= entry
.openInputStream(0);
64 pumpReadStream(inputStream
, function (read
) {
71 // Makes a request with the INHIBIT_CACHING load flag
72 function test_inhibit_caching() {
73 var chan
= NetUtil
.newChannel({
75 loadUsingSystemPrincipal
: true,
77 chan
.QueryInterface(Ci
.nsIRequest
).loadFlags
|= Ci
.nsIRequest
.INHIBIT_CACHING
;
78 chan
.asyncOpen(new ChannelListener(check_second_response
, null));
81 // Checks that we got a different response from the first request
82 function check_second_response(request
, buffer
) {
83 request
.QueryInterface(Ci
.nsIHttpChannel
);
84 Assert
.equal(request
.responseStatus
, 200);
85 Assert
.equal(buffer
, "second");
86 // Checks that the cache entry still contains the content from the first request
90 Ci
.nsICacheStorage
.OPEN_READONLY
,