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 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 2 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 3 | |
michael@0 | 4 | // Bug 453440 - Test the timespan-based logic of the sanitizer code |
michael@0 | 5 | let now_mSec = Date.now(); |
michael@0 | 6 | let now_uSec = now_mSec * 1000; |
michael@0 | 7 | |
michael@0 | 8 | const kMsecPerMin = 60 * 1000; |
michael@0 | 9 | const kUsecPerMin = 60 * 1000000; |
michael@0 | 10 | |
michael@0 | 11 | let tempScope = {}; |
michael@0 | 12 | Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader) |
michael@0 | 13 | .loadSubScript("chrome://browser/content/sanitize.js", tempScope); |
michael@0 | 14 | let Sanitizer = tempScope.Sanitizer; |
michael@0 | 15 | |
michael@0 | 16 | let FormHistory = (Components.utils.import("resource://gre/modules/FormHistory.jsm", {})).FormHistory; |
michael@0 | 17 | let Downloads = (Components.utils.import("resource://gre/modules/Downloads.jsm", {})).Downloads; |
michael@0 | 18 | |
michael@0 | 19 | function promiseFormHistoryRemoved() { |
michael@0 | 20 | let deferred = Promise.defer(); |
michael@0 | 21 | Services.obs.addObserver(function onfh() { |
michael@0 | 22 | Services.obs.removeObserver(onfh, "satchel-storage-changed", false); |
michael@0 | 23 | deferred.resolve(); |
michael@0 | 24 | }, "satchel-storage-changed", false); |
michael@0 | 25 | return deferred.promise; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function promiseDownloadRemoved(list) { |
michael@0 | 29 | let deferred = Promise.defer(); |
michael@0 | 30 | |
michael@0 | 31 | let view = { |
michael@0 | 32 | onDownloadRemoved: function(download) { |
michael@0 | 33 | list.removeView(view); |
michael@0 | 34 | deferred.resolve(); |
michael@0 | 35 | } |
michael@0 | 36 | }; |
michael@0 | 37 | |
michael@0 | 38 | list.addView(view); |
michael@0 | 39 | |
michael@0 | 40 | return deferred.promise; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | function test() { |
michael@0 | 44 | waitForExplicitFinish(); |
michael@0 | 45 | |
michael@0 | 46 | Task.spawn(function() { |
michael@0 | 47 | yield setupDownloads(); |
michael@0 | 48 | yield setupFormHistory(); |
michael@0 | 49 | yield setupHistory(); |
michael@0 | 50 | yield onHistoryReady(); |
michael@0 | 51 | }).then(null, ex => ok(false, ex)).then(finish); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | function countEntries(name, message, check) { |
michael@0 | 55 | let deferred = Promise.defer(); |
michael@0 | 56 | |
michael@0 | 57 | var obj = {}; |
michael@0 | 58 | if (name !== null) |
michael@0 | 59 | obj.fieldname = name; |
michael@0 | 60 | |
michael@0 | 61 | let count; |
michael@0 | 62 | FormHistory.count(obj, { handleResult: function (result) count = result, |
michael@0 | 63 | handleError: function (error) { |
michael@0 | 64 | do_throw("Error occurred searching form history: " + error); |
michael@0 | 65 | deferred.reject(error) |
michael@0 | 66 | }, |
michael@0 | 67 | handleCompletion: function (reason) { |
michael@0 | 68 | if (!reason) { |
michael@0 | 69 | check(count, message); |
michael@0 | 70 | deferred.resolve(); |
michael@0 | 71 | } |
michael@0 | 72 | }, |
michael@0 | 73 | }); |
michael@0 | 74 | |
michael@0 | 75 | return deferred.promise; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | function onHistoryReady() { |
michael@0 | 79 | var hoursSinceMidnight = new Date().getHours(); |
michael@0 | 80 | var minutesSinceMidnight = hoursSinceMidnight * 60 + new Date().getMinutes(); |
michael@0 | 81 | |
michael@0 | 82 | // Should test cookies here, but nsICookieManager/nsICookieService |
michael@0 | 83 | // doesn't let us fake creation times. bug 463127 |
michael@0 | 84 | |
michael@0 | 85 | let s = new Sanitizer(); |
michael@0 | 86 | s.ignoreTimespan = false; |
michael@0 | 87 | s.prefDomain = "privacy.cpd."; |
michael@0 | 88 | var itemPrefs = gPrefService.getBranch(s.prefDomain); |
michael@0 | 89 | itemPrefs.setBoolPref("history", true); |
michael@0 | 90 | itemPrefs.setBoolPref("downloads", true); |
michael@0 | 91 | itemPrefs.setBoolPref("cache", false); |
michael@0 | 92 | itemPrefs.setBoolPref("cookies", false); |
michael@0 | 93 | itemPrefs.setBoolPref("formdata", true); |
michael@0 | 94 | itemPrefs.setBoolPref("offlineApps", false); |
michael@0 | 95 | itemPrefs.setBoolPref("passwords", false); |
michael@0 | 96 | itemPrefs.setBoolPref("sessions", false); |
michael@0 | 97 | itemPrefs.setBoolPref("siteSettings", false); |
michael@0 | 98 | |
michael@0 | 99 | let publicList = yield Downloads.getList(Downloads.PUBLIC); |
michael@0 | 100 | let downloadPromise = promiseDownloadRemoved(publicList); |
michael@0 | 101 | |
michael@0 | 102 | // Clear 10 minutes ago |
michael@0 | 103 | s.range = [now_uSec - 10*60*1000000, now_uSec]; |
michael@0 | 104 | s.sanitize(); |
michael@0 | 105 | s.range = null; |
michael@0 | 106 | |
michael@0 | 107 | yield promiseFormHistoryRemoved(); |
michael@0 | 108 | yield downloadPromise; |
michael@0 | 109 | |
michael@0 | 110 | ok(!(yield promiseIsURIVisited(makeURI("http://10minutes.com"))), |
michael@0 | 111 | "Pretend visit to 10minutes.com should now be deleted"); |
michael@0 | 112 | ok((yield promiseIsURIVisited(makeURI("http://1hour.com"))), |
michael@0 | 113 | "Pretend visit to 1hour.com should should still exist"); |
michael@0 | 114 | ok((yield promiseIsURIVisited(makeURI("http://1hour10minutes.com"))), |
michael@0 | 115 | "Pretend visit to 1hour10minutes.com should should still exist"); |
michael@0 | 116 | ok((yield promiseIsURIVisited(makeURI("http://2hour.com"))), |
michael@0 | 117 | "Pretend visit to 2hour.com should should still exist"); |
michael@0 | 118 | ok((yield promiseIsURIVisited(makeURI("http://2hour10minutes.com"))), |
michael@0 | 119 | "Pretend visit to 2hour10minutes.com should should still exist"); |
michael@0 | 120 | ok((yield promiseIsURIVisited(makeURI("http://4hour.com"))), |
michael@0 | 121 | "Pretend visit to 4hour.com should should still exist"); |
michael@0 | 122 | ok((yield promiseIsURIVisited(makeURI("http://4hour10minutes.com"))), |
michael@0 | 123 | "Pretend visit to 4hour10minutes.com should should still exist"); |
michael@0 | 124 | if (minutesSinceMidnight > 10) { |
michael@0 | 125 | ok((yield promiseIsURIVisited(makeURI("http://today.com"))), |
michael@0 | 126 | "Pretend visit to today.com should still exist"); |
michael@0 | 127 | } |
michael@0 | 128 | ok((yield promiseIsURIVisited(makeURI("http://before-today.com"))), |
michael@0 | 129 | "Pretend visit to before-today.com should still exist"); |
michael@0 | 130 | |
michael@0 | 131 | let checkZero = function(num, message) { is(num, 0, message); } |
michael@0 | 132 | let checkOne = function(num, message) { is(num, 1, message); } |
michael@0 | 133 | |
michael@0 | 134 | yield countEntries("10minutes", "10minutes form entry should be deleted", checkZero); |
michael@0 | 135 | yield countEntries("1hour", "1hour form entry should still exist", checkOne); |
michael@0 | 136 | yield countEntries("1hour10minutes", "1hour10minutes form entry should still exist", checkOne); |
michael@0 | 137 | yield countEntries("2hour", "2hour form entry should still exist", checkOne); |
michael@0 | 138 | yield countEntries("2hour10minutes", "2hour10minutes form entry should still exist", checkOne); |
michael@0 | 139 | yield countEntries("4hour", "4hour form entry should still exist", checkOne); |
michael@0 | 140 | yield countEntries("4hour10minutes", "4hour10minutes form entry should still exist", checkOne); |
michael@0 | 141 | if (minutesSinceMidnight > 10) |
michael@0 | 142 | yield countEntries("today", "today form entry should still exist", checkOne); |
michael@0 | 143 | yield countEntries("b4today", "b4today form entry should still exist", checkOne); |
michael@0 | 144 | |
michael@0 | 145 | ok(!(yield downloadExists(publicList, "fakefile-10-minutes")), "10 minute download should now be deleted"); |
michael@0 | 146 | ok((yield downloadExists(publicList, "fakefile-1-hour")), "<1 hour download should still be present"); |
michael@0 | 147 | ok((yield downloadExists(publicList, "fakefile-1-hour-10-minutes")), "1 hour 10 minute download should still be present"); |
michael@0 | 148 | ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present"); |
michael@0 | 149 | ok((yield downloadExists(publicList, "fakefile-2-hour")), "<2 hour old download should still be present"); |
michael@0 | 150 | ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute download should still be present"); |
michael@0 | 151 | ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present"); |
michael@0 | 152 | ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present"); |
michael@0 | 153 | |
michael@0 | 154 | if (minutesSinceMidnight > 10) |
michael@0 | 155 | ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present"); |
michael@0 | 156 | |
michael@0 | 157 | downloadPromise = promiseDownloadRemoved(publicList); |
michael@0 | 158 | |
michael@0 | 159 | // Clear 1 hour |
michael@0 | 160 | Sanitizer.prefs.setIntPref("timeSpan", 1); |
michael@0 | 161 | s.sanitize(); |
michael@0 | 162 | |
michael@0 | 163 | yield promiseFormHistoryRemoved(); |
michael@0 | 164 | yield downloadPromise; |
michael@0 | 165 | |
michael@0 | 166 | ok(!(yield promiseIsURIVisited(makeURI("http://1hour.com"))), |
michael@0 | 167 | "Pretend visit to 1hour.com should now be deleted"); |
michael@0 | 168 | ok((yield promiseIsURIVisited(makeURI("http://1hour10minutes.com"))), |
michael@0 | 169 | "Pretend visit to 1hour10minutes.com should should still exist"); |
michael@0 | 170 | ok((yield promiseIsURIVisited(makeURI("http://2hour.com"))), |
michael@0 | 171 | "Pretend visit to 2hour.com should should still exist"); |
michael@0 | 172 | ok((yield promiseIsURIVisited(makeURI("http://2hour10minutes.com"))), |
michael@0 | 173 | "Pretend visit to 2hour10minutes.com should should still exist"); |
michael@0 | 174 | ok((yield promiseIsURIVisited(makeURI("http://4hour.com"))), |
michael@0 | 175 | "Pretend visit to 4hour.com should should still exist"); |
michael@0 | 176 | ok((yield promiseIsURIVisited(makeURI("http://4hour10minutes.com"))), |
michael@0 | 177 | "Pretend visit to 4hour10minutes.com should should still exist"); |
michael@0 | 178 | if (hoursSinceMidnight > 1) { |
michael@0 | 179 | ok((yield promiseIsURIVisited(makeURI("http://today.com"))), |
michael@0 | 180 | "Pretend visit to today.com should still exist"); |
michael@0 | 181 | } |
michael@0 | 182 | ok((yield promiseIsURIVisited(makeURI("http://before-today.com"))), |
michael@0 | 183 | "Pretend visit to before-today.com should still exist"); |
michael@0 | 184 | |
michael@0 | 185 | yield countEntries("1hour", "1hour form entry should be deleted", checkZero); |
michael@0 | 186 | yield countEntries("1hour10minutes", "1hour10minutes form entry should still exist", checkOne); |
michael@0 | 187 | yield countEntries("2hour", "2hour form entry should still exist", checkOne); |
michael@0 | 188 | yield countEntries("2hour10minutes", "2hour10minutes form entry should still exist", checkOne); |
michael@0 | 189 | yield countEntries("4hour", "4hour form entry should still exist", checkOne); |
michael@0 | 190 | yield countEntries("4hour10minutes", "4hour10minutes form entry should still exist", checkOne); |
michael@0 | 191 | if (hoursSinceMidnight > 1) |
michael@0 | 192 | yield countEntries("today", "today form entry should still exist", checkOne); |
michael@0 | 193 | yield countEntries("b4today", "b4today form entry should still exist", checkOne); |
michael@0 | 194 | |
michael@0 | 195 | ok(!(yield downloadExists(publicList, "fakefile-1-hour")), "<1 hour download should now be deleted"); |
michael@0 | 196 | ok((yield downloadExists(publicList, "fakefile-1-hour-10-minutes")), "1 hour 10 minute download should still be present"); |
michael@0 | 197 | ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present"); |
michael@0 | 198 | ok((yield downloadExists(publicList, "fakefile-2-hour")), "<2 hour old download should still be present"); |
michael@0 | 199 | ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute download should still be present"); |
michael@0 | 200 | ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present"); |
michael@0 | 201 | ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present"); |
michael@0 | 202 | |
michael@0 | 203 | if (hoursSinceMidnight > 1) |
michael@0 | 204 | ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present"); |
michael@0 | 205 | |
michael@0 | 206 | downloadPromise = promiseDownloadRemoved(publicList); |
michael@0 | 207 | |
michael@0 | 208 | // Clear 1 hour 10 minutes |
michael@0 | 209 | s.range = [now_uSec - 70*60*1000000, now_uSec]; |
michael@0 | 210 | s.sanitize(); |
michael@0 | 211 | s.range = null; |
michael@0 | 212 | |
michael@0 | 213 | yield promiseFormHistoryRemoved(); |
michael@0 | 214 | yield downloadPromise; |
michael@0 | 215 | |
michael@0 | 216 | ok(!(yield promiseIsURIVisited(makeURI("http://1hour10minutes.com"))), |
michael@0 | 217 | "Pretend visit to 1hour10minutes.com should now be deleted"); |
michael@0 | 218 | ok((yield promiseIsURIVisited(makeURI("http://2hour.com"))), |
michael@0 | 219 | "Pretend visit to 2hour.com should should still exist"); |
michael@0 | 220 | ok((yield promiseIsURIVisited(makeURI("http://2hour10minutes.com"))), |
michael@0 | 221 | "Pretend visit to 2hour10minutes.com should should still exist"); |
michael@0 | 222 | ok((yield promiseIsURIVisited(makeURI("http://4hour.com"))), |
michael@0 | 223 | "Pretend visit to 4hour.com should should still exist"); |
michael@0 | 224 | ok((yield promiseIsURIVisited(makeURI("http://4hour10minutes.com"))), |
michael@0 | 225 | "Pretend visit to 4hour10minutes.com should should still exist"); |
michael@0 | 226 | if (minutesSinceMidnight > 70) { |
michael@0 | 227 | ok((yield promiseIsURIVisited(makeURI("http://today.com"))), |
michael@0 | 228 | "Pretend visit to today.com should still exist"); |
michael@0 | 229 | } |
michael@0 | 230 | ok((yield promiseIsURIVisited(makeURI("http://before-today.com"))), |
michael@0 | 231 | "Pretend visit to before-today.com should still exist"); |
michael@0 | 232 | |
michael@0 | 233 | yield countEntries("1hour10minutes", "1hour10minutes form entry should be deleted", checkZero); |
michael@0 | 234 | yield countEntries("2hour", "2hour form entry should still exist", checkOne); |
michael@0 | 235 | yield countEntries("2hour10minutes", "2hour10minutes form entry should still exist", checkOne); |
michael@0 | 236 | yield countEntries("4hour", "4hour form entry should still exist", checkOne); |
michael@0 | 237 | yield countEntries("4hour10minutes", "4hour10minutes form entry should still exist", checkOne); |
michael@0 | 238 | if (minutesSinceMidnight > 70) |
michael@0 | 239 | yield countEntries("today", "today form entry should still exist", checkOne); |
michael@0 | 240 | yield countEntries("b4today", "b4today form entry should still exist", checkOne); |
michael@0 | 241 | |
michael@0 | 242 | ok(!(yield downloadExists(publicList, "fakefile-1-hour-10-minutes")), "1 hour 10 minute old download should now be deleted"); |
michael@0 | 243 | ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present"); |
michael@0 | 244 | ok((yield downloadExists(publicList, "fakefile-2-hour")), "<2 hour old download should still be present"); |
michael@0 | 245 | ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute download should still be present"); |
michael@0 | 246 | ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present"); |
michael@0 | 247 | ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present"); |
michael@0 | 248 | if (minutesSinceMidnight > 70) |
michael@0 | 249 | ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present"); |
michael@0 | 250 | |
michael@0 | 251 | downloadPromise = promiseDownloadRemoved(publicList); |
michael@0 | 252 | |
michael@0 | 253 | // Clear 2 hours |
michael@0 | 254 | Sanitizer.prefs.setIntPref("timeSpan", 2); |
michael@0 | 255 | s.sanitize(); |
michael@0 | 256 | |
michael@0 | 257 | yield promiseFormHistoryRemoved(); |
michael@0 | 258 | yield downloadPromise; |
michael@0 | 259 | |
michael@0 | 260 | ok(!(yield promiseIsURIVisited(makeURI("http://2hour.com"))), |
michael@0 | 261 | "Pretend visit to 2hour.com should now be deleted"); |
michael@0 | 262 | ok((yield promiseIsURIVisited(makeURI("http://2hour10minutes.com"))), |
michael@0 | 263 | "Pretend visit to 2hour10minutes.com should should still exist"); |
michael@0 | 264 | ok((yield promiseIsURIVisited(makeURI("http://4hour.com"))), |
michael@0 | 265 | "Pretend visit to 4hour.com should should still exist"); |
michael@0 | 266 | ok((yield promiseIsURIVisited(makeURI("http://4hour10minutes.com"))), |
michael@0 | 267 | "Pretend visit to 4hour10minutes.com should should still exist"); |
michael@0 | 268 | if (hoursSinceMidnight > 2) { |
michael@0 | 269 | ok((yield promiseIsURIVisited(makeURI("http://today.com"))), |
michael@0 | 270 | "Pretend visit to today.com should still exist"); |
michael@0 | 271 | } |
michael@0 | 272 | ok((yield promiseIsURIVisited(makeURI("http://before-today.com"))), |
michael@0 | 273 | "Pretend visit to before-today.com should still exist"); |
michael@0 | 274 | |
michael@0 | 275 | yield countEntries("2hour", "2hour form entry should be deleted", checkZero); |
michael@0 | 276 | yield countEntries("2hour10minutes", "2hour10minutes form entry should still exist", checkOne); |
michael@0 | 277 | yield countEntries("4hour", "4hour form entry should still exist", checkOne); |
michael@0 | 278 | yield countEntries("4hour10minutes", "4hour10minutes form entry should still exist", checkOne); |
michael@0 | 279 | if (hoursSinceMidnight > 2) |
michael@0 | 280 | yield countEntries("today", "today form entry should still exist", checkOne); |
michael@0 | 281 | yield countEntries("b4today", "b4today form entry should still exist", checkOne); |
michael@0 | 282 | |
michael@0 | 283 | ok(!(yield downloadExists(publicList, "fakefile-2-hour")), "<2 hour old download should now be deleted"); |
michael@0 | 284 | ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present"); |
michael@0 | 285 | ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute download should still be present"); |
michael@0 | 286 | ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present"); |
michael@0 | 287 | ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present"); |
michael@0 | 288 | if (hoursSinceMidnight > 2) |
michael@0 | 289 | ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present"); |
michael@0 | 290 | |
michael@0 | 291 | downloadPromise = promiseDownloadRemoved(publicList); |
michael@0 | 292 | |
michael@0 | 293 | // Clear 2 hours 10 minutes |
michael@0 | 294 | s.range = [now_uSec - 130*60*1000000, now_uSec]; |
michael@0 | 295 | s.sanitize(); |
michael@0 | 296 | s.range = null; |
michael@0 | 297 | |
michael@0 | 298 | yield promiseFormHistoryRemoved(); |
michael@0 | 299 | yield downloadPromise; |
michael@0 | 300 | |
michael@0 | 301 | ok(!(yield promiseIsURIVisited(makeURI("http://2hour10minutes.com"))), |
michael@0 | 302 | "Pretend visit to 2hour10minutes.com should now be deleted"); |
michael@0 | 303 | ok((yield promiseIsURIVisited(makeURI("http://4hour.com"))), |
michael@0 | 304 | "Pretend visit to 4hour.com should should still exist"); |
michael@0 | 305 | ok((yield promiseIsURIVisited(makeURI("http://4hour10minutes.com"))), |
michael@0 | 306 | "Pretend visit to 4hour10minutes.com should should still exist"); |
michael@0 | 307 | if (minutesSinceMidnight > 130) { |
michael@0 | 308 | ok((yield promiseIsURIVisited(makeURI("http://today.com"))), |
michael@0 | 309 | "Pretend visit to today.com should still exist"); |
michael@0 | 310 | } |
michael@0 | 311 | ok((yield promiseIsURIVisited(makeURI("http://before-today.com"))), |
michael@0 | 312 | "Pretend visit to before-today.com should still exist"); |
michael@0 | 313 | |
michael@0 | 314 | yield countEntries("2hour10minutes", "2hour10minutes form entry should be deleted", checkZero); |
michael@0 | 315 | yield countEntries("4hour", "4hour form entry should still exist", checkOne); |
michael@0 | 316 | yield countEntries("4hour10minutes", "4hour10minutes form entry should still exist", checkOne); |
michael@0 | 317 | if (minutesSinceMidnight > 130) |
michael@0 | 318 | yield countEntries("today", "today form entry should still exist", checkOne); |
michael@0 | 319 | yield countEntries("b4today", "b4today form entry should still exist", checkOne); |
michael@0 | 320 | |
michael@0 | 321 | ok(!(yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute old download should now be deleted"); |
michael@0 | 322 | ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present"); |
michael@0 | 323 | ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present"); |
michael@0 | 324 | ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present"); |
michael@0 | 325 | if (minutesSinceMidnight > 130) |
michael@0 | 326 | ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present"); |
michael@0 | 327 | |
michael@0 | 328 | downloadPromise = promiseDownloadRemoved(publicList); |
michael@0 | 329 | |
michael@0 | 330 | // Clear 4 hours |
michael@0 | 331 | Sanitizer.prefs.setIntPref("timeSpan", 3); |
michael@0 | 332 | s.sanitize(); |
michael@0 | 333 | |
michael@0 | 334 | yield promiseFormHistoryRemoved(); |
michael@0 | 335 | yield downloadPromise; |
michael@0 | 336 | |
michael@0 | 337 | ok(!(yield promiseIsURIVisited(makeURI("http://4hour.com"))), |
michael@0 | 338 | "Pretend visit to 4hour.com should now be deleted"); |
michael@0 | 339 | ok((yield promiseIsURIVisited(makeURI("http://4hour10minutes.com"))), |
michael@0 | 340 | "Pretend visit to 4hour10minutes.com should should still exist"); |
michael@0 | 341 | if (hoursSinceMidnight > 4) { |
michael@0 | 342 | ok((yield promiseIsURIVisited(makeURI("http://today.com"))), |
michael@0 | 343 | "Pretend visit to today.com should still exist"); |
michael@0 | 344 | } |
michael@0 | 345 | ok((yield promiseIsURIVisited(makeURI("http://before-today.com"))), |
michael@0 | 346 | "Pretend visit to before-today.com should still exist"); |
michael@0 | 347 | |
michael@0 | 348 | yield countEntries("4hour", "4hour form entry should be deleted", checkZero); |
michael@0 | 349 | yield countEntries("4hour10minutes", "4hour10minutes form entry should still exist", checkOne); |
michael@0 | 350 | if (hoursSinceMidnight > 4) |
michael@0 | 351 | yield countEntries("today", "today form entry should still exist", checkOne); |
michael@0 | 352 | yield countEntries("b4today", "b4today form entry should still exist", checkOne); |
michael@0 | 353 | |
michael@0 | 354 | ok(!(yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should now be deleted"); |
michael@0 | 355 | ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present"); |
michael@0 | 356 | ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present"); |
michael@0 | 357 | if (hoursSinceMidnight > 4) |
michael@0 | 358 | ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present"); |
michael@0 | 359 | |
michael@0 | 360 | downloadPromise = promiseDownloadRemoved(publicList); |
michael@0 | 361 | |
michael@0 | 362 | // Clear 4 hours 10 minutes |
michael@0 | 363 | s.range = [now_uSec - 250*60*1000000, now_uSec]; |
michael@0 | 364 | s.sanitize(); |
michael@0 | 365 | s.range = null; |
michael@0 | 366 | |
michael@0 | 367 | yield promiseFormHistoryRemoved(); |
michael@0 | 368 | yield downloadPromise; |
michael@0 | 369 | |
michael@0 | 370 | ok(!(yield promiseIsURIVisited(makeURI("http://4hour10minutes.com"))), |
michael@0 | 371 | "Pretend visit to 4hour10minutes.com should now be deleted"); |
michael@0 | 372 | if (minutesSinceMidnight > 250) { |
michael@0 | 373 | ok((yield promiseIsURIVisited(makeURI("http://today.com"))), |
michael@0 | 374 | "Pretend visit to today.com should still exist"); |
michael@0 | 375 | } |
michael@0 | 376 | ok((yield promiseIsURIVisited(makeURI("http://before-today.com"))), |
michael@0 | 377 | "Pretend visit to before-today.com should still exist"); |
michael@0 | 378 | |
michael@0 | 379 | yield countEntries("4hour10minutes", "4hour10minutes form entry should be deleted", checkZero); |
michael@0 | 380 | if (minutesSinceMidnight > 250) |
michael@0 | 381 | yield countEntries("today", "today form entry should still exist", checkOne); |
michael@0 | 382 | yield countEntries("b4today", "b4today form entry should still exist", checkOne); |
michael@0 | 383 | |
michael@0 | 384 | ok(!(yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should now be deleted"); |
michael@0 | 385 | ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present"); |
michael@0 | 386 | if (minutesSinceMidnight > 250) |
michael@0 | 387 | ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present"); |
michael@0 | 388 | |
michael@0 | 389 | // The 'Today' download might have been already deleted, in which case we |
michael@0 | 390 | // should not wait for a download removal notification. |
michael@0 | 391 | if (minutesSinceMidnight > 250) { |
michael@0 | 392 | downloadPromise = promiseDownloadRemoved(publicList); |
michael@0 | 393 | } else { |
michael@0 | 394 | downloadPromise = Promise.resolve(); |
michael@0 | 395 | } |
michael@0 | 396 | |
michael@0 | 397 | // Clear Today |
michael@0 | 398 | Sanitizer.prefs.setIntPref("timeSpan", 4); |
michael@0 | 399 | s.sanitize(); |
michael@0 | 400 | |
michael@0 | 401 | yield promiseFormHistoryRemoved(); |
michael@0 | 402 | yield downloadPromise; |
michael@0 | 403 | |
michael@0 | 404 | // Be careful. If we add our objectss just before midnight, and sanitize |
michael@0 | 405 | // runs immediately after, they won't be expired. This is expected, but |
michael@0 | 406 | // we should not test in that case. We cannot just test for opposite |
michael@0 | 407 | // condition because we could cross midnight just one moment after we |
michael@0 | 408 | // cache our time, then we would have an even worse random failure. |
michael@0 | 409 | var today = isToday(new Date(now_mSec)); |
michael@0 | 410 | if (today) { |
michael@0 | 411 | ok(!(yield promiseIsURIVisited(makeURI("http://today.com"))), |
michael@0 | 412 | "Pretend visit to today.com should now be deleted"); |
michael@0 | 413 | |
michael@0 | 414 | yield countEntries("today", "today form entry should be deleted", checkZero); |
michael@0 | 415 | ok(!(yield downloadExists(publicList, "fakefile-today")), "'Today' download should now be deleted"); |
michael@0 | 416 | } |
michael@0 | 417 | |
michael@0 | 418 | ok((yield promiseIsURIVisited(makeURI("http://before-today.com"))), |
michael@0 | 419 | "Pretend visit to before-today.com should still exist"); |
michael@0 | 420 | yield countEntries("b4today", "b4today form entry should still exist", checkOne); |
michael@0 | 421 | ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present"); |
michael@0 | 422 | |
michael@0 | 423 | downloadPromise = promiseDownloadRemoved(publicList); |
michael@0 | 424 | |
michael@0 | 425 | // Choose everything |
michael@0 | 426 | Sanitizer.prefs.setIntPref("timeSpan", 0); |
michael@0 | 427 | s.sanitize(); |
michael@0 | 428 | |
michael@0 | 429 | yield promiseFormHistoryRemoved(); |
michael@0 | 430 | yield downloadPromise; |
michael@0 | 431 | |
michael@0 | 432 | ok(!(yield promiseIsURIVisited(makeURI("http://before-today.com"))), |
michael@0 | 433 | "Pretend visit to before-today.com should now be deleted"); |
michael@0 | 434 | |
michael@0 | 435 | yield countEntries("b4today", "b4today form entry should be deleted", checkZero); |
michael@0 | 436 | |
michael@0 | 437 | ok(!(yield downloadExists(publicList, "fakefile-old")), "Year old download should now be deleted"); |
michael@0 | 438 | } |
michael@0 | 439 | |
michael@0 | 440 | function setupHistory() { |
michael@0 | 441 | let deferred = Promise.defer(); |
michael@0 | 442 | |
michael@0 | 443 | let places = []; |
michael@0 | 444 | |
michael@0 | 445 | function addPlace(aURI, aTitle, aVisitDate) { |
michael@0 | 446 | places.push({ |
michael@0 | 447 | uri: aURI, |
michael@0 | 448 | title: aTitle, |
michael@0 | 449 | visits: [{ |
michael@0 | 450 | visitDate: aVisitDate, |
michael@0 | 451 | transitionType: Ci.nsINavHistoryService.TRANSITION_LINK |
michael@0 | 452 | }] |
michael@0 | 453 | }); |
michael@0 | 454 | } |
michael@0 | 455 | |
michael@0 | 456 | addPlace(makeURI("http://10minutes.com/"), "10 minutes ago", now_uSec - 10 * kUsecPerMin); |
michael@0 | 457 | addPlace(makeURI("http://1hour.com/"), "Less than 1 hour ago", now_uSec - 45 * kUsecPerMin); |
michael@0 | 458 | addPlace(makeURI("http://1hour10minutes.com/"), "1 hour 10 minutes ago", now_uSec - 70 * kUsecPerMin); |
michael@0 | 459 | addPlace(makeURI("http://2hour.com/"), "Less than 2 hours ago", now_uSec - 90 * kUsecPerMin); |
michael@0 | 460 | addPlace(makeURI("http://2hour10minutes.com/"), "2 hours 10 minutes ago", now_uSec - 130 * kUsecPerMin); |
michael@0 | 461 | addPlace(makeURI("http://4hour.com/"), "Less than 4 hours ago", now_uSec - 180 * kUsecPerMin); |
michael@0 | 462 | addPlace(makeURI("http://4hour10minutes.com/"), "4 hours 10 minutesago", now_uSec - 250 * kUsecPerMin); |
michael@0 | 463 | |
michael@0 | 464 | let today = new Date(); |
michael@0 | 465 | today.setHours(0); |
michael@0 | 466 | today.setMinutes(0); |
michael@0 | 467 | today.setSeconds(1); |
michael@0 | 468 | addPlace(makeURI("http://today.com/"), "Today", today.getTime() * 1000); |
michael@0 | 469 | |
michael@0 | 470 | let lastYear = new Date(); |
michael@0 | 471 | lastYear.setFullYear(lastYear.getFullYear() - 1); |
michael@0 | 472 | addPlace(makeURI("http://before-today.com/"), "Before Today", lastYear.getTime() * 1000); |
michael@0 | 473 | |
michael@0 | 474 | PlacesUtils.asyncHistory.updatePlaces(places, { |
michael@0 | 475 | handleError: function () ok(false, "Unexpected error in adding visit."), |
michael@0 | 476 | handleResult: function () { }, |
michael@0 | 477 | handleCompletion: function () deferred.resolve() |
michael@0 | 478 | }); |
michael@0 | 479 | |
michael@0 | 480 | return deferred.promise; |
michael@0 | 481 | } |
michael@0 | 482 | |
michael@0 | 483 | function setupFormHistory() { |
michael@0 | 484 | |
michael@0 | 485 | function searchEntries(terms, params) { |
michael@0 | 486 | let deferred = Promise.defer(); |
michael@0 | 487 | |
michael@0 | 488 | let results = []; |
michael@0 | 489 | FormHistory.search(terms, params, { handleResult: function (result) results.push(result), |
michael@0 | 490 | handleError: function (error) { |
michael@0 | 491 | do_throw("Error occurred searching form history: " + error); |
michael@0 | 492 | deferred.reject(error); |
michael@0 | 493 | }, |
michael@0 | 494 | handleCompletion: function (reason) { deferred.resolve(results); } |
michael@0 | 495 | }); |
michael@0 | 496 | return deferred.promise; |
michael@0 | 497 | } |
michael@0 | 498 | |
michael@0 | 499 | function update(changes) |
michael@0 | 500 | { |
michael@0 | 501 | let deferred = Promise.defer(); |
michael@0 | 502 | FormHistory.update(changes, { handleError: function (error) { |
michael@0 | 503 | do_throw("Error occurred searching form history: " + error); |
michael@0 | 504 | deferred.reject(error); |
michael@0 | 505 | }, |
michael@0 | 506 | handleCompletion: function (reason) { deferred.resolve(); } |
michael@0 | 507 | }); |
michael@0 | 508 | return deferred.promise; |
michael@0 | 509 | } |
michael@0 | 510 | |
michael@0 | 511 | // Make sure we've got a clean DB to start with, then add the entries we'll be testing. |
michael@0 | 512 | yield update( |
michael@0 | 513 | [{ |
michael@0 | 514 | op: "remove" |
michael@0 | 515 | }, |
michael@0 | 516 | { |
michael@0 | 517 | op : "add", |
michael@0 | 518 | fieldname : "10minutes", |
michael@0 | 519 | value : "10m" |
michael@0 | 520 | }, { |
michael@0 | 521 | op : "add", |
michael@0 | 522 | fieldname : "1hour", |
michael@0 | 523 | value : "1h" |
michael@0 | 524 | }, { |
michael@0 | 525 | op : "add", |
michael@0 | 526 | fieldname : "1hour10minutes", |
michael@0 | 527 | value : "1h10m" |
michael@0 | 528 | }, { |
michael@0 | 529 | op : "add", |
michael@0 | 530 | fieldname : "2hour", |
michael@0 | 531 | value : "2h" |
michael@0 | 532 | }, { |
michael@0 | 533 | op : "add", |
michael@0 | 534 | fieldname : "2hour10minutes", |
michael@0 | 535 | value : "2h10m" |
michael@0 | 536 | }, { |
michael@0 | 537 | op : "add", |
michael@0 | 538 | fieldname : "4hour", |
michael@0 | 539 | value : "4h" |
michael@0 | 540 | }, { |
michael@0 | 541 | op : "add", |
michael@0 | 542 | fieldname : "4hour10minutes", |
michael@0 | 543 | value : "4h10m" |
michael@0 | 544 | }, { |
michael@0 | 545 | op : "add", |
michael@0 | 546 | fieldname : "today", |
michael@0 | 547 | value : "1d" |
michael@0 | 548 | }, { |
michael@0 | 549 | op : "add", |
michael@0 | 550 | fieldname : "b4today", |
michael@0 | 551 | value : "1y" |
michael@0 | 552 | }]); |
michael@0 | 553 | |
michael@0 | 554 | // Artifically age the entries to the proper vintage. |
michael@0 | 555 | let timestamp = now_uSec - 10 * kUsecPerMin; |
michael@0 | 556 | let results = yield searchEntries(["guid"], { fieldname: "10minutes" }); |
michael@0 | 557 | yield update({ op: "update", firstUsed: timestamp, guid: results[0].guid }); |
michael@0 | 558 | |
michael@0 | 559 | timestamp = now_uSec - 45 * kUsecPerMin; |
michael@0 | 560 | results = yield searchEntries(["guid"], { fieldname: "1hour" }); |
michael@0 | 561 | yield update({ op: "update", firstUsed: timestamp, guid: results[0].guid }); |
michael@0 | 562 | |
michael@0 | 563 | timestamp = now_uSec - 70 * kUsecPerMin; |
michael@0 | 564 | results = yield searchEntries(["guid"], { fieldname: "1hour10minutes" }); |
michael@0 | 565 | yield update({ op: "update", firstUsed: timestamp, guid: results[0].guid }); |
michael@0 | 566 | |
michael@0 | 567 | timestamp = now_uSec - 90 * kUsecPerMin; |
michael@0 | 568 | results = yield searchEntries(["guid"], { fieldname: "2hour" }); |
michael@0 | 569 | yield update({ op: "update", firstUsed: timestamp, guid: results[0].guid }); |
michael@0 | 570 | |
michael@0 | 571 | timestamp = now_uSec - 130 * kUsecPerMin; |
michael@0 | 572 | results = yield searchEntries(["guid"], { fieldname: "2hour10minutes" }); |
michael@0 | 573 | yield update({ op: "update", firstUsed: timestamp, guid: results[0].guid }); |
michael@0 | 574 | |
michael@0 | 575 | timestamp = now_uSec - 180 * kUsecPerMin; |
michael@0 | 576 | results = yield searchEntries(["guid"], { fieldname: "4hour" }); |
michael@0 | 577 | yield update({ op: "update", firstUsed: timestamp, guid: results[0].guid }); |
michael@0 | 578 | |
michael@0 | 579 | timestamp = now_uSec - 250 * kUsecPerMin; |
michael@0 | 580 | results = yield searchEntries(["guid"], { fieldname: "4hour10minutes" }); |
michael@0 | 581 | yield update({ op: "update", firstUsed: timestamp, guid: results[0].guid }); |
michael@0 | 582 | |
michael@0 | 583 | let today = new Date(); |
michael@0 | 584 | today.setHours(0); |
michael@0 | 585 | today.setMinutes(0); |
michael@0 | 586 | today.setSeconds(1); |
michael@0 | 587 | timestamp = today.getTime() * 1000; |
michael@0 | 588 | results = yield searchEntries(["guid"], { fieldname: "today" }); |
michael@0 | 589 | yield update({ op: "update", firstUsed: timestamp, guid: results[0].guid }); |
michael@0 | 590 | |
michael@0 | 591 | let lastYear = new Date(); |
michael@0 | 592 | lastYear.setFullYear(lastYear.getFullYear() - 1); |
michael@0 | 593 | timestamp = lastYear.getTime() * 1000; |
michael@0 | 594 | results = yield searchEntries(["guid"], { fieldname: "b4today" }); |
michael@0 | 595 | yield update({ op: "update", firstUsed: timestamp, guid: results[0].guid }); |
michael@0 | 596 | |
michael@0 | 597 | var checks = 0; |
michael@0 | 598 | let checkOne = function(num, message) { is(num, 1, message); checks++; } |
michael@0 | 599 | |
michael@0 | 600 | // Sanity check. |
michael@0 | 601 | yield countEntries("10minutes", "Checking for 10minutes form history entry creation", checkOne); |
michael@0 | 602 | yield countEntries("1hour", "Checking for 1hour form history entry creation", checkOne); |
michael@0 | 603 | yield countEntries("1hour10minutes", "Checking for 1hour10minutes form history entry creation", checkOne); |
michael@0 | 604 | yield countEntries("2hour", "Checking for 2hour form history entry creation", checkOne); |
michael@0 | 605 | yield countEntries("2hour10minutes", "Checking for 2hour10minutes form history entry creation", checkOne); |
michael@0 | 606 | yield countEntries("4hour", "Checking for 4hour form history entry creation", checkOne); |
michael@0 | 607 | yield countEntries("4hour10minutes", "Checking for 4hour10minutes form history entry creation", checkOne); |
michael@0 | 608 | yield countEntries("today", "Checking for today form history entry creation", checkOne); |
michael@0 | 609 | yield countEntries("b4today", "Checking for b4today form history entry creation", checkOne); |
michael@0 | 610 | is(checks, 9, "9 checks made"); |
michael@0 | 611 | } |
michael@0 | 612 | |
michael@0 | 613 | function setupDownloads() { |
michael@0 | 614 | |
michael@0 | 615 | let publicList = yield Downloads.getList(Downloads.PUBLIC); |
michael@0 | 616 | |
michael@0 | 617 | let download = yield Downloads.createDownload({ |
michael@0 | 618 | source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169", |
michael@0 | 619 | target: "fakefile-10-minutes" |
michael@0 | 620 | }); |
michael@0 | 621 | download.startTime = new Date(now_mSec - 10 * kMsecPerMin), // 10 minutes ago |
michael@0 | 622 | download.canceled = true; |
michael@0 | 623 | yield publicList.add(download); |
michael@0 | 624 | |
michael@0 | 625 | download = yield Downloads.createDownload({ |
michael@0 | 626 | source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440", |
michael@0 | 627 | target: "fakefile-1-hour" |
michael@0 | 628 | }); |
michael@0 | 629 | download.startTime = new Date(now_mSec - 45 * kMsecPerMin), // 45 minutes ago |
michael@0 | 630 | download.canceled = true; |
michael@0 | 631 | yield publicList.add(download); |
michael@0 | 632 | |
michael@0 | 633 | download = yield Downloads.createDownload({ |
michael@0 | 634 | source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169", |
michael@0 | 635 | target: "fakefile-1-hour-10-minutes" |
michael@0 | 636 | }); |
michael@0 | 637 | download.startTime = new Date(now_mSec - 70 * kMsecPerMin), // 70 minutes ago |
michael@0 | 638 | download.canceled = true; |
michael@0 | 639 | yield publicList.add(download); |
michael@0 | 640 | |
michael@0 | 641 | download = yield Downloads.createDownload({ |
michael@0 | 642 | source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440", |
michael@0 | 643 | target: "fakefile-2-hour" |
michael@0 | 644 | }); |
michael@0 | 645 | download.startTime = new Date(now_mSec - 90 * kMsecPerMin), // 90 minutes ago |
michael@0 | 646 | download.canceled = true; |
michael@0 | 647 | yield publicList.add(download); |
michael@0 | 648 | |
michael@0 | 649 | download = yield Downloads.createDownload({ |
michael@0 | 650 | source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169", |
michael@0 | 651 | target: "fakefile-2-hour-10-minutes" |
michael@0 | 652 | }); |
michael@0 | 653 | download.startTime = new Date(now_mSec - 130 * kMsecPerMin), // 130 minutes ago |
michael@0 | 654 | download.canceled = true; |
michael@0 | 655 | yield publicList.add(download); |
michael@0 | 656 | |
michael@0 | 657 | download = yield Downloads.createDownload({ |
michael@0 | 658 | source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440", |
michael@0 | 659 | target: "fakefile-4-hour" |
michael@0 | 660 | }); |
michael@0 | 661 | download.startTime = new Date(now_mSec - 180 * kMsecPerMin), // 180 minutes ago |
michael@0 | 662 | download.canceled = true; |
michael@0 | 663 | yield publicList.add(download); |
michael@0 | 664 | |
michael@0 | 665 | download = yield Downloads.createDownload({ |
michael@0 | 666 | source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169", |
michael@0 | 667 | target: "fakefile-4-hour-10-minutes" |
michael@0 | 668 | }); |
michael@0 | 669 | download.startTime = new Date(now_mSec - 250 * kMsecPerMin), // 250 minutes ago |
michael@0 | 670 | download.canceled = true; |
michael@0 | 671 | yield publicList.add(download); |
michael@0 | 672 | |
michael@0 | 673 | // Add "today" download |
michael@0 | 674 | let today = new Date(); |
michael@0 | 675 | today.setHours(0); |
michael@0 | 676 | today.setMinutes(0); |
michael@0 | 677 | today.setSeconds(1); |
michael@0 | 678 | |
michael@0 | 679 | download = yield Downloads.createDownload({ |
michael@0 | 680 | source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440", |
michael@0 | 681 | target: "fakefile-today" |
michael@0 | 682 | }); |
michael@0 | 683 | download.startTime = today, // 12:00:01 AM this morning |
michael@0 | 684 | download.canceled = true; |
michael@0 | 685 | yield publicList.add(download); |
michael@0 | 686 | |
michael@0 | 687 | // Add "before today" download |
michael@0 | 688 | let lastYear = new Date(); |
michael@0 | 689 | lastYear.setFullYear(lastYear.getFullYear() - 1); |
michael@0 | 690 | |
michael@0 | 691 | download = yield Downloads.createDownload({ |
michael@0 | 692 | source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440", |
michael@0 | 693 | target: "fakefile-old" |
michael@0 | 694 | }); |
michael@0 | 695 | download.startTime = lastYear, |
michael@0 | 696 | download.canceled = true; |
michael@0 | 697 | yield publicList.add(download); |
michael@0 | 698 | |
michael@0 | 699 | // Confirm everything worked |
michael@0 | 700 | let downloads = yield publicList.getAll(); |
michael@0 | 701 | is(downloads.length, 9, "9 Pretend downloads added"); |
michael@0 | 702 | |
michael@0 | 703 | ok((yield downloadExists(publicList, "fakefile-old")), "Pretend download for everything case should exist"); |
michael@0 | 704 | ok((yield downloadExists(publicList, "fakefile-10-minutes")), "Pretend download for 10-minutes case should exist"); |
michael@0 | 705 | ok((yield downloadExists(publicList, "fakefile-1-hour")), "Pretend download for 1-hour case should exist"); |
michael@0 | 706 | ok((yield downloadExists(publicList, "fakefile-1-hour-10-minutes")), "Pretend download for 1-hour-10-minutes case should exist"); |
michael@0 | 707 | ok((yield downloadExists(publicList, "fakefile-2-hour")), "Pretend download for 2-hour case should exist"); |
michael@0 | 708 | ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "Pretend download for 2-hour-10-minutes case should exist"); |
michael@0 | 709 | ok((yield downloadExists(publicList, "fakefile-4-hour")), "Pretend download for 4-hour case should exist"); |
michael@0 | 710 | ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "Pretend download for 4-hour-10-minutes case should exist"); |
michael@0 | 711 | ok((yield downloadExists(publicList, "fakefile-today")), "Pretend download for Today case should exist"); |
michael@0 | 712 | } |
michael@0 | 713 | |
michael@0 | 714 | /** |
michael@0 | 715 | * Checks to see if the downloads with the specified id exists. |
michael@0 | 716 | * |
michael@0 | 717 | * @param aID |
michael@0 | 718 | * The ids of the downloads to check. |
michael@0 | 719 | */ |
michael@0 | 720 | function downloadExists(list, path) |
michael@0 | 721 | { |
michael@0 | 722 | return Task.spawn(function() { |
michael@0 | 723 | let listArray = yield list.getAll(); |
michael@0 | 724 | throw new Task.Result(listArray.some(i => i.target.path == path)); |
michael@0 | 725 | }); |
michael@0 | 726 | } |
michael@0 | 727 | |
michael@0 | 728 | function isToday(aDate) { |
michael@0 | 729 | return aDate.getDate() == new Date().getDate(); |
michael@0 | 730 | } |