1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 const { HttpServer
} = ChromeUtils
.importESModule(
8 "resource://testing-common/httpd.sys.mjs"
11 var httpserver
= new HttpServer();
13 function make_uri(urlStr
) {
14 return Services
.io
.newURI(urlStr
);
17 function serverHandler(_metadata
, response
) {
18 const body
= "hello world";
19 response
.setHeader("Content-Type", "text/plain", false);
20 response
.bodyOutputStream
.write(body
, body
.length
);
23 add_setup(async
function setup() {
24 httpserver
.registerPathHandler("/test", serverHandler
);
28 add_task(async
function test_clear_cache_with_usercontext_oa() {
29 let port
= httpserver
.identity
.primaryPort
;
30 info("Starting test with port " + port
);
32 let url
= `http://localhost:${port}/test`;
33 let chan
= makeHTTPChannel(url
);
34 chan
.loadInfo
.originAttributes
= { userContextId
: 0 };
35 await
new Promise(resolve
=> {
36 chan
.asyncOpen(new ChannelListener(resolve
, null, CL_ALLOW_UNKNOWN_CL
));
39 let cache_storage
= getCacheStorage("disk");
40 let exists
= cache_storage
.exists(make_uri(url
), null);
41 Assert
.ok(exists
, "Entry should be in cache");
43 Services
.cache2
.clearOriginAttributes(JSON
.stringify({ userContextId
: 0 }));
45 // clearOriginAttributes is async, so we block on cacheIOThread
46 await
new Promise(resolve
=> {
47 syncWithCacheIOThread(resolve
, true);
50 let existsAgain
= cache_storage
.exists(make_uri(url
), null);
51 Assert
.ok(!existsAgain
, "Entry should not be in cache");
53 await httpserver
.stop();