michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const URL = "http://mochi.test:8888/"; michael@0: const URL_COPY = URL + "#copy"; michael@0: michael@0: XPCOMUtils.defineLazyGetter(this, "Sanitizer", function () { michael@0: let tmp = {}; michael@0: Cc["@mozilla.org/moz/jssubscript-loader;1"] michael@0: .getService(Ci.mozIJSSubScriptLoader) michael@0: .loadSubScript("chrome://browser/content/sanitize.js", tmp); michael@0: return tmp.Sanitizer; michael@0: }); michael@0: michael@0: /** michael@0: * These tests ensure that the thumbnail storage is working as intended. michael@0: * Newly captured thumbnails should be saved as files and they should as well michael@0: * be removed when the user sanitizes their history. michael@0: */ michael@0: function runTests() { michael@0: dontExpireThumbnailURLs([URL, URL_COPY]); michael@0: michael@0: yield clearHistory(); michael@0: yield addVisitsAndRepopulateNewTabLinks(URL, next); michael@0: yield createThumbnail(); michael@0: michael@0: // Make sure Storage.copy() updates an existing file. michael@0: yield PageThumbsStorage.copy(URL, URL_COPY); michael@0: let copy = new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL_COPY)); michael@0: let mtime = copy.lastModifiedTime -= 60; michael@0: michael@0: yield PageThumbsStorage.copy(URL, URL_COPY); michael@0: isnot(new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL_COPY)).lastModifiedTime, mtime, michael@0: "thumbnail file was updated"); michael@0: michael@0: let file = new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL)); michael@0: let fileCopy = new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL_COPY)); michael@0: michael@0: // Clear the browser history. Retry until the files are gone because Windows michael@0: // locks them sometimes. michael@0: while (file.exists() || fileCopy.exists()) { michael@0: yield clearHistory(); michael@0: } michael@0: michael@0: yield addVisitsAndRepopulateNewTabLinks(URL, next); michael@0: yield createThumbnail(); michael@0: michael@0: // Clear the last 10 minutes of browsing history. michael@0: yield clearHistory(true); michael@0: michael@0: // Retry until the file is gone because Windows locks it sometimes. michael@0: clearFile(file, URL); michael@0: } michael@0: michael@0: function clearFile(aFile, aURL) { michael@0: if (aFile.exists()) michael@0: // Re-add our URL to the history so that history observer's onDeleteURI() michael@0: // is called again. michael@0: addVisits(makeURI(aURL), function() { michael@0: // Try again... michael@0: yield clearHistory(true); michael@0: clearFile(aFile, aURL); michael@0: }); michael@0: } michael@0: michael@0: function clearHistory(aUseRange) { michael@0: let s = new Sanitizer(); michael@0: s.prefDomain = "privacy.cpd."; michael@0: michael@0: let prefs = gPrefService.getBranch(s.prefDomain); michael@0: prefs.setBoolPref("history", true); michael@0: prefs.setBoolPref("downloads", false); michael@0: prefs.setBoolPref("cache", false); michael@0: prefs.setBoolPref("cookies", false); michael@0: prefs.setBoolPref("formdata", false); michael@0: prefs.setBoolPref("offlineApps", false); michael@0: prefs.setBoolPref("passwords", false); michael@0: prefs.setBoolPref("sessions", false); michael@0: prefs.setBoolPref("siteSettings", false); michael@0: michael@0: if (aUseRange) { michael@0: let usec = Date.now() * 1000; michael@0: s.range = [usec - 10 * 60 * 1000 * 1000, usec]; michael@0: s.ignoreTimespan = false; michael@0: } michael@0: michael@0: s.sanitize(); michael@0: s.range = null; michael@0: s.ignoreTimespan = true; michael@0: michael@0: executeSoon(next); michael@0: } michael@0: michael@0: function createThumbnail() { michael@0: addTab(URL, function () { michael@0: whenFileExists(URL, function () { michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: next(); michael@0: }); michael@0: }); michael@0: }