gecko/toolkit/components/thumbnails/test/browser_thumbnails_expiration.js
Matt Brubeck ee84cf85ff Bug 811548 - Move PageThumbs.jsm from /browser to /toolkit
--HG--
rename : browser/components/thumbnails/BrowserPageThumbs.manifest => toolkit/components/thumbnails/BrowserPageThumbs.manifest
rename : browser/components/thumbnails/Makefile.in => toolkit/components/thumbnails/Makefile.in
rename : browser/components/thumbnails/PageThumbs.jsm => toolkit/components/thumbnails/PageThumbs.jsm
rename : browser/components/thumbnails/PageThumbsProtocol.js => toolkit/components/thumbnails/PageThumbsProtocol.js
rename : browser/components/thumbnails/PageThumbsWorker.js => toolkit/components/thumbnails/PageThumbsWorker.js
rename : browser/components/thumbnails/test/Makefile.in => toolkit/components/thumbnails/test/Makefile.in
rename : browser/components/thumbnails/test/background_red.html => toolkit/components/thumbnails/test/background_red.html
rename : browser/components/thumbnails/test/background_red_redirect.sjs => toolkit/components/thumbnails/test/background_red_redirect.sjs
rename : browser/components/thumbnails/test/browser_thumbnails_bug726727.js => toolkit/components/thumbnails/test/browser_thumbnails_bug726727.js
rename : browser/components/thumbnails/test/browser_thumbnails_capture.js => toolkit/components/thumbnails/test/browser_thumbnails_capture.js
rename : browser/components/thumbnails/test/browser_thumbnails_expiration.js => toolkit/components/thumbnails/test/browser_thumbnails_expiration.js
rename : browser/components/thumbnails/test/browser_thumbnails_privacy.js => toolkit/components/thumbnails/test/browser_thumbnails_privacy.js
rename : browser/components/thumbnails/test/browser_thumbnails_redirect.js => toolkit/components/thumbnails/test/browser_thumbnails_redirect.js
rename : browser/components/thumbnails/test/browser_thumbnails_storage.js => toolkit/components/thumbnails/test/browser_thumbnails_storage.js
rename : browser/components/thumbnails/test/browser_thumbnails_storage_migrate3.js => toolkit/components/thumbnails/test/browser_thumbnails_storage_migrate3.js
rename : browser/components/thumbnails/test/head.js => toolkit/components/thumbnails/test/head.js
rename : browser/components/thumbnails/test/privacy_cache_control.sjs => toolkit/components/thumbnails/test/privacy_cache_control.sjs
2013-02-16 20:15:41 -08:00

79 lines
2.5 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const URL = "http://mochi.test:8888/?t=" + Date.now();
const URL1 = URL + "#1";
const URL2 = URL + "#2";
const URL3 = URL + "#3";
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
"resource://gre/modules/FileUtils.jsm");
let tmp = {};
Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader)
.loadSubScript("resource://gre/modules/PageThumbs.jsm", tmp);
const {EXPIRATION_MIN_CHUNK_SIZE, PageThumbsExpiration} = tmp;
function runTests() {
// Create three thumbnails.
createDummyThumbnail(URL1);
ok(thumbnailExists(URL1), "first thumbnail created");
createDummyThumbnail(URL2);
ok(thumbnailExists(URL2), "second thumbnail created");
createDummyThumbnail(URL3);
ok(thumbnailExists(URL3), "third thumbnail created");
// Remove the third thumbnail.
yield expireThumbnails([URL1, URL2]);
ok(thumbnailExists(URL1), "first thumbnail still exists");
ok(thumbnailExists(URL2), "second thumbnail still exists");
ok(!thumbnailExists(URL3), "third thumbnail has been removed");
// Remove the second thumbnail.
yield expireThumbnails([URL1]);
ok(thumbnailExists(URL1), "first thumbnail still exists");
ok(!thumbnailExists(URL2), "second thumbnail has been removed");
// Remove all thumbnails.
yield expireThumbnails([]);
ok(!thumbnailExists(URL1), "all thumbnails have been removed");
// Create some more files than the min chunk size.
let urls = [];
for (let i = 0; i < EXPIRATION_MIN_CHUNK_SIZE + 10; i++) {
urls.push(URL + "#dummy" + i);
}
urls.forEach(createDummyThumbnail);
ok(urls.every(thumbnailExists), "all dummy thumbnails created");
// Expire thumbnails and expect 10 remaining.
yield expireThumbnails([]);
let remainingURLs = [u for (u of urls) if (thumbnailExists(u))];
is(remainingURLs.length, 10, "10 dummy thumbnails remaining");
// Expire thumbnails again. All should be gone by now.
yield expireThumbnails([]);
remainingURLs = [u for (u of remainingURLs) if (thumbnailExists(u))];
is(remainingURLs.length, 0, "no dummy thumbnails remaining");
}
function createDummyThumbnail(aURL) {
let file = PageThumbsStorage.getFileForURL(aURL);
let fos = FileUtils.openSafeFileOutputStream(file);
let data = "dummy";
fos.write(data, data.length);
FileUtils.closeSafeFileOutputStream(fos);
}
function expireThumbnails(aKeep) {
PageThumbsExpiration.expireThumbnails(aKeep, function () {
executeSoon(next);
});
}