toolkit/components/thumbnails/test/browser_thumbnails_expiration.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 const URL = "http://mochi.test:8888/?t=" + Date.now();
     5 const URL1 = URL + "#1";
     6 const URL2 = URL + "#2";
     7 const URL3 = URL + "#3";
     9 let tmp = {};
    10 Cc["@mozilla.org/moz/jssubscript-loader;1"]
    11   .getService(Ci.mozIJSSubScriptLoader)
    12   .loadSubScript("resource://gre/modules/PageThumbs.jsm", tmp);
    14 const {EXPIRATION_MIN_CHUNK_SIZE, PageThumbsExpiration} = tmp;
    16 function runTests() {
    17   // Create dummy URLs.
    18   let dummyURLs = [];
    19   for (let i = 0; i < EXPIRATION_MIN_CHUNK_SIZE + 10; i++) {
    20     dummyURLs.push(URL + "#dummy" + i);
    21   }
    23   // Make sure our thumbnails aren't expired too early.
    24   dontExpireThumbnailURLs([URL1, URL2, URL3].concat(dummyURLs));
    26   // Create three thumbnails.
    27   yield createDummyThumbnail(URL1);
    28   ok(thumbnailExists(URL1), "first thumbnail created");
    30   yield createDummyThumbnail(URL2);
    31   ok(thumbnailExists(URL2), "second thumbnail created");
    33   yield createDummyThumbnail(URL3);
    34   ok(thumbnailExists(URL3), "third thumbnail created");
    36   // Remove the third thumbnail.
    37   yield expireThumbnails([URL1, URL2]);
    38   ok(thumbnailExists(URL1), "first thumbnail still exists");
    39   ok(thumbnailExists(URL2), "second thumbnail still exists");
    40   ok(!thumbnailExists(URL3), "third thumbnail has been removed");
    42   // Remove the second thumbnail.
    43   yield expireThumbnails([URL1]);
    44   ok(thumbnailExists(URL1), "first thumbnail still exists");
    45   ok(!thumbnailExists(URL2), "second thumbnail has been removed");
    47   // Remove all thumbnails.
    48   yield expireThumbnails([]);
    49   ok(!thumbnailExists(URL1), "all thumbnails have been removed");
    51   // Create some more files than the min chunk size.
    52   for (let url of dummyURLs) {
    53     yield createDummyThumbnail(url);
    54   }
    56   ok(dummyURLs.every(thumbnailExists), "all dummy thumbnails created");
    58   // Expire thumbnails and expect 10 remaining.
    59   yield expireThumbnails([]);
    60   let remainingURLs = [u for (u of dummyURLs) if (thumbnailExists(u))];
    61   is(remainingURLs.length, 10, "10 dummy thumbnails remaining");
    63   // Expire thumbnails again. All should be gone by now.
    64   yield expireThumbnails([]);
    65   remainingURLs = [u for (u of remainingURLs) if (thumbnailExists(u))];
    66   is(remainingURLs.length, 0, "no dummy thumbnails remaining");
    67 }
    69 function createDummyThumbnail(aURL) {
    70   info("Creating dummy thumbnail for " + aURL);
    71   let dummy = new Uint8Array(10);
    72   for (let i = 0; i < 10; ++i) {
    73     dummy[i] = i;
    74   }
    75   PageThumbsStorage.writeData(aURL, dummy).then(
    76     function onSuccess() {
    77       info("createDummyThumbnail succeeded");
    78       executeSoon(next);
    79     },
    80     function onFailure(error) {
    81       ok(false, "createDummyThumbnail failed " + error);
    82     }
    83   );
    84 }
    86 function expireThumbnails(aKeep) {
    87   PageThumbsExpiration.expireThumbnails(aKeep).then(
    88     function onSuccess() {
    89       info("expireThumbnails succeeded");
    90       executeSoon(next);
    91     },
    92     function onFailure(error) {
    93       ok(false, "expireThumbnails failed " + error);
    94     }
    95   );
    96 }

mercurial