browser_about_cache.js (4271B)
1 "use strict"; 2 3 /** 4 * Open a dummy page, then open about:cache and verify the opened page shows up in the cache. 5 */ 6 add_task(async function () { 7 const kRoot = getRootDirectory(gTestPath).replace( 8 "chrome://mochitests/content/", 9 "https://example.com/" 10 ); 11 const kTestPage = kRoot + "dummy.html"; 12 // Open the dummy page to get it cached. 13 let tab = await BrowserTestUtils.openNewForegroundTab( 14 gBrowser, 15 kTestPage, 16 true 17 ); 18 BrowserTestUtils.removeTab(tab); 19 20 tab = await BrowserTestUtils.openNewForegroundTab( 21 gBrowser, 22 "about:cache", 23 true 24 ); 25 let expectedPageCheck = function (uri) { 26 info("Saw load for " + uri); 27 // Can't easily use searchParms and new URL() because it's an about: URI... 28 return uri.startsWith("about:cache?") && uri.includes("storage=disk"); 29 }; 30 let diskPageLoaded = BrowserTestUtils.browserLoaded( 31 tab.linkedBrowser, 32 false, 33 expectedPageCheck 34 ); 35 await SpecialPowers.spawn(tab.linkedBrowser, [], function () { 36 ok( 37 !content.document.nodePrincipal.isSystemPrincipal, 38 "about:cache should not have system principal" 39 ); 40 let principal = content.document.nodePrincipal; 41 let channel = content.docShell.currentDocumentChannel; 42 ok(!channel.loadInfo.loadingPrincipal, "Loading principal should be null."); 43 is( 44 principal.spec, 45 content.document.location.href, 46 "Principal matches location" 47 ); 48 let links = [...content.document.querySelectorAll("a[href*=disk]")]; 49 is(links.length, 1, "Should have 1 link to the disk entries"); 50 links[0].click(); 51 }); 52 await diskPageLoaded; 53 info("about:cache disk subpage loaded"); 54 55 expectedPageCheck = function (uri) { 56 info("Saw load for " + uri); 57 return uri.startsWith("about:cache-entry") && uri.includes("dummy.html"); 58 }; 59 let triggeringURISpec = tab.linkedBrowser.currentURI.spec; 60 let entryLoaded = BrowserTestUtils.browserLoaded( 61 tab.linkedBrowser, 62 false, 63 expectedPageCheck 64 ); 65 await SpecialPowers.spawn( 66 tab.linkedBrowser, 67 [kTestPage], 68 function (kTestPage) { 69 ok( 70 !content.document.nodePrincipal.isSystemPrincipal, 71 "about:cache with query params should still not have system principal" 72 ); 73 let principal = content.document.nodePrincipal; 74 is( 75 principal.spec, 76 content.document.location.href, 77 "Principal matches location" 78 ); 79 let channel = content.docShell.currentDocumentChannel; 80 principal = channel.loadInfo.triggeringPrincipal; 81 is( 82 principal.spec, 83 "about:cache", 84 "Triggering principal matches previous location" 85 ); 86 ok( 87 !channel.loadInfo.loadingPrincipal, 88 "Loading principal should be null." 89 ); 90 let links = [ 91 ...content.document.querySelectorAll("a[href*='" + kTestPage + "']"), 92 ]; 93 is(links.length, 1, "Should have 1 link to entries for " + kTestPage); 94 // Make sure to pick correct entry - only the partitioned one has data. 95 let partitioned = Array.from(links).filter(e => 96 e.href.includes("https%2Cexample.com") 97 ); 98 is(partitioned.length, 1, "Should have 1 partitioned entry"); 99 partitioned[0].click(); 100 } 101 ); 102 await entryLoaded; 103 info("about:cache entry loaded"); 104 105 await SpecialPowers.spawn( 106 tab.linkedBrowser, 107 [triggeringURISpec], 108 function (triggeringURISpec) { 109 ok( 110 !content.document.nodePrincipal.isSystemPrincipal, 111 "about:cache-entry should also not have system principal" 112 ); 113 let principal = content.document.nodePrincipal; 114 is( 115 principal.spec, 116 content.document.location.href, 117 "Principal matches location" 118 ); 119 let channel = content.docShell.currentDocumentChannel; 120 principal = channel.loadInfo.triggeringPrincipal; 121 is( 122 principal.spec, 123 triggeringURISpec, 124 "Triggering principal matches previous location" 125 ); 126 ok( 127 !channel.loadInfo.loadingPrincipal, 128 "Loading principal should be null." 129 ); 130 ok( 131 content.document.querySelectorAll("th").length, 132 "Should have several table headers with data." 133 ); 134 } 135 ); 136 BrowserTestUtils.removeTab(tab); 137 });