diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
commit | 9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/components/thumbnails/test/browser_thumbnails_privacy.js | |
parent | Initial commit. (diff) | |
download | thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/thumbnails/test/browser_thumbnails_privacy.js')
-rw-r--r-- | toolkit/components/thumbnails/test/browser_thumbnails_privacy.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/toolkit/components/thumbnails/test/browser_thumbnails_privacy.js b/toolkit/components/thumbnails/test/browser_thumbnails_privacy.js new file mode 100644 index 0000000000..d03297f69d --- /dev/null +++ b/toolkit/components/thumbnails/test/browser_thumbnails_privacy.js @@ -0,0 +1,72 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const PREF_DISK_CACHE_SSL = "browser.cache.disk_cache_ssl"; +const URL = + "://example.com/browser/toolkit/components/thumbnails/" + + "test/privacy_cache_control.sjs"; + +add_task(async function thumbnails_privacy() { + registerCleanupFunction(function () { + Services.prefs.clearUserPref(PREF_DISK_CACHE_SSL); + }); + + let positive = [ + // A normal HTTP page without any Cache-Control header. + { scheme: "http", cacheControl: null, diskCacheSSL: false }, + + // A normal HTTP page with 'Cache-Control: private'. + { scheme: "http", cacheControl: "private", diskCacheSSL: false }, + + // Capture HTTPS pages if browser.cache.disk_cache_ssl == true. + { scheme: "https", cacheControl: null, diskCacheSSL: true }, + { scheme: "https", cacheControl: "public", diskCacheSSL: true }, + { scheme: "https", cacheControl: "private", diskCacheSSL: true }, + ]; + + let negative = [ + // Never capture pages with 'Cache-Control: no-store'. + { scheme: "http", cacheControl: "no-store", diskCacheSSL: false }, + { scheme: "http", cacheControl: "no-store", diskCacheSSL: true }, + { scheme: "https", cacheControl: "no-store", diskCacheSSL: false }, + { scheme: "https", cacheControl: "no-store", diskCacheSSL: true }, + + // Don't capture HTTPS pages by default. + { scheme: "https", cacheControl: null, diskCacheSSL: false }, + { scheme: "https", cacheControl: "public", diskCacheSSL: false }, + { scheme: "https", cacheControl: "private", diskCacheSSL: false }, + ]; + + await checkCombinations(positive, true); + await checkCombinations(negative, false); +}); + +async function checkCombinations(aCombinations, aResult) { + for (let combination of aCombinations) { + let url = combination.scheme + URL; + if (combination.cacheControl) { + url += "?" + combination.cacheControl; + } + + await SpecialPowers.pushPrefEnv({ + set: [[PREF_DISK_CACHE_SSL, combination.diskCacheSSL]], + }); + + // Add the test page as a top link so it has a chance to be thumbnailed + await promiseAddVisitsAndRepopulateNewTabLinks(url); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url, + }, + async browser => { + let msg = JSON.stringify(combination) + " == " + aResult; + let aIsSafeSite = await PageThumbs.shouldStoreThumbnail(browser); + Assert.equal(aIsSafeSite, aResult, msg); + } + ); + + await SpecialPowers.popPrefEnv(); + } +} |