Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_cache2_clear_with_usercontext_oa.js
blob824f3311d13c7faef13a5259e51571913d77a0d7
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/. */
5 "use strict";
7 const { HttpServer } = ChromeUtils.importESModule(
8 "resource://testing-common/httpd.sys.mjs"
9 );
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);
25 httpserver.start(-1);
26 });
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));
37 });
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);
48 });
50 let existsAgain = cache_storage.exists(make_uri(url), null);
51 Assert.ok(!existsAgain, "Entry should not be in cache");
53 await httpserver.stop();
54 });