Sat, 03 Jan 2015 20:18:00 +0100
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/";
5 const URL_COPY = URL + "#copy";
7 XPCOMUtils.defineLazyGetter(this, "Sanitizer", function () {
8 let tmp = {};
9 Cc["@mozilla.org/moz/jssubscript-loader;1"]
10 .getService(Ci.mozIJSSubScriptLoader)
11 .loadSubScript("chrome://browser/content/sanitize.js", tmp);
12 return tmp.Sanitizer;
13 });
15 /**
16 * These tests ensure that the thumbnail storage is working as intended.
17 * Newly captured thumbnails should be saved as files and they should as well
18 * be removed when the user sanitizes their history.
19 */
20 function runTests() {
21 dontExpireThumbnailURLs([URL, URL_COPY]);
23 yield clearHistory();
24 yield addVisitsAndRepopulateNewTabLinks(URL, next);
25 yield createThumbnail();
27 // Make sure Storage.copy() updates an existing file.
28 yield PageThumbsStorage.copy(URL, URL_COPY);
29 let copy = new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL_COPY));
30 let mtime = copy.lastModifiedTime -= 60;
32 yield PageThumbsStorage.copy(URL, URL_COPY);
33 isnot(new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL_COPY)).lastModifiedTime, mtime,
34 "thumbnail file was updated");
36 let file = new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL));
37 let fileCopy = new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL_COPY));
39 // Clear the browser history. Retry until the files are gone because Windows
40 // locks them sometimes.
41 while (file.exists() || fileCopy.exists()) {
42 yield clearHistory();
43 }
45 yield addVisitsAndRepopulateNewTabLinks(URL, next);
46 yield createThumbnail();
48 // Clear the last 10 minutes of browsing history.
49 yield clearHistory(true);
51 // Retry until the file is gone because Windows locks it sometimes.
52 clearFile(file, URL);
53 }
55 function clearFile(aFile, aURL) {
56 if (aFile.exists())
57 // Re-add our URL to the history so that history observer's onDeleteURI()
58 // is called again.
59 addVisits(makeURI(aURL), function() {
60 // Try again...
61 yield clearHistory(true);
62 clearFile(aFile, aURL);
63 });
64 }
66 function clearHistory(aUseRange) {
67 let s = new Sanitizer();
68 s.prefDomain = "privacy.cpd.";
70 let prefs = gPrefService.getBranch(s.prefDomain);
71 prefs.setBoolPref("history", true);
72 prefs.setBoolPref("downloads", false);
73 prefs.setBoolPref("cache", false);
74 prefs.setBoolPref("cookies", false);
75 prefs.setBoolPref("formdata", false);
76 prefs.setBoolPref("offlineApps", false);
77 prefs.setBoolPref("passwords", false);
78 prefs.setBoolPref("sessions", false);
79 prefs.setBoolPref("siteSettings", false);
81 if (aUseRange) {
82 let usec = Date.now() * 1000;
83 s.range = [usec - 10 * 60 * 1000 * 1000, usec];
84 s.ignoreTimespan = false;
85 }
87 s.sanitize();
88 s.range = null;
89 s.ignoreTimespan = true;
91 executeSoon(next);
92 }
94 function createThumbnail() {
95 addTab(URL, function () {
96 whenFileExists(URL, function () {
97 gBrowser.removeTab(gBrowser.selectedTab);
98 next();
99 });
100 });
101 }