summaryrefslogtreecommitdiffstats
path: root/comm/suite/components/downloads/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /comm/suite/components/downloads/tests
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/suite/components/downloads/tests')
-rw-r--r--comm/suite/components/downloads/tests/chrome/chrome.ini21
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_action_keys_respect_focus.xul376
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_basic_functionality.xul281
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_cleanup_search.xul172
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_clear_button_disabled.xul201
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_close_download_manager.xul117
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_delete_key_cancels.xul200
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_delete_key_removes.xul198
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_drag.xul201
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_enter_dblclick_opens.xul243
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_multi_select.xul204
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_multiword_search.xul173
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_open_properties.xul197
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_removeDownload_updates_ui.xul150
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_search_clearlist.xul168
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_search_keys.xul128
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_select_all.xul145
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_space_key_pauses_resumes.xul221
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_space_key_retries.xul198
-rw-r--r--comm/suite/components/downloads/tests/chrome/test_ui_stays_open_on_alert_clickback.xul115
20 files changed, 3709 insertions, 0 deletions
diff --git a/comm/suite/components/downloads/tests/chrome/chrome.ini b/comm/suite/components/downloads/tests/chrome/chrome.ini
new file mode 100644
index 0000000000..dd5f9fc31f
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/chrome.ini
@@ -0,0 +1,21 @@
+[DEFAULT]
+
+[test_action_keys_respect_focus.xul]
+[test_basic_functionality.xul]
+[test_cleanup_search.xul]
+[test_clear_button_disabled.xul]
+[test_close_download_manager.xul]
+[test_delete_key_cancels.xul]
+[test_delete_key_removes.xul]
+[test_drag.xul]
+[test_enter_dblclick_opens.xul]
+[test_multi_select.xul]
+[test_multiword_search.xul]
+[test_open_properties.xul]
+[test_removeDownload_updates_ui.xul]
+[test_search_clearlist.xul]
+[test_search_keys.xul]
+[test_select_all.xul]
+[test_space_key_pauses_resumes.xul]
+[test_space_key_retries.xul]
+[test_ui_stays_open_on_alert_clickback.xul]
diff --git a/comm/suite/components/downloads/tests/chrome/test_action_keys_respect_focus.xul b/comm/suite/components/downloads/tests/chrome/test_action_keys_respect_focus.xul
new file mode 100644
index 0000000000..765e0a3a9c
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_action_keys_respect_focus.xul
@@ -0,0 +1,376 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Download Manager UI Test Code.
+ *
+ * The Initial Developer of the Original Code is
+ * Edward Lee <edward.lee@engineering.uiuc.edu>.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Jens Hatlak <jh@junetz.de> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Test for bug 474622 to check that action keys (Del, Backspace, Return)
+ * respect focus, i.e. work as expected in the Search field, Clear List button
+ * and download list.
+ */
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+ <script>
+ <![CDATA[
+
+var openInvokeCount = 0;
+var removeInvokeCount = 0;
+var resumeInvokeCount = 0;
+var testedFunctions = {
+ openDownload : null,
+ removeDownload : null,
+ resumeDownload : null
+};
+
+function getCounter(aFn)
+{
+ switch (aFn) {
+ case "openDownload":
+ return () => openInvokeCount++;
+ case "removeDownload":
+ return () => removeInvokeCount++;
+ case "resumeDownload":
+ return () => resumeInvokeCount++;
+ }
+}
+
+function backupTestedFunction(aFn, aWin)
+{
+ ok(true, "(info) backupTestedFunction('" + aFn + "')");
+
+ [testedFunctions[aFn], aWin[aFn]] = [aWin[aFn], getCounter(aFn)];
+}
+function restoreTestedFunction(aFn, aWin)
+{
+ aWin[aFn] = testedFunctions[aFn];
+ testedFunctions[aFn] = null;
+
+ ok(true, "(info) restoreTestedFunction('" + aFn + "')");
+}
+
+function keyPressObs(aWin, aKey)
+{
+ this.mWin = aWin;
+ this.mKey = aKey;
+}
+keyPressObs.prototype = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if ("timer-callback" == aTopic)
+ synthesizeKey(this.mKey, {}, this.mWin);
+ }
+};
+var searchAndPressKey = function(aKey, aWin, aValue) {
+ var searchbox = aWin.document.getElementById("search-box");
+ searchbox.focus();
+ if (aValue != null)
+ searchbox.value = aValue;
+
+ // Press given key after a short delay to allow focus() to complete
+ var timer = Cc["@mozilla.org/timer;1"]
+ .createInstance(Ci.nsITimer);
+ timer.init(new keyPressObs(aWin, aKey), 500,
+ Ci.nsITimer.TYPE_ONE_SHOT);
+}
+
+function dlObs(aWin)
+{
+ this.mWin = aWin;
+ this.wasPaused = false;
+ this.wasResumed = false;
+ this.wasFinished = false;
+}
+dlObs.prototype = {
+ onDownloadStateChange: function(aState, aDownload)
+ {
+ if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING &&
+ !this.wasPaused)
+ {
+ this.wasPaused = true;
+ this.mWin.pauseDownload(aDownload.id);
+ return;
+ }
+
+ var searchbox = this.mWin.document.getElementById("search-box");
+ if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_PAUSED &&
+ !this.wasResumed)
+ {
+ this.wasResumed = true;
+
+ // Fill Search with an added space (test continues in testObs)
+ backupTestedFunction("resumeDownload", this.mWin);
+ searchAndPressKey(" ", this.mWin, "paused");
+ } else
+ if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED &&
+ !this.wasFinished)
+ {
+ this.wasFinished = true;
+
+ // The formerly paused download was resumed successfully, is now complete
+ // and still selected. Since it is a real download it can be opened.
+
+ // Init Search (test continues in testObs)
+ backupTestedFunction("openDownload", this.mWin);
+ searchAndPressKey("VK_RETURN", this.mWin, "delete me");
+
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ dm.removeListener(this);
+ }
+ },
+ onStateChange: function(a, b, c, d, e) { },
+ onProgressChange: function(a, b, c, d, e, f, g) { },
+ onSecurityChange: function(a, b, c, d) { }
+};
+
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+
+ function addDownload()
+ {
+ function createURI(aObj)
+ {
+ return (aObj instanceof Ci.nsIFile) ? Services.io.newFileURI(aObj) :
+ Services.io.newURI(aObj);
+ }
+
+ const nsIWBP = Ci.nsIWebBrowserPersist;
+ var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
+ .createInstance(nsIWBP);
+ persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
+ nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
+ nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
+
+ var destFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
+ // The "paused" part of this filename will be searched for later.
+ destFile.append("download.paused");
+ if (destFile.exists())
+ destFile.remove(false);
+
+ var dl = dm.addDownload(Ci.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOAD,
+ createURI("http://example.com/httpd.js"),
+ createURI(destFile), null, null,
+ Math.round(Date.now() * 1000), null, persist, false);
+
+ persist.progressListener = dl.QueryInterface(Ci.nsIWebProgressListener);
+ persist.saveURI(dl.source, null, null, 0, null, null, dl.targetFile, null);
+
+ return dl;
+ }
+
+ // Empty any old downloads
+ dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
+
+ // Make a file name for the downloads
+ var file = Services.dirsvc.get("TmpD", Ci.nsIFile);
+ file.append("cleanUp");
+ var filePath = Services.io.newFileURI(file).spec;
+
+ var stmt = dm.DBConnection.createStatement(
+ "INSERT INTO moz_downloads (name, target, source, state) " +
+ "VALUES (?1, ?2, ?3, ?4)");
+
+ try {
+ for (let site of ["delete.me", "i.live"]) {
+ stmt.bindByIndex(0, "Finished Download");
+ stmt.bindByIndex(1, filePath);
+ stmt.bindByIndex(2, "http://" + site + "/file");
+ stmt.bindByIndex(3, dm.DOWNLOAD_FINISHED);
+
+ // Add it!
+ stmt.execute();
+ }
+ }
+ finally {
+ stmt.reset();
+ stmt.finalize();
+ }
+
+ // Close the UI if necessary
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win) win.close();
+
+ var obs = Cc["@mozilla.org/observer-service;1"]
+ .getService(Ci.nsIObserverService);
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+ const IS_MAC = Cc["@mozilla.org/xre/app-info;1"]
+ .getService(Ci.nsIXULRuntime)
+ .OS == "Darwin";
+
+ var testPhase = 0;
+ var testObs = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ SimpleTest.waitForFocus(function () { continueTest(aSubject) }, aSubject);
+ }
+ };
+
+ function continueTest(win) {
+ var downloadTree = win.document.getElementById("downloadTree");
+ var searchbox = win.document.getElementById("search-box");
+ var clearList = win.document.getElementById("clearListButton");
+
+ // The list must have built, so figure out what test to do
+ switch (testPhase++) {
+ case 0:
+ // Init Search
+ searchbox.value = "delete me";
+ searchbox.doCommand();
+
+ break;
+ case 1:
+ // Clear Search
+ backupTestedFunction("removeDownload", win);
+ searchAndPressKey("VK_DELETE", win);
+
+ break;
+ case 2:
+ is(removeInvokeCount, 0, "Search box: Del didn't remove download");
+
+ // Search has been cleared, init again
+ searchbox.value = "live";
+ searchbox.doCommand();
+
+ break;
+ case 3:
+ // Clear Search
+ searchAndPressKey("VK_BACK_SPACE", win);
+
+ break;
+ case 4:
+ is(removeInvokeCount, 0, "Search box: Backspace didn't remove download");
+ restoreTestedFunction("removeDownload", win);
+
+ // Add paused download (test continues in dlObs)
+ dm.addListener(new dlObs(win));
+ addDownload();
+
+ break;
+ case 5:
+ // Back from dlObs
+ is(resumeInvokeCount, 0, "Search box: Space didn't resume download");
+
+ // Focus download tree and select first (paused) download
+ downloadTree.focus();
+ downloadTree.view.selection.select(0);
+
+ // Simulate Resume download
+ synthesizeKey(" ", {}, win);
+ is(resumeInvokeCount, 1, "Download list: Space resumed download");
+
+ // Resume download for real (test continues in dlObs)
+ restoreTestedFunction("resumeDownload", win);
+ synthesizeKey(" ", {}, win);
+
+ break;
+ case 6:
+ // Back from dlObs
+ is(openInvokeCount, 0, "Search box: Return didn't open download");
+
+ // Search has been changed, init again to get formerly paused download
+ searchbox.value = "paused";
+ searchbox.doCommand();
+
+ break;
+ case 7:
+ // Focus download tree and select first (formerly paused) download
+ downloadTree.focus();
+ downloadTree.view.selection.select(0);
+
+ // Simulate Open download
+ synthesizeKey("VK_RETURN", {}, win);
+ is(openInvokeCount, 1, "Download list: Return opened download");
+
+ // Clear List: Return (execute Clear List)
+ // MacOSX: VK_RETURN doesn't work on this button (See bug 506850).
+ if (IS_MAC)
+ // Workaround not to time out.
+ clearList.doCommand();
+ else {
+ clearList.focus();
+ synthesizeKey("VK_RETURN", {}, win);
+ }
+
+ break;
+ case 8:
+ if (IS_MAC)
+ is(openInvokeCount, 1, "Clear List: doCommand() didn't open download (MacOSX)");
+ else
+ is(openInvokeCount, 1, "Clear List: Enter didn't open download (Linux, Windows)");
+ restoreTestedFunction("openDownload", win);
+
+ // We're done here
+ obs.removeObserver(testObs, DLMGR_UI_DONE);
+ win.close();
+ SimpleTest.finish();
+
+ break;
+ }
+ }
+
+ obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_basic_functionality.xul b/comm/suite/components/downloads/tests/chrome/test_basic_functionality.xul
new file mode 100644
index 0000000000..ffedc65227
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_basic_functionality.xul
@@ -0,0 +1,281 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Shawn Wilsher <me@shawnwilsher.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Make sure the download manager can display downloads in the right order and
+ * contains the expected data. The list has one of each download state ordered
+ * by the start/end times.
+ */
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+ <script>
+ <![CDATA[
+
+var dmFile = Services.dirsvc.get("TmpD", Ci.nsIFile);
+dmFile.append("dm-ui-test.file");
+dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
+var gTestPath = Services.io.newFileURI(dmFile).spec;
+
+// Downloads are sorted by endTime, so make sure the end times are distinct
+const DownloadData = [
+ /* Active states first */
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859239,
+ state: Ci.nsIDownloadManager.DOWNLOAD_NOTSTARTED,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859238,
+ state: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859237,
+ state: Ci.nsIDownloadManager.DOWNLOAD_PAUSED,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859236,
+ state: Ci.nsIDownloadManager.DOWNLOAD_SCANNING,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859235,
+ state: Ci.nsIDownloadManager.DOWNLOAD_QUEUED,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ /* Finished states */
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859234,
+ state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859233,
+ state: Ci.nsIDownloadManager.DOWNLOAD_FAILED,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859232,
+ state: Ci.nsIDownloadManager.DOWNLOAD_CANCELED,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859231,
+ state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859230,
+ state: Ci.nsIDownloadManager.DOWNLOAD_DIRTY,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859229,
+ endTime: 1180493839859229,
+ state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_POLICY,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
+];
+
+function test_numberOfTreeItems(aWin)
+{
+ var doc = aWin.document;
+ var dlTree = doc.getElementById("downloadTree");
+ is(dlTree.view.rowCount, DownloadData.length,
+ "There is the correct number of tree items");
+}
+
+function test_properDownloadData(aWin)
+{
+ // This also tests the ordering of the display
+ var doc = aWin.document;
+ var dlTree = doc.getElementById("downloadTree");
+ var view = dlTree.view;
+ var colName = dlTree.columns.getNamedColumn("Name");
+ var colState = dlTree.columns.getNamedColumn("Status");
+ var colTarget = dlTree.columns.getNamedColumn("Name");
+ var colSource = dlTree.columns.getNamedColumn("Source");
+ var stateString;
+ var statusBar = doc.getElementById("statusbar-display");
+
+ for (var i = 0; i < view.rowCount; i++) {
+ view.selection.select(i);
+ is(view.getCellText(i, colName), DownloadData[i].name,
+ "Download names match up");
+ switch (DownloadData[i].state) {
+ case Ci.nsIDownloadManager.DOWNLOAD_PAUSED:
+ stateString = "Paused";
+ break;
+ case Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING:
+ stateString = "Downloading";
+ break;
+ case Ci.nsIDownloadManager.DOWNLOAD_FINISHED:
+ stateString = "Finished";
+ break;
+ case Ci.nsIDownloadManager.DOWNLOAD_FAILED:
+ stateString = "Failed";
+ break;
+ case Ci.nsIDownloadManager.DOWNLOAD_CANCELED:
+ stateString = "Canceled";
+ break;
+ case Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL: // Parental Controls
+ case Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_POLICY: // Security Zone Policy
+ case Ci.nsIDownloadManager.DOWNLOAD_DIRTY: // possible virus/spyware
+ stateString = "Blocked";
+ break;
+ default:
+ stateString = "Not Started";
+ break;
+ }
+ is(view.getCellText(i, colState), stateString,
+ "Download states match up");
+
+ var filePath = Services.io.newURI(DownloadData[i].target)
+ .QueryInterface(Ci.nsIFileURL)
+ .file.clone()
+ .QueryInterface(Ci.nsIFile)
+ .path;
+ is(statusBar.label, filePath,
+ "Download targets match up");
+ is(view.getCellText(i, colSource), DownloadData[i].source,
+ "Download sources match up");
+ }
+}
+
+var testFuncs = [
+ test_numberOfTreeItems
+ , test_properDownloadData
+];
+
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ var db = dm.DBConnection;
+
+ // First, we populate the database with some fake data
+ db.executeSimpleSQL("DELETE FROM moz_downloads");
+ var stmt = db.createStatement(
+ "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " +
+ "state, currBytes, maxBytes, preferredAction, autoResume) " +
+ "VALUES (:name, :source, :target, :startTime, :endTime, :state, " +
+ ":currBytes, :maxBytes, :preferredAction, :autoResume)");
+ for (let dl of DownloadData) {
+ for (let [prop, value] of Object.entries(dl))
+ stmt.params[prop] = value;
+
+ stmt.execute();
+ }
+ stmt.finalize();
+
+ // See if the DM is already open, and if it is, close it!
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win)
+ win.close();
+
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testObs = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ var win = aSubject;
+
+ // Now we can run our tests
+ for (let t of testFuncs)
+ t(win);
+
+ win.close();
+ dmFile.remove(false);
+ Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
+ SimpleTest.finish();
+ }
+ };
+
+ // Register with the observer service
+ Services.obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_cleanup_search.xul b/comm/suite/components/downloads/tests/chrome/test_cleanup_search.xul
new file mode 100644
index 0000000000..37394168dc
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_cleanup_search.xul
@@ -0,0 +1,172 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Download Manager UI Test Code.
+ *
+ * The Initial Developer of the Original Code is
+ * Edward Lee <edward.lee@engineering.uiuc.edu>.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Test for bug 414850 to make sure only downloads that are shown when
+ * searching are cleared and afterwards, the default list is shown.
+ *
+ * Test bug 430486 to make sure the Clear list button is disabled only when
+ * there are no download items visible.
+ */
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+ <script>
+ <![CDATA[
+
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ var db = dm.DBConnection;
+
+ // Empty any old downloads
+ db.executeSimpleSQL("DELETE FROM moz_downloads");
+
+ // Make a file name for the downloads
+ var file = Services.dirsvc.get("TmpD", Ci.nsIFile);
+ file.append("cleanUp");
+ var filePath = Services.io.newFileURI(file).spec;
+
+ var stmt = db.createStatement(
+ "INSERT INTO moz_downloads (name, target, source, state) " +
+ "VALUES (?1, ?2, ?3, ?4)");
+
+ try {
+ for (let site of ["delete.me", "i.live"]) {
+ stmt.bindByIndex(0, "Super Pimped Download");
+ stmt.bindByIndex(1, filePath);
+ stmt.bindByIndex(2, "http://" + site + "/file");
+ stmt.bindByIndex(3, dm.DOWNLOAD_FINISHED);
+
+ // Add it!
+ stmt.execute();
+ }
+ }
+ finally {
+ stmt.reset();
+ stmt.finalize();
+ }
+
+ // Close the UI if necessary
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win) win.close();
+
+ var obs = Cc["@mozilla.org/observer-service;1"]
+ .getService(Ci.nsIObserverService);
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testPhase = 0;
+ var testObs = {
+ observe: function(aSubject, aTopic, aData) {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ var win = aSubject;
+ var downloadView = win.document.getElementById("downloadTree").view;
+ var searchbox = win.document.getElementById("search-box");
+ var clearList = win.document.getElementById("clearListButton");
+
+ // The list must have built, so figure out what test to do
+ switch (testPhase++) {
+ case 0:
+ // Make sure the button is initially enabled
+ is(clearList.disabled, false, "Clear list is enabled for default 2 item view");
+
+ // Search for multiple words in any order in all places
+ searchbox.value = "delete me";
+ searchbox.doCommand();
+
+ break;
+ case 1:
+ // Search came back with 1 item
+ is(downloadView.rowCount, 1, "Search found the item to delete");
+ is(clearList.disabled, false, "Clear list is enabled for search matching 1 item");
+
+ // Clear the list that has the single matched item
+ clearList.doCommand();
+
+ break;
+ case 2:
+ // Done rebuilding with one item left
+ is(downloadView.rowCount, 1, "Clear list rebuilt the list with one");
+ is(clearList.disabled, false, "Clear list still enabled for 1 item in default view");
+
+ // Clear the whole list
+ clearList.doCommand();
+
+ break;
+ case 3:
+ // There's nothing left
+ is(downloadView.rowCount, 0, "Clear list killed everything");
+ is(clearList.disabled, true, "Clear list is disabled for no items");
+
+ // We're done!
+ win.close();
+ obs.removeObserver(testObs, DLMGR_UI_DONE);
+ SimpleTest.finish();
+
+ break;
+ }
+ }
+ };
+ obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_clear_button_disabled.xul b/comm/suite/components/downloads/tests/chrome/test_clear_button_disabled.xul
new file mode 100644
index 0000000000..0b713a31c3
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_clear_button_disabled.xul
@@ -0,0 +1,201 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Anoop Saldanha <poonaatsoc@gmail.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * This tests 437422. This test basically intends to checks if the clear list
+ * button is disabled when:
+ * 1. an invalid search string has been entered into the search box.
+ * 2. active downloads are present in the dm ui
+ * 3. we have both case (1) and (2)
+ */
+-->
+
+<window title="Download Manager Test"
+ onload="runTest();"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+ <script>
+ <![CDATA[
+
+const nsIDownloadManager = Ci.nsIDownloadManager;
+var dmFile = Services.dirsvc.get("TmpD", Ci.nsIFile);
+dmFile.append("dm-ui-test.file");
+dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
+var gTestPath = Services.io.newFileURI(dmFile).spec;
+
+const DoneDownloadData = [
+ { name: "Dead",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859239,
+ state: nsIDownloadManager.DOWNLOAD_CANCELED,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
+];
+
+const ActiveDownloadData = [
+ { name: "Patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859239,
+ state: nsIDownloadManager.DOWNLOAD_DOWNLOADING,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
+];
+
+function runTest()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ var db = dm.DBConnection;
+
+ // Empty any old downloads
+ db.executeSimpleSQL("DELETE FROM moz_downloads");
+
+ var stmt = db.createStatement(
+ "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " +
+ "state, currBytes, maxBytes, preferredAction, autoResume) " +
+ "VALUES (:name, :source, :target, :startTime, :endTime, :state, " +
+ ":currBytes, :maxBytes, :preferredAction, :autoResume)");
+ for (let dl of DoneDownloadData) {
+ for (let [prop, value] of Object.entries(dl))
+ stmt.params[prop] = value;
+
+ stmt.execute();
+ }
+ //stmt.finalize();
+
+ // Close the UI if necessary
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win) win.close();
+
+ var obs = Cc["@mozilla.org/observer-service;1"]
+ .getService(Ci.nsIObserverService);
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testPhase = 0;
+ var testObs = {
+ observe: function(aSubject, aTopic, aData) {
+ var doc = aSubject.document;
+ var searchbox = doc.getElementById("search-box");
+ var clearButton = doc.getElementById("clearListButton");
+
+ switch (testPhase++) {
+ case 0:
+ // Ensure that the clear list button is enabled at first
+ ok(!clearButton.disabled,
+ "The clear list button is not disabled initially.");
+
+ // Now, insert an nonsensical search string - nothing should show up,
+ // and the button should be disabled in the next test phase
+ searchbox.value = "Nonsensical";
+ searchbox.doCommand();
+
+ break;
+ case 1:
+ ok(clearButton.disabled,
+ "The clear list button is disabled with a nonsensical search " +
+ "term entered");
+
+ // Clear the search box
+ searchbox.value = "";
+ searchbox.doCommand();
+ break;
+
+ case 2:
+ // Populate the download manager with an active download now, and
+ // rebuild the list
+ stmt.reset();
+ for (let dl of ActiveDownloadData) {
+ for (let [prop, value] of Object.entries(dl))
+ stmt.params[prop] = value;
+
+ stmt.execute();
+ }
+ stmt.finalize();
+ dm.cleanUp();
+
+ break;
+ case 3:
+ ok(clearButton.disabled,
+ "The clear list button is disabled when we only have an active " +
+ "download");
+
+ // Now, insert an nonsensical search string - only the active download
+ // should show up, and the button should be disabled in the next test
+ // phase
+ searchbox.value = "Nonsensical";
+ searchbox.doCommand();
+ break;
+ case 4:
+ ok(clearButton.disabled,
+ "The clear list button is disabled with a nonsensical search " +
+ "term entered and one active download");
+
+ obs.removeObserver(testObs, DLMGR_UI_DONE);
+ db.executeSimpleSQL("DELETE FROM moz_downloads");
+ SimpleTest.finish();
+
+ break;
+ }
+ }
+ };
+
+ obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display: none"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_close_download_manager.xul b/comm/suite/components/downloads/tests/chrome/test_close_download_manager.xul
new file mode 100644
index 0000000000..94251a3771
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_close_download_manager.xul
@@ -0,0 +1,117 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Download Manager UI Test Code.
+ *
+ * The Initial Developer of the Original Code is
+ * Anoop Saldanha <poonaatsoc@gmail.com>
+ *
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * This test basically checks if the download manager
+ * closes when you press the esc key and accel + w.
+ */
+-->
+
+<window title="Download Manager Test"
+ onload="runTest();"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+ <script>
+ <![CDATA[
+
+const dmui = Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsIDownloadManagerUI);
+
+function testCloseDMWithAccelKey(aWin)
+{
+ function dmWindowClosedListener() {
+ aWin.removeEventListener("unload", dmWindowClosedListener, false);
+ ok(!dmui.visible, "DMUI closes with accel + w");
+ SimpleTest.finish();
+ }
+ aWin.addEventListener("unload", dmWindowClosedListener, false);
+
+ synthesizeKey("w", { accelKey: true }, aWin);
+}
+
+function runTest()
+{
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ // Close the UI if necessary
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win) win.close();
+
+ var testPhase = 0;
+ // Specify an observer that will be notified when the dm has been rendered on screen
+ var obs = Cc["@mozilla.org/observer-service;1"]
+ .getService(Ci.nsIObserverService);
+ var testObs = {
+ observe: function(aSubject, aTopic, aData) {
+ SimpleTest.waitForFocus(function () { closeDM(aSubject) }, aSubject);
+ }
+ };
+
+ function closeDM(win) {
+ // if we add more ways to close DM with keys, add more cases here
+ switch(testPhase++) {
+ case 0:
+ obs.removeObserver(testObs, DLMGR_UI_DONE);
+ testCloseDMWithAccelKey(win);
+ }
+ }
+
+ obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display: none"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_delete_key_cancels.xul b/comm/suite/components/downloads/tests/chrome/test_delete_key_cancels.xul
new file mode 100644
index 0000000000..f02459dd6f
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_delete_key_cancels.xul
@@ -0,0 +1,200 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Jens Hatlak <jh@junetz.de> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * This tests that the delete key will cancel a download in the UI.
+ * This test was added in bug 474622.
+ */
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+ <script>
+ <![CDATA[
+
+var invokeCount = 0;
+var cancelDownload = null;
+
+function dlObs(aWin)
+{
+ this.mWin = aWin;
+ this.wasPaused = false;
+ this.wasCanceled = false;
+}
+dlObs.prototype = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if ("timer-callback" == aTopic) {
+ // We're done!
+ this.mWin.close();
+ SimpleTest.finish();
+ }
+ },
+
+ onDownloadStateChange: function(aState, aDownload)
+ {
+ if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING &&
+ !this.wasPaused) {
+ // Make a copy of the cancelDownload function and replace it with a test
+ var counter = () => invokeCount++;
+ [cancelDownload, this.mWin["cancelDownload"]] = [this.mWin["cancelDownload"], counter];
+
+ synthesizeKey("VK_DELETE", {}, this.mWin);
+ is(invokeCount, 1, "Delete canceled the active download");
+
+ this.wasPaused = true;
+ this.mWin.pauseDownload(aDownload.id);
+ }
+
+ if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_PAUSED &&
+ !this.wasCanceled) {
+ synthesizeKey("VK_DELETE", {}, this.mWin);
+ is(invokeCount, 2, "Delete canceled the paused download");
+
+ // After all tests, restore original function
+ this.mWin["cancelDownload"] = cancelDownload;
+
+ this.wasCanceled = true;
+ this.mWin.cancelDownload(aDownload);
+
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ dm.removeListener(this);
+
+ // We have to do this on a timer so other JS stuff that handles the UI
+ // can actually catch up to us...
+ var timer = Cc["@mozilla.org/timer;1"]
+ .createInstance(Ci.nsITimer);
+ timer.init(this, 0, Ci.nsITimer.TYPE_ONE_SHOT);
+ }
+ },
+ onStateChange: function(a, b, c, d, e) { },
+ onProgressChange: function(a, b, c, d, e, f, g) { },
+ onSecurityChange: function(a, b, c, d) { }
+};
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+
+ function addDownload() {
+ function createURI(aObj) {
+ return (aObj instanceof Ci.nsIFile) ? Services.io.newFileURI(aObj) :
+ Services.io.newURI(aObj);
+ }
+
+ const nsIWBP = Ci.nsIWebBrowserPersist;
+ var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
+ .createInstance(nsIWBP);
+ persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
+ nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
+ nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
+
+ var destFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
+ destFile.append("download.result");
+ if (destFile.exists())
+ destFile.remove(false);
+
+ var dl = dm.addDownload(Ci.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOAD,
+ createURI("http://example.com/httpd.js"),
+ createURI(destFile), null, null,
+ Math.round(Date.now() * 1000), null, persist, false);
+
+ persist.progressListener = dl.QueryInterface(Ci.nsIWebProgressListener);
+ persist.saveURI(dl.source, null, null, 0, null, null, dl.targetFile, null);
+
+ return dl;
+ }
+
+ // First, we clear out the database
+ dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
+
+ // See if the DM is already open, and if it is, close it!
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win)
+ win.close();
+
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testObs = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ SimpleTest.waitForFocus(function () { cancelDL(aSubject) }, aSubject);
+ }
+ };
+
+ function cancelDL(win) {
+ var doc = win.document;
+ dm.addListener(new dlObs(win));
+
+ addDownload();
+ // we need to focus the download as well
+ doc.getElementById("downloadTree").view.selection.select(0);
+ Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
+ }
+
+ // Register with the observer service
+ Services.obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_delete_key_removes.xul b/comm/suite/components/downloads/tests/chrome/test_delete_key_removes.xul
new file mode 100644
index 0000000000..8462c3323b
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_delete_key_removes.xul
@@ -0,0 +1,198 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Shawn Wilsher <me@shawnwilsher.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * This test ensures that the delete key removes a download. This was added by
+ * bug 411172.
+ */
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+ <script>
+ <![CDATA[
+
+var dmFile = Services.dirsvc.get("TmpD", Ci.nsIFile);
+dmFile.append("dm-ui-test.file");
+dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
+var gTestPath = Services.io.newFileURI(dmFile).spec;
+
+// Downloads are sorted by endTime, so make sure the end times are distinct
+const DownloadData = [
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859239,
+ state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859236,
+ state: Ci.nsIDownloadManager.DOWNLOAD_FAILED,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859234,
+ state: Ci.nsIDownloadManager.DOWNLOAD_CANCELED,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859232,
+ state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859230,
+ state: Ci.nsIDownloadManager.DOWNLOAD_DIRTY,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859229,
+ endTime: 1180493839859229,
+ state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_POLICY,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
+];
+
+
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ var db = dm.DBConnection;
+
+ // First, we populate the database with some fake data
+ db.executeSimpleSQL("DELETE FROM moz_downloads");
+ var stmt = db.createStatement(
+ "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " +
+ "state, currBytes, maxBytes, preferredAction, autoResume) " +
+ "VALUES (:name, :source, :target, :startTime, :endTime, :state, " +
+ ":currBytes, :maxBytes, :preferredAction, :autoResume)");
+ for (let dl of DownloadData) {
+ for (let [prop, value] of Object.entries(dl))
+ stmt.params[prop] = value;
+
+ stmt.execute();
+ }
+ stmt.finalize();
+
+ // See if the DM is already open, and if it is, close it!
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win)
+ win.close();
+
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testObs = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ SimpleTest.waitForFocus(function () { deleteDL(aSubject) }, aSubject);
+ }
+ };
+
+ function deleteDL(win) {
+ var doc = win.document;
+
+ var stmt = db.createStatement("SELECT COUNT(*) FROM moz_downloads");
+ try {
+ stmt.executeStep();
+ let dlTree = doc.getElementById("downloadTree");
+ is(stmt.getInt32(0), dlTree.view.rowCount,
+ "The database and the number of downloads display matches");
+ stmt.reset();
+
+ let len = DownloadData.length;
+ for (let i = 0; i < len; i++) {
+ synthesizeKey("VK_DELETE", {}, win);
+
+ stmt.executeStep();
+ is(stmt.getInt32(0), len - (i + 1),
+ "The download was properly removed");
+ stmt.reset();
+ }
+ }
+ finally {
+ stmt.reset();
+ stmt.finalize();
+ }
+
+ win.close();
+ dmFile.remove(false);
+ Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
+ SimpleTest.finish();
+ }
+
+ // Register with the observer service
+ Services.obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_drag.xul b/comm/suite/components/downloads/tests/chrome/test_drag.xul
new file mode 100644
index 0000000000..133e633c39
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_drag.xul
@@ -0,0 +1,201 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Phil Lacy <philbaseless-firefox@yahoo.com> (Original Author)
+ * Jens Hatlak <jh@junetz.de>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Assure download manager can load valid list item as
+ * "application/moz-x-file", "text/uri-list" and "text/plain"
+ */
+
+based on toolkit/mozapps/downloads/tests/chrome/test_bug_462172.xul
+https://bugzilla.mozilla.org/show_bug.cgi?id=462172
+
+create a file with unique name
+create another file with unique name and delete it
+load into downloads database
+open download manager
+synthesize drag on both files
+missing file should not init drag
+real file should return transferdata with application/x-moz-file,
+ text/uri-list (CRLF-terminated) and text/plain (LF-terminated)
+close window
+-->
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
+ <script src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
+
+ <script>
+ <![CDATA[
+var missingFileElid;
+var realFileElid;
+const kFiller = "notApplicable";
+const kFillerURL = "https://bugzilla.mozilla.org/show_bug.cgi?id=462172"
+var realFile = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
+var missingFile = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
+
+realFile.append(kFiller);
+realFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
+var realFilePath = Services.io.newFileURI(realFile).spec;
+
+missingFile.append(kFiller);
+missingFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
+var missingFilePath = Services.io.newFileURI(missingFile).spec;
+missingFile.remove(false);
+
+// Dummy data for our files.
+// 'source' field must be in form of a URL.
+const DownloadData = [
+ { name: kFiller,
+ source: kFillerURL,
+ target: realFilePath,
+ state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED },
+ { name: kFiller,
+ source: kFillerURL,
+ target: missingFilePath,
+ state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED }
+];
+
+function mouseDragStartOnCell(aTree, aRow, aColumn, aWin, aFile)
+{
+ // get cell coordinates
+ if (typeof aTree.columns != "undefined")
+ aColumn = aTree.columns[aColumn];
+ var rect = aTree.treeBoxObject.getCoordsForCellItem(aRow, aColumn, "text");
+ return synthesizeDragStart(aTree.body, aFile, aWin, rect.x, rect.y);
+}
+
+function compareFunc(actualData, expectedData)
+{
+ return expectedData.equals(actualData);
+}
+
+var dragRealFile = [[
+ { type: "application/x-moz-file",
+ data: realFile,
+ eqTest: compareFunc },
+ { type: "text/uri-list",
+ data: realFilePath + "\r\n" },
+ { type: "text/plain",
+ data: realFilePath + "\n" }
+]];
+var dragMissingFile = [[
+ { type: "application/x-moz-file",
+ data: missingFile,
+ eqTest: compareFunc },
+ { type: "text/uri-list",
+ data: missingFilePath + "\r\n" },
+ { type: "text/plain",
+ data: missingFilePath + "\n" }
+]];
+
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+
+ // See if the DM is already open, and if it is, close it!
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win)
+ win.close();
+
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ // load files into db
+ var db = dm.DBConnection;
+
+ var stmt = db.createStatement(
+ "INSERT INTO moz_downloads ( name, source, target, state)" +
+ "VALUES (:name, :source, :target, :state)");
+ for (let dl of DownloadData) {
+ for (let [prop, value] of Object.entries(dl))
+ stmt.params[prop] = value;
+ stmt.execute();
+ }
+ stmt.finalize();
+
+ var testObs = {
+ observe: function(aSubject, aTopic, aData) {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ var win = aSubject;
+ win.focus();
+
+ var downloadTree = win.document.getElementById("downloadTree");
+
+ // Now we can run our tests
+ // Unordered sorting -> DownloadData/insert order: realFile, missingFile
+ // Column 4 is "Progress" (column 1, "Status", is hidden by default)
+ var result = mouseDragStartOnCell(downloadTree, 0, 4, win, dragRealFile);
+ is(result, null, "Checking for Real file match");
+ result = mouseDragStartOnCell(downloadTree, 1, 4, win, dragMissingFile);
+ isnot(result, null, "Drag start did not return item for missing file");
+
+ // Done.
+ win.close();
+ realFile.remove(false);
+ Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
+ SimpleTest.finish();
+ }
+ };
+
+ // Register with the observer service
+ Services.obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_enter_dblclick_opens.xul b/comm/suite/components/downloads/tests/chrome/test_enter_dblclick_opens.xul
new file mode 100644
index 0000000000..59c105ceaa
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_enter_dblclick_opens.xul
@@ -0,0 +1,243 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Download Manager UI Test Code.
+ *
+ * The Initial Developer of the Original Code is
+ * Edward Lee <edward.lee@engineering.uiuc.edu>.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Jens Hatlak <jh@junetz.de> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Test bug 495545 (implemented by bug 474622) to make sure the enter key
+ * or a double click actually calls opening the downloaded file.
+ */
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+ <script>
+ <![CDATA[
+
+// similar, but not equal to the one in tree_shared.js
+function mouseDblClickOnCell(aTree, aRow, aColumn, aWin)
+{
+ // get cell coordinates
+ if (typeof aTree.columns != "undefined")
+ aColumn = aTree.columns[aColumn];
+ var rect = aTree.treeBoxObject.getCoordsForCellItem(aRow, aColumn, "text");
+ synthesizeMouse(aTree.body, rect.x, rect.y, { clickCount: 2 }, aWin);
+}
+
+function dlObs(aWin)
+{
+ this.mWin = aWin;
+ this.currDownload = null;
+}
+dlObs.prototype = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if ("timer-callback" == aTopic) {
+ var downloadTree = this.mWin.document.getElementById("downloadTree");
+ var downloadView = downloadTree.view;
+
+ // Default test/check for invocations
+ var invokeCount = 0;
+ var counter = () => invokeCount++;
+
+ // Run tests
+
+ // Make a copy of the openDownload function and replace it with a test
+ let copy;
+ [copy, this.mWin["openDownload"]] = [this.mWin["openDownload"], counter];
+
+ // Select the first (paused) download for not calling openDownload
+ downloadView.selection.select(0);
+
+ synthesizeKey("VK_RETURN", {}, this.mWin);
+ is(invokeCount, 0, "Enter didn't do anything");
+
+ mouseDblClickOnCell(downloadTree, 0, 3, this.mWin);
+ is(invokeCount, 0, "Double click didn't do anything");
+
+ // Select the second (finished) download for calling openDownload
+ downloadView.selection.select(1);
+
+ synthesizeKey("VK_RETURN", {}, this.mWin);
+ is(invokeCount, 1, "Enter opened download");
+
+ mouseDblClickOnCell(downloadTree, 1, 3, this.mWin);
+ is(invokeCount, 2, "Double click opened download");
+
+ // After all tests, restore original function
+ this.mWin["openDownload"] = copy;
+
+ // We're done!
+ this.mWin.close();
+ this.currDownload.targetFile.remove(false);
+ SimpleTest.finish();
+ }
+ },
+
+ onDownloadStateChange: function(aState, aDownload)
+ {
+ if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED) {
+ this.currDownload = aDownload;
+ // We have to do this on a timer so other JS stuff that handles the UI
+ // can actually catch up to us...
+ var timer = Cc["@mozilla.org/timer;1"]
+ .createInstance(Ci.nsITimer);
+ timer.init(this, 0, Ci.nsITimer.TYPE_ONE_SHOT);
+
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ dm.removeListener(this);
+ }
+ },
+ onStateChange: function(a, b, c, d, e) { },
+ onProgressChange: function(a, b, c, d, e, f, g) { },
+ onSecurityChange: function(a, b, c, d) { }
+};
+
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+
+ function addDownload() {
+ function createURI(aObj) {
+ return (aObj instanceof Ci.nsIFile) ? Services.io.newFileURI(aObj) :
+ Services.io.newURI(aObj);
+ }
+
+ const nsIWBP = Ci.nsIWebBrowserPersist;
+ var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
+ .createInstance(nsIWBP);
+ persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
+ nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
+ nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
+
+ var destFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
+ destFile.append("download.result");
+ if (destFile.exists())
+ destFile.remove(false);
+
+ var dl = dm.addDownload(Ci.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOAD,
+ createURI("http://example.com/httpd.js"),
+ createURI(destFile), null, null,
+ Math.round(Date.now() * 1000), null, persist, false);
+
+ persist.progressListener = dl.QueryInterface(Ci.nsIWebProgressListener);
+ persist.saveURI(dl.source, null, null, 0, null, null, dl.targetFile, null);
+
+ return dl;
+ }
+
+ var db = dm.DBConnection;
+
+ // Empty any old downloads
+ db.executeSimpleSQL("DELETE FROM moz_downloads");
+
+ var stmt = db.createStatement(
+ "INSERT INTO moz_downloads (source, state, target, referrer) " +
+ "VALUES (?1, ?2, ?3, ?4)");
+
+ // add first download: PAUSED state
+ try {
+ var file = Services.dirsvc.get("TmpD", Ci.nsIFile);
+ file.append("dltest-paused");
+ var fileSpec = Services.io.newFileURI(file).spec;
+ stmt.bindByIndex(0, "http://example.com/file");
+ stmt.bindByIndex(1, dm.DOWNLOAD_PAUSED);
+ stmt.bindByIndex(2, fileSpec);
+ stmt.bindByIndex(3, "http://referrer/");
+
+ // Add it!
+ stmt.execute();
+ }
+ finally {
+ stmt.reset();
+ stmt.finalize();
+ }
+
+ // Close the UI if necessary
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win) win.close();
+
+ var obs = Cc["@mozilla.org/observer-service;1"]
+ .getService(Ci.nsIObserverService);
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testObs = {
+ observe: function(aSubject, aTopic, aData) {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ SimpleTest.waitForFocus(function () { continueTest(aSubject) }, aSubject);
+ }
+ };
+
+ function continueTest(win) {
+ dm.addListener(new dlObs(win));
+
+ // add second download: FINISHED state, actually created
+ // (checked by cmd_open)
+ addDownload();
+
+ obs.removeObserver(testObs, DLMGR_UI_DONE);
+ }
+
+ obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_multi_select.xul b/comm/suite/components/downloads/tests/chrome/test_multi_select.xul
new file mode 100644
index 0000000000..0c0a05cf4b
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_multi_select.xul
@@ -0,0 +1,204 @@
+<?xml version="1.0"?>
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+<!--
+ * Test bug 228842 to make sure multiple selections work in the download
+ * manager by making sure commands work as expected for both single and doubly
+ * selected items.
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+ <script>
+ <![CDATA[
+
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ var db = dm.DBConnection;
+
+ // Empty any old downloads
+ db.executeSimpleSQL("DELETE FROM moz_downloads");
+
+ var stmt = db.createStatement(
+ "INSERT INTO moz_downloads (source, state, target, referrer) " +
+ "VALUES (?1, ?2, ?3, ?4)");
+
+ try {
+ for (let site of ["ed.agadak.net", "mozilla.org", "mozilla.com", "mozilla.net"]) {
+ let file = Services.dirsvc.get("TmpD", Ci.nsIFile);
+ file.append(site);
+ let fileSpec = Services.io.newFileURI(file).spec;
+
+ stmt.bindByIndex(0, "http://" + site + "/file");
+ stmt.bindByIndex(1, dm.DOWNLOAD_FINISHED);
+ stmt.bindByIndex(2, fileSpec);
+ stmt.bindByIndex(3, "http://referrer/");
+
+ // Add it!
+ stmt.execute();
+ }
+ }
+ finally {
+ stmt.reset();
+ stmt.finalize();
+ }
+
+ // Close the UI if necessary
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win) win.close();
+
+ var obs = Cc["@mozilla.org/observer-service;1"]
+ .getService(Ci.nsIObserverService);
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testPhase = 0;
+ var testObs = {
+ observe: function(aSubject, aTopic, aData) {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ SimpleTest.waitForFocus(function () { continueTest(aSubject) }, aSubject);
+ }
+ };
+
+ function continueTest(win) {
+ var downloadView = win.document.getElementById("downloadTree").view;
+
+ // Default test/check for invocations
+ var invokeCount = 0;
+ var counter = () => invokeCount++;
+
+ // Accessors for returning a value for various properties
+ var getItems = () => downloadView.rowCount;
+ var getSelected = () => downloadView.selection.count;
+ var getClipboard = function() {
+ var clip = Cc["@mozilla.org/widget/clipboard;1"]
+ .getService(Ci.nsIClipboard);
+ var trans = Cc["@mozilla.org/widget/transferable;1"]
+ .createInstance(Ci.nsITransferable);
+
+ trans.init(null);
+ trans.addDataFlavor("text/unicode");
+ clip.getData(trans, clip.kGlobalClipboard);
+ var str = {};
+ trans.getTransferData("text/unicode", str, {});
+ return str.value.QueryInterface(Ci.nsISupportsString)
+ .data;
+ };
+
+ // Array of tests that consist of the command name, download manager
+ // function to temporarily replace, method to use in its place, value to
+ // use when checking correctness
+ var commandTests = [
+ ["pause", "pauseDownload", counter, counter],
+ ["resume", "resumeDownload", counter, counter],
+ ["cancel", "cancelDownload", counter, counter],
+ ["open", "openDownload", counter, counter],
+ ["show", "showDownload", counter, counter],
+ ["properties", "showProperties", counter, counter],
+ ["retry", "retryDownload", counter, counter],
+ ["openReferrer", "openUILink", counter, counter],
+ ["copyLocation", null, null, getClipboard],
+ ["remove", null, null, getItems],
+ ["selectAll", null, null, getSelected],
+ ];
+
+ // All the expected results for both single and double selections
+ var allExpected = {
+ single: {
+ pause: [0, "Paused no downloads"],
+ resume: [0, "Resumed no downloads"],
+ cancel: [0, "Canceled no downloads"],
+ open: [0, "Opened no downloads"],
+ show: [0, "Showed no downloads"],
+ properties: [1, "Called properties for one download"],
+ retry: [0, "Retried no downloads"],
+ openReferrer: [1, "Opened one referrer"],
+ copyLocation: ["http://ed.agadak.net/file", "Copied one location"],
+ remove: [3, "Removed one download, remaining 3"],
+ selectAll: [3, "Selected all 3 remaining downloads"],
+ },
+ double: {
+ pause: [0, "Paused neither download"],
+ resume: [0, "Resumed neither download"],
+ cancel: [0, "Canceled neither download"],
+ open: [0, "Opened neither download"],
+ show: [0, "Showed neither download"],
+ properties: [0, "Called properties for neither download"],
+ retry: [0, "Retried neither download"],
+ openReferrer: [0, "Opened neither referrer"],
+ copyLocation: ["http://mozilla.org/file\nhttp://mozilla.com/file", "Copied both locations"],
+ remove: [1, "Removed both downloads, remaining 1"],
+ selectAll: [1, "Selected the 1 remaining download"],
+ },
+ };
+
+ var cmdName;
+
+ // Run two tests: single selected, double selected
+ for (let whichTest of ["single", "double"]) {
+ let expected = allExpected[whichTest];
+
+ if (whichTest == "double")
+ // Select the first 2 downloads for double
+ downloadView.selection.rangedSelect(0, 1, false);
+ else
+ // Select the first download for single
+ downloadView.selection.select(0);
+
+ for (let [command, func, test, value] of commandTests) {
+ // Make a copy of the original function and replace it with a test
+ let copy;
+ [copy, win[func]] = [win[func], test];
+
+ // Run the command from the menu
+ if (command == "selectAll")
+ cmdName = "menu_" + command;
+ else
+ cmdName = "dlMenu_" + command;
+
+ win.document.getElementById(cmdName).doCommand();
+
+ // Make sure the value is as expected
+ let [correct, message] = expected[command];
+ is(value(), correct, message);
+
+ // Restore original values
+ invokeCount = 0;
+ win[func] = copy;
+ }
+ }
+
+ // We're done!
+ win.close();
+ obs.removeObserver(testObs, DLMGR_UI_DONE);
+ SimpleTest.finish();
+ }
+ obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_multiword_search.xul b/comm/suite/components/downloads/tests/chrome/test_multiword_search.xul
new file mode 100644
index 0000000000..ae2817c3fa
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_multiword_search.xul
@@ -0,0 +1,173 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Download Manager UI Test Code.
+ *
+ * The Initial Developer of the Original Code is
+ * Edward Lee <edward.lee@engineering.uiuc.edu>.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Test for bug 419403 that lets the download manager support multiple word
+ * search against the download name, source/referrer, date/time, file size,
+ * etc.
+ */
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+ <script>
+ <![CDATA[
+
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ var db = dm.DBConnection;
+
+ // Empty any old downloads
+ db.executeSimpleSQL("DELETE FROM moz_downloads");
+
+ // Make a file name for the downloads
+ var file = Services.dirsvc.get("TmpD", Ci.nsIFile);
+ file.append("multiWord");
+ var filePath = Services.io.newFileURI(file).spec;
+
+ var stmt = db.createStatement(
+ "INSERT INTO moz_downloads (name, target, source, state, endTime, maxBytes) " +
+ "VALUES (?1, ?2, ?3, ?4, ?5, ?6)");
+
+ try {
+ for (let site of ["ed.agadak.net", "mozilla.org"]) {
+ stmt.bindByIndex(0, "Super Pimped Download");
+ stmt.bindByIndex(1, filePath);
+ stmt.bindByIndex(2, "http://" + site + "/file");
+ stmt.bindByIndex(3, dm.DOWNLOAD_FINISHED);
+ stmt.bindByIndex(4, new Date(1985, 7, 2) * 1000);
+ stmt.bindByIndex(5, 111222333444);
+
+ // Add it!
+ stmt.execute();
+ }
+ } finally {
+ stmt.reset();
+ stmt.finalize();
+ }
+
+ // Close the UI if necessary
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win) win.close();
+
+ var obs = Cc["@mozilla.org/observer-service;1"]
+ .getService(Ci.nsIObserverService);
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testPhase = -1;
+ var testObs = {
+ observe: function(aSubject, aTopic, aData) {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ var win = aSubject;
+ var downloadView = win.document.getElementById("downloadTree").view;
+ var searchbox = win.document.getElementById("search-box");
+
+ var search = function(aTerms) {
+ searchbox.value = aTerms;
+ searchbox.doCommand();
+ };
+
+ let testResults = function(aExpected) {
+ is(downloadView.rowCount, aExpected,
+ "Phase " + testPhase + ": search matched " + aExpected + " download(s)");
+ };
+
+ // The list must have built, so figure out what test to do
+ switch (++testPhase) {
+ case 0:
+ // Search for multiple words in any order in all places
+ search("download super pimped multiWord");
+
+ break;
+ case 1:
+ // Done populating the two items
+ testResults(2);
+
+ // Do partial word matches including the site
+ search("Agadak.net downl pimp multi");
+
+ break;
+ case 2:
+ // Done populating the one result
+ testResults(1);
+
+ // The search term shouldn't be treated like a regular expression,
+ // e.g. "D.wnload" shouldn't match "Download".
+ search("D.wnload");
+
+ break;
+ case 3:
+ testResults(0);
+
+ // We're done!
+ win.close();
+ obs.removeObserver(testObs, DLMGR_UI_DONE);
+ SimpleTest.finish();
+
+ break;
+ }
+ }
+ };
+ obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_open_properties.xul b/comm/suite/components/downloads/tests/chrome/test_open_properties.xul
new file mode 100644
index 0000000000..2f319d6766
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_open_properties.xul
@@ -0,0 +1,197 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2008-2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Anoop Saldanha <poonaatsoc@gmail.com> (Original Author)
+ * Robert Kaiser <kairo@kairo.at>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * This tests bug 474620 - opening a progress dialog with the "properties"
+ * item in the download manager.
+ */
+-->
+
+<window title="Download Manager Test"
+ onload="runTest();"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+ <script>
+ <![CDATA[
+
+const nsIDownloadManager = Ci.nsIDownloadManager;
+var dmFile = Services.dirsvc.get("TmpD", Ci.nsIFile);
+dmFile.append("dm-ui-test.file");
+dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
+var gTestPath = Services.io.newFileURI(dmFile).spec;
+
+const DoneDownloadData = [
+ { name: "Dead",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859239,
+ state: nsIDownloadManager.DOWNLOAD_CANCELED,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
+];
+
+const ActiveDownloadData = [
+ { name: "Patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859239,
+ state: nsIDownloadManager.DOWNLOAD_DOWNLOADING,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
+];
+
+function runTest()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ var db = dm.DBConnection;
+
+ // Empty any old downloads
+ db.executeSimpleSQL("DELETE FROM moz_downloads");
+
+ var stmt = db.createStatement(
+ "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " +
+ "state, currBytes, maxBytes, preferredAction, autoResume) " +
+ "VALUES (:name, :source, :target, :startTime, :endTime, :state, " +
+ ":currBytes, :maxBytes, :preferredAction, :autoResume)");
+ for (let dl of DoneDownloadData) {
+ for (let [prop, value] of Object.entries(dl))
+ stmt.params[prop] = value;
+
+ stmt.execute();
+ }
+ //stmt.finalize();
+
+ // Close the UI if necessary
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win) win.close();
+
+ var obs = Cc["@mozilla.org/observer-service;1"]
+ .getService(Ci.nsIObserverService);
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var dmview;
+ var testStartTime = Date.now();
+ var testPhase = 0;
+ var testObs = {
+ observe: function(aSubject, aTopic, aData) {
+ switch (testPhase++) {
+ case 0:
+ ok(!!aSubject.document.getElementById("dlWinCommands"),
+ "The download manager window is active");
+ // the download manager is started, select the first download
+ dmview = aSubject.document.getElementById("downloadTree").view;
+ dmview.selection.select(0);
+ // call "properties"
+ aSubject.document.getElementById("dlMenu_properties").doCommand();
+
+ break;
+ case 1:
+ ok(!!aSubject.document.getElementById("dlProgressCommands"),
+ "The progress dialog was called for a canceled download");
+ var endTimeSeconds = Math.round(DoneDownloadData[0].endTime / 1000);
+ is(aSubject.gEndTime, endTimeSeconds, "End time matches data");
+
+ // Close the progress window
+ aSubject.close();
+
+ // Populate the download manager with an active download now, and
+ // rebuild the list
+ stmt.reset();
+ for (let dl of ActiveDownloadData) {
+ for (let [prop, value] of Object.entries(dl))
+ stmt.params[prop] = value;
+
+ stmt.execute();
+ }
+ stmt.finalize();
+ dm.cleanUp();
+
+ break;
+ case 2:
+ ok(!!aSubject.document.getElementById("dlWinCommands"),
+ "The download manager window got an event");
+ // the download manager UI is rebuilt, select the first download
+ dmview.selection.select(0);
+ // call "properties"
+ aSubject.document.getElementById("dlMenu_properties").doCommand();
+
+ break;
+ case 3:
+ ok(!!aSubject.document.getElementById("dlProgressCommands"),
+ "The progress dialog was called for an active download");
+ // active downloads updated to current time,
+ // just check if it's set to later than start of the test
+ ok(aSubject.gEndTime >= testStartTime, "End time within test run");
+
+ // Close the progress window
+ aSubject.close();
+
+ obs.removeObserver(testObs, DLMGR_UI_DONE);
+ db.executeSimpleSQL("DELETE FROM moz_downloads");
+ SimpleTest.finish();
+
+ break;
+ }
+ }
+ };
+
+ obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display: none"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_removeDownload_updates_ui.xul b/comm/suite/components/downloads/tests/chrome/test_removeDownload_updates_ui.xul
new file mode 100644
index 0000000000..d5b5d6c657
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_removeDownload_updates_ui.xul
@@ -0,0 +1,150 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Shawn Wilsher <me@shawnwilsher.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Test bug 394039 to make sure calling removeDownload of the
+ * nsIDownloadManager service correctly updates the download window.
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+ <script>
+ <![CDATA[
+
+var dmFile = Services.dirsvc.get("TmpD", Ci.nsIFile);
+dmFile.append("dm-ui-test.file");
+dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
+var gTestPath = Services.io.newFileURI(dmFile).spec;
+
+const DownloadData = [
+ { name: "381603.patch",
+ source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
+ target: gTestPath,
+ startTime: 1180493839859230,
+ endTime: 1180493839859239,
+ state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
+ currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
+];
+
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ var db = dm.DBConnection;
+
+ // First, we populate the database with some fake data
+ db.executeSimpleSQL("DELETE FROM moz_downloads");
+ var stmt = db.createStatement(
+ "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " +
+ "state, currBytes, maxBytes, preferredAction, autoResume) " +
+ "VALUES (:name, :source, :target, :startTime, :endTime, :state, " +
+ ":currBytes, :maxBytes, :preferredAction, :autoResume)");
+ for (let dl of DownloadData) {
+ for (let [prop, value] of Object.entries(dl))
+ stmt.params[prop] = value;
+
+ stmt.execute();
+ }
+ stmt.finalize();
+
+ // See if the DM is already open, and if it is, close it!
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win)
+ win.close();
+
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testObs = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ var win = aSubject;
+ var doc = win.document;
+
+ // Note: This also tests the ordering of the display
+ var stmt = db.createStatement("SELECT id FROM moz_downloads");
+ var id = -1;
+ try {
+ stmt.executeStep();
+ id = stmt.getInt64(0);
+ }
+ finally {
+ stmt.reset();
+ stmt.finalize();
+ }
+
+ dm.removeDownload(id);
+ var dlTreeView = doc.getElementById("downloadTree").view;
+ is(dlTreeView.rowCount, 0,
+ "The download was properly removed");
+
+ win.close();
+ dmFile.remove(false);
+ Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
+ SimpleTest.finish();
+ }
+ }
+
+ // Register with the observer service
+ Services.obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_search_clearlist.xul b/comm/suite/components/downloads/tests/chrome/test_search_clearlist.xul
new file mode 100644
index 0000000000..862291cd5d
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_search_clearlist.xul
@@ -0,0 +1,168 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Download Manager UI Test Code.
+ *
+ * The Initial Developer of the Original Code is
+ * Edward Lee <edward.lee@engineering.uiuc.edu>.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Test bug 431188 to make sure the Clear list button is enabled after doing a
+ * search and finding results.
+ */
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+ <script>
+ <![CDATA[
+
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ var db = dm.DBConnection;
+
+ // Empty any old downloads
+ db.executeSimpleSQL("DELETE FROM moz_downloads");
+
+ // Make a file name for the downloads
+ var file = Services.dirsvc.get("TmpD", Ci.nsIFile);
+ file.append("cleanUp");
+ var filePath = Services.io.newFileURI(file).spec;
+
+ var stmt = db.createStatement(
+ "INSERT INTO moz_downloads (target, source, state, endTime) " +
+ "VALUES (?1, ?2, ?3, ?4)");
+
+ // Add a bunch of downloads that don't match the search
+ var sites = [];
+ for (let i = 0; i < 50; i++)
+ sites.push("i-hate.clear-list-" + i);
+
+ // Add one download that matches the search
+ var searchTerm = "one-download.match-search";
+ sites.push(searchTerm);
+
+ try {
+ for (let site of sites) {
+ stmt.bindByIndex(0, filePath);
+ stmt.bindByIndex(1, "http://" + site + "/file");
+ stmt.bindByIndex(2, dm.DOWNLOAD_FINISHED);
+ // Make the one that matches slightly older so it appears last
+ stmt.bindByIndex(3, 1112223334445556 - (site == searchTerm));
+
+ // Add it!
+ stmt.execute();
+ }
+ }
+ finally {
+ stmt.reset();
+ stmt.finalize();
+ }
+
+ // Close the UI if necessary
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win) win.close();
+
+ var obs = Cc["@mozilla.org/observer-service;1"]
+ .getService(Ci.nsIObserverService);
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testPhase = 0;
+ var testObs = {
+ observe: function(aSubject, aTopic, aData) {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ var win = aSubject;
+ var downloadView = win.document.getElementById("downloadTree").view;
+ var searchbox = win.document.getElementById("search-box");
+ var clearList = win.document.getElementById("clearListButton");
+
+ // The list must have built, so figure out what test to do
+ switch (testPhase++) {
+ case 0:
+ case 2:
+ // Search for the one download
+ searchbox.value = searchTerm;
+ searchbox.doCommand();
+
+ break;
+ case 1:
+ // Search came back with 1 item
+ is(downloadView.rowCount, 1, "Search found the item to delete");
+ is(clearList.disabled, false, "Clear list is enabled for search matching 1 item");
+
+ // Clear the list that has the single matched item
+ clearList.doCommand();
+
+ break;
+ case 3:
+ // There's nothing that matches the search
+ is(downloadView.rowCount, 0, "Clear list killed the one matching download");
+ is(clearList.disabled, true, "Clear list is disabled for no items");
+
+ // We're done!
+ win.close();
+ obs.removeObserver(testObs, DLMGR_UI_DONE);
+ SimpleTest.finish();
+
+ break;
+ }
+ }
+ };
+ obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_search_keys.xul b/comm/suite/components/downloads/tests/chrome/test_search_keys.xul
new file mode 100644
index 0000000000..e651e341b5
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_search_keys.xul
@@ -0,0 +1,128 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Shawn Wilsher <me@shawnwilsher.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Make sure the download manager can display downloads in the right order and
+ * contains the expected data. The list has one of each download state ordered
+ * by the start/end times.
+ */
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+ <script>
+ <![CDATA[
+
+function test_meta_f(aWin)
+{
+ var doc = aWin.document;
+ var searchbox = doc.getElementById("search-box");
+ var dlTree = doc.getElementById("downloadTree");
+
+ // Enusre the searchbox is not focused
+ dlTree.focus();
+
+ // Dispatch the right key combination
+ synthesizeKey("f", {accelKey: true}, aWin);
+
+ ok(searchbox.hasAttribute("focused"), "Searchbox is focused");
+}
+
+var testFuncs = [
+ test_meta_f,
+]
+
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+
+ // See if the DM is already open, and if it is, close it!
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win)
+ win.close();
+
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testObs = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ SimpleTest.waitForFocus(function () { continueTest(aSubject) }, aSubject);
+ }
+ };
+
+ function continueTest(win) {
+ // Now we can run our tests
+ for (let t of testFuncs)
+ t(win);
+
+ win.close();
+ Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
+ SimpleTest.finish();
+ }
+
+ // Register with the observer service
+ Services.obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_select_all.xul b/comm/suite/components/downloads/tests/chrome/test_select_all.xul
new file mode 100644
index 0000000000..85dadcb168
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_select_all.xul
@@ -0,0 +1,145 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Download Manager UI Test Code.
+ *
+ * The Initial Developer of the Original Code is
+ * Edward Lee <edward.lee@engineering.uiuc.edu>.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Test bug 429614 to make sure ctrl/cmd-a work to select all downloads and
+ * hitting delete removes them all.
+ */
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+ <script>
+ <![CDATA[
+
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ var db = dm.DBConnection;
+
+ // Empty any old downloads
+ db.executeSimpleSQL("DELETE FROM moz_downloads");
+
+ // Make a file name for the downloads
+ var file = Services.dirsvc.get("TmpD", Ci.nsIFile);
+ file.append("selectAll");
+ var filePath = Services.io.newFileURI(file).spec;
+
+ var stmt = db.createStatement(
+ "INSERT INTO moz_downloads (target, source, state) " +
+ "VALUES (?1, ?2, ?3)");
+
+ var sites = ["mozilla.org", "mozilla.com", "select.all"];
+ try {
+ for (let site of sites) {
+ stmt.bindByIndex(0, filePath);
+ stmt.bindByIndex(1, "http://" + site + "/file");
+ stmt.bindByIndex(2, dm.DOWNLOAD_FINISHED);
+
+ // Add it!
+ stmt.execute();
+ }
+ }
+ finally {
+ stmt.reset();
+ stmt.finalize();
+ }
+
+ // Close the UI if necessary
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win) win.close();
+
+ var obs = Cc["@mozilla.org/observer-service;1"]
+ .getService(Ci.nsIObserverService);
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testObs = {
+ observe: function(aSubject, aTopic, aData) {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ SimpleTest.waitForFocus(function () { continueTest(aSubject) }, aSubject);
+ }
+ };
+
+ function continueTest(win) {
+ var downloadView = win.document.getElementById("downloadTree").view;
+
+ is(downloadView.rowCount, sites.length, "All downloads displayed");
+
+ // Select all downloads
+ var isMac = AppConstants.platform == "macosx";
+ synthesizeKey("a", { metaKey: isMac, ctrlKey: !isMac }, win);
+ is(downloadView.selection.count, sites.length, "All downloads selected");
+
+ // Delete all downloads
+ synthesizeKey("VK_DELETE", {}, win);
+ is(downloadView.rowCount, 0, "All downloads removed");
+
+ // We're done!
+ win.close();
+ obs.removeObserver(testObs, DLMGR_UI_DONE);
+ SimpleTest.finish();
+ }
+
+ obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_space_key_pauses_resumes.xul b/comm/suite/components/downloads/tests/chrome/test_space_key_pauses_resumes.xul
new file mode 100644
index 0000000000..d22624be62
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_space_key_pauses_resumes.xul
@@ -0,0 +1,221 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Shawn Wilsher <me@shawnwilsher.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * This tests that the space key will pause and resume a download in the UI.
+ * This test was added in bug 413985.
+ */
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+ <script>
+ <![CDATA[
+
+function bug413985obs(aWin)
+{
+ this.mWin = aWin;
+ this.wasPaused = false;
+ this.wasResumed = false;
+ this.wasFinished = false;
+}
+bug413985obs.prototype = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if ("timer-callback" == aTopic) {
+ if (this.wasFinished) {
+ // We're done!
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ dm.removeListener(this);
+ this.mWin.close();
+ SimpleTest.finish();
+ } else {
+ if (!this.wasPaused)
+ this.wasPaused = true;
+ else if (!this.wasResumed)
+ this.wasResumed = true;
+
+ // dispatch a space keypress to pause/resume the download
+ synthesizeKey(" ", {}, this.mWin);
+ }
+ }
+ },
+
+ onDownloadStateChange: function(aState, aDownload)
+ {
+ ok(true, "State value = " + aDownload.state);
+ switch (aDownload.state) {
+ case Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING:
+ if (!this.wasPaused) {
+ ok(true, "The download was started successfully");
+ // We have to do this on a timer so other JS stuff that handles the UI
+ // can actually catch up to us...
+ var timer = Cc["@mozilla.org/timer;1"]
+ .createInstance(Ci.nsITimer);
+ timer.init(this, 0, Ci.nsITimer.TYPE_ONE_SHOT);
+ } else {
+ ok(this.wasResumed, "The download was resumed successfully");
+ }
+ break;
+
+ case Ci.nsIDownloadManager.DOWNLOAD_PAUSED:
+ ok(this.wasPaused && !this.wasResumed,
+ "The download was paused successfully");
+ if (!this.wasResumed) {
+ // We have to do this on a timer so other JS stuff that handles the UI
+ // can actually catch up to us...
+ var timer = Cc["@mozilla.org/timer;1"]
+ .createInstance(Ci.nsITimer);
+ timer.init(this, 0, Ci.nsITimer.TYPE_ONE_SHOT);
+ }
+ break;
+
+ case Ci.nsIDownloadManager.DOWNLOAD_FINISHED:
+ ok(this.wasPaused && this.wasResumed,
+ "The download was paused, and then resumed to completion");
+ this.wasFinished = true;
+ aDownload.targetFile.remove(false);
+
+ // We have to do this on a timer so other JS stuff that handles the UI
+ // can actually catch up to us...
+ var timer = Cc["@mozilla.org/timer;1"]
+ .createInstance(Ci.nsITimer);
+ timer.init(this, 0, Ci.nsITimer.TYPE_ONE_SHOT);
+ break;
+
+ default:
+ break;
+ }
+ },
+ onStateChange: function(a, b, c, d, e) { },
+ onProgressChange: function(a, b, c, d, e, f, g) { },
+ onSecurityChange: function(a, b, c, d) { }
+};
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+
+ function addDownload() {
+ function createURI(aObj) {
+ return (aObj instanceof Ci.nsIFile) ? Services.io.newFileURI(aObj) :
+ Services.io.newURI(aObj);
+ }
+
+ const nsIWBP = Ci.nsIWebBrowserPersist;
+ var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
+ .createInstance(nsIWBP);
+ persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
+ nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
+ nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
+
+ var destFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
+ destFile.append("download.result");
+ if (destFile.exists())
+ destFile.remove(false);
+
+ // SeaMonkey: Use a bigger file than "http://example.com/httpd.js". (Bug 595685)
+ var dl = dm.addDownload(Ci.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOAD,
+ createURI("http://example.com/tests/fonts/mplus/mplus-1p-regular.ttf"),
+ createURI(destFile), null, null,
+ Math.round(Date.now() * 1000), null, persist, false);
+
+ persist.progressListener = dl.QueryInterface(Ci.nsIWebProgressListener);
+ persist.saveURI(dl.source, null, null, 0, null, null, dl.targetFile, null);
+
+ return dl;
+ }
+
+ // First, we clear out the database
+ dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
+
+ // See if the DM is already open, and if it is, close it!
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win)
+ win.close();
+
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testObs = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ SimpleTest.waitForFocus(function () { continueTest(aSubject) }, aSubject);
+ }
+ };
+
+ function continueTest(win) {
+ var doc = win.document;
+ dm.addListener(new bug413985obs(win));
+
+ addDownload();
+ // we need to focus the download as well
+ doc.getElementById("downloadTree").view.selection.select(0);
+ Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
+ }
+
+ // Register with the observer service
+ Services.obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_space_key_retries.xul b/comm/suite/components/downloads/tests/chrome/test_space_key_retries.xul
new file mode 100644
index 0000000000..5255f9caea
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_space_key_retries.xul
@@ -0,0 +1,198 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Jens Hatlak <jh@junetz.de> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * This tests that the space key will retry a download in the UI.
+ * This test was added in bug 474622.
+ */
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+ <script>
+ <![CDATA[
+
+function dlObs(aWin)
+{
+ this.mWin = aWin;
+ this.wasCanceled = false;
+ this.wasFinished = false;
+}
+dlObs.prototype = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if ("timer-callback" == aTopic) {
+ if (this.wasFinished) {
+ // We're done!
+ this.mWin.close();
+ SimpleTest.finish();
+ } else {
+ // dispatch a space keypress to retry the download
+ synthesizeKey(" ", {}, this.mWin);
+ }
+ }
+ },
+
+ onDownloadStateChange: function(aState, aDownload)
+ {
+ if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING &&
+ !this.wasCanceled) {
+ this.wasCanceled = true;
+ this.mWin.cancelDownload(aDownload);
+ }
+
+ if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_CANCELED) {
+ // We have to do this on a timer so other JS stuff that handles the UI
+ // can actually catch up to us...
+ var timer = Cc["@mozilla.org/timer;1"]
+ .createInstance(Ci.nsITimer);
+ timer.init(this, 0, Ci.nsITimer.TYPE_ONE_SHOT);
+ }
+
+ if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED) {
+ ok(this.wasCanceled,
+ "The download was canceled, retried and then ran to completion");
+ this.wasFinished = true;
+ aDownload.targetFile.remove(false);
+
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+ dm.removeListener(this);
+
+ // We have to do this on a timer so other JS stuff that handles the UI
+ // can actually catch up to us...
+ var timer = Cc["@mozilla.org/timer;1"]
+ .createInstance(Ci.nsITimer);
+ timer.init(this, 0, Ci.nsITimer.TYPE_ONE_SHOT);
+ }
+ },
+ onStateChange: function(a, b, c, d, e) { },
+ onProgressChange: function(a, b, c, d, e, f, g) { },
+ onSecurityChange: function(a, b, c, d) { }
+};
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+
+ function addDownload() {
+ function createURI(aObj) {
+ return (aObj instanceof Ci.nsIFile) ? Services.io.newFileURI(aObj) :
+ Services.io.newURI(aObj);
+ }
+
+ const nsIWBP = Ci.nsIWebBrowserPersist;
+ var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
+ .createInstance(nsIWBP);
+ persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
+ nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
+ nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
+
+ var destFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
+ destFile.append("download.result");
+ if (destFile.exists())
+ destFile.remove(false);
+
+ var dl = dm.addDownload(Ci.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOAD,
+ createURI("http://example.com/httpd.js"),
+ createURI(destFile), null, null,
+ Math.round(Date.now() * 1000), null, persist, false);
+
+ persist.progressListener = dl.QueryInterface(Ci.nsIWebProgressListener);
+ persist.saveURI(dl.source, null, null, 0, null, null, dl.targetFile, null);
+
+ return dl;
+ }
+
+ // First, we clear out the database
+ dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
+
+ // See if the DM is already open, and if it is, close it!
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win)
+ win.close();
+
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testObs = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ SimpleTest.waitForFocus(function () { continueTest(aSubject) }, aSubject);
+ }
+ };
+
+ function continueTest(win) {
+ var doc = win.document;
+ dm.addListener(new dlObs(win));
+
+ addDownload();
+ // we need to focus the download as well
+ doc.getElementById("downloadTree").view.selection.select(0);
+ Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
+ }
+
+ // Register with the observer service
+ Services.obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Show the Download Manager UI
+ Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsISuiteDownloadManagerUI)
+ .showManager();
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>
diff --git a/comm/suite/components/downloads/tests/chrome/test_ui_stays_open_on_alert_clickback.xul b/comm/suite/components/downloads/tests/chrome/test_ui_stays_open_on_alert_clickback.xul
new file mode 100644
index 0000000000..f54fb2dc21
--- /dev/null
+++ b/comm/suite/components/downloads/tests/chrome/test_ui_stays_open_on_alert_clickback.xul
@@ -0,0 +1,115 @@
+<?xml version="1.0"?>
+<!--
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Download Manager UI Test Code.
+ *
+ * The Initial Developer of the Original Code is
+ * Edward Lee <edward.lee@engineering.uiuc.edu>.
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Test bug 397935 to make sure the download manager ui window stays open when
+ * it's opened by the user clicking the alert and has the close-when-done pref
+ * set.
+ */
+-->
+
+<window title="Download Manager Test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="test();">
+
+ <script src="chrome://mochikit/content/MochiKit/packed.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+ <script>
+ <![CDATA[
+const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+function test()
+{
+ var dm = Cc["@mozilla.org/download-manager;1"]
+ .getService(Ci.nsIDownloadManager);
+
+ // Empty any old downloads
+ dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
+
+ var setClose = aVal =>
+ Services.prefs.setBoolPref("browser.download.manager.closeWhenDone", aVal);
+
+ // Close the UI if necessary
+ var win = Services.wm.getMostRecentWindow("Download:Manager");
+ if (win) win.close();
+
+ const DLMGR_UI_DONE = "download-manager-ui-done";
+
+ var testObs = {
+ observe: function(aSubject, aTopic, aData)
+ {
+ if (aTopic != DLMGR_UI_DONE)
+ return;
+
+ var win = aSubject;
+
+ // Note: This test will not be valid if the download list is built
+ // synchronously in Startup in downloads.js
+ // Make sure the window stays open
+ var dmui = Cc["@mozilla.org/download-manager-ui;1"]
+ .getService(Ci.nsIDownloadManagerUI);
+ ok(dmui.visible, "Download Manager stays open on alert click");
+
+ win.close();
+ setClose(false);
+ Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
+ SimpleTest.finish();
+ }
+ };
+
+ // Register with the observer service
+ Services.obs.addObserver(testObs, DLMGR_UI_DONE);
+
+ // Simulate an alert click with pref set to true
+ setClose(true);
+ dm.QueryInterface(Ci.nsIObserver)
+ .observe(null, "alertclickcallback", null);
+
+ SimpleTest.waitForExplicitFinish();
+}
+
+ ]]>
+ </script>
+
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <p id="display"></p>
+ <div id="content" style="display:none;"></div>
+ <pre id="test"></pre>
+ </body>
+</window>