browser_styleeditor_private_perwindowpb.js (2145B)
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/. */ 4 5 "use strict"; 6 7 // This test makes sure that the style editor does not store any 8 // content CSS files in the permanent cache when opened from a private window tab. 9 10 const TEST_URL = `http://${TEST_HOST}/browser/devtools/client/styleeditor/test/test_private.html`; 11 12 add_task(async function () { 13 info("Opening a new private window"); 14 const win = await BrowserTestUtils.openNewBrowserWindow({ private: true }); 15 16 info("Clearing the browser cache"); 17 Services.cache2.clear(); 18 19 const { toolbox, ui } = await openStyleEditorForURL(TEST_URL, win); 20 21 is(ui.editors.length, 1, "The style editor contains one sheet."); 22 const editor = ui.editors[0]; 23 is( 24 editor.friendlyName, 25 "test_private.css", 26 "The style editor contains the expected stylesheet" 27 ); 28 29 await editor.getSourceEditor(); 30 31 await checkDiskCacheFor(editor.friendlyName); 32 33 await toolbox.destroy(); 34 35 const onUnload = new Promise(done => { 36 win.addEventListener("unload", function listener(event) { 37 if (event.target == win.document) { 38 win.removeEventListener("unload", listener); 39 done(); 40 } 41 }); 42 }); 43 win.close(); 44 await onUnload; 45 }); 46 47 function checkDiskCacheFor(fileName) { 48 let foundPrivateData = false; 49 50 return new Promise(resolve => { 51 Visitor.prototype = { 52 onCacheStorageInfo(num) { 53 info("disk storage contains " + num + " entries"); 54 }, 55 onCacheEntryInfo(uri) { 56 const urispec = uri.asciiSpec; 57 info(urispec); 58 foundPrivateData = foundPrivateData || urispec.includes(fileName); 59 }, 60 onCacheEntryVisitCompleted() { 61 is(foundPrivateData, false, "web content present in disk cache"); 62 resolve(); 63 }, 64 }; 65 function Visitor() {} 66 67 const storage = Services.cache2.diskCacheStorage( 68 Services.loadContextInfo.default 69 ); 70 storage.asyncVisitStorage( 71 new Visitor(), 72 /* Do walk entries */ 73 true 74 ); 75 }); 76 }