bug 472001 - Tree-based UI for toolkit download manager in SeaMonkey, download manager UI tests, r=Neil

This commit is contained in:
Robert Kaiser 2009-05-29 12:06:45 +02:00
Родитель d743324b43
Коммит a2a13ae22f
17 изменённых файлов: 2546 добавлений и 1 удалений

Просмотреть файл

@ -45,7 +45,7 @@ include $(DEPTH)/config/autoconf.mk
PARALLEL_DIRS = public src
ifdef ENABLE_TESTS
PARALLEL_DIRS += tests
PARALLEL_DIRS += tests downloads/tests
endif
EXTRA_COMPONENTS = \

Просмотреть файл

@ -0,0 +1,69 @@
# ***** 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 Foundation.
# Portions created by the Initial Developer are Copyright (C) 2007
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of 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 *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = suite/common/downloads/tests
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_CHROME_FILES = \
test_basic_functionality.xul \
test_cleanup_search.xul \
test_clear_button_disabled.xul \
test_close_download_manager.xul \
test_delete_key_removes.xul \
test_multi_select.xul \
test_multiword_search.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_ui_stays_open_on_alert_clickback.xul \
$(NULL)
_BROWSER_FILES = browser_nsISuiteDownloadManagerUI.js \
$(NULL)
libs:: $(addprefix chrome/, $(_CHROME_FILES))
$(INSTALL) $(foreach f,$^,"$f") $(MOZDEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
libs:: $(addprefix browser/, $(_BROWSER_FILES))
$(INSTALL) $(foreach f,$^,"$f") $(MOZDEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)

Просмотреть файл

@ -0,0 +1,106 @@
/* ***** 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) 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 ***** */
function test_visibility_open()
{
var dmui = Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.nsIDownloadManagerUI);
is(dmui.visible, true,
"nsIDownloadManagerUI indicates that the UI is visible");
}
function test_visibility_closed(aWin)
{
var dmui = Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.nsIDownloadManagerUI);
function dmWindowClosedListener() {
aWin.removeEventListener("unload", dmWindowClosedListener, false);
is(dmui.visible, false,
"nsIDownloadManagerUI indicates that the UI is not visible");
finish();
}
aWin.addEventListener("unload", dmWindowClosedListener, false);
aWin.close();
}
var testFuncs = [
test_visibility_open
, test_visibility_closed /* all tests after this *must* expect there to be
no open window, otherwise they will fail! */
];
function test()
{
var dm = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
var db = dm.DBConnection;
// First, we populate the database with some fake data
db.executeSimpleSQL("DELETE FROM moz_downloads");
// See if the DM is already open, and if it is, close it!
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Download:Manager");
if (win)
win.close();
// OK, now that all the data is in, let's pull up the UI
Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.nsISuiteDownloadManagerUI).showManager();
let obs = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
const DLMGR_UI_DONE = "download-manager-ui-done";
let testObs = {
observe: function(aSubject, aTopic, aData) {
obs.removeObserver(testObs, DLMGR_UI_DONE);
var win = wm.getMostRecentWindow("Download:Manager");
// Now we can run our tests
for each (var t in testFuncs)
t(win);
// finish will be called by the last test that also hides the DM UI
}
};
waitForExplicitFinish();
obs.addObserver(testObs, DLMGR_UI_DONE, false);
}

Просмотреть файл

