|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 const URL = "http://mochi.test:8888/"; |
|
5 const URL_COPY = URL + "#copy"; |
|
6 |
|
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 }); |
|
14 |
|
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]); |
|
22 |
|
23 yield clearHistory(); |
|
24 yield addVisitsAndRepopulateNewTabLinks(URL, next); |
|
25 yield createThumbnail(); |
|
26 |
|
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; |
|
31 |
|
32 yield PageThumbsStorage.copy(URL, URL_COPY); |
|
33 isnot(new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL_COPY)).lastModifiedTime, mtime, |
|
34 "thumbnail file was updated"); |
|
35 |
|
36 let file = new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL)); |
|
37 let fileCopy = new FileUtils.File(PageThumbsStorage.getFilePathForURL(URL_COPY)); |
|
38 |
|
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 } |
|
44 |
|
45 yield addVisitsAndRepopulateNewTabLinks(URL, next); |
|
46 yield createThumbnail(); |
|
47 |
|
48 // Clear the last 10 minutes of browsing history. |
|
49 yield clearHistory(true); |
|
50 |
|
51 // Retry until the file is gone because Windows locks it sometimes. |
|
52 clearFile(file, URL); |
|
53 } |
|
54 |
|
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 } |
|
65 |
|
66 function clearHistory(aUseRange) { |
|
67 let s = new Sanitizer(); |
|
68 s.prefDomain = "privacy.cpd."; |
|
69 |
|
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); |
|
80 |
|
81 if (aUseRange) { |
|
82 let usec = Date.now() * 1000; |
|
83 s.range = [usec - 10 * 60 * 1000 * 1000, usec]; |
|
84 s.ignoreTimespan = false; |
|
85 } |
|
86 |
|
87 s.sanitize(); |
|
88 s.range = null; |
|
89 s.ignoreTimespan = true; |
|
90 |
|
91 executeSoon(next); |
|
92 } |
|
93 |
|
94 function createThumbnail() { |
|
95 addTab(URL, function () { |
|
96 whenFileExists(URL, function () { |
|
97 gBrowser.removeTab(gBrowser.selectedTab); |
|
98 next(); |
|
99 }); |
|
100 }); |
|
101 } |