From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../test/browser/browser_privatebrowsing_cache.js | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js (limited to 'browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js') diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js new file mode 100644 index 0000000000..c365dff5df --- /dev/null +++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js @@ -0,0 +1,93 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Check about:cache after private browsing +// This test covers MozTrap test 6047 +// bug 880621 + +var tmp = {}; + +function test() { + waitForExplicitFinish(); + + SpecialPowers.pushPrefEnv( + { + set: [["privacy.partition.network_state", false]], + }, + function () { + Sanitizer.sanitize(["cache"], { ignoreTimespan: false }); + + getStorageEntryCount("regular", function (nrEntriesR1) { + is(nrEntriesR1, 0, "Disk cache reports 0KB and has no entries"); + + get_cache_for_private_window(); + }); + } + ); +} + +function getStorageEntryCount(device, goon) { + var storage; + switch (device) { + case "private": + storage = Services.cache2.diskCacheStorage( + Services.loadContextInfo.private + ); + break; + case "regular": + storage = Services.cache2.diskCacheStorage( + Services.loadContextInfo.default + ); + break; + default: + throw new Error(`Unknown device ${device} at getStorageEntryCount`); + } + + var visitor = { + entryCount: 0, + onCacheStorageInfo(aEntryCount, aConsumption) {}, + onCacheEntryInfo(uri) { + var urispec = uri.asciiSpec; + info(device + ":" + urispec + "\n"); + if (urispec.match(/^https:\/\/example.com\//)) { + ++this.entryCount; + } + }, + onCacheEntryVisitCompleted() { + goon(this.entryCount); + }, + }; + + storage.asyncVisitStorage(visitor, true); +} + +function get_cache_for_private_window() { + let win = whenNewWindowLoaded({ private: true }, function () { + executeSoon(function () { + ok(true, "The private window got loaded"); + + let tab = BrowserTestUtils.addTab(win.gBrowser, "https://example.com"); + win.gBrowser.selectedTab = tab; + let newTabBrowser = win.gBrowser.getBrowserForTab(tab); + + BrowserTestUtils.browserLoaded(newTabBrowser).then(function () { + executeSoon(function () { + getStorageEntryCount("private", function (nrEntriesP) { + ok( + nrEntriesP >= 1, + "Memory cache reports some entries from example.org domain" + ); + + getStorageEntryCount("regular", function (nrEntriesR2) { + is(nrEntriesR2, 0, "Disk cache reports 0KB and has no entries"); + + win.close(); + finish(); + }); + }); + }); + }); + }); + }); +} -- cgit v1.2.3