Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | const URL = "http://mochi.test:8888/"; |
michael@0 | 5 | const URL_COPY = URL + "#copy"; |
michael@0 | 6 | |
michael@0 | 7 | XPCOMUtils.defineLazyGetter(this, "Sanitizer", function () { |
michael@0 | 8 | let tmp = {}; |
michael@0 | 9 | Cc["@mozilla.org/moz/jssubscript-loader;1"] |
michael@0 | 10 | .getService(Ci.mozIJSSubScriptLoader) |
michael@0 | 11 | .loadSubScript("chrome://browser/content/sanitize.js", tmp); |
michael@0 | 12 | return tmp.Sanitizer; |
michael@0 | 13 | }); |
michael@0 | 14 | |
michael@0 | 15 | /** |
michael@0 | 16 | * These tests ensure that the thumbnail storage is working as intended. |
michael@0 | 17 | * Newly captured thumbnails should be saved as files and they should as well |
michael@0 | 18 | * be removed when the user sanitizes their history. |
michael@0 | 19 | */ |
michael@0 | 20 | function runTests() { |
michael@0 | 21 | dontExpireThumbnailURLs([URL, URL_COPY]); |
michael@0 | 22 | |
michael@0 | 23 | yield clearHistory(); |
michael@0 | 24 | yield addVisitsAndRepopulateNewTabLinks(URL, next); |
michael@0 | 25 | yield createThumbnail(); |
michael@0 | 26 | |
michael@0 | 27 | // Make sure Storage.copy() updates an existing file. |
michael@0 | 28 | yield PageThumbsStorage.copy(URL, URL_COPY); |
michael@0 | 29 | let copy = new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL_COPY)); |
michael@0 | 30 | let mtime = copy.lastModifiedTime -= 60; |
michael@0 | 31 | |
michael@0 | 32 | yield PageThumbsStorage.copy(URL, URL_COPY); |
michael@0 | 33 | isnot(new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL_COPY)).lastModifiedTime, mtime, |
michael@0 | 34 | "thumbnail file was updated"); |
michael@0 | 35 | |
michael@0 | 36 | let file = new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL)); |
michael@0 | 37 | let fileCopy = new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL_COPY)); |
michael@0 | 38 | |
michael@0 | 39 | // Clear the browser history. Retry until the files are gone because Windows |
michael@0 | 40 | // locks them sometimes. |
michael@0 | 41 | while (file.exists() || fileCopy.exists()) { |
michael@0 | 42 | yield clearHistory(); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | yield addVisitsAndRepopulateNewTabLinks(URL, next); |
michael@0 | 46 | yield createThumbnail(); |
michael@0 | 47 | |
michael@0 | 48 | // Clear the last 10 minutes of browsing history. |
michael@0 | 49 | yield clearHistory(true); |
michael@0 | 50 | |
michael@0 | 51 | // Retry until the file is gone because Windows locks it sometimes. |
michael@0 | 52 | clearFile(file, URL); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function clearFile(aFile, aURL) { |
michael@0 | 56 | if (aFile.exists()) |
michael@0 | 57 | // Re-add our URL to the history so that history observer's onDeleteURI() |
michael@0 | 58 | // is called again. |
michael@0 | 59 | addVisits(makeURI(aURL), function() { |
michael@0 | 60 | // Try again... |
michael@0 | 61 | yield clearHistory(true); |
michael@0 | 62 | clearFile(aFile, aURL); |
michael@0 | 63 | }); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function clearHistory(aUseRange) { |
michael@0 | 67 | let s = new Sanitizer(); |
michael@0 | 68 | s.prefDomain = "privacy.cpd."; |
michael@0 | 69 | |
michael@0 | 70 | let prefs = gPrefService.getBranch(s.prefDomain); |
michael@0 | 71 | prefs.setBoolPref("history", true); |
michael@0 | 72 | prefs.setBoolPref("downloads", false); |
michael@0 | 73 | prefs.setBoolPref("cache", false); |
michael@0 | 74 | prefs.setBoolPref("cookies", false); |
michael@0 | 75 | prefs.setBoolPref("formdata", false); |
michael@0 | 76 | prefs.setBoolPref("offlineApps", false); |
michael@0 | 77 | prefs.setBoolPref("passwords", false); |
michael@0 | 78 | prefs.setBoolPref("sessions", false); |
michael@0 | 79 | prefs.setBoolPref("siteSettings", false); |
michael@0 | 80 | |
michael@0 | 81 | if (aUseRange) { |
michael@0 | 82 | let usec = Date.now() * 1000; |
michael@0 | 83 | s.range = [usec - 10 * 60 * 1000 * 1000, usec]; |
michael@0 | 84 | s.ignoreTimespan = false; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | s.sanitize(); |
michael@0 | 88 | s.range = null; |
michael@0 | 89 | s.ignoreTimespan = true; |
michael@0 | 90 | |
michael@0 | 91 | executeSoon(next); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | function createThumbnail() { |
michael@0 | 95 | addTab(URL, function () { |
michael@0 | 96 | whenFileExists(URL, function () { |
michael@0 | 97 | gBrowser.removeTab(gBrowser.selectedTab); |
michael@0 | 98 | next(); |
michael@0 | 99 | }); |
michael@0 | 100 | }); |
michael@0 | 101 | } |