michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const PREF_DISK_CACHE_SSL = "browser.cache.disk_cache_ssl"; michael@0: const URL = "://example.com/browser/toolkit/components/thumbnails/" + michael@0: "test/privacy_cache_control.sjs"; michael@0: michael@0: function runTests() { michael@0: registerCleanupFunction(function () { michael@0: Services.prefs.clearUserPref(PREF_DISK_CACHE_SSL); michael@0: }); michael@0: michael@0: let positive = [ michael@0: // A normal HTTP page without any Cache-Control header. michael@0: {scheme: "http", cacheControl: null, diskCacheSSL: false}, michael@0: michael@0: // A normal HTTP page with 'Cache-Control: private'. michael@0: {scheme: "http", cacheControl: "private", diskCacheSSL: false}, michael@0: michael@0: // Capture HTTPS pages if browser.cache.disk_cache_ssl == true. michael@0: {scheme: "https", cacheControl: null, diskCacheSSL: true}, michael@0: {scheme: "https", cacheControl: "public", diskCacheSSL: true}, michael@0: {scheme: "https", cacheControl: "private", diskCacheSSL: true} michael@0: ]; michael@0: michael@0: let negative = [ michael@0: // Never capture pages with 'Cache-Control: no-store'. michael@0: {scheme: "http", cacheControl: "no-store", diskCacheSSL: false}, michael@0: {scheme: "http", cacheControl: "no-store", diskCacheSSL: true}, michael@0: {scheme: "https", cacheControl: "no-store", diskCacheSSL: false}, michael@0: {scheme: "https", cacheControl: "no-store", diskCacheSSL: true}, michael@0: michael@0: // Don't capture HTTPS pages by default. michael@0: {scheme: "https", cacheControl: null, diskCacheSSL: false}, michael@0: {scheme: "https", cacheControl: "public", diskCacheSSL: false}, michael@0: {scheme: "https", cacheControl: "private", diskCacheSSL: false} michael@0: ]; michael@0: michael@0: let urls = positive.map((combi) => { michael@0: let url = combi.scheme + URL; michael@0: if (combi.cacheControl) michael@0: url += "?" + combi.cacheControl; michael@0: return url; michael@0: }); michael@0: yield addVisitsAndRepopulateNewTabLinks(urls, next); michael@0: michael@0: yield checkCombinations(positive, true); michael@0: yield checkCombinations(negative, false); michael@0: } michael@0: michael@0: function checkCombinations(aCombinations, aResult) { michael@0: let combi = aCombinations.shift(); michael@0: if (!combi) { michael@0: next(); michael@0: return; michael@0: } michael@0: michael@0: let url = combi.scheme + URL; michael@0: if (combi.cacheControl) michael@0: url += "?" + combi.cacheControl; michael@0: Services.prefs.setBoolPref(PREF_DISK_CACHE_SSL, combi.diskCacheSSL); michael@0: michael@0: let tab = gBrowser.selectedTab = gBrowser.addTab(url); michael@0: let browser = gBrowser.selectedBrowser; michael@0: michael@0: whenLoaded(browser, function () { michael@0: let msg = JSON.stringify(combi) + " == " + aResult; michael@0: is(gBrowserThumbnails._shouldCapture(browser), aResult, msg); michael@0: gBrowser.removeTab(tab); michael@0: michael@0: // Continue with the next combination. michael@0: checkCombinations(aCombinations, aResult); michael@0: }); michael@0: }