@ -0,0 +1,296 @@
<?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) 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 type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript">
<![CDATA[
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var dmFile = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
dmFile.append("dm-ui-test.file");
dmFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
var gTestPath = ios.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: Components.interfaces.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: Components.interfaces.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: Components.interfaces.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: Components.interfaces.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: Components.interfaces.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: Components.interfaces.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: Components.interfaces.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: Components.interfaces.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: Components.interfaces.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: Components.interfaces.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: Components.interfaces.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");
var ioSvc = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
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 Components.interfaces.nsIDownloadManager.DOWNLOAD_PAUSED:
stateString = "Paused";
break;
case Components.interfaces.nsIDownloadManager.DOWNLOAD_DOWNLOADING:
stateString = "Downloading";
break;
case Components.interfaces.nsIDownloadManager.DOWNLOAD_FINISHED:
stateString = "Finished";
break;
case Components.interfaces.nsIDownloadManager.DOWNLOAD_FAILED:
stateString = "Failed";
break;
case Components.interfaces.nsIDownloadManager.DOWNLOAD_CANCELED:
stateString = "Canceled";
break;
case Components.interfaces.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL: // Parental Controls
case Components.interfaces.nsIDownloadManager.DOWNLOAD_BLOCKED_POLICY: // Security Zone Policy
case Components.interfaces.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 = ioSvc.newURI(DownloadData[i].target, null, null)
.QueryInterface(Components.interfaces.nsIFileURL)
.file.clone()
.QueryInterface(Components.interfaces.nsILocalFile)
.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 = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
var db = dm.DBConnection;
// First, we populate the database with some fake data
db.executeSimpleSQL("DELETE FROM moz_downloads");
var rawStmt = 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)");
var stmt = Components.classes["@mozilla.org/storage/statement-wrapper;1"]
.createInstance(Components.interfaces.mozIStorageStatementWrapper);
stmt.initialize(rawStmt);
for each (var dl in DownloadData) {
for (var prop in dl)
stmt.params[prop] = dl[prop];
stmt.execute();
}
stmt.statement.finalize();
// See if the DM is already open, and if it is, close it!
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Download:Manager");
if (win)
win.close();
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
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 each (let t in testFuncs)
t(win);
win.close();
dmFile.remove(false);
os.removeObserver(testObs, DLMGR_UI_DONE);
SimpleTest.finish();
}
};
// Register with the observer service
os.addObserver(testObs, DLMGR_UI_DONE, false);
// Show the Download Manager UI
Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.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>

Просмотреть файл

