test_preloading.js (2009B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 6 add_task(async function testSteps() { 7 const principals = [ 8 getPrincipal("http://example.com", {}), 9 getPrincipal("http://example.com", { privateBrowsingId: 1 }), 10 ]; 11 12 async function isPreloaded(principal) { 13 return Services.domStorageManager.isPreloaded(principal); 14 } 15 16 info("Setting prefs"); 17 18 Services.prefs.setBoolPref( 19 "dom.storage.enable_unsupported_legacy_implementation", 20 false 21 ); 22 Services.prefs.setBoolPref("dom.storage.snapshot_reusing", false); 23 24 for (const principal of principals) { 25 info("Getting storage"); 26 27 let storage = getLocalStorage(principal); 28 29 ok( 30 !(await isPreloaded(principal)), 31 "Data is not preloaded after getting storage" 32 ); 33 34 info("Opening storage"); 35 36 storage.open(); 37 38 ok(await isPreloaded(principal), "Data is preloaded after opening storage"); 39 40 info("Closing storage"); 41 42 storage.close(); 43 44 if (principal.privateBrowsingId > 0) { 45 ok( 46 await isPreloaded(principal), 47 "Data is still preloaded after closing storage" 48 ); 49 50 info("Closing private session"); 51 52 Services.obs.notifyObservers(null, "last-pb-context-exited"); 53 54 ok( 55 !(await isPreloaded(principal)), 56 "Data is not preloaded anymore after closing private session" 57 ); 58 } else { 59 ok( 60 !(await isPreloaded(principal)), 61 "Data is not preloaded anymore after closing storage" 62 ); 63 } 64 65 info("Opening storage again"); 66 67 storage.open(); 68 69 ok( 70 await isPreloaded(principal), 71 "Data is preloaded after opening storage again" 72 ); 73 74 info("Clearing origin"); 75 76 let request = clearOrigin( 77 principal, 78 principal.privateBrowsingId > 0 ? "private" : "default" 79 ); 80 await requestFinished(request); 81 82 ok( 83 !(await isPreloaded(principal)), 84 "Data is not preloaded after clearing origin" 85 ); 86 } 87 });