toolkit/components/thumbnails/test/browser_thumbnails_privacy.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:9f8907e5c7db
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 const PREF_DISK_CACHE_SSL = "browser.cache.disk_cache_ssl";
5 const URL = "://example.com/browser/toolkit/components/thumbnails/" +
6 "test/privacy_cache_control.sjs";
7
8 function runTests() {
9 registerCleanupFunction(function () {
10 Services.prefs.clearUserPref(PREF_DISK_CACHE_SSL);
11 });
12
13 let positive = [
14 // A normal HTTP page without any Cache-Control header.
15 {scheme: "http", cacheControl: null, diskCacheSSL: false},
16
17 // A normal HTTP page with 'Cache-Control: private'.
18 {scheme: "http", cacheControl: "private", diskCacheSSL: false},
19
20 // Capture HTTPS pages if browser.cache.disk_cache_ssl == true.
21 {scheme: "https", cacheControl: null, diskCacheSSL: true},
22 {scheme: "https", cacheControl: "public", diskCacheSSL: true},
23 {scheme: "https", cacheControl: "private", diskCacheSSL: true}
24 ];
25
26 let negative = [
27 // Never capture pages with 'Cache-Control: no-store'.
28 {scheme: "http", cacheControl: "no-store", diskCacheSSL: false},
29 {scheme: "http", cacheControl: "no-store", diskCacheSSL: true},
30 {scheme: "https", cacheControl: "no-store", diskCacheSSL: false},
31 {scheme: "https", cacheControl: "no-store", diskCacheSSL: true},
32
33 // Don't capture HTTPS pages by default.
34 {scheme: "https", cacheControl: null, diskCacheSSL: false},
35 {scheme: "https", cacheControl: "public", diskCacheSSL: false},
36 {scheme: "https", cacheControl: "private", diskCacheSSL: false}
37 ];
38
39 let urls = positive.map((combi) => {
40 let url = combi.scheme + URL;
41 if (combi.cacheControl)
42 url += "?" + combi.cacheControl;
43 return url;
44 });
45 yield addVisitsAndRepopulateNewTabLinks(urls, next);
46
47 yield checkCombinations(positive, true);
48 yield checkCombinations(negative, false);
49 }
50
51 function checkCombinations(aCombinations, aResult) {
52 let combi = aCombinations.shift();
53 if (!combi) {
54 next();
55 return;
56 }
57
58 let url = combi.scheme + URL;
59 if (combi.cacheControl)
60 url += "?" + combi.cacheControl;
61 Services.prefs.setBoolPref(PREF_DISK_CACHE_SSL, combi.diskCacheSSL);
62
63 let tab = gBrowser.selectedTab = gBrowser.addTab(url);
64 let browser = gBrowser.selectedBrowser;
65
66 whenLoaded(browser, function () {
67 let msg = JSON.stringify(combi) + " == " + aResult;
68 is(gBrowserThumbnails._shouldCapture(browser), aResult, msg);
69 gBrowser.removeTab(tab);
70
71 // Continue with the next combination.
72 checkCombinations(aCombinations, aResult);
73 });
74 }

mercurial