@ -0,0 +1,180 @@
<?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 type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript">
<![CDATA[
function test()
{
var dm = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
var db = dm.DBConnection;
// Empty any old downloads
db.executeSimpleSQL("DELETE FROM moz_downloads");
// Make a file name for the downloads
var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
file.append("cleanUp");
var filePath = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newFileURI(file).spec;
var stmt = db.createStatement(
"INSERT INTO moz_downloads (name, target, source, state) " +
"VALUES (?1, ?2, ?3, ?4)");
try {
for each (let site in ["delete.me", "i.live"]) {
stmt.bindStringParameter(0, "Super Pimped Download");
stmt.bindStringParameter(1, filePath);
stmt.bindStringParameter(2, "http://" + site + "/file");
stmt.bindInt32Parameter(3, dm.DOWNLOAD_FINISHED);
// Add it!
stmt.execute();
}
}
finally {
stmt.reset();
stmt.finalize();
}
// Close the UI if necessary
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Download:Manager");
if (win) win.close();
var obs = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.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, false);
// Show the Download Manager UI
Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.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>

Просмотреть файл

@ -0,0 +1,213 @@
<?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) 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 type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript">
<![CDATA[
const nsIDownloadManager = Components.interfaces.nsIDownloadManager;
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var dmFile = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
dmFile.append("dm-ui-test.file");
dmFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
var gTestPath = ios.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 = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
var db = dm.DBConnection;
// Empty any old downloads
db.executeSimpleSQL("DELETE FROM moz_downloads");
var rawStmt = 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)");
var stmt = Components.classes["@mozilla.org/storage/statement-wrapper;1"]
.createInstance(Components.interfaces.mozIStorageStatementWrapper);
stmt.initialize(rawStmt);
for each (var dl in DoneDownloadData) {
for (var prop in dl)
stmt.params[prop] = dl[prop];
stmt.execute();
}
//stmt.statement.finalize();
// Close the UI if necessary
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Download:Manager");
if (win) win.close();
var obs = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.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 each (var dl in ActiveDownloadData) {
for (var prop in dl)
stmt.params[prop] = dl[prop];
stmt.execute();
}
stmt.statement.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, false);
Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.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>

Просмотреть файл

@ -0,0 +1,119 @@
<?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 type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<script type="application/javascript">
<![CDATA[
const dmui = Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.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 wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = 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 = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var testObs = {
observe: function(aSubject, aTopic, aData) {
var win = aSubject;
// 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, false);
Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.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>

Просмотреть файл

@ -0,0 +1,209 @@
<?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) 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 type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<script type="application/javascript">
<![CDATA[
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var dmFile = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
dmFile.append("dm-ui-test.file");
dmFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
var gTestPath = ios.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: Components.interfaces.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: Components.interfaces.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: Components.interfaces.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: Components.interfaces.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: Components.interfaces.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: Components.interfaces.nsIDownloadManager.DOWNLOAD_BLOCKED_POLICY,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
];
function test()
{
var dm = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
var db = dm.DBConnection;
// First, we populate the database with some fake data
db.executeSimpleSQL("DELETE FROM moz_downloads");
var rawStmt = 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)");
var stmt = Components.classes["@mozilla.org/storage/statement-wrapper;1"]
.createInstance(Components.interfaces.mozIStorageStatementWrapper)
stmt.initialize(rawStmt);
for each (var dl in DownloadData) {
for (var prop in dl)
stmt.params[prop] = dl[prop];
stmt.execute();
}
stmt.statement.finalize();
// See if the DM is already open, and if it is, close it!
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Download:Manager");
if (win)
win.close();
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
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;
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();
todo_is(stmt.getInt32(0), len - (i + 1),
"The download was properly removed");
stmt.reset();
}
}
finally {
stmt.reset();
stmt.finalize();
}
win.close();
dmFile.remove(false);
os.removeObserver(testObs, DLMGR_UI_DONE);
SimpleTest.finish();
}
};
// Register with the observer service
os.addObserver(testObs, DLMGR_UI_DONE, false);
// Show the Download Manager UI
Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.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>

Просмотреть файл

@ -0,0 +1,241 @@
<?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 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 type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<script type="application/javascript">
<![CDATA[
function test()
{
var dm = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.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 each (let site in ["ed.agadak.net", "mozilla.org", "mozilla.com", "mozilla.net"]) {
let file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
file.append(site);
let fileSpec = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newFileURI(file).spec;
stmt.bindStringParameter(0, "http://" + site + "/file");
stmt.bindInt32Parameter(1, dm.DOWNLOAD_FINISHED);
stmt.bindStringParameter(2, fileSpec);
stmt.bindStringParameter(3, "http://referrer/");
// Add it!
stmt.execute();
}
}
finally {
stmt.reset();
stmt.finalize();
}
// Close the UI if necessary
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Download:Manager");
if (win) win.close();
var obs = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.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;
// Default test/check for invocations
var invokeCount = 0;
var counter = function() invokeCount++;
// Accessors for returning a value for various properties
var getItems = function() downloadView.rowCount;
var getSelected = function() downloadView.selection.count;
var getClipboard = function() {
var clip = Components.classes["@mozilla.org/widget/clipboard;1"]
.getService(Components.interfaces.nsIClipboard);
var trans = Components.classes["@mozilla.org/widget/transferable;1"]
.createInstance(Components.interfaces.nsITransferable);
trans.addDataFlavor("text/unicode");
clip.getData(trans, clip.kGlobalClipboard);
var str = {};
var strLen = {};
trans.getTransferData("text/unicode", str, strLen);
return str.value.QueryInterface(Components.interfaces.nsISupportsString)
.data.substring(0, strLen.value / 2);
};
// 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],
["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"],
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"],
retry: [0, "Retried neither download"],
openReferrer: [0, "Opened neither referrer"],
copyLocation: ["http://mozilla.org/file\nhttp://mozilla.com/file", "Copied both locations"],
remove: [3, "Removed no downloads, remaining 3"],
selectAll: [3, "Selected the 3 remaining downloads"],
},
};
var cmdName;
// Run two tests: single selected, double selected
for each (let whichTest in ["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 each (let [command, func, test, value] in 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, false);
// Show the Download Manager UI
Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.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>

Просмотреть файл

@ -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 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 type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript">
<![CDATA[
function test()
{
var dm = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
var db = dm.DBConnection;
// Empty any old downloads
db.executeSimpleSQL("DELETE FROM moz_downloads");
// Make a file name for the downloads
var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
file.append("multiWord");
var filePath = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.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 each (let site in ["ed.agadak.net", "mozilla.org"]) {
stmt.bindStringParameter(0, "Super Pimped Download");
stmt.bindStringParameter(1, filePath);
stmt.bindStringParameter(2, "http://" + site + "/file");
stmt.bindInt32Parameter(3, dm.DOWNLOAD_FINISHED);
stmt.bindInt64Parameter(4, new Date(1985, 7, 2) * 1000);
stmt.bindInt64Parameter(5, 111222333444);
// Add it!
stmt.execute();
}
} finally {
stmt.reset();
stmt.finalize();
}
// Close the UI if necessary
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Download:Manager");
if (win) win.close();
var obs = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.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 search = function(aTerms) {
searchbox.value = aTerms;
searchbox.doCommand();
};
// 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
ok(downloadView.rowCount == 2, "Search matched both downloads");
// Do partial word matches including the site
search("agadak downl pimp multi");
break;
case 2:
// Done populating the one result
ok(downloadView.rowCount == 1, "Found the single download");
// We're done!
win.close();
obs.removeObserver(testObs, DLMGR_UI_DONE);
SimpleTest.finish();
break;
}
}
};
obs.addObserver(testObs, DLMGR_UI_DONE, false);
// Show the Download Manager UI
Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.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>

Просмотреть файл

@ -0,0 +1,163 @@
<?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) 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 type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript">
<![CDATA[
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var dmFile = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
dmFile.append("dm-ui-test.file");
dmFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
var gTestPath = ios.newFileURI(dmFile).spec;
const DownloadData = [
{ name: "381603.patch",
source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
target: gTestPath,
startTime: 1180493839859230,
endTime: 1180493839859239,
state: Components.interfaces.nsIDownloadManager.DOWNLOAD_FINISHED,
currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
];
function test()
{
var dm = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
var db = dm.DBConnection;
// First, we populate the database with some fake data
db.executeSimpleSQL("DELETE FROM moz_downloads");
var rawStmt = 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)");
var stmt = Components.classes["@mozilla.org/storage/statement-wrapper;1"]
.createInstance(Components.interfaces.mozIStorageStatementWrapper)
stmt.initialize(rawStmt);
for each (var dl in DownloadData) {
for (var prop in dl)
stmt.params[prop] = dl[prop];
stmt.execute();
}
stmt.statement.finalize();
// See if the DM is already open, and if it is, close it!
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Download:Manager");
if (win)
win.close();
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
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);
os.removeObserver(testObs, DLMGR_UI_DONE);
SimpleTest.finish();
}
}
// Register with the observer service
os.addObserver(testObs, DLMGR_UI_DONE, false);
// Show the Download Manager UI
Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.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>

Просмотреть файл

@ -0,0 +1,176 @@
<?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 type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript">
<![CDATA[
function test()
{
var dm = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
var db = dm.DBConnection;
// Empty any old downloads
db.executeSimpleSQL("DELETE FROM moz_downloads");
// Make a file name for the downloads
var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
file.append("cleanUp");
var filePath = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.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 each (let site in sites) {
stmt.bindStringParameter(0, filePath);
stmt.bindStringParameter(1, "http://" + site + "/file");
stmt.bindInt32Parameter(2, dm.DOWNLOAD_FINISHED);
// Make the one that matches slightly older so it appears last
stmt.bindInt64Parameter(3, 1112223334445556 - (site == searchTerm));
// Add it!
stmt.execute();
}
}
finally {
stmt.reset();
stmt.finalize();
}
// Close the UI if necessary
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Download:Manager");
if (win) win.close();
var obs = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.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, false);
// Show the Download Manager UI
Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.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>

Просмотреть файл

@ -0,0 +1,133 @@
<?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) 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 type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<script type="application/javascript">
<![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 = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
// See if the DM is already open, and if it is, close it!
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Download:Manager");
if (win)
win.close();
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
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 each (let t in testFuncs)
t(win);
win.close();
os.removeObserver(testObs, DLMGR_UI_DONE);
SimpleTest.finish();
}
};
// Register with the observer service
os.addObserver(testObs, DLMGR_UI_DONE, false);
// Show the Download Manager UI
Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.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>

Просмотреть файл

@ -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 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 type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<script type="application/javascript">
<![CDATA[
function test()
{
var dm = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
var db = dm.DBConnection;
// Empty any old downloads
db.executeSimpleSQL("DELETE FROM moz_downloads");
// Make a file name for the downloads
var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
file.append("selectAll");
var filePath = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.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 each (let site in sites) {
stmt.bindStringParameter(0, filePath);
stmt.bindStringParameter(1, "http://" + site + "/file");
stmt.bindInt32Parameter(2, dm.DOWNLOAD_FINISHED);
// Add it!
stmt.execute();
}
}
finally {
stmt.reset();
stmt.finalize();
}
// Close the UI if necessary
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Download:Manager");
if (win) win.close();
var obs = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
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 downloadView = win.document.getElementById("downloadTree").view;
is(downloadView.rowCount, sites.length, "All downloads displayed");
// Select all downloads
var isMac = navigator.platform.search("Mac") == 0;
synthesizeKey("a", { metaKey: isMac, ctrlKey: !isMac }, win);
is(downloadView.selection.count, sites.length, "All downloads selected");
// Delete all downloads
synthesizeKey("VK_DELETE", {}, win);
todo_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, false);
// Show the Download Manager UI
Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.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>

Просмотреть файл

@ -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
* Mozilla Corporation.
* 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 type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<script type="application/javascript">
<![CDATA[
function bug413985obs(aWin)
{
this.mWin = aWin;
this.wasPaused = false;
this.wasResumed = false;
}
bug413985obs.prototype = {
observe: function(aSubject, aTopic, aData)
{
if ("timer-callback" == aTopic) {
// dispatch a space keypress to resume the download
synthesizeKey(" ", {}, this.mWin);
}
},
onDownloadStateChange: function(aState, aDownload)
{
if (aDownload.state == Components.interfaces.nsIDownloadManager.DOWNLOAD_DOWNLOADING &&
!this.wasPaused) {
this.wasPaused = true;
// dispatch a space keypress to pause the download
synthesizeKey(" ", {}, this.mWin);
}
if (aDownload.state == Components.interfaces.nsIDownloadManager.DOWNLOAD_PAUSED &&
!this.wasResumed) {
this.wasResumed = true;
// We have to do this on a timer so other JS stuff that handles the UI
// can actually catch up to us...
var timer = Components.classes["@mozilla.org/timer;1"]
.createInstance(Components.interfaces.nsITimer);
timer.init(this, 0, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
}
if (aDownload.state == Components.interfaces.nsIDownloadManager.DOWNLOAD_FINISHED) {
todo(this.wasPaused && this.wasResumed,
"The download was paused, and then resumed to completion");
aDownload.targetFile.remove(false);
var dm = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
dm.removeListener(this);
SimpleTest.finish();
}
},
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 = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
function addDownload() {
function createURI(aObj) {
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
return (aObj instanceof Components.interfaces.nsIFile) ? ios.newFileURI(aObj) :
ios.newURI(aObj, null, null);
}
const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
var persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
.createInstance(Components.interfaces.nsIWebBrowserPersist);
persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var destFile = dirSvc.get("ProfD", Components.interfaces.nsIFile);
destFile.append("download.result");
if (destFile.exists())
destFile.remove(false);
var dl = dm.addDownload(Components.interfaces.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOAD,
createURI("http://example.com/httpd.js"),
createURI(destFile), null, null,
Math.round(Date.now() * 1000), null, persist);
persist.progressListener = dl.QueryInterface(Components.interfaces.nsIWebProgressListener);
persist.saveURI(dl.source, null, null, null, null, dl.targetFile);
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 wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Download:Manager");
if (win)
win.close();
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
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;
dm.addListener(new bug413985obs(win));
var dl = addDownload();
// we need to focus the download as well
doc.getElementById("downloadTree").view.selecttion.select(0);
os.removeObserver(testObs, DLMGR_UI_DONE);
}
};
// Register with the observer service
os.addObserver(testObs, DLMGR_UI_DONE, false);
// Show the Download Manager UI
Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.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>

Просмотреть файл

@ -0,0 +1,122 @@
<?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 type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript">
<![CDATA[
function test()
{
var dm = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
// Empty any old downloads
dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
var setClose = function(aVal)
Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch)
.setBoolPref("browser.download.manager.closeWhenDone", aVal);
// Close the UI if necessary
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("Download:Manager");
if (win) win.close();
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
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 = Components.classes["@mozilla.org/download-manager-ui;1"]
.getService(Components.interfaces.nsIDownloadManagerUI);
ok(dmui.visible, "Download Manager stays open on alert click");
win.close();
setClose(false);
os.removeObserver(testObs, DLMGR_UI_DONE);
SimpleTest.finish();
}
};
// Register with the observer service
os.addObserver(testObs, DLMGR_UI_DONE, false);
// Simulate an alert click with pref set to true
setClose(true);
dm.QueryInterface(Components.interfaces.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>

Просмотреть файл

@ -365,6 +365,8 @@ DownloadTreeView.prototype = {
},
initTree: function() {
if (!this._tree)
return
// We're resetting the whole list, either because we're creating the tree
// or because we need to recreate it
this._tree.beginUpdateBatch();