зеркало из https://github.com/mozilla/gecko-dev.git
Merge mozilla-central and fx-team
This commit is contained in:
Коммит
d76e308416
|
@ -336,7 +336,7 @@ pref("browser.download.manager.scanWhenDone", true);
|
||||||
pref("browser.download.manager.resumeOnWakeDelay", 10000);
|
pref("browser.download.manager.resumeOnWakeDelay", 10000);
|
||||||
|
|
||||||
// Enables the asynchronous Downloads API in the Downloads Panel.
|
// Enables the asynchronous Downloads API in the Downloads Panel.
|
||||||
pref("browser.download.useJSTransfer", false);
|
pref("browser.download.useJSTransfer", true);
|
||||||
|
|
||||||
// This allows disabling the Downloads Panel in favor of the old interface.
|
// This allows disabling the Downloads Panel in favor of the old interface.
|
||||||
pref("browser.download.useToolkitUI", false);
|
pref("browser.download.useToolkitUI", false);
|
||||||
|
|
|
@ -16,7 +16,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||||
"resource://gre/modules/Task.jsm");
|
"resource://gre/modules/Task.jsm");
|
||||||
XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon",
|
XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon",
|
||||||
"resource:///modules/DownloadsCommon.jsm");
|
"resource:///modules/DownloadsCommon.jsm");
|
||||||
|
|
||||||
function Sanitizer() {}
|
function Sanitizer() {}
|
||||||
Sanitizer.prototype = {
|
Sanitizer.prototype = {
|
||||||
// warning to the caller: this one may raise an exception (e.g. bug #265028)
|
// warning to the caller: this one may raise an exception (e.g. bug #265028)
|
||||||
|
@ -37,14 +37,14 @@ Sanitizer.prototype = {
|
||||||
aCallback(aItemName, canClear, aArg);
|
aCallback(aItemName, canClear, aArg);
|
||||||
return canClear;
|
return canClear;
|
||||||
},
|
},
|
||||||
|
|
||||||
prefDomain: "",
|
prefDomain: "",
|
||||||
|
|
||||||
getNameFromPreference: function (aPreferenceName)
|
getNameFromPreference: function (aPreferenceName)
|
||||||
{
|
{
|
||||||
return aPreferenceName.substr(this.prefDomain.length);
|
return aPreferenceName.substr(this.prefDomain.length);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes privacy sensitive data in a batch, according to user preferences.
|
* Deletes privacy sensitive data in a batch, according to user preferences.
|
||||||
* Returns a promise which is resolved if no errors occurred. If an error
|
* Returns a promise which is resolved if no errors occurred. If an error
|
||||||
|
@ -87,7 +87,8 @@ Sanitizer.prototype = {
|
||||||
item.clear();
|
item.clear();
|
||||||
} catch(er) {
|
} catch(er) {
|
||||||
seenError = true;
|
seenError = true;
|
||||||
Cu.reportError("Error sanitizing " + itemName + ": " + er + "\n");
|
Components.utils.reportError("Error sanitizing " + itemName +
|
||||||
|
": " + er + "\n");
|
||||||
}
|
}
|
||||||
onItemComplete();
|
onItemComplete();
|
||||||
};
|
};
|
||||||
|
@ -99,7 +100,7 @@ Sanitizer.prototype = {
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Time span only makes sense in certain cases. Consumers who want
|
// Time span only makes sense in certain cases. Consumers who want
|
||||||
// to only clear some private data can opt in by setting this to false,
|
// to only clear some private data can opt in by setting this to false,
|
||||||
// and can optionally specify a specific range. If timespan is not ignored,
|
// and can optionally specify a specific range. If timespan is not ignored,
|
||||||
|
@ -107,7 +108,7 @@ Sanitizer.prototype = {
|
||||||
// pref to determine a range
|
// pref to determine a range
|
||||||
ignoreTimespan : true,
|
ignoreTimespan : true,
|
||||||
range : null,
|
range : null,
|
||||||
|
|
||||||
items: {
|
items: {
|
||||||
cache: {
|
cache: {
|
||||||
clear: function ()
|
clear: function ()
|
||||||
|
@ -126,13 +127,13 @@ Sanitizer.prototype = {
|
||||||
imageCache.clearCache(false); // true=chrome, false=content
|
imageCache.clearCache(false); // true=chrome, false=content
|
||||||
} catch(er) {}
|
} catch(er) {}
|
||||||
},
|
},
|
||||||
|
|
||||||
get canClear()
|
get canClear()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
cookies: {
|
cookies: {
|
||||||
clear: function ()
|
clear: function ()
|
||||||
{
|
{
|
||||||
|
@ -143,7 +144,7 @@ Sanitizer.prototype = {
|
||||||
var cookiesEnum = cookieMgr.enumerator;
|
var cookiesEnum = cookieMgr.enumerator;
|
||||||
while (cookiesEnum.hasMoreElements()) {
|
while (cookiesEnum.hasMoreElements()) {
|
||||||
var cookie = cookiesEnum.getNext().QueryInterface(Ci.nsICookie2);
|
var cookie = cookiesEnum.getNext().QueryInterface(Ci.nsICookie2);
|
||||||
|
|
||||||
if (cookie.creationTime > this.range[0])
|
if (cookie.creationTime > this.range[0])
|
||||||
// This cookie was created after our cutoff, clear it
|
// This cookie was created after our cutoff, clear it
|
||||||
cookieMgr.remove(cookie.host, cookie.name, cookie.path, false);
|
cookieMgr.remove(cookie.host, cookie.name, cookie.path, false);
|
||||||
|
@ -211,14 +212,14 @@ Sanitizer.prototype = {
|
||||||
PlacesUtils.history.removeVisitsByTimeframe(this.range[0], this.range[1]);
|
PlacesUtils.history.removeVisitsByTimeframe(this.range[0], this.range[1]);
|
||||||
else
|
else
|
||||||
PlacesUtils.history.removeAllPages();
|
PlacesUtils.history.removeAllPages();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var os = Components.classes["@mozilla.org/observer-service;1"]
|
var os = Components.classes["@mozilla.org/observer-service;1"]
|
||||||
.getService(Components.interfaces.nsIObserverService);
|
.getService(Components.interfaces.nsIObserverService);
|
||||||
os.notifyObservers(null, "browser:purge-session-history", "");
|
os.notifyObservers(null, "browser:purge-session-history", "");
|
||||||
}
|
}
|
||||||
catch (e) { }
|
catch (e) { }
|
||||||
|
|
||||||
// Clear last URL of the Open Web Location dialog
|
// Clear last URL of the Open Web Location dialog
|
||||||
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||||
.getService(Components.interfaces.nsIPrefBranch);
|
.getService(Components.interfaces.nsIPrefBranch);
|
||||||
|
@ -227,7 +228,7 @@ Sanitizer.prototype = {
|
||||||
}
|
}
|
||||||
catch (e) { }
|
catch (e) { }
|
||||||
},
|
},
|
||||||
|
|
||||||
get canClear()
|
get canClear()
|
||||||
{
|
{
|
||||||
// bug 347231: Always allow clearing history due to dependencies on
|
// bug 347231: Always allow clearing history due to dependencies on
|
||||||
|
@ -235,7 +236,7 @@ Sanitizer.prototype = {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
formdata: {
|
formdata: {
|
||||||
clear: function ()
|
clear: function ()
|
||||||
{
|
{
|
||||||
|
@ -305,15 +306,20 @@ Sanitizer.prototype = {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
downloads: {
|
downloads: {
|
||||||
clear: function ()
|
clear: function ()
|
||||||
{
|
{
|
||||||
if (DownloadsCommon.useJSTransfer) {
|
if (DownloadsCommon.useJSTransfer) {
|
||||||
Task.spawn(function () {
|
Task.spawn(function () {
|
||||||
let filterByTime = this.range ?
|
let filterByTime = null;
|
||||||
(download => download.startTime >= this.range[0] &&
|
if (this.range) {
|
||||||
download.startTime <= this.range[1]) : null;
|
// Convert microseconds back to milliseconds for date comparisons.
|
||||||
|
let rangeBeginMs = this.range[0] / 1000;
|
||||||
|
let rangeEndMs = this.range[1] / 1000;
|
||||||
|
filterByTime = download => download.startTime >= rangeBeginMs &&
|
||||||
|
download.startTime <= rangeEndMs;
|
||||||
|
}
|
||||||
|
|
||||||
// Clear all completed/cancelled downloads
|
// Clear all completed/cancelled downloads
|
||||||
let publicList = yield Downloads.getPublicDownloadList();
|
let publicList = yield Downloads.getPublicDownloadList();
|
||||||
|
@ -321,7 +327,7 @@ Sanitizer.prototype = {
|
||||||
|
|
||||||
let privateList = yield Downloads.getPrivateDownloadList();
|
let privateList = yield Downloads.getPrivateDownloadList();
|
||||||
privateList.removeFinished(filterByTime);
|
privateList.removeFinished(filterByTime);
|
||||||
}.bind(this)).then(null, Cu.reportError);
|
}.bind(this)).then(null, Components.utils.reportError);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var dlMgr = Components.classes["@mozilla.org/download-manager;1"]
|
var dlMgr = Components.classes["@mozilla.org/download-manager;1"]
|
||||||
|
@ -352,7 +358,7 @@ Sanitizer.prototype = {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
passwords: {
|
passwords: {
|
||||||
clear: function ()
|
clear: function ()
|
||||||
{
|
{
|
||||||
|
@ -361,7 +367,7 @@ Sanitizer.prototype = {
|
||||||
// Passwords are timeless, and don't respect the timeSpan setting
|
// Passwords are timeless, and don't respect the timeSpan setting
|
||||||
pwmgr.removeAllLogins();
|
pwmgr.removeAllLogins();
|
||||||
},
|
},
|
||||||
|
|
||||||
get canClear()
|
get canClear()
|
||||||
{
|
{
|
||||||
var pwmgr = Components.classes["@mozilla.org/login-manager;1"]
|
var pwmgr = Components.classes["@mozilla.org/login-manager;1"]
|
||||||
|
@ -370,7 +376,7 @@ Sanitizer.prototype = {
|
||||||
return (count > 0);
|
return (count > 0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sessions: {
|
sessions: {
|
||||||
clear: function ()
|
clear: function ()
|
||||||
{
|
{
|
||||||
|
@ -384,13 +390,13 @@ Sanitizer.prototype = {
|
||||||
.getService(Components.interfaces.nsIObserverService);
|
.getService(Components.interfaces.nsIObserverService);
|
||||||
os.notifyObservers(null, "net:clear-active-logins", null);
|
os.notifyObservers(null, "net:clear-active-logins", null);
|
||||||
},
|
},
|
||||||
|
|
||||||
get canClear()
|
get canClear()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
siteSettings: {
|
siteSettings: {
|
||||||
clear: function ()
|
clear: function ()
|
||||||
{
|
{
|
||||||
|
@ -398,12 +404,12 @@ Sanitizer.prototype = {
|
||||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||||
.getService(Components.interfaces.nsIPermissionManager);
|
.getService(Components.interfaces.nsIPermissionManager);
|
||||||
pm.removeAll();
|
pm.removeAll();
|
||||||
|
|
||||||
// Clear site-specific settings like page-zoom level
|
// Clear site-specific settings like page-zoom level
|
||||||
var cps = Components.classes["@mozilla.org/content-pref/service;1"]
|
var cps = Components.classes["@mozilla.org/content-pref/service;1"]
|
||||||
.getService(Components.interfaces.nsIContentPrefService2);
|
.getService(Components.interfaces.nsIContentPrefService2);
|
||||||
cps.removeAllDomains(null);
|
cps.removeAllDomains(null);
|
||||||
|
|
||||||
// Clear "Never remember passwords for this site", which is not handled by
|
// Clear "Never remember passwords for this site", which is not handled by
|
||||||
// the permission manager
|
// the permission manager
|
||||||
var pwmgr = Components.classes["@mozilla.org/login-manager;1"]
|
var pwmgr = Components.classes["@mozilla.org/login-manager;1"]
|
||||||
|
@ -413,7 +419,7 @@ Sanitizer.prototype = {
|
||||||
pwmgr.setLoginSavingEnabled(host, true);
|
pwmgr.setLoginSavingEnabled(host, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
get canClear()
|
get canClear()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -446,7 +452,7 @@ Sanitizer.getClearRange = function (ts) {
|
||||||
ts = Sanitizer.prefs.getIntPref("timeSpan");
|
ts = Sanitizer.prefs.getIntPref("timeSpan");
|
||||||
if (ts === Sanitizer.TIMESPAN_EVERYTHING)
|
if (ts === Sanitizer.TIMESPAN_EVERYTHING)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// PRTime is microseconds while JS time is milliseconds
|
// PRTime is microseconds while JS time is milliseconds
|
||||||
var endDate = Date.now() * 1000;
|
var endDate = Date.now() * 1000;
|
||||||
switch (ts) {
|
switch (ts) {
|
||||||
|
@ -473,7 +479,7 @@ Sanitizer.getClearRange = function (ts) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Sanitizer._prefs = null;
|
Sanitizer._prefs = null;
|
||||||
Sanitizer.__defineGetter__("prefs", function()
|
Sanitizer.__defineGetter__("prefs", function()
|
||||||
{
|
{
|
||||||
return Sanitizer._prefs ? Sanitizer._prefs
|
return Sanitizer._prefs ? Sanitizer._prefs
|
||||||
: Sanitizer._prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
: Sanitizer._prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||||
|
@ -482,7 +488,7 @@ Sanitizer.__defineGetter__("prefs", function()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Shows sanitization UI
|
// Shows sanitization UI
|
||||||
Sanitizer.showUI = function(aParentWindow)
|
Sanitizer.showUI = function(aParentWindow)
|
||||||
{
|
{
|
||||||
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
|
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
|
||||||
.getService(Components.interfaces.nsIWindowWatcher);
|
.getService(Components.interfaces.nsIWindowWatcher);
|
||||||
|
@ -497,32 +503,32 @@ Sanitizer.showUI = function(aParentWindow)
|
||||||
null);
|
null);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes privacy sensitive data in a batch, optionally showing the
|
* Deletes privacy sensitive data in a batch, optionally showing the
|
||||||
* sanitize UI, according to user preferences
|
* sanitize UI, according to user preferences
|
||||||
*/
|
*/
|
||||||
Sanitizer.sanitize = function(aParentWindow)
|
Sanitizer.sanitize = function(aParentWindow)
|
||||||
{
|
{
|
||||||
Sanitizer.showUI(aParentWindow);
|
Sanitizer.showUI(aParentWindow);
|
||||||
};
|
};
|
||||||
|
|
||||||
Sanitizer.onStartup = function()
|
Sanitizer.onStartup = function()
|
||||||
{
|
{
|
||||||
// we check for unclean exit with pending sanitization
|
// we check for unclean exit with pending sanitization
|
||||||
Sanitizer._checkAndSanitize();
|
Sanitizer._checkAndSanitize();
|
||||||
};
|
};
|
||||||
|
|
||||||
Sanitizer.onShutdown = function()
|
Sanitizer.onShutdown = function()
|
||||||
{
|
{
|
||||||
// we check if sanitization is needed and perform it
|
// we check if sanitization is needed and perform it
|
||||||
Sanitizer._checkAndSanitize();
|
Sanitizer._checkAndSanitize();
|
||||||
};
|
};
|
||||||
|
|
||||||
// this is called on startup and shutdown, to perform pending sanitizations
|
// this is called on startup and shutdown, to perform pending sanitizations
|
||||||
Sanitizer._checkAndSanitize = function()
|
Sanitizer._checkAndSanitize = function()
|
||||||
{
|
{
|
||||||
const prefs = Sanitizer.prefs;
|
const prefs = Sanitizer.prefs;
|
||||||
if (prefs.getBoolPref(Sanitizer.prefShutdown) &&
|
if (prefs.getBoolPref(Sanitizer.prefShutdown) &&
|
||||||
!prefs.prefHasUserValue(Sanitizer.prefDidShutdown)) {
|
!prefs.prefHasUserValue(Sanitizer.prefDidShutdown)) {
|
||||||
// this is a shutdown or a startup after an unclean exit
|
// this is a shutdown or a startup after an unclean exit
|
||||||
var s = new Sanitizer();
|
var s = new Sanitizer();
|
||||||
|
|
|
@ -2,10 +2,10 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
Cu.import("resource://gre/modules/Services.jsm");
|
Cu.import("resource://gre/modules/Services.jsm");
|
||||||
|
|
||||||
// Bug 453440 - Test the timespan-based logic of the sanitizer code
|
// Bug 453440 - Test the timespan-based logic of the sanitizer code
|
||||||
var now_uSec = Date.now() * 1000;
|
let now_mSec = Date.now();
|
||||||
|
let now_uSec = now_mSec * 1000;
|
||||||
const dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
|
|
||||||
|
|
||||||
|
const kMsecPerMin = 60 * 1000;
|
||||||
const kUsecPerMin = 60 * 1000000;
|
const kUsecPerMin = 60 * 1000000;
|
||||||
|
|
||||||
let tempScope = {};
|
let tempScope = {};
|
||||||
|
@ -14,6 +14,7 @@ Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
|
||||||
let Sanitizer = tempScope.Sanitizer;
|
let Sanitizer = tempScope.Sanitizer;
|
||||||
|
|
||||||
let FormHistory = (Components.utils.import("resource://gre/modules/FormHistory.jsm", {})).FormHistory;
|
let FormHistory = (Components.utils.import("resource://gre/modules/FormHistory.jsm", {})).FormHistory;
|
||||||
|
let Downloads = (Components.utils.import("resource://gre/modules/Downloads.jsm", {})).Downloads;
|
||||||
|
|
||||||
function promiseFormHistoryRemoved() {
|
function promiseFormHistoryRemoved() {
|
||||||
let deferred = Promise.defer();
|
let deferred = Promise.defer();
|
||||||
|
@ -24,15 +25,30 @@ function promiseFormHistoryRemoved() {
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function promiseDownloadRemoved(list) {
|
||||||
|
let deferred = Promise.defer();
|
||||||
|
|
||||||
|
let view = {
|
||||||
|
onDownloadRemoved: function(download) {
|
||||||
|
list.removeView(view);
|
||||||
|
deferred.resolve();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
list.addView(view);
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
function test() {
|
function test() {
|
||||||
waitForExplicitFinish();
|
waitForExplicitFinish();
|
||||||
|
|
||||||
Task.spawn(function() {
|
Task.spawn(function() {
|
||||||
setupDownloads();
|
yield setupDownloads();
|
||||||
yield setupFormHistory();
|
yield setupFormHistory();
|
||||||
yield setupHistory();
|
yield setupHistory();
|
||||||
yield onHistoryReady();
|
yield onHistoryReady();
|
||||||
}).then(finish);
|
}).then(null, ex => ok(false, ex)).then(finish);
|
||||||
}
|
}
|
||||||
|
|
||||||
function countEntries(name, message, check) {
|
function countEntries(name, message, check) {
|
||||||
|
@ -80,12 +96,16 @@ function onHistoryReady() {
|
||||||
itemPrefs.setBoolPref("sessions", false);
|
itemPrefs.setBoolPref("sessions", false);
|
||||||
itemPrefs.setBoolPref("siteSettings", false);
|
itemPrefs.setBoolPref("siteSettings", false);
|
||||||
|
|
||||||
|
let publicList = yield Downloads.getPublicDownloadList();
|
||||||
|
let downloadPromise = promiseDownloadRemoved(publicList);
|
||||||
|
|
||||||
// Clear 10 minutes ago
|
// Clear 10 minutes ago
|
||||||
s.range = [now_uSec - 10*60*1000000, now_uSec];
|
s.range = [now_uSec - 10*60*1000000, now_uSec];
|
||||||
s.sanitize();
|
s.sanitize();
|
||||||
s.range = null;
|
s.range = null;
|
||||||
|
|
||||||
yield promiseFormHistoryRemoved();
|
yield promiseFormHistoryRemoved();
|
||||||
|
yield downloadPromise;
|
||||||
|
|
||||||
ok(!(yield promiseIsURIVisited(makeURI("http://10minutes.com"))),
|
ok(!(yield promiseIsURIVisited(makeURI("http://10minutes.com"))),
|
||||||
"Pretend visit to 10minutes.com should now be deleted");
|
"Pretend visit to 10minutes.com should now be deleted");
|
||||||
|
@ -122,23 +142,26 @@ function onHistoryReady() {
|
||||||
yield countEntries("today", "today form entry should still exist", checkOne);
|
yield countEntries("today", "today form entry should still exist", checkOne);
|
||||||
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
||||||
|
|
||||||
ok(!downloadExists(5555555), "10 minute download should now be deleted");
|
ok(!(yield downloadExists(publicList, "fakefile-10-minutes")), "10 minute download should now be deleted");
|
||||||
ok(downloadExists(5555551), "<1 hour download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-1-hour")), "<1 hour download should still be present");
|
||||||
ok(downloadExists(5555556), "1 hour 10 minute download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-1-hour-10-minutes")), "1 hour 10 minute download should still be present");
|
||||||
ok(downloadExists(5555550), "Year old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
|
||||||
ok(downloadExists(5555552), "<2 hour old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-2-hour")), "<2 hour old download should still be present");
|
||||||
ok(downloadExists(5555557), "2 hour 10 minute download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute download should still be present");
|
||||||
ok(downloadExists(5555553), "<4 hour old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present");
|
||||||
ok(downloadExists(5555558), "4 hour 10 minute download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present");
|
||||||
|
|
||||||
if (minutesSinceMidnight > 10)
|
if (minutesSinceMidnight > 10)
|
||||||
ok(downloadExists(5555554), "'Today' download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
|
||||||
|
|
||||||
|
downloadPromise = promiseDownloadRemoved(publicList);
|
||||||
|
|
||||||
// Clear 1 hour
|
// Clear 1 hour
|
||||||
Sanitizer.prefs.setIntPref("timeSpan", 1);
|
Sanitizer.prefs.setIntPref("timeSpan", 1);
|
||||||
s.sanitize();
|
s.sanitize();
|
||||||
|
|
||||||
yield promiseFormHistoryRemoved();
|
yield promiseFormHistoryRemoved();
|
||||||
|
yield downloadPromise;
|
||||||
|
|
||||||
ok(!(yield promiseIsURIVisited(makeURI("http://1hour.com"))),
|
ok(!(yield promiseIsURIVisited(makeURI("http://1hour.com"))),
|
||||||
"Pretend visit to 1hour.com should now be deleted");
|
"Pretend visit to 1hour.com should now be deleted");
|
||||||
|
@ -169,23 +192,26 @@ function onHistoryReady() {
|
||||||
yield countEntries("today", "today form entry should still exist", checkOne);
|
yield countEntries("today", "today form entry should still exist", checkOne);
|
||||||
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
||||||
|
|
||||||
ok(!downloadExists(5555551), "<1 hour download should now be deleted");
|
ok(!(yield downloadExists(publicList, "fakefile-1-hour")), "<1 hour download should now be deleted");
|
||||||
ok(downloadExists(5555556), "1 hour 10 minute download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-1-hour-10-minutes")), "1 hour 10 minute download should still be present");
|
||||||
ok(downloadExists(5555550), "Year old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
|
||||||
ok(downloadExists(5555552), "<2 hour old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-2-hour")), "<2 hour old download should still be present");
|
||||||
ok(downloadExists(5555557), "2 hour 10 minute download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute download should still be present");
|
||||||
ok(downloadExists(5555553), "<4 hour old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present");
|
||||||
ok(downloadExists(5555558), "4 hour 10 minute download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present");
|
||||||
|
|
||||||
if (hoursSinceMidnight > 1)
|
if (hoursSinceMidnight > 1)
|
||||||
ok(downloadExists(5555554), "'Today' download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
|
||||||
|
|
||||||
|
downloadPromise = promiseDownloadRemoved(publicList);
|
||||||
|
|
||||||
// Clear 1 hour 10 minutes
|
// Clear 1 hour 10 minutes
|
||||||
s.range = [now_uSec - 70*60*1000000, now_uSec];
|
s.range = [now_uSec - 70*60*1000000, now_uSec];
|
||||||
s.sanitize();
|
s.sanitize();
|
||||||
s.range = null;
|
s.range = null;
|
||||||
|
|
||||||
yield promiseFormHistoryRemoved();
|
yield promiseFormHistoryRemoved();
|
||||||
|
yield downloadPromise;
|
||||||
|
|
||||||
ok(!(yield promiseIsURIVisited(makeURI("http://1hour10minutes.com"))),
|
ok(!(yield promiseIsURIVisited(makeURI("http://1hour10minutes.com"))),
|
||||||
"Pretend visit to 1hour10minutes.com should now be deleted");
|
"Pretend visit to 1hour10minutes.com should now be deleted");
|
||||||
|
@ -213,20 +239,23 @@ function onHistoryReady() {
|
||||||
yield countEntries("today", "today form entry should still exist", checkOne);
|
yield countEntries("today", "today form entry should still exist", checkOne);
|
||||||
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
||||||
|
|
||||||
ok(!downloadExists(5555556), "1 hour 10 minute old download should now be deleted");
|
ok(!(yield downloadExists(publicList, "fakefile-1-hour-10-minutes")), "1 hour 10 minute old download should now be deleted");
|
||||||
ok(downloadExists(5555550), "Year old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
|
||||||
ok(downloadExists(5555552), "<2 hour old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-2-hour")), "<2 hour old download should still be present");
|
||||||
ok(downloadExists(5555557), "2 hour 10 minute download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute download should still be present");
|
||||||
ok(downloadExists(5555553), "<4 hour old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present");
|
||||||
ok(downloadExists(5555558), "4 hour 10 minute download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present");
|
||||||
if (minutesSinceMidnight > 70)
|
if (minutesSinceMidnight > 70)
|
||||||
ok(downloadExists(5555554), "'Today' download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
|
||||||
|
|
||||||
|
downloadPromise = promiseDownloadRemoved(publicList);
|
||||||
|
|
||||||
// Clear 2 hours
|
// Clear 2 hours
|
||||||
Sanitizer.prefs.setIntPref("timeSpan", 2);
|
Sanitizer.prefs.setIntPref("timeSpan", 2);
|
||||||
s.sanitize();
|
s.sanitize();
|
||||||
|
|
||||||
yield promiseFormHistoryRemoved();
|
yield promiseFormHistoryRemoved();
|
||||||
|
yield downloadPromise;
|
||||||
|
|
||||||
ok(!(yield promiseIsURIVisited(makeURI("http://2hour.com"))),
|
ok(!(yield promiseIsURIVisited(makeURI("http://2hour.com"))),
|
||||||
"Pretend visit to 2hour.com should now be deleted");
|
"Pretend visit to 2hour.com should now be deleted");
|
||||||
|
@ -251,20 +280,23 @@ function onHistoryReady() {
|
||||||
yield countEntries("today", "today form entry should still exist", checkOne);
|
yield countEntries("today", "today form entry should still exist", checkOne);
|
||||||
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
||||||
|
|
||||||
ok(!downloadExists(5555552), "<2 hour old download should now be deleted");
|
ok(!(yield downloadExists(publicList, "fakefile-2-hour")), "<2 hour old download should now be deleted");
|
||||||
ok(downloadExists(5555550), "Year old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
|
||||||
ok(downloadExists(5555557), "2 hour 10 minute download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute download should still be present");
|
||||||
ok(downloadExists(5555553), "<4 hour old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present");
|
||||||
ok(downloadExists(5555558), "4 hour 10 minute download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present");
|
||||||
if (hoursSinceMidnight > 2)
|
if (hoursSinceMidnight > 2)
|
||||||
ok(downloadExists(5555554), "'Today' download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
|
||||||
|
|
||||||
|
downloadPromise = promiseDownloadRemoved(publicList);
|
||||||
|
|
||||||
// Clear 2 hours 10 minutes
|
// Clear 2 hours 10 minutes
|
||||||
s.range = [now_uSec - 130*60*1000000, now_uSec];
|
s.range = [now_uSec - 130*60*1000000, now_uSec];
|
||||||
s.sanitize();
|
s.sanitize();
|
||||||
s.range = null;
|
s.range = null;
|
||||||
|
|
||||||
yield promiseFormHistoryRemoved();
|
yield promiseFormHistoryRemoved();
|
||||||
|
yield downloadPromise;
|
||||||
|
|
||||||
ok(!(yield promiseIsURIVisited(makeURI("http://2hour10minutes.com"))),
|
ok(!(yield promiseIsURIVisited(makeURI("http://2hour10minutes.com"))),
|
||||||
"Pretend visit to 2hour10minutes.com should now be deleted");
|
"Pretend visit to 2hour10minutes.com should now be deleted");
|
||||||
|
@ -286,18 +318,21 @@ function onHistoryReady() {
|
||||||
yield countEntries("today", "today form entry should still exist", checkOne);
|
yield countEntries("today", "today form entry should still exist", checkOne);
|
||||||
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
||||||
|
|
||||||
ok(!downloadExists(5555557), "2 hour 10 minute old download should now be deleted");
|
ok(!(yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "2 hour 10 minute old download should now be deleted");
|
||||||
ok(downloadExists(5555553), "<4 hour old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should still be present");
|
||||||
ok(downloadExists(5555558), "4 hour 10 minute download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present");
|
||||||
ok(downloadExists(5555550), "Year old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
|
||||||
if (minutesSinceMidnight > 130)
|
if (minutesSinceMidnight > 130)
|
||||||
ok(downloadExists(5555554), "'Today' download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
|
||||||
|
|
||||||
|
downloadPromise = promiseDownloadRemoved(publicList);
|
||||||
|
|
||||||
// Clear 4 hours
|
// Clear 4 hours
|
||||||
Sanitizer.prefs.setIntPref("timeSpan", 3);
|
Sanitizer.prefs.setIntPref("timeSpan", 3);
|
||||||
s.sanitize();
|
s.sanitize();
|
||||||
|
|
||||||
yield promiseFormHistoryRemoved();
|
yield promiseFormHistoryRemoved();
|
||||||
|
yield downloadPromise;
|
||||||
|
|
||||||
ok(!(yield promiseIsURIVisited(makeURI("http://4hour.com"))),
|
ok(!(yield promiseIsURIVisited(makeURI("http://4hour.com"))),
|
||||||
"Pretend visit to 4hour.com should now be deleted");
|
"Pretend visit to 4hour.com should now be deleted");
|
||||||
|
@ -316,11 +351,13 @@ function onHistoryReady() {
|
||||||
yield countEntries("today", "today form entry should still exist", checkOne);
|
yield countEntries("today", "today form entry should still exist", checkOne);
|
||||||
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
||||||
|
|
||||||
ok(!downloadExists(5555553), "<4 hour old download should now be deleted");
|
ok(!(yield downloadExists(publicList, "fakefile-4-hour")), "<4 hour old download should now be deleted");
|
||||||
ok(downloadExists(5555558), "4 hour 10 minute download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should still be present");
|
||||||
ok(downloadExists(5555550), "Year old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
|
||||||
if (hoursSinceMidnight > 4)
|
if (hoursSinceMidnight > 4)
|
||||||
ok(downloadExists(5555554), "'Today' download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
|
||||||
|
|
||||||
|
downloadPromise = promiseDownloadRemoved(publicList);
|
||||||
|
|
||||||
// Clear 4 hours 10 minutes
|
// Clear 4 hours 10 minutes
|
||||||
s.range = [now_uSec - 250*60*1000000, now_uSec];
|
s.range = [now_uSec - 250*60*1000000, now_uSec];
|
||||||
|
@ -328,6 +365,7 @@ function onHistoryReady() {
|
||||||
s.range = null;
|
s.range = null;
|
||||||
|
|
||||||
yield promiseFormHistoryRemoved();
|
yield promiseFormHistoryRemoved();
|
||||||
|
yield downloadPromise;
|
||||||
|
|
||||||
ok(!(yield promiseIsURIVisited(makeURI("http://4hour10minutes.com"))),
|
ok(!(yield promiseIsURIVisited(makeURI("http://4hour10minutes.com"))),
|
||||||
"Pretend visit to 4hour10minutes.com should now be deleted");
|
"Pretend visit to 4hour10minutes.com should now be deleted");
|
||||||
|
@ -343,48 +381,60 @@ function onHistoryReady() {
|
||||||
yield countEntries("today", "today form entry should still exist", checkOne);
|
yield countEntries("today", "today form entry should still exist", checkOne);
|
||||||
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
||||||
|
|
||||||
ok(!downloadExists(5555558), "4 hour 10 minute download should now be deleted");
|
ok(!(yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "4 hour 10 minute download should now be deleted");
|
||||||
ok(downloadExists(5555550), "Year old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
|
||||||
if (minutesSinceMidnight > 250)
|
if (minutesSinceMidnight > 250)
|
||||||
ok(downloadExists(5555554), "'Today' download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-today")), "'Today' download should still be present");
|
||||||
|
|
||||||
|
// The 'Today' download might have been already deleted, in which case we
|
||||||
|
// should not wait for a download removal notification.
|
||||||
|
if (minutesSinceMidnight > 250) {
|
||||||
|
downloadPromise = promiseDownloadRemoved(publicList);
|
||||||
|
} else {
|
||||||
|
downloadPromise = Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
// Clear Today
|
// Clear Today
|
||||||
Sanitizer.prefs.setIntPref("timeSpan", 4);
|
Sanitizer.prefs.setIntPref("timeSpan", 4);
|
||||||
s.sanitize();
|
s.sanitize();
|
||||||
|
|
||||||
yield promiseFormHistoryRemoved();
|
yield promiseFormHistoryRemoved();
|
||||||
|
yield downloadPromise;
|
||||||
|
|
||||||
// Be careful. If we add our objectss just before midnight, and sanitize
|
// Be careful. If we add our objectss just before midnight, and sanitize
|
||||||
// runs immediately after, they won't be expired. This is expected, but
|
// runs immediately after, they won't be expired. This is expected, but
|
||||||
// we should not test in that case. We cannot just test for opposite
|
// we should not test in that case. We cannot just test for opposite
|
||||||
// condition because we could cross midnight just one moment after we
|
// condition because we could cross midnight just one moment after we
|
||||||
// cache our time, then we would have an even worse random failure.
|
// cache our time, then we would have an even worse random failure.
|
||||||
var today = isToday(new Date(now_uSec/1000));
|
var today = isToday(new Date(now_mSec));
|
||||||
if (today) {
|
if (today) {
|
||||||
ok(!(yield promiseIsURIVisited(makeURI("http://today.com"))),
|
ok(!(yield promiseIsURIVisited(makeURI("http://today.com"))),
|
||||||
"Pretend visit to today.com should now be deleted");
|
"Pretend visit to today.com should now be deleted");
|
||||||
|
|
||||||
yield countEntries("today", "today form entry should be deleted", checkZero);
|
yield countEntries("today", "today form entry should be deleted", checkZero);
|
||||||
ok(!downloadExists(5555554), "'Today' download should now be deleted");
|
ok(!(yield downloadExists(publicList, "fakefile-today")), "'Today' download should now be deleted");
|
||||||
}
|
}
|
||||||
|
|
||||||
ok((yield promiseIsURIVisited(makeURI("http://before-today.com"))),
|
ok((yield promiseIsURIVisited(makeURI("http://before-today.com"))),
|
||||||
"Pretend visit to before-today.com should still exist");
|
"Pretend visit to before-today.com should still exist");
|
||||||
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
yield countEntries("b4today", "b4today form entry should still exist", checkOne);
|
||||||
ok(downloadExists(5555550), "Year old download should still be present");
|
ok((yield downloadExists(publicList, "fakefile-old")), "Year old download should still be present");
|
||||||
|
|
||||||
|
downloadPromise = promiseDownloadRemoved(publicList);
|
||||||
|
|
||||||
// Choose everything
|
// Choose everything
|
||||||
Sanitizer.prefs.setIntPref("timeSpan", 0);
|
Sanitizer.prefs.setIntPref("timeSpan", 0);
|
||||||
s.sanitize();
|
s.sanitize();
|
||||||
|
|
||||||
yield promiseFormHistoryRemoved();
|
yield promiseFormHistoryRemoved();
|
||||||
|
yield downloadPromise;
|
||||||
|
|
||||||
ok(!(yield promiseIsURIVisited(makeURI("http://before-today.com"))),
|
ok(!(yield promiseIsURIVisited(makeURI("http://before-today.com"))),
|
||||||
"Pretend visit to before-today.com should now be deleted");
|
"Pretend visit to before-today.com should now be deleted");
|
||||||
|
|
||||||
yield countEntries("b4today", "b4today form entry should be deleted", checkZero);
|
yield countEntries("b4today", "b4today form entry should be deleted", checkZero);
|
||||||
|
|
||||||
ok(!downloadExists(5555550), "Year old download should now be deleted");
|
ok(!(yield downloadExists(publicList, "fakefile-old")), "Year old download should now be deleted");
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupHistory() {
|
function setupHistory() {
|
||||||
|
@ -562,227 +612,103 @@ function setupFormHistory() {
|
||||||
|
|
||||||
function setupDownloads() {
|
function setupDownloads() {
|
||||||
|
|
||||||
// Add 10-minutes download to DB
|
let publicList = yield Downloads.getPublicDownloadList();
|
||||||
let data = {
|
|
||||||
id: "5555555",
|
|
||||||
name: "fakefile-10-minutes",
|
|
||||||
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
|
|
||||||
target: "fakefile-10-minutes",
|
|
||||||
startTime: now_uSec - 10 * kUsecPerMin, // 10 minutes ago, in uSec
|
|
||||||
endTime: now_uSec - 11 * kUsecPerMin, // 1 minute later
|
|
||||||
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
|
|
||||||
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
|
|
||||||
guid: "a1bcD23eF4g5"
|
|
||||||
};
|
|
||||||
|
|
||||||
let db = dm.DBConnection;
|
let download = yield Downloads.createDownload({
|
||||||
let stmt = db.createStatement(
|
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
|
||||||
"INSERT INTO moz_downloads (id, name, source, target, startTime, endTime, " +
|
target: "fakefile-10-minutes"
|
||||||
"state, currBytes, maxBytes, preferredAction, autoResume, guid) " +
|
});
|
||||||
"VALUES (:id, :name, :source, :target, :startTime, :endTime, :state, " +
|
download.startTime = new Date(now_mSec - 10 * kMsecPerMin), // 10 minutes ago
|
||||||
":currBytes, :maxBytes, :preferredAction, :autoResume, :guid)");
|
download.canceled = true;
|
||||||
try {
|
publicList.add(download);
|
||||||
for (let prop in data)
|
|
||||||
stmt.params[prop] = data[prop];
|
download = yield Downloads.createDownload({
|
||||||
stmt.execute();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
stmt.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add within-1-hour download to DB
|
|
||||||
data = {
|
|
||||||
id: "5555551",
|
|
||||||
name: "fakefile-1-hour",
|
|
||||||
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
|
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
|
||||||
target: "fakefile-1-hour",
|
target: "fakefile-1-hour"
|
||||||
startTime: now_uSec - 45 * kUsecPerMin, // 45 minutes ago, in uSec
|
});
|
||||||
endTime: now_uSec - 44 * kUsecPerMin, // 1 minute later
|
download.startTime = new Date(now_mSec - 45 * kMsecPerMin), // 45 minutes ago
|
||||||
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
|
download.canceled = true;
|
||||||
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
|
publicList.add(download);
|
||||||
guid: "1bcD23eF4g5a"
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
download = yield Downloads.createDownload({
|
||||||
for (let prop in data)
|
|
||||||
stmt.params[prop] = data[prop];
|
|
||||||
stmt.execute();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
stmt.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add 1-hour-10-minutes download to DB
|
|
||||||
data = {
|
|
||||||
id: "5555556",
|
|
||||||
name: "fakefile-1-hour-10-minutes",
|
|
||||||
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
|
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
|
||||||
target: "fakefile-1-hour-10-minutes",
|
target: "fakefile-1-hour-10-minutes"
|
||||||
startTime: now_uSec - 70 * kUsecPerMin, // 70 minutes ago, in uSec
|
});
|
||||||
endTime: now_uSec - 71 * kUsecPerMin, // 1 minute later
|
download.startTime = new Date(now_mSec - 70 * kMsecPerMin), // 70 minutes ago
|
||||||
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
|
download.canceled = true;
|
||||||
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
|
publicList.add(download);
|
||||||
guid: "a1cbD23e4Fg5"
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
download = yield Downloads.createDownload({
|
||||||
for (let prop in data)
|
|
||||||
stmt.params[prop] = data[prop];
|
|
||||||
stmt.execute();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
stmt.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add within-2-hour download
|
|
||||||
data = {
|
|
||||||
id: "5555552",
|
|
||||||
name: "fakefile-2-hour",
|
|
||||||
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
|
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
|
||||||
target: "fakefile-2-hour",
|
target: "fakefile-2-hour"
|
||||||
startTime: now_uSec - 90 * kUsecPerMin, // 90 minutes ago, in uSec
|
});
|
||||||
endTime: now_uSec - 89 * kUsecPerMin, // 1 minute later
|
download.startTime = new Date(now_mSec - 90 * kMsecPerMin), // 90 minutes ago
|
||||||
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
|
download.canceled = true;
|
||||||
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
|
publicList.add(download);
|
||||||
guid: "b1aDc23eFg54"
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
download = yield Downloads.createDownload({
|
||||||
for (let prop in data)
|
|
||||||
stmt.params[prop] = data[prop];
|
|
||||||
stmt.execute();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
stmt.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add 2-hour-10-minutes download
|
|
||||||
data = {
|
|
||||||
id: "5555557",
|
|
||||||
name: "fakefile-2-hour-10-minutes",
|
|
||||||
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
|
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
|
||||||
target: "fakefile-2-hour-10-minutes",
|
target: "fakefile-2-hour-10-minutes"
|
||||||
startTime: now_uSec - 130 * kUsecPerMin, // 130 minutes ago, in uSec
|
});
|
||||||
endTime: now_uSec - 131 * kUsecPerMin, // 1 minute later
|
download.startTime = new Date(now_mSec - 130 * kMsecPerMin), // 130 minutes ago
|
||||||
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
|
download.canceled = true;
|
||||||
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
|
publicList.add(download);
|
||||||
guid: "z1bcD23eF4g5"
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
download = yield Downloads.createDownload({
|
||||||
for (let prop in data)
|
|
||||||
stmt.params[prop] = data[prop];
|
|
||||||
stmt.execute();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
stmt.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add within-4-hour download
|
|
||||||
data = {
|
|
||||||
id: "5555553",
|
|
||||||
name: "fakefile-4-hour",
|
|
||||||
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
|
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
|
||||||
target: "fakefile-4-hour",
|
target: "fakefile-4-hour"
|
||||||
startTime: now_uSec - 180 * kUsecPerMin, // 180 minutes ago, in uSec
|
});
|
||||||
endTime: now_uSec - 179 * kUsecPerMin, // 1 minute later
|
download.startTime = new Date(now_mSec - 180 * kMsecPerMin), // 180 minutes ago
|
||||||
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
|
download.canceled = true;
|
||||||
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
|
publicList.add(download);
|
||||||
guid: "zzzcD23eF4g5"
|
|
||||||
};
|
download = yield Downloads.createDownload({
|
||||||
|
|
||||||
try {
|
|
||||||
for (let prop in data)
|
|
||||||
stmt.params[prop] = data[prop];
|
|
||||||
stmt.execute();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
stmt.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add 4-hour-10-minutes download
|
|
||||||
data = {
|
|
||||||
id: "5555558",
|
|
||||||
name: "fakefile-4-hour-10-minutes",
|
|
||||||
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
|
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
|
||||||
target: "fakefile-4-hour-10-minutes",
|
target: "fakefile-4-hour-10-minutes"
|
||||||
startTime: now_uSec - 250 * kUsecPerMin, // 250 minutes ago, in uSec
|
});
|
||||||
endTime: now_uSec - 251 * kUsecPerMin, // 1 minute later
|
download.startTime = new Date(now_mSec - 250 * kMsecPerMin), // 250 minutes ago
|
||||||
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
|
download.canceled = true;
|
||||||
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
|
publicList.add(download);
|
||||||
guid: "z1bzz23eF4gz"
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (let prop in data)
|
|
||||||
stmt.params[prop] = data[prop];
|
|
||||||
stmt.execute();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
stmt.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add "today" download
|
// Add "today" download
|
||||||
let today = new Date();
|
let today = new Date();
|
||||||
today.setHours(0);
|
today.setHours(0);
|
||||||
today.setMinutes(0);
|
today.setMinutes(0);
|
||||||
today.setSeconds(1);
|
today.setSeconds(1);
|
||||||
|
|
||||||
data = {
|
download = yield Downloads.createDownload({
|
||||||
id: "5555554",
|
|
||||||
name: "fakefile-today",
|
|
||||||
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
|
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
|
||||||
target: "fakefile-today",
|
target: "fakefile-today"
|
||||||
startTime: today.getTime() * 1000, // 12:00:30am this morning, in uSec
|
});
|
||||||
endTime: (today.getTime() + 1000) * 1000, // 1 second later
|
download.startTime = today, // 12:00:01 AM this morning
|
||||||
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
|
download.canceled = true;
|
||||||
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
|
publicList.add(download);
|
||||||
guid: "ffffD23eF4g5"
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (let prop in data)
|
|
||||||
stmt.params[prop] = data[prop];
|
|
||||||
stmt.execute();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
stmt.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add "before today" download
|
// Add "before today" download
|
||||||
let lastYear = new Date();
|
let lastYear = new Date();
|
||||||
lastYear.setFullYear(lastYear.getFullYear() - 1);
|
lastYear.setFullYear(lastYear.getFullYear() - 1);
|
||||||
data = {
|
|
||||||
id: "5555550",
|
download = yield Downloads.createDownload({
|
||||||
name: "fakefile-old",
|
|
||||||
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
|
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=453440",
|
||||||
target: "fakefile-old",
|
target: "fakefile-old"
|
||||||
startTime: lastYear.getTime() * 1000, // 1 year ago, in uSec
|
});
|
||||||
endTime: (lastYear.getTime() + 1000) * 1000, // 1 second later
|
download.startTime = lastYear,
|
||||||
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
|
download.canceled = true;
|
||||||
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0,
|
publicList.add(download);
|
||||||
guid: "ggggg23eF4g5"
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (let prop in data)
|
|
||||||
stmt.params[prop] = data[prop];
|
|
||||||
stmt.execute();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
stmt.finalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Confirm everything worked
|
// Confirm everything worked
|
||||||
ok(downloadExists(5555550), "Pretend download for everything case should exist");
|
let downloads = yield publicList.getAll();
|
||||||
ok(downloadExists(5555555), "Pretend download for 10-minutes case should exist");
|
is(downloads.length, 9, "9 Pretend downloads added");
|
||||||
ok(downloadExists(5555551), "Pretend download for 1-hour case should exist");
|
|
||||||
ok(downloadExists(5555556), "Pretend download for 1-hour-10-minutes case should exist");
|
ok((yield downloadExists(publicList, "fakefile-old")), "Pretend download for everything case should exist");
|
||||||
ok(downloadExists(5555552), "Pretend download for 2-hour case should exist");
|
ok((yield downloadExists(publicList, "fakefile-10-minutes")), "Pretend download for 10-minutes case should exist");
|
||||||
ok(downloadExists(5555557), "Pretend download for 2-hour-10-minutes case should exist");
|
ok((yield downloadExists(publicList, "fakefile-1-hour")), "Pretend download for 1-hour case should exist");
|
||||||
ok(downloadExists(5555553), "Pretend download for 4-hour case should exist");
|
ok((yield downloadExists(publicList, "fakefile-1-hour-10-minutes")), "Pretend download for 1-hour-10-minutes case should exist");
|
||||||
ok(downloadExists(5555558), "Pretend download for 4-hour-10-minutes case should exist");
|
ok((yield downloadExists(publicList, "fakefile-2-hour")), "Pretend download for 2-hour case should exist");
|
||||||
ok(downloadExists(5555554), "Pretend download for Today case should exist");
|
ok((yield downloadExists(publicList, "fakefile-2-hour-10-minutes")), "Pretend download for 2-hour-10-minutes case should exist");
|
||||||
|
ok((yield downloadExists(publicList, "fakefile-4-hour")), "Pretend download for 4-hour case should exist");
|
||||||
|
ok((yield downloadExists(publicList, "fakefile-4-hour-10-minutes")), "Pretend download for 4-hour-10-minutes case should exist");
|
||||||
|
ok((yield downloadExists(publicList, "fakefile-today")), "Pretend download for Today case should exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -791,18 +717,12 @@ function setupDownloads() {
|
||||||
* @param aID
|
* @param aID
|
||||||
* The ids of the downloads to check.
|
* The ids of the downloads to check.
|
||||||
*/
|
*/
|
||||||
function downloadExists(aID)
|
function downloadExists(list, path)
|
||||||
{
|
{
|
||||||
let db = dm.DBConnection;
|
return Task.spawn(function() {
|
||||||
let stmt = db.createStatement(
|
let listArray = yield list.getAll();
|
||||||
"SELECT * " +
|
throw new Task.Result(listArray.some(i => i.target.path == path));
|
||||||
"FROM moz_downloads " +
|
});
|
||||||
"WHERE id = :id"
|
|
||||||
);
|
|
||||||
stmt.params.id = aID;
|
|
||||||
var rows = stmt.executeStep();
|
|
||||||
stmt.finalize();
|
|
||||||
return rows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isToday(aDate) {
|
function isToday(aDate) {
|
||||||
|
|
|
@ -21,18 +21,18 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
|
||||||
XPCOMUtils.defineLazyModuleGetter(this, "FormHistory",
|
XPCOMUtils.defineLazyModuleGetter(this, "FormHistory",
|
||||||
"resource://gre/modules/FormHistory.jsm");
|
"resource://gre/modules/FormHistory.jsm");
|
||||||
|
XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
|
||||||
|
"resource://gre/modules/Downloads.jsm");
|
||||||
|
|
||||||
let tempScope = {};
|
let tempScope = {};
|
||||||
Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
|
Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
|
||||||
.loadSubScript("chrome://browser/content/sanitize.js", tempScope);
|
.loadSubScript("chrome://browser/content/sanitize.js", tempScope);
|
||||||
let Sanitizer = tempScope.Sanitizer;
|
let Sanitizer = tempScope.Sanitizer;
|
||||||
|
|
||||||
const dm = Cc["@mozilla.org/download-manager;1"].
|
const kMsecPerMin = 60 * 1000;
|
||||||
getService(Ci.nsIDownloadManager);
|
|
||||||
|
|
||||||
const kUsecPerMin = 60 * 1000000;
|
const kUsecPerMin = 60 * 1000000;
|
||||||
|
|
||||||
let formEntries;
|
let formEntries, downloadIDs, olderDownloadIDs;
|
||||||
|
|
||||||
// Add tests here. Each is a function that's called by doNextTest().
|
// Add tests here. Each is a function that's called by doNextTest().
|
||||||
var gAllTests = [
|
var gAllTests = [
|
||||||
|
@ -92,6 +92,23 @@ var gAllTests = [
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
function () {
|
||||||
|
// Add downloads (within the past hour).
|
||||||
|
Task.spawn(function () {
|
||||||
|
downloadIDs = [];
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
yield addDownloadWithMinutesAgo(downloadIDs, i);
|
||||||
|
}
|
||||||
|
// Add downloads (over an hour ago).
|
||||||
|
olderDownloadIDs = [];
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
yield addDownloadWithMinutesAgo(olderDownloadIDs, 61 + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
doNextTest();
|
||||||
|
}).then(null, Components.utils.reportError);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the combined history-downloads checkbox clears both history
|
* Ensures that the combined history-downloads checkbox clears both history
|
||||||
* visits and downloads when checked; the dialog respects simple timespan.
|
* visits and downloads when checked; the dialog respects simple timespan.
|
||||||
|
@ -115,16 +132,6 @@ var gAllTests = [
|
||||||
}
|
}
|
||||||
|
|
||||||
addVisits(places, function() {
|
addVisits(places, function() {
|
||||||
// Add downloads (within the past hour).
|
|
||||||
let downloadIDs = [];
|
|
||||||
for (let i = 0; i < 5; i++) {
|
|
||||||
downloadIDs.push(addDownloadWithMinutesAgo(i));
|
|
||||||
}
|
|
||||||
// Add downloads (over an hour ago).
|
|
||||||
let olderDownloadIDs = [];
|
|
||||||
for (let i = 0; i < 5; i++) {
|
|
||||||
olderDownloadIDs.push(addDownloadWithMinutesAgo(61 + i));
|
|
||||||
}
|
|
||||||
let totalHistoryVisits = uris.length + olderURIs.length;
|
let totalHistoryVisits = uris.length + olderURIs.length;
|
||||||
|
|
||||||
let wh = new WindowHelper();
|
let wh = new WindowHelper();
|
||||||
|
@ -146,16 +153,16 @@ var gAllTests = [
|
||||||
wh.onunload = function () {
|
wh.onunload = function () {
|
||||||
// History visits and downloads within one hour should be cleared.
|
// History visits and downloads within one hour should be cleared.
|
||||||
yield promiseHistoryClearedState(uris, true);
|
yield promiseHistoryClearedState(uris, true);
|
||||||
ensureDownloadsClearedState(downloadIDs, true);
|
yield ensureDownloadsClearedState(downloadIDs, true);
|
||||||
|
|
||||||
// Visits and downloads > 1 hour should still exist.
|
// Visits and downloads > 1 hour should still exist.
|
||||||
yield promiseHistoryClearedState(olderURIs, false);
|
yield promiseHistoryClearedState(olderURIs, false);
|
||||||
ensureDownloadsClearedState(olderDownloadIDs, false);
|
yield ensureDownloadsClearedState(olderDownloadIDs, false);
|
||||||
|
|
||||||
// OK, done, cleanup after ourselves.
|
// OK, done, cleanup after ourselves.
|
||||||
yield blankSlate();
|
yield blankSlate();
|
||||||
yield promiseHistoryClearedState(olderURIs, true);
|
yield promiseHistoryClearedState(olderURIs, true);
|
||||||
ensureDownloadsClearedState(olderDownloadIDs, true);
|
yield ensureDownloadsClearedState(olderDownloadIDs, true);
|
||||||
};
|
};
|
||||||
wh.open();
|
wh.open();
|
||||||
});
|
});
|
||||||
|
@ -178,6 +185,18 @@ var gAllTests = [
|
||||||
iter.next();
|
iter.next();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
function () {
|
||||||
|
// Add downloads (within the past hour).
|
||||||
|
Task.spawn(function () {
|
||||||
|
downloadIDs = [];
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
yield addDownloadWithMinutesAgo(downloadIDs, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
doNextTest();
|
||||||
|
}).then(null, Components.utils.reportError);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the combined history-downloads checkbox removes neither
|
* Ensures that the combined history-downloads checkbox removes neither
|
||||||
* history visits nor downloads when not checked.
|
* history visits nor downloads when not checked.
|
||||||
|
@ -194,11 +213,6 @@ var gAllTests = [
|
||||||
}
|
}
|
||||||
|
|
||||||
addVisits(places, function() {
|
addVisits(places, function() {
|
||||||
let downloadIDs = [];
|
|
||||||
for (let i = 0; i < 5; i++) {
|
|
||||||
downloadIDs.push(addDownloadWithMinutesAgo(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
let wh = new WindowHelper();
|
let wh = new WindowHelper();
|
||||||
wh.onload = function () {
|
wh.onload = function () {
|
||||||
is(this.isWarningPanelVisible(), false,
|
is(this.isWarningPanelVisible(), false,
|
||||||
|
@ -224,7 +238,7 @@ var gAllTests = [
|
||||||
wh.onunload = function () {
|
wh.onunload = function () {
|
||||||
// Of the three only form entries should be cleared.
|
// Of the three only form entries should be cleared.
|
||||||
yield promiseHistoryClearedState(uris, false);
|
yield promiseHistoryClearedState(uris, false);
|
||||||
ensureDownloadsClearedState(downloadIDs, false);
|
yield ensureDownloadsClearedState(downloadIDs, false);
|
||||||
|
|
||||||
formEntries.forEach(function (entry) {
|
formEntries.forEach(function (entry) {
|
||||||
let exists = yield formNameExists(entry);
|
let exists = yield formNameExists(entry);
|
||||||
|
@ -234,7 +248,7 @@ var gAllTests = [
|
||||||
// OK, done, cleanup after ourselves.
|
// OK, done, cleanup after ourselves.
|
||||||
yield blankSlate();
|
yield blankSlate();
|
||||||
yield promiseHistoryClearedState(uris, true);
|
yield promiseHistoryClearedState(uris, true);
|
||||||
ensureDownloadsClearedState(downloadIDs, true);
|
yield ensureDownloadsClearedState(downloadIDs, true);
|
||||||
};
|
};
|
||||||
wh.open();
|
wh.open();
|
||||||
});
|
});
|
||||||
|
@ -639,15 +653,12 @@ var gAllTests = [
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
// Used as the download database ID for a new download. Incremented for each
|
|
||||||
// new download. See addDownloadWithMinutesAgo().
|
|
||||||
var gDownloadId = 5555551;
|
|
||||||
|
|
||||||
// Index in gAllTests of the test currently being run. Incremented for each
|
// Index in gAllTests of the test currently being run. Incremented for each
|
||||||
// test run. See doNextTest().
|
// test run. See doNextTest().
|
||||||
var gCurrTest = 0;
|
var gCurrTest = 0;
|
||||||
|
|
||||||
var now_uSec = Date.now() * 1000;
|
let now_mSec = Date.now();
|
||||||
|
let now_uSec = now_mSec * 1000;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -847,7 +858,7 @@ WindowHelper.prototype = {
|
||||||
if (wh.onunload) {
|
if (wh.onunload) {
|
||||||
Task.spawn(wh.onunload).then(function() {
|
Task.spawn(wh.onunload).then(function() {
|
||||||
waitForAsyncUpdates(doNextTest);
|
waitForAsyncUpdates(doNextTest);
|
||||||
});
|
}).then(null, Components.utils.reportError);
|
||||||
} else {
|
} else {
|
||||||
waitForAsyncUpdates(doNextTest);
|
waitForAsyncUpdates(doNextTest);
|
||||||
}
|
}
|
||||||
|
@ -900,40 +911,23 @@ WindowHelper.prototype = {
|
||||||
* @param aMinutesAgo
|
* @param aMinutesAgo
|
||||||
* The download will be downloaded this many minutes ago
|
* The download will be downloaded this many minutes ago
|
||||||
*/
|
*/
|
||||||
function addDownloadWithMinutesAgo(aMinutesAgo) {
|
function addDownloadWithMinutesAgo(aExpectedPathList, aMinutesAgo) {
|
||||||
|
let publicList = yield Downloads.getPublicDownloadList();
|
||||||
|
|
||||||
let name = "fakefile-" + aMinutesAgo + "-minutes-ago";
|
let name = "fakefile-" + aMinutesAgo + "-minutes-ago";
|
||||||
let data = {
|
let download = yield Downloads.createDownload({
|
||||||
id: gDownloadId,
|
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
|
||||||
name: name,
|
target: name
|
||||||
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
|
});
|
||||||
target: name,
|
download.startTime = new Date(now_mSec - (aMinutesAgo * kMsecPerMin));
|
||||||
startTime: now_uSec - (aMinutesAgo * kUsecPerMin),
|
download.canceled = true;
|
||||||
endTime: now_uSec - ((aMinutesAgo + 1) * kUsecPerMin),
|
publicList.add(download);
|
||||||
state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
|
|
||||||
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
let db = dm.DBConnection;
|
ok((yield downloadExists(name)),
|
||||||
let stmt = db.createStatement(
|
"Sanity check: download " + name +
|
||||||
"INSERT INTO moz_downloads (id, name, source, target, startTime, endTime, " +
|
|
||||||
"state, currBytes, maxBytes, preferredAction, autoResume) " +
|
|
||||||
"VALUES (:id, :name, :source, :target, :startTime, :endTime, :state, " +
|
|
||||||
":currBytes, :maxBytes, :preferredAction, :autoResume)");
|
|
||||||
try {
|
|
||||||
for (let prop in data) {
|
|
||||||
stmt.params[prop] = data[prop];
|
|
||||||
}
|
|
||||||
stmt.execute();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
stmt.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
is(downloadExists(gDownloadId), true,
|
|
||||||
"Sanity check: download " + gDownloadId +
|
|
||||||
" should exist after creating it");
|
" should exist after creating it");
|
||||||
|
|
||||||
return gDownloadId++;
|
aExpectedPathList.push(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -984,15 +978,37 @@ function formNameExists(name)
|
||||||
*/
|
*/
|
||||||
function blankSlate() {
|
function blankSlate() {
|
||||||
PlacesUtils.bhistory.removeAllPages();
|
PlacesUtils.bhistory.removeAllPages();
|
||||||
dm.cleanUp();
|
|
||||||
|
|
||||||
|
// The promise is resolved only when removing both downloads and form history are done.
|
||||||
let deferred = Promise.defer();
|
let deferred = Promise.defer();
|
||||||
|
let formHistoryDone = false, downloadsDone = false;
|
||||||
|
|
||||||
|
Task.spawn(function deleteAllDownloads() {
|
||||||
|
let publicList = yield Downloads.getPublicDownloadList();
|
||||||
|
let downloads = yield publicList.getAll();
|
||||||
|
for (let download of downloads) {
|
||||||
|
publicList.remove(download);
|
||||||
|
yield download.finalize(true);
|
||||||
|
}
|
||||||
|
downloadsDone = true;
|
||||||
|
if (formHistoryDone) {
|
||||||
|
deferred.resolve();
|
||||||
|
}
|
||||||
|
}).then(null, Components.utils.reportError);
|
||||||
|
|
||||||
FormHistory.update({ op: "remove" },
|
FormHistory.update({ op: "remove" },
|
||||||
{ handleError: function (error) {
|
{ handleError: function (error) {
|
||||||
do_throw("Error occurred updating form history: " + error);
|
do_throw("Error occurred updating form history: " + error);
|
||||||
deferred.reject(error);
|
deferred.reject(error);
|
||||||
},
|
},
|
||||||
handleCompletion: function (reason) { if (!reason) deferred.resolve(); }
|
handleCompletion: function (reason) {
|
||||||
|
if (!reason) {
|
||||||
|
formHistoryDone = true;
|
||||||
|
if (downloadsDone) {
|
||||||
|
deferred.resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
@ -1012,24 +1028,19 @@ function boolPrefIs(aPrefName, aExpectedVal, aMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks to see if the download with the specified ID exists.
|
* Checks to see if the download with the specified path exists.
|
||||||
*
|
*
|
||||||
* @param aID
|
* @param aPath
|
||||||
* The ID of the download to check
|
* The path of the download to check
|
||||||
* @return True if the download exists, false otherwise
|
* @return True if the download exists, false otherwise
|
||||||
*/
|
*/
|
||||||
function downloadExists(aID)
|
function downloadExists(aPath)
|
||||||
{
|
{
|
||||||
let db = dm.DBConnection;
|
return Task.spawn(function() {
|
||||||
let stmt = db.createStatement(
|
let publicList = yield Downloads.getPublicDownloadList();
|
||||||
"SELECT * " +
|
let listArray = yield publicList.getAll();
|
||||||
"FROM moz_downloads " +
|
throw new Task.Result(listArray.some(i => i.target.path == aPath));
|
||||||
"WHERE id = :id"
|
});
|
||||||
);
|
|
||||||
stmt.params.id = aID;
|
|
||||||
let rows = stmt.executeStep();
|
|
||||||
stmt.finalize();
|
|
||||||
return !!rows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1059,7 +1070,7 @@ function doNextTest() {
|
||||||
function ensureDownloadsClearedState(aDownloadIDs, aShouldBeCleared) {
|
function ensureDownloadsClearedState(aDownloadIDs, aShouldBeCleared) {
|
||||||
let niceStr = aShouldBeCleared ? "no longer" : "still";
|
let niceStr = aShouldBeCleared ? "no longer" : "still";
|
||||||
aDownloadIDs.forEach(function (id) {
|
aDownloadIDs.forEach(function (id) {
|
||||||
is(downloadExists(id), !aShouldBeCleared,
|
is((yield downloadExists(id)), !aShouldBeCleared,
|
||||||
"download " + id + " should " + niceStr + " exist");
|
"download " + id + " should " + niceStr + " exist");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,39 +7,33 @@
|
||||||
* Make sure the downloads panel can display items in the right order and
|
* Make sure the downloads panel can display items in the right order and
|
||||||
* contains the expected data.
|
* contains the expected data.
|
||||||
*/
|
*/
|
||||||
function gen_test()
|
function test_task()
|
||||||
{
|
{
|
||||||
// Display one of each download state.
|
// Display one of each download state.
|
||||||
const DownloadData = [
|
const DownloadData = [
|
||||||
{ endTime: 1180493839859239, state: nsIDM.DOWNLOAD_NOTSTARTED },
|
{ state: nsIDM.DOWNLOAD_NOTSTARTED },
|
||||||
{ endTime: 1180493839859238, state: nsIDM.DOWNLOAD_DOWNLOADING },
|
{ state: nsIDM.DOWNLOAD_PAUSED },
|
||||||
{ endTime: 1180493839859237, state: nsIDM.DOWNLOAD_PAUSED },
|
{ state: nsIDM.DOWNLOAD_FINISHED },
|
||||||
{ endTime: 1180493839859236, state: nsIDM.DOWNLOAD_SCANNING },
|
{ state: nsIDM.DOWNLOAD_FAILED },
|
||||||
{ endTime: 1180493839859235, state: nsIDM.DOWNLOAD_QUEUED },
|
{ state: nsIDM.DOWNLOAD_CANCELED },
|
||||||
{ endTime: 1180493839859234, state: nsIDM.DOWNLOAD_FINISHED },
|
|
||||||
{ endTime: 1180493839859233, state: nsIDM.DOWNLOAD_FAILED },
|
|
||||||
{ endTime: 1180493839859232, state: nsIDM.DOWNLOAD_CANCELED },
|
|
||||||
{ endTime: 1180493839859231, state: nsIDM.DOWNLOAD_BLOCKED_PARENTAL },
|
|
||||||
{ endTime: 1180493839859230, state: nsIDM.DOWNLOAD_DIRTY },
|
|
||||||
{ endTime: 1180493839859229, state: nsIDM.DOWNLOAD_BLOCKED_POLICY },
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// For testing purposes, show all the download items at once.
|
|
||||||
var originalCountLimit = DownloadsView.kItemCountLimit;
|
|
||||||
DownloadsView.kItemCountLimit = DownloadData.length;
|
|
||||||
registerCleanupFunction(function () {
|
|
||||||
DownloadsView.kItemCountLimit = originalCountLimit;
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Ensure that state is reset in case previous tests didn't finish.
|
// Ensure that state is reset in case previous tests didn't finish.
|
||||||
for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield undefined;
|
yield task_resetState();
|
||||||
|
|
||||||
|
// For testing purposes, show all the download items at once.
|
||||||
|
var originalCountLimit = DownloadsView.kItemCountLimit;
|
||||||
|
DownloadsView.kItemCountLimit = DownloadData.length;
|
||||||
|
registerCleanupFunction(function () {
|
||||||
|
DownloadsView.kItemCountLimit = originalCountLimit;
|
||||||
|
});
|
||||||
|
|
||||||
// Populate the downloads database with the data required by this test.
|
// Populate the downloads database with the data required by this test.
|
||||||
for (let yy in gen_addDownloadRows(DownloadData)) yield undefined;
|
yield task_addDownloads(DownloadData);
|
||||||
|
|
||||||
// Open the user interface and wait for data to be fully loaded.
|
// Open the user interface and wait for data to be fully loaded.
|
||||||
for (let yy in gen_openPanel(DownloadsCommon.getData(window))) yield undefined;
|
yield task_openPanel();
|
||||||
|
|
||||||
// Test item data and count. This also tests the ordering of the display.
|
// Test item data and count. This also tests the ordering of the display.
|
||||||
let richlistbox = document.getElementById("downloadsListBox");
|
let richlistbox = document.getElementById("downloadsListBox");
|
||||||
|
@ -47,16 +41,14 @@ function gen_test()
|
||||||
is(richlistbox.children.length, DownloadData.length,
|
is(richlistbox.children.length, DownloadData.length,
|
||||||
"There is the correct number of richlistitems");
|
"There is the correct number of richlistitems");
|
||||||
*/
|
*/
|
||||||
for (let i = 0; i < richlistbox.children.length; i++) {
|
let itemCount = richlistbox.children.length;
|
||||||
let element = richlistbox.children[i];
|
for (let i = 0; i < itemCount; i++) {
|
||||||
|
let element = richlistbox.children[itemCount - i - 1];
|
||||||
let dataItem = new DownloadsViewItemController(element).dataItem;
|
let dataItem = new DownloadsViewItemController(element).dataItem;
|
||||||
is(dataItem.target, DownloadData[i].name, "Download names match up");
|
|
||||||
is(dataItem.state, DownloadData[i].state, "Download states match up");
|
is(dataItem.state, DownloadData[i].state, "Download states match up");
|
||||||
is(dataItem.file, DownloadData[i].target, "Download targets match up");
|
|
||||||
is(dataItem.uri, DownloadData[i].source, "Download sources match up");
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// Clean up when the test finishes.
|
// Clean up when the test finishes.
|
||||||
for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield undefined;
|
yield task_resetState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,19 +8,19 @@
|
||||||
* download it notices. All subsequent downloads, even across sessions, should
|
* download it notices. All subsequent downloads, even across sessions, should
|
||||||
* not open the panel automatically.
|
* not open the panel automatically.
|
||||||
*/
|
*/
|
||||||
function gen_test()
|
function test_task()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Ensure that state is reset in case previous tests didn't finish.
|
// Ensure that state is reset in case previous tests didn't finish.
|
||||||
for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield undefined;
|
yield task_resetState();
|
||||||
|
|
||||||
// With this set to false, we should automatically open the panel
|
// With this set to false, we should automatically open the panel the first
|
||||||
// the first time a download is started.
|
// time a download is started.
|
||||||
DownloadsCommon.getData(window).panelHasShownBefore = false;
|
DownloadsCommon.getData(window).panelHasShownBefore = false;
|
||||||
|
|
||||||
prepareForPanelOpen();
|
let promise = promisePanelOpened();
|
||||||
DownloadsCommon.getData(window)._notifyDownloadEvent("start");
|
DownloadsCommon.getData(window)._notifyDownloadEvent("start");
|
||||||
yield undefined;
|
yield promise;
|
||||||
|
|
||||||
// If we got here, that means the panel opened.
|
// If we got here, that means the panel opened.
|
||||||
DownloadsPanel.hidePanel();
|
DownloadsPanel.hidePanel();
|
||||||
|
@ -28,29 +28,26 @@ function gen_test()
|
||||||
ok(DownloadsCommon.getData(window).panelHasShownBefore,
|
ok(DownloadsCommon.getData(window).panelHasShownBefore,
|
||||||
"Should have recorded that the panel was opened on a download.")
|
"Should have recorded that the panel was opened on a download.")
|
||||||
|
|
||||||
// Next, make sure that if we start another download, we don't open
|
// Next, make sure that if we start another download, we don't open the
|
||||||
// the panel automatically.
|
// panel automatically.
|
||||||
panelShouldNotOpen();
|
let originalOnPopupShown = DownloadsPanel.onPopupShown;
|
||||||
DownloadsCommon.getData(window)._notifyDownloadEvent("start");
|
DownloadsPanel.onPopupShown = function () {
|
||||||
yield waitFor(2);
|
originalOnPopupShown.apply(this, arguments);
|
||||||
} catch(e) {
|
ok(false, "Should not have opened the downloads panel.");
|
||||||
ok(false, e);
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
DownloadsCommon.getData(window)._notifyDownloadEvent("start");
|
||||||
|
|
||||||
|
// Wait 2 seconds to ensure that the panel does not open.
|
||||||
|
let deferTimeout = Promise.defer();
|
||||||
|
setTimeout(deferTimeout.resolve, 2000);
|
||||||
|
yield deferTimeout.promise;
|
||||||
|
} finally {
|
||||||
|
DownloadsPanel.onPopupShown = originalOnPopupShown;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// Clean up when the test finishes.
|
// Clean up when the test finishes.
|
||||||
for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield undefined;
|
yield task_resetState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this to record a test failure for the next time the downloads panel
|
|
||||||
* opens.
|
|
||||||
*/
|
|
||||||
function panelShouldNotOpen()
|
|
||||||
{
|
|
||||||
// Hook to wait until the test data has been loaded.
|
|
||||||
let originalOnViewLoadCompleted = DownloadsPanel.onViewLoadCompleted;
|
|
||||||
DownloadsPanel.onViewLoadCompleted = function () {
|
|
||||||
DownloadsPanel.onViewLoadCompleted = originalOnViewLoadCompleted;
|
|
||||||
ok(false, "Should not have opened the downloads panel.");
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -10,10 +10,16 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
//// Globals
|
//// Globals
|
||||||
|
|
||||||
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
|
XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
|
||||||
"resource://gre/modules/FileUtils.jsm");
|
"resource://gre/modules/Downloads.jsm");
|
||||||
XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon",
|
XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon",
|
||||||
"resource:///modules/DownloadsCommon.jsm");
|
"resource:///modules/DownloadsCommon.jsm");
|
||||||
|
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
|
||||||
|
"resource://gre/modules/FileUtils.jsm");
|
||||||
|
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
|
||||||
|
"resource://gre/modules/Promise.jsm");
|
||||||
|
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||||
|
"resource://gre/modules/Task.jsm");
|
||||||
const nsIDM = Ci.nsIDownloadManager;
|
const nsIDM = Ci.nsIDownloadManager;
|
||||||
|
|
||||||
let gTestTargetFile = FileUtils.getFile("TmpD", ["dm-ui-test.file"]);
|
let gTestTargetFile = FileUtils.getFile("TmpD", ["dm-ui-test.file"]);
|
||||||
|
@ -22,253 +28,85 @@ registerCleanupFunction(function () {
|
||||||
gTestTargetFile.remove(false);
|
gTestTargetFile.remove(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* This objects contains a property for each column in the downloads table.
|
|
||||||
*/
|
|
||||||
let gDownloadRowTemplate = {
|
|
||||||
name: "test-download.txt",
|
|
||||||
source: "http://www.example.com/test-download.txt",
|
|
||||||
target: NetUtil.newURI(gTestTargetFile).spec,
|
|
||||||
startTime: 1180493839859230,
|
|
||||||
endTime: 1180493839859234,
|
|
||||||
state: nsIDM.DOWNLOAD_FINISHED,
|
|
||||||
currBytes: 0,
|
|
||||||
maxBytes: -1,
|
|
||||||
preferredAction: 0,
|
|
||||||
autoResume: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
//// Infrastructure
|
//// Infrastructure
|
||||||
|
|
||||||
// All test are run through the test runner.
|
|
||||||
function test()
|
function test()
|
||||||
{
|
{
|
||||||
testRunner.runTest(this.gen_test);
|
waitForExplicitFinish();
|
||||||
|
Task.spawn(test_task).then(null, ex => ok(false, ex)).then(finish);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs a browser-chrome test defined through a generator function.
|
|
||||||
*
|
|
||||||
* This object is a singleton, initialized automatically when this script is
|
|
||||||
* included. Every browser-chrome test file includes a new copy of this object.
|
|
||||||
*/
|
|
||||||
var testRunner = {
|
|
||||||
_testIterator: null,
|
|
||||||
_lastEventResult: undefined,
|
|
||||||
_testRunning: false,
|
|
||||||
_eventRaised: false,
|
|
||||||
|
|
||||||
// --- Main test runner ---
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs the test described by the provided generator function asynchronously.
|
|
||||||
*
|
|
||||||
* Calling yield in the generator will cause it to wait until continueTest is
|
|
||||||
* called. The parameter provided to continueTest will be the return value of
|
|
||||||
* the yield operator.
|
|
||||||
*
|
|
||||||
* @param aGenerator
|
|
||||||
* Test generator function. The function will be called with no
|
|
||||||
* arguments to retrieve its iterator.
|
|
||||||
*/
|
|
||||||
runTest: function TR_runTest(aGenerator) {
|
|
||||||
waitForExplicitFinish();
|
|
||||||
testRunner._testIterator = aGenerator();
|
|
||||||
testRunner.continueTest();
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Continues the currently running test.
|
|
||||||
*
|
|
||||||
* @param aEventResult
|
|
||||||
* This will be the return value of the yield operator in the test.
|
|
||||||
*/
|
|
||||||
continueTest: function TR_continueTest(aEventResult) {
|
|
||||||
// Store the last event result, or set it to undefined.
|
|
||||||
testRunner._lastEventResult = aEventResult;
|
|
||||||
|
|
||||||
// Never reenter the main loop, but notify that the event has been raised.
|
|
||||||
if (testRunner._testRunning) {
|
|
||||||
testRunner._eventRaised = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enter the main iteration loop.
|
|
||||||
testRunner._testRunning = true;
|
|
||||||
try {
|
|
||||||
do {
|
|
||||||
// Call the iterator, but don't leave the loop if the expected event is
|
|
||||||
// raised during the execution of the generator.
|
|
||||||
testRunner._eventRaised = false;
|
|
||||||
testRunner._testIterator.send(testRunner._lastEventResult);
|
|
||||||
} while (testRunner._eventRaised);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
// This block catches exceptions raised by the generator, including the
|
|
||||||
// normal StopIteration exception. Unexpected exceptions are reported as
|
|
||||||
// test failures.
|
|
||||||
if (!(e instanceof StopIteration))
|
|
||||||
ok(false, e);
|
|
||||||
// In any case, stop the tests in this file.
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for the next event or finish.
|
|
||||||
testRunner._testRunning = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
//// Asynchronous generator-based support subroutines
|
//// Asynchronous support subroutines
|
||||||
|
|
||||||
//
|
function promiseFocus()
|
||||||
// The following functions are all generators that can be used inside the main
|
|
||||||
// test generator to perform specific tasks asynchronously. To invoke these
|
|
||||||
// subroutines correctly, an iteration syntax should be used:
|
|
||||||
//
|
|
||||||
// for (let yy in gen_example("Parameter")) yield undefined;
|
|
||||||
//
|
|
||||||
|
|
||||||
function gen_resetState(aData)
|
|
||||||
{
|
{
|
||||||
let statement = Services.downloads.DBConnection.createAsyncStatement(
|
let deferred = Promise.defer();
|
||||||
"DELETE FROM moz_downloads");
|
waitForFocus(deferred.resolve);
|
||||||
try {
|
return deferred.promise;
|
||||||
statement.executeAsync({
|
}
|
||||||
handleResult: function(aResultSet) { },
|
|
||||||
handleError: function(aError)
|
function promisePanelOpened()
|
||||||
{
|
{
|
||||||
Cu.reportError(aError);
|
let deferred = Promise.defer();
|
||||||
},
|
|
||||||
handleCompletion: function(aReason)
|
// Hook to wait until the panel is shown.
|
||||||
{
|
let originalOnPopupShown = DownloadsPanel.onPopupShown;
|
||||||
testRunner.continueTest();
|
DownloadsPanel.onPopupShown = function () {
|
||||||
}
|
DownloadsPanel.onPopupShown = originalOnPopupShown;
|
||||||
});
|
originalOnPopupShown.apply(this, arguments);
|
||||||
yield undefined;
|
|
||||||
} finally {
|
// Defer to the next tick of the event loop so that we don't continue
|
||||||
statement.finalize();
|
// processing during the DOM event handler itself.
|
||||||
|
setTimeout(deferred.resolve, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
function task_resetState()
|
||||||
|
{
|
||||||
|
// Remove all downloads.
|
||||||
|
let publicList = yield Downloads.getPublicDownloadList();
|
||||||
|
let downloads = yield publicList.getAll();
|
||||||
|
for (let download of downloads) {
|
||||||
|
publicList.remove(download);
|
||||||
|
yield download.finalize(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset any prefs that might have been changed.
|
// Reset any prefs that might have been changed.
|
||||||
Services.prefs.clearUserPref("browser.download.panel.shown");
|
Services.prefs.clearUserPref("browser.download.panel.shown");
|
||||||
|
|
||||||
// Ensure that the panel is closed and data is unloaded.
|
|
||||||
aData.clear();
|
|
||||||
aData._loadState = aData.kLoadNone;
|
|
||||||
DownloadsPanel.hidePanel();
|
DownloadsPanel.hidePanel();
|
||||||
|
|
||||||
// Wait for focus on the main window.
|
yield promiseFocus();
|
||||||
waitForFocus(testRunner.continueTest);
|
|
||||||
yield undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function gen_addDownloadRows(aDataRows)
|
function task_addDownloads(aItems)
|
||||||
{
|
{
|
||||||
let columnNames = Object.keys(gDownloadRowTemplate).join(", ");
|
let startTimeMs = Date.now();
|
||||||
let parameterNames = Object.keys(gDownloadRowTemplate)
|
|
||||||
.map(function(n) ":" + n)
|
|
||||||
.join(", ");
|
|
||||||
let statement = Services.downloads.DBConnection.createAsyncStatement(
|
|
||||||
"INSERT INTO moz_downloads (" + columnNames +
|
|
||||||
", guid) VALUES(" + parameterNames + ", GENERATE_GUID())");
|
|
||||||
try {
|
|
||||||
// Execute the statement for each of the provided downloads in reverse.
|
|
||||||
for (let i = aDataRows.length - 1; i >= 0; i--) {
|
|
||||||
let dataRow = aDataRows[i];
|
|
||||||
|
|
||||||
// Populate insert parameters from the provided data.
|
let publicList = yield Downloads.getPublicDownloadList();
|
||||||
for (let columnName in gDownloadRowTemplate) {
|
for (let item of aItems) {
|
||||||
if (!(columnName in dataRow)) {
|
publicList.add(yield Downloads.createDownload({
|
||||||
// Update the provided row object with data from the global template,
|
source: "http://www.example.com/test-download.txt",
|
||||||
// for columns whose value is not provided explicitly.
|
target: gTestTargetFile,
|
||||||
dataRow[columnName] = gDownloadRowTemplate[columnName];
|
succeeded: item.state == nsIDM.DOWNLOAD_FINISHED,
|
||||||
}
|
canceled: item.state == nsIDM.DOWNLOAD_CANCELED ||
|
||||||
statement.params[columnName] = dataRow[columnName];
|
item.state == nsIDM.DOWNLOAD_PAUSED,
|
||||||
}
|
error: item.state == nsIDM.DOWNLOAD_FAILED ? new Error("Failed.") : null,
|
||||||
|
hasPartialData: item.state == nsIDM.DOWNLOAD_PAUSED,
|
||||||
// Run the statement asynchronously and wait.
|
startTime: new Date(startTimeMs++),
|
||||||
statement.executeAsync({
|
}));
|
||||||
handleResult: function(aResultSet) { },
|
|
||||||
handleError: function(aError)
|
|
||||||
{
|
|
||||||
Cu.reportError(aError.message + " (Result = " + aError.result + ")");
|
|
||||||
},
|
|
||||||
handleCompletion: function(aReason)
|
|
||||||
{
|
|
||||||
testRunner.continueTest();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
yield undefined;
|
|
||||||
|
|
||||||
// At each iteration, ensure that the start and end time in the global
|
|
||||||
// template is distinct, as these column are used to sort each download
|
|
||||||
// in its category.
|
|
||||||
gDownloadRowTemplate.startTime++;
|
|
||||||
gDownloadRowTemplate.endTime++;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
statement.finalize();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function gen_openPanel(aData)
|
function task_openPanel()
|
||||||
{
|
{
|
||||||
// Hook to wait until the test data has been loaded.
|
yield promiseFocus();
|
||||||
let originalOnViewLoadCompleted = DownloadsPanel.onViewLoadCompleted;
|
|
||||||
DownloadsPanel.onViewLoadCompleted = function () {
|
|
||||||
DownloadsPanel.onViewLoadCompleted = originalOnViewLoadCompleted;
|
|
||||||
originalOnViewLoadCompleted.apply(this);
|
|
||||||
testRunner.continueTest();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Start loading all the downloads from the database asynchronously.
|
let promise = promisePanelOpened();
|
||||||
aData.ensurePersistentDataLoaded(false);
|
|
||||||
|
|
||||||
// Wait for focus on the main window.
|
|
||||||
waitForFocus(testRunner.continueTest);
|
|
||||||
yield undefined;
|
|
||||||
|
|
||||||
// Open the downloads panel, waiting until loading is completed.
|
|
||||||
DownloadsPanel.showPanel();
|
DownloadsPanel.showPanel();
|
||||||
yield undefined;
|
yield promise;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Spin the event loop for aSeconds seconds, and then signal the test to
|
|
||||||
* continue.
|
|
||||||
*
|
|
||||||
* @param aSeconds the number of seconds to wait.
|
|
||||||
* @note This helper should _only_ be used when there's no valid event to
|
|
||||||
* listen to and one can't be made.
|
|
||||||
*/
|
|
||||||
function waitFor(aSeconds)
|
|
||||||
{
|
|
||||||
setTimeout(function() {
|
|
||||||
testRunner.continueTest();
|
|
||||||
}, aSeconds * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make it so that the next time the downloads panel opens, we signal to
|
|
||||||
* continue the test. This function needs to be called each time you want
|
|
||||||
* to wait for the panel to open.
|
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
*
|
|
||||||
* prepareForPanelOpen();
|
|
||||||
* // Do something to open the panel
|
|
||||||
* yield undefined;
|
|
||||||
* // We can assume the panel is open now.
|
|
||||||
*/
|
|
||||||
function prepareForPanelOpen()
|
|
||||||
{
|
|
||||||
// Hook to wait until the test data has been loaded.
|
|
||||||
let originalOnPopupShown = DownloadsPanel.onPopupShown;
|
|
||||||
DownloadsPanel.onPopupShown = function (aEvent) {
|
|
||||||
DownloadsPanel.onPopupShown = originalOnPopupShown;
|
|
||||||
DownloadsPanel.onPopupShown.apply(this, [aEvent]);
|
|
||||||
testRunner.continueTest();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче