toolkit/components/thumbnails/test/browser_thumbnails_privacy.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     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";
     8 function runTests() {
     9   registerCleanupFunction(function () {
    10     Services.prefs.clearUserPref(PREF_DISK_CACHE_SSL);
    11   });
    13   let positive = [
    14     // A normal HTTP page without any Cache-Control header.
    15     {scheme: "http", cacheControl: null, diskCacheSSL: false},
    17     // A normal HTTP page with 'Cache-Control: private'.
    18     {scheme: "http", cacheControl: "private", diskCacheSSL: false},
    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   ];
    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},
    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   ];
    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);
    47   yield checkCombinations(positive, true);
    48   yield checkCombinations(negative, false);
    49 }
    51 function checkCombinations(aCombinations, aResult) {
    52   let combi = aCombinations.shift();
    53   if (!combi) {
    54     next();
    55     return;
    56   }
    58   let url = combi.scheme + URL;
    59   if (combi.cacheControl)
    60     url += "?" + combi.cacheControl;
    61   Services.prefs.setBoolPref(PREF_DISK_CACHE_SSL, combi.diskCacheSSL);
    63   let tab = gBrowser.selectedTab = gBrowser.addTab(url);
    64   let browser = gBrowser.selectedBrowser;
    66   whenLoaded(browser, function () {
    67     let msg = JSON.stringify(combi) + " == " + aResult;
    68     is(gBrowserThumbnails._shouldCapture(browser), aResult, msg);
    69     gBrowser.removeTab(tab);
    71     // Continue with the next combination.
    72     checkCombinations(aCombinations, aResult);
    73   });
    74 }

mercurial