test_cache2-33-clear-base-domain.js (1952B)
1 "use strict"; 2 3 const URL = "http://example.net"; 4 const URL_SUBDOMAIN = "http://subdomain.example.net"; 5 const URL2 = "http://foo.bar"; 6 7 /** 8 * Helper to wrap the OpenCallback in a Promise. 9 */ 10 function OpenCallbackPromise(behavior, workingMetadata, workingData, url) { 11 return new Promise(resolve => { 12 asyncOpenCacheEntry( 13 url, 14 "disk", 15 Ci.nsICacheStorage.OPEN_NORMALLY, 16 null, 17 new OpenCallback(behavior, workingMetadata, workingData, resolve) 18 ); 19 }); 20 } 21 22 async function run_test() { 23 do_get_profile(); 24 do_test_pending(); 25 26 try { 27 info(`Create first entry for ${URL}/a`); 28 await OpenCallbackPromise(NEW, "e1m", "e1d", URL + "/a"); 29 30 info(`Verify first entry for ${URL}/a`); 31 await OpenCallbackPromise(NORMAL, "e1m", "e1d", URL + "/a"); 32 33 info(`Create entry for ${URL_SUBDOMAIN}/a`); 34 await OpenCallbackPromise(NEW, "es1m", "es1d", URL_SUBDOMAIN + "/a"); 35 36 info(`Verify entry for ${URL_SUBDOMAIN}/a`); 37 await OpenCallbackPromise(NORMAL, "es1m", "es1d", URL_SUBDOMAIN + "/a"); 38 39 info(`Create entry for ${URL2}/a`); 40 await OpenCallbackPromise(NEW, "f1m", "f1d", URL2 + "/a"); 41 42 info(`Verify entry for ${URL2}/a`); 43 await OpenCallbackPromise(NORMAL, "f1m", "f1d", URL2 + "/a"); 44 45 info(`Clear base domain associated with ${URL}`); 46 const url = Services.io.newURI(URL); 47 const principal = Services.scriptSecurityManager.createContentPrincipal( 48 url, 49 {} 50 ); 51 Services.cache2.clearBaseDomain(principal.baseDomain); 52 53 info(`${URL}/a entry should be new after clearing`); 54 await OpenCallbackPromise(NEW, "e1m", "e1d", URL + "/a"); 55 56 info(`${URL_SUBDOMAIN}/a entry should be new after clearing`); 57 await OpenCallbackPromise(NEW, "es1m", "es1d", URL_SUBDOMAIN + "/a"); 58 59 info(`${URL2}/a entry should still exist`); 60 await OpenCallbackPromise(NORMAL, "f1m", "f1d", URL2 + "/a"); 61 62 finish_cache2_test(); 63 } catch (e) { 64 do_throw(e); 65 } 66 }