toolkit/components/thumbnails/test/browser_thumbnails_privacy.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/thumbnails/test/browser_thumbnails_privacy.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +const PREF_DISK_CACHE_SSL = "browser.cache.disk_cache_ssl";
     1.8 +const URL = "://example.com/browser/toolkit/components/thumbnails/" +
     1.9 +            "test/privacy_cache_control.sjs";
    1.10 +
    1.11 +function runTests() {
    1.12 +  registerCleanupFunction(function () {
    1.13 +    Services.prefs.clearUserPref(PREF_DISK_CACHE_SSL);
    1.14 +  });
    1.15 +
    1.16 +  let positive = [
    1.17 +    // A normal HTTP page without any Cache-Control header.
    1.18 +    {scheme: "http", cacheControl: null, diskCacheSSL: false},
    1.19 +
    1.20 +    // A normal HTTP page with 'Cache-Control: private'.
    1.21 +    {scheme: "http", cacheControl: "private", diskCacheSSL: false},
    1.22 +
    1.23 +    // Capture HTTPS pages if browser.cache.disk_cache_ssl == true.
    1.24 +    {scheme: "https", cacheControl: null, diskCacheSSL: true},
    1.25 +    {scheme: "https", cacheControl: "public", diskCacheSSL: true},
    1.26 +    {scheme: "https", cacheControl: "private", diskCacheSSL: true}
    1.27 +  ];
    1.28 +
    1.29 +  let negative = [
    1.30 +    // Never capture pages with 'Cache-Control: no-store'.
    1.31 +    {scheme: "http", cacheControl: "no-store", diskCacheSSL: false},
    1.32 +    {scheme: "http", cacheControl: "no-store", diskCacheSSL: true},
    1.33 +    {scheme: "https", cacheControl: "no-store", diskCacheSSL: false},
    1.34 +    {scheme: "https", cacheControl: "no-store", diskCacheSSL: true},
    1.35 +
    1.36 +    // Don't capture HTTPS pages by default.
    1.37 +    {scheme: "https", cacheControl: null, diskCacheSSL: false},
    1.38 +    {scheme: "https", cacheControl: "public", diskCacheSSL: false},
    1.39 +    {scheme: "https", cacheControl: "private", diskCacheSSL: false}
    1.40 +  ];
    1.41 +
    1.42 +  let urls = positive.map((combi) => {
    1.43 +    let url = combi.scheme + URL;
    1.44 +    if (combi.cacheControl)
    1.45 +      url += "?" + combi.cacheControl;
    1.46 +    return url;
    1.47 +  });
    1.48 +  yield addVisitsAndRepopulateNewTabLinks(urls, next);
    1.49 +
    1.50 +  yield checkCombinations(positive, true);
    1.51 +  yield checkCombinations(negative, false);
    1.52 +}
    1.53 +
    1.54 +function checkCombinations(aCombinations, aResult) {
    1.55 +  let combi = aCombinations.shift();
    1.56 +  if (!combi) {
    1.57 +    next();
    1.58 +    return;
    1.59 +  }
    1.60 +
    1.61 +  let url = combi.scheme + URL;
    1.62 +  if (combi.cacheControl)
    1.63 +    url += "?" + combi.cacheControl;
    1.64 +  Services.prefs.setBoolPref(PREF_DISK_CACHE_SSL, combi.diskCacheSSL);
    1.65 +
    1.66 +  let tab = gBrowser.selectedTab = gBrowser.addTab(url);
    1.67 +  let browser = gBrowser.selectedBrowser;
    1.68 +
    1.69 +  whenLoaded(browser, function () {
    1.70 +    let msg = JSON.stringify(combi) + " == " + aResult;
    1.71 +    is(gBrowserThumbnails._shouldCapture(browser), aResult, msg);
    1.72 +    gBrowser.removeTab(tab);
    1.73 +
    1.74 +    // Continue with the next combination.
    1.75 +    checkCombinations(aCombinations, aResult);
    1.76 +  });
    1.77 +}

mercurial