--- a/toolkit/components/downloads/moz.build
+++ b/toolkit/components/downloads/moz.build
@@ -16,20 +16,16 @@ with Files('csd.pb.*'):
with Files('generate_csd.sh'):
BUG_COMPONENT = ('Core', 'DOM: Security')
with Files('nsIApplicationReputation.idl'):
BUG_COMPONENT = ('Core', 'DOM: Security')
XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
-if not CONFIG['MOZ_JSDOWNLOADS']:
- XPCSHELL_TESTS_MANIFESTS += ['test/schema_migration/xpcshell.ini']
- BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']
-
XPIDL_SOURCES += [
'nsIApplicationReputation.idl',
'nsIDownload.idl',
'nsIDownloadManager.idl',
'nsIDownloadManagerUI.idl',
'nsIDownloadProgressListener.idl',
]
deleted file mode 100644
--- a/toolkit/components/downloads/test/browser/.eslintrc
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "extends": [
- "../../../../../testing/mochitest/mochitest.eslintrc"
- ]
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/browser/browser.ini
+++ /dev/null
@@ -1,7 +0,0 @@
-[DEFAULT]
-support-files =
- download.html
- download.test
-
-[browser_download_history.js]
-[browser_nsIDownloadManagerUI.js]
deleted file mode 100644
--- a/toolkit/components/downloads/test/browser/browser_bug414214.js
+++ /dev/null
@@ -1,59 +0,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/. */
-
-function test()
-{
- try {
- if (Services.prefs.getBoolPref("browser.download.useJSTransfer")) {
- return;
- }
- } catch (ex) { }
-
- const PREF_BDM_CLOSEWHENDONE = "browser.download.manager.closeWhenDone";
- var dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- var db = dm.DBConnection;
-
- // First, we clean up the DM
- db.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();
-
- // We need to set browser.download.manager.closeWhenDone to true to test this
- Services.prefs.setBoolPref(PREF_BDM_CLOSEWHENDONE, true);
-
- // register a callback to add a load listener to know when the download
- // manager opens
- Services.ww.registerNotification(function (aSubject, aTopic, aData) {
- Services.ww.unregisterNotification(arguments.callee);
-
- var win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
- win.addEventListener("DOMContentLoaded", finishUp, false);
- });
-
- // The window doesn't open once we call show, so we need to wait a little bit
- function finishUp() {
- var dmui = Cc["@mozilla.org/download-manager-ui;1"].
- getService(Ci.nsIDownloadManagerUI);
- ok(dmui.visible, "Download Manager window is open, as expected.");
-
- // Reset the pref to its default value
- try {
- Services.prefs.clearUserPref(PREF_BDM_CLOSEWHENDONE);
- }
- catch (err) { }
-
- finish();
- }
-
- // OK, let's pull up the UI
- // Linux uses y, everything else is j
- var key = navigator.platform.match("Linux") ? "y" : "j";
- EventUtils.synthesizeKey(key, {metaKey: true}, window.opener);
-
- waitForExplicitFinish();
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/browser/browser_download_history.js
+++ /dev/null
@@ -1,147 +0,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/. */
-
-function test() {
- try {
- if (Services.prefs.getBoolPref("browser.download.useJSTransfer")) {
- return;
- }
- } catch (ex) { }
-
- waitForExplicitFinish();
-
- let privateWin = null;
- let itemCount = 0;
- let sourceURL =
- "http://example.org/tests/toolkit/components/downloads/test/browser/download.html";
- let linkURL =
- "http://mochi.test:8888/tests/toolkit/components/downloads/test/browser/download.test";
- let linkURI = Services.io.newURI(linkURL, null, null);
- let downloadDialogURL =
- "chrome://mozapps/content/downloads/unknownContentType.xul";
-
- let downloadListener = {
- onDownloadStateChange: function(aState, aDownload) {
- switch (aDownload.state) {
- case Services.downloads.DOWNLOAD_FINISHED:
- info("Download finished");
- Services.downloads.removeListener(downloadListener);
- executeSoon(function() { checkDownload(aDownload); });
- break;
- }
- },
- onStateChange: function(a, b, c, d, e) { },
- onProgressChange: function(a, b, c, d, e, f, g) { },
- onSecurityChange: function(a, b, c, d) { }
- };
-
- let historyObserver = {
- onVisit: function (aURI, aVisitID, aTime, aSessionID, aReferringID, aTransitionType) {
- ok(false, "Download should not fired a visit notification: " + aURI.spec);
- },
- onBeginUpdateBatch: function () {},
- onEndUpdateBatch: function () {},
- onTitleChanged: function () {},
- onBeforeDeleteURI: function () {},
- onDeleteURI: function () {},
- onClearHistory: function () {},
- onPageChanged: function () {},
- onDeleteVisits: function () {},
- QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver])
- };
-
- let windowListener = {
- onOpenWindow: function(aXULWindow) {
- info("Window opened");
- Services.wm.removeListener(windowListener);
-
- let domWindow =
- aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).
- getInterface(Ci.nsIDOMWindow);
- waitForFocus(function() {
- is(domWindow.document.location.href, downloadDialogURL,
- "Should have seen the right window open");
-
- executeSoon(function() {
- let button = domWindow.document.documentElement.getButton("accept");
- button.disabled = false;
- domWindow.document.documentElement.acceptDialog();
- });
- }, domWindow);
- },
- onCloseWindow: function(aXULWindow) {},
- onWindowTitleChange: function(aXULWindow, aNewTitle) {}
- };
-
- registerCleanupFunction(function() {
- privateWin.close();
- Services.prefs.clearUserPref("browser.download.manager.showAlertOnComplete");
- });
-
- function getHistoryItemCount() {
- let options = PlacesUtils.history.getNewQueryOptions();
- options.includeHidden = true;
- options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY;
- let query = PlacesUtils.history.getNewQuery();
- let root = PlacesUtils.history.executeQuery(query, options).root;
- root.containerOpen = true;
- let cc = root.childCount;
- root.containerOpen = false;
- return cc;
- }
-
- function whenNewWindowLoaded(aIsPrivate, aCallback) {
- let win = OpenBrowserWindow({private: aIsPrivate});
- win.addEventListener("load", function onLoad() {
- win.removeEventListener("load", onLoad, false);
- executeSoon(() => aCallback(win));
- }, false);
- }
-
- function whenPageLoad(aWin, aURL, aCallback) {
- let browser = aWin.gBrowser.selectedBrowser;
- browser.addEventListener("load", function onLoad() {
- browser.removeEventListener("load", onLoad, true);
- executeSoon(() => aCallback(browser.contentDocument));
- }, true);
- browser.loadURI(aURL);
- }
-
- function checkDownload(aDownload) {
- PlacesUtils.history.removeObserver(historyObserver);
- ok(aDownload.isPrivate, "Download should be private");
- is(getHistoryItemCount(), itemCount,
- "History items count should not change after a download");
- PlacesUtils.asyncHistory.isURIVisited(linkURI, function(aURI, aIsVisited) {
- is(aIsVisited, false, "Download source should not be set as visited");
- // Clean up
- if (aDownload.targetFile.exists()) {
- aDownload.targetFile.remove(false);
- }
- waitForFocus(function() {
- if (privateWin.DownloadsPanel.isPanelShowing) {
- privateWin.DownloadsPanel.hidePanel();
- }
- finish();
- }, privateWin);
- });
- }
-
- // Disable alert service notifications
- Services.prefs.setBoolPref("browser.download.manager.showAlertOnComplete", false);
-
- whenNewWindowLoaded(true, function(win) {
- info("Start listeners");
- privateWin = win;
- Services.wm.addListener(windowListener);
- Services.downloads.addPrivacyAwareListener(downloadListener);
- PlacesUtils.history.addObserver(historyObserver, false);
- info("Load test page");
- whenPageLoad(win, sourceURL, function(doc) {
- info("Start download");
- itemCount = getHistoryItemCount();
- doc.getElementById("download-link").click();
- });
- });
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/browser/browser_nsIDownloadManagerUI.js
+++ /dev/null
@@ -1,106 +0,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/. */
-var Cr = Components.results;
-
-function test_visibility_open()
-{
- var dmui = Cc["@mozilla.org/download-manager-ui;1"].
- getService(Ci.nsIDownloadManagerUI);
- is(dmui.visible, true,
- "nsIDownloadManagerUI indicates that the UI is visible");
-}
-
-function test_getAttention_opened()
-{
- var dmui = Cc["@mozilla.org/download-manager-ui;1"].
- getService(Ci.nsIDownloadManagerUI);
-
- // switch focus to this window
- window.focus();
-
- dmui.getAttention();
- is(dmui.visible, true,
- "nsIDownloadManagerUI indicates that the UI is visible");
-}
-
-function test_visibility_closed(aWin)
-{
- var dmui = Cc["@mozilla.org/download-manager-ui;1"].
- getService(Ci.nsIDownloadManagerUI);
- aWin.close();
- is(dmui.visible, false,
- "nsIDownloadManagerUI indicates that the UI is not visible");
-}
-
-function test_getAttention_closed()
-{
- var dmui = Cc["@mozilla.org/download-manager-ui;1"].
- getService(Ci.nsIDownloadManagerUI);
-
- var exceptionCaught = false;
- try {
- dmui.getAttention();
- } catch (e) {
- is(e.result, Cr.NS_ERROR_UNEXPECTED,
- "Proper exception was caught");
- exceptionCaught = true;
- } finally {
- is(exceptionCaught, true,
- "Exception was caught, as expected");
- }
-}
-
-var testFuncs = [
- test_visibility_open
- , test_getAttention_opened
- , test_visibility_closed /* all tests after this *must* expect there to be
- no open window, otherwise they will fail! */
- , test_getAttention_closed
-];
-
-function test()
-{
- try {
- if (Services.prefs.getBoolPref("browser.download.useJSTransfer")) {
- return;
- }
- } catch (ex) { }
-
- 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");
-
- // See if the DM is already open, and if it is, close it!
- var win = Services.wm.getMostRecentWindow("Download:Manager");
- if (win)
- win.close();
-
- // Ensure that the download manager callbacks and nsIDownloadManagerUI always
- // use the window UI instead of the panel in the browser's window.
- Services.prefs.setBoolPref("browser.download.useToolkitUI", true);
- registerCleanupFunction(function() {
- Services.prefs.clearUserPref("browser.download.useToolkitUI");
- });
-
- // OK, now that all the data is in, let's pull up the UI
- Cc["@mozilla.org/download-manager-ui;1"].
- getService(Ci.nsIDownloadManagerUI).show();
-
- // The window doesn't open once we call show, so we need to wait a little bit
- function finishUp() {
- var win = Services.wm.getMostRecentWindow("Download:Manager");
-
- // Now we can run our tests
- for (var t of testFuncs)
- t(win);
-
- finish();
- }
-
- waitForExplicitFinish();
- window.setTimeout(finishUp, 1000);
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/browser/download.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<!--
- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/
--->
-
-<html>
- <head>
- </head>
- <body>
- <a id="download-link"
- href="http://mochi.test:8888/tests/toolkit/components/downloads/test/browser/download.test" >LINK</a>
- </body>
-</html>
deleted file mode 100644
--- a/toolkit/components/downloads/test/browser/download.test
+++ /dev/null
@@ -1,1 +0,0 @@
-TEST FILE
deleted file mode 100644
--- a/toolkit/components/downloads/test/schema_migration/.eslintrc
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "extends": [
- "../../../../../testing/xpcshell/xpcshell.eslintrc"
- ]
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/schema_migration/head_migration.js
+++ /dev/null
@@ -1,37 +0,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/. */
-
-Components.utils.import("resource://gre/modules/Services.jsm");
-
-var Cc = Components.classes;
-var Ci = Components.interfaces;
-var Cr = Components.results;
-
-do_get_profile();
-
-do_register_cleanup(function() {
- Services.obs.notifyObservers(null, "quit-application", null);
-});
-
-var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties);
-
-function importDatabaseFile(aFName)
-{
- var file = do_get_file(aFName);
- var newFile = dirSvc.get("ProfD", Ci.nsIFile);
- file.copyTo(newFile, "downloads.sqlite");
-}
-
-function cleanup()
-{
- // removing database
- var dbFile = dirSvc.get("ProfD", Ci.nsIFile);
- dbFile.append("downloads.sqlite");
- if (dbFile.exists())
- try { dbFile.remove(true); } catch(e) { /* stupid windows box */ }
-}
-
-cleanup();
-
deleted file mode 100644
--- a/toolkit/components/downloads/test/schema_migration/test_migration_to_2.js
+++ /dev/null
@@ -1,49 +0,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/. */
-
-// This file tests migration from v1 to v2
-
-function run_test()
-{
- // First import the downloads.sqlite file
- importDatabaseFile("v1.sqlite");
-
- // ok, now it is OK to init the download manager - this will perform the
- // migration!
- var dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- var dbConn = dm.DBConnection;
- var stmt = null;
-
- // check schema version
- do_check_true(dbConn.schemaVersion >= 2);
-
- // Check that the column no longer exists
- try {
- // throws when it doesn't exist
- stmt = dbConn.createStatement("SELECT iconURL FROM moz_downloads");
- do_throw("should not get here");
- } catch (e) {
- do_check_eq(Cr.NS_ERROR_FAILURE, e.result);
- }
-
- // now we check the entries
- stmt = dbConn.createStatement(
- "SELECT name, source, target, startTime, endTime, state " +
- "FROM moz_downloads " +
- "WHERE id = 2");
- stmt.executeStep();
- do_check_eq("381603.patch", stmt.getString(0));
- do_check_eq("https://bugzilla.mozilla.org/attachment.cgi?id=266520",
- stmt.getUTF8String(1));
- do_check_eq("file:///Users/sdwilsh/Desktop/381603.patch",
- stmt.getUTF8String(2));
- do_check_eq(1180493839859230, stmt.getInt64(3));
- do_check_eq(1180493839859230, stmt.getInt64(4));
- do_check_eq(1, stmt.getInt32(5));
- stmt.finalize();
-
- cleanup();
-}
-
deleted file mode 100644
--- a/toolkit/components/downloads/test/schema_migration/test_migration_to_3.js
+++ /dev/null
@@ -1,45 +0,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/. */
-
-// This file tests migration from v1 to v2
-
-function run_test()
-{
- // First import the downloads.sqlite file
- importDatabaseFile("v2.sqlite");
-
- // ok, now it is OK to init the download manager - this will perform the
- // migration!
- var dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- var dbConn = dm.DBConnection;
- var stmt = null;
-
- // check schema version
- do_check_true(dbConn.schemaVersion >= 3);
-
- // Check that the column exists (statement should not throw)
- stmt = dbConn.createStatement("SELECT referrer FROM moz_downloads");
- stmt.finalize();
-
- // now we check the entries
- stmt = dbConn.createStatement(
- "SELECT name, source, target, startTime, endTime, state, referrer " +
- "FROM moz_downloads " +
- "WHERE id = 2");
- stmt.executeStep();
- do_check_eq("381603.patch", stmt.getString(0));
- do_check_eq("https://bugzilla.mozilla.org/attachment.cgi?id=266520",
- stmt.getUTF8String(1));
- do_check_eq("file:///Users/sdwilsh/Desktop/381603.patch",
- stmt.getUTF8String(2));
- do_check_eq(1180493839859230, stmt.getInt64(3));
- do_check_eq(1180493839859230, stmt.getInt64(4));
- do_check_eq(1, stmt.getInt32(5));
- do_check_true(stmt.getIsNull(6));
- stmt.finalize();
-
- cleanup();
-}
-
deleted file mode 100644
--- a/toolkit/components/downloads/test/schema_migration/test_migration_to_4.js
+++ /dev/null
@@ -1,46 +0,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/. */
-
-// This file tests migration from v3 to v4
-
-function run_test()
-{
- // First import the downloads.sqlite file
- importDatabaseFile("v3.sqlite");
-
- // ok, now it is OK to init the download manager - this will perform the
- // migration!
- var dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- var dbConn = dm.DBConnection;
- var stmt = null;
-
- // check schema version
- do_check_true(dbConn.schemaVersion >= 4);
-
- // Check that the column exists (statement should not throw)
- stmt = dbConn.createStatement("SELECT entityID FROM moz_downloads");
- stmt.finalize();
-
- // now we check the entries
- stmt = dbConn.createStatement(
- "SELECT name, source, target, startTime, endTime, state, referrer, entityID " +
- "FROM moz_downloads " +
- "WHERE id = 27");
- stmt.executeStep();
- do_check_eq("Firefox 2.0.0.6.dmg", stmt.getString(0));
- do_check_eq("http://ftp-mozilla.netscape.com/pub/mozilla.org/firefox/releases/2.0.0.6/mac/en-US/Firefox%202.0.0.6.dmg",
- stmt.getUTF8String(1));
- do_check_eq("file:///Users/sdwilsh/Desktop/Firefox%202.0.0.6.dmg",
- stmt.getUTF8String(2));
- do_check_eq(1187390974170783, stmt.getInt64(3));
- do_check_eq(1187391001257446, stmt.getInt64(4));
- do_check_eq(1, stmt.getInt32(5));
- do_check_eq("http://www.mozilla.com/en-US/products/download.html?product=firefox-2.0.0.6&os=osx&lang=en-US",stmt.getUTF8String(6));
- do_check_true(stmt.getIsNull(7));
- stmt.finalize();
-
- cleanup();
-}
-
deleted file mode 100644
--- a/toolkit/components/downloads/test/schema_migration/test_migration_to_5.js
+++ /dev/null
@@ -1,42 +0,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/. */
-
-// This file tests migration from v4 to v5
-
-function run_test()
-{
- // First import the downloads.sqlite file
- importDatabaseFile("v4.sqlite");
-
- // ok, now it is OK to init the download manager - this will perform the
- // migration!
- var dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- var dbConn = dm.DBConnection;
-
- // check schema version
- do_check_true(dbConn.schemaVersion >= 5);
-
- // Check that the columns exist (no throw) and entries are correct
- var stmt = dbConn.createStatement(
- "SELECT name, source, target, startTime, endTime, state, referrer, " +
- "entityID, tempPath " +
- "FROM moz_downloads " +
- "WHERE id = 27");
- stmt.executeStep();
- do_check_eq("Firefox 2.0.0.6.dmg", stmt.getString(0));
- do_check_eq("http://ftp-mozilla.netscape.com/pub/mozilla.org/firefox/releases/2.0.0.6/mac/en-US/Firefox%202.0.0.6.dmg",
- stmt.getUTF8String(1));
- do_check_eq("file:///Users/sdwilsh/Desktop/Firefox%202.0.0.6.dmg",
- stmt.getUTF8String(2));
- do_check_eq(1187390974170783, stmt.getInt64(3));
- do_check_eq(1187391001257446, stmt.getInt64(4));
- do_check_eq(1, stmt.getInt32(5));
- do_check_eq("http://www.mozilla.com/en-US/products/download.html?product=firefox-2.0.0.6&os=osx&lang=en-US",stmt.getUTF8String(6));
- do_check_true(stmt.getIsNull(7));
- do_check_true(stmt.getIsNull(8));
- stmt.finalize();
-
- cleanup();
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/schema_migration/test_migration_to_6.js
+++ /dev/null
@@ -1,44 +0,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/. */
-
-// This file tests migration from v5 to v6
-
-function run_test()
-{
- // First import the downloads.sqlite file
- importDatabaseFile("v5.sqlite");
-
- // ok, now it is OK to init the download manager - this will perform the
- // migration!
- var dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- var dbConn = dm.DBConnection;
-
- // check schema version
- do_check_true(dbConn.schemaVersion >= 6);
-
- // Check that the columns exist (no throw) and entries are correct
- var stmt = dbConn.createStatement(
- "SELECT name, source, target, startTime, endTime, state, referrer, " +
- "entityID, tempPath, currBytes, maxBytes " +
- "FROM moz_downloads " +
- "WHERE id = 27");
- stmt.executeStep();
- do_check_eq("Firefox 2.0.0.6.dmg", stmt.getString(0));
- do_check_eq("http://ftp-mozilla.netscape.com/pub/mozilla.org/firefox/releases/2.0.0.6/mac/en-US/Firefox%202.0.0.6.dmg",
- stmt.getUTF8String(1));
- do_check_eq("file:///Users/sdwilsh/Desktop/Firefox%202.0.0.6.dmg",
- stmt.getUTF8String(2));
- do_check_eq(1187390974170783, stmt.getInt64(3));
- do_check_eq(1187391001257446, stmt.getInt64(4));
- do_check_eq(1, stmt.getInt32(5));
- do_check_eq("http://www.mozilla.com/en-US/products/download.html?product=firefox-2.0.0.6&os=osx&lang=en-US",stmt.getUTF8String(6));
- do_check_true(stmt.getIsNull(7));
- do_check_true(stmt.getIsNull(8));
- do_check_eq(0, stmt.getInt64(9));
- do_check_eq(-1, stmt.getInt64(10));
- stmt.finalize();
-
- cleanup();
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/schema_migration/test_migration_to_7.js
+++ /dev/null
@@ -1,70 +0,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/. */
-
-function run_test()
-{
- // We're testing migration to this version from one version below
- var targetVersion = 7;
-
- // First import the downloads.sqlite file
- importDatabaseFile("v" + (targetVersion - 1) + ".sqlite");
-
- // Init the download manager which will try migrating to the new version
- var dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- var dbConn = dm.DBConnection;
-
- // Check schema version
- do_check_true(dbConn.schemaVersion >= targetVersion);
-
- // Make sure all the columns are there
- var stmt = dbConn.createStatement(
- "SELECT name, source, target, tempPath, startTime, endTime, state, " +
- "referrer, entityID, currBytes, maxBytes, mimeType, " +
- "preferredApplication, preferredAction " +
- "FROM moz_downloads " +
- "WHERE id = 28");
- stmt.executeStep();
-
- // This data is based on the original values in the table
- var data = [
- "firefox-3.0a9pre.en-US.linux-i686.tar.bz2",
- "http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/firefox-3.0a9pre.en-US.linux-i686.tar.bz2",
- "file:///Users/Ed/Desktop/firefox-3.0a9pre.en-US.linux-i686.tar.bz2",
- "/Users/Ed/Desktop/+EZWafFQ.bz2.part",
- 1192469856209164,
- 1192469877017396,
- Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
- "http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/",
- "%2210e66c1-8a2d6b-9b33f380%22/9055595/Mon, 15 Oct 2007 11:45:34 GMT",
- 1210772,
- 9055595,
- // For the new columns added, check for null or default values
- true,
- true,
- 0,
- ];
-
- // Make sure the values are correct after the migration
- var i = 0;
- do_check_eq(data[i], stmt.getString(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getString(i++));
- do_check_eq(data[i], stmt.getInt64(i++));
- do_check_eq(data[i], stmt.getInt64(i++));
- do_check_eq(data[i], stmt.getInt32(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getInt64(i++));
- do_check_eq(data[i], stmt.getInt64(i++));
- do_check_eq(data[i], stmt.getIsNull(i++));
- do_check_eq(data[i], stmt.getIsNull(i++));
- do_check_eq(data[i], stmt.getInt32(i++));
-
- stmt.reset();
- stmt.finalize();
-
- cleanup();
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/schema_migration/test_migration_to_8.js
+++ /dev/null
@@ -1,72 +0,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/. */
-
-function run_test()
-{
- // We're testing migration to this version from one version below
- var targetVersion = 8;
-
- // First import the downloads.sqlite file
- importDatabaseFile("v" + (targetVersion - 1) + ".sqlite");
-
- // Init the download manager which will try migrating to the new version
- var dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- var dbConn = dm.DBConnection;
-
- // Check schema version
- do_check_true(dbConn.schemaVersion >= targetVersion);
-
- // Make sure all the columns are there
- var stmt = dbConn.createStatement(
- "SELECT name, source, target, tempPath, startTime, endTime, state, " +
- "referrer, entityID, currBytes, maxBytes, mimeType, " +
- "preferredApplication, preferredAction, autoResume " +
- "FROM moz_downloads " +
- "WHERE id = 28");
- stmt.executeStep();
-
- // This data is based on the original values in the table
- var data = [
- "firefox-3.0a9pre.en-US.linux-i686.tar.bz2",
- "http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/firefox-3.0a9pre.en-US.linux-i686.tar.bz2",
- "file:///Users/Ed/Desktop/firefox-3.0a9pre.en-US.linux-i686.tar.bz2",
- "/Users/Ed/Desktop/+EZWafFQ.bz2.part",
- 1192469856209164,
- 1192469877017396,
- Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
- "http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/",
- "%2210e66c1-8a2d6b-9b33f380%22/9055595/Mon, 15 Oct 2007 11:45:34 GMT",
- 1210772,
- 9055595,
- "application/x-bzip2",
- "AAAAAAGqAAIAAQxNYWNpbnRvc2ggSEQAAAAAAAAAAAAAAAAAAAC+91IESCsAAAAHc5UUU3R1ZmZJdCBFeHBhbmRlci5hcHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAdzmb3SGI8AAAAAAAAAAP////8AAAkgAAAAAAAAAAAAAAAAAAAAFFN0dWZmSXQgU3RhbmRhcmQgOS4wABAACAAAvveYVAAAABEACAAAvdJs7wAAAAEACAAHc5UAAAAWAAIAQ01hY2ludG9zaCBIRDpBcHBsaWNhdGlvbnM6U3R1ZmZJdCBTdGFuZGFyZCA5LjA6U3R1ZmZJdCBFeHBhbmRlci5hcHAAAA4AKgAUAFMAdAB1AGYAZgBJAHQAIABFAHgAcABhAG4AZABlAHIALgBhAHAAcAAPABoADABNAGEAYwBpAG4AdABvAHMAaAAgAEgARAASADZBcHBsaWNhdGlvbnMvU3R1ZmZJdCBTdGFuZGFyZCA5LjAvU3R1ZmZJdCBFeHBhbmRlci5hcHAAEwABLwD//wAA",
- 2,
- // For the new columns added, check for null or default values
- 0,
- ];
-
- // Make sure the values are correct after the migration
- var i = 0;
- do_check_eq(data[i], stmt.getString(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getString(i++));
- do_check_eq(data[i], stmt.getInt64(i++));
- do_check_eq(data[i], stmt.getInt64(i++));
- do_check_eq(data[i], stmt.getInt32(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getInt64(i++));
- do_check_eq(data[i], stmt.getInt64(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getInt32(i++));
- do_check_eq(data[i], stmt.getInt32(i++));
-
- stmt.reset();
- stmt.finalize();
-
- cleanup();
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/schema_migration/test_migration_to_9.js
+++ /dev/null
@@ -1,74 +0,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/. */
-
-function run_test()
-{
- // We're testing migration to this version from one version below
- var targetVersion = 9;
-
- // First import the downloads.sqlite file
- importDatabaseFile("v" + (targetVersion - 1) + ".sqlite");
-
- // Init the download manager which will try migrating to the new version
- var dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- var dbConn = dm.DBConnection;
-
- // Check schema version
- do_check_true(dbConn.schemaVersion >= targetVersion);
-
- // Make sure all the columns are there
- var stmt = dbConn.createStatement(
- "SELECT name, source, target, tempPath, startTime, endTime, state, " +
- "referrer, entityID, currBytes, maxBytes, mimeType, " +
- "preferredApplication, preferredAction, autoResume, guid " +
- "FROM moz_downloads " +
- "WHERE id = 28");
- stmt.executeStep();
-
- // This data is based on the original values in the table
- var data = [
- "firefox-3.0a9pre.en-US.linux-i686.tar.bz2",
- "http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/firefox-3.0a9pre.en-US.linux-i686.tar.bz2",
- "file:///Users/Ed/Desktop/firefox-3.0a9pre.en-US.linux-i686.tar.bz2",
- "/Users/Ed/Desktop/+EZWafFQ.bz2.part",
- 1192469856209164,
- 1192469877017396,
- Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
- "http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/",
- "%2210e66c1-8a2d6b-9b33f380%22/9055595/Mon, 15 Oct 2007 11:45:34 GMT",
- 1210772,
- 9055595,
- "application/x-bzip2",
- "AAAAAAGqAAIAAQxNYWNpbnRvc2ggSEQAAAAAAAAAAAAAAAAAAAC+91IESCsAAAAHc5UUU3R1ZmZJdCBFeHBhbmRlci5hcHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAdzmb3SGI8AAAAAAAAAAP////8AAAkgAAAAAAAAAAAAAAAAAAAAFFN0dWZmSXQgU3RhbmRhcmQgOS4wABAACAAAvveYVAAAABEACAAAvdJs7wAAAAEACAAHc5UAAAAWAAIAQ01hY2ludG9zaCBIRDpBcHBsaWNhdGlvbnM6U3R1ZmZJdCBTdGFuZGFyZCA5LjA6U3R1ZmZJdCBFeHBhbmRlci5hcHAAAA4AKgAUAFMAdAB1AGYAZgBJAHQAIABFAHgAcABhAG4AZABlAHIALgBhAHAAcAAPABoADABNAGEAYwBpAG4AdABvAHMAaAAgAEgARAASADZBcHBsaWNhdGlvbnMvU3R1ZmZJdCBTdGFuZGFyZCA5LjAvU3R1ZmZJdCBFeHBhbmRlci5hcHAAEwABLwD//wAA",
- 2,
- 0,
- // For the new columns added, check that default values are sensible
- 'ignored-value'
- ];
-
- // Make sure the values are correct after the migration
- var i = 0;
- do_check_eq(data[i], stmt.getString(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getString(i++));
- do_check_eq(data[i], stmt.getInt64(i++));
- do_check_eq(data[i], stmt.getInt64(i++));
- do_check_eq(data[i], stmt.getInt32(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getInt64(i++));
- do_check_eq(data[i], stmt.getInt64(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getUTF8String(i++));
- do_check_eq(data[i], stmt.getInt32(i++));
- do_check_eq(data[i], stmt.getInt32(i++));
- do_check_true(/^[a-zA-Z0-9\-_]{12}$/.test(stmt.getString(i++)));
-
- stmt.reset();
- stmt.finalize();
-
- cleanup();
-}
deleted file mode 100644
index 4c28fdf22c5038d202a9c6b43906459b86832eee..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 4b4d615362182d249b8ee37b457f3314402f3e76..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 9924dbe31b401bfbbf25bf6003acdf26a13692c7..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index ae5798ae230b2406d0bd0d0b96b410e40bb2b4b6..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 1e5454d95b279ef9336889c0c253c5a5bc86bd30..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 099389b5cd7fc956bd030471bee0ca375f06cc47..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 33f474e92cdded3f2a41f74bdb23cc30f06ba223..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 7d3f8f76d848ea3c23ba9725ece703082a399dca..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
--- a/toolkit/components/downloads/test/schema_migration/xpcshell.ini
+++ /dev/null
@@ -1,21 +0,0 @@
-[DEFAULT]
-head = head_migration.js
-tail =
-support-files =
- v1.sqlite
- v2.sqlite
- v3.sqlite
- v4.sqlite
- v5.sqlite
- v6.sqlite
- v7.sqlite
- v8.sqlite
-
-[test_migration_to_2.js]
-[test_migration_to_3.js]
-[test_migration_to_4.js]
-[test_migration_to_5.js]
-[test_migration_to_6.js]
-[test_migration_to_7.js]
-[test_migration_to_8.js]
-[test_migration_to_9.js]
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/downloads_manifest.js
+++ /dev/null
@@ -1,22 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ */
-
-// Shared functions for files testing Bug 593815
-
-Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-
-function HelperAppDlg() { }
-HelperAppDlg.prototype = {
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIHelperAppLauncherDialog]),
- classID: Components.ID("49456eda-4dc4-4d1a-b8e8-0b94749bf99e"),
- show: function (launcher, ctx, reason) {
- launcher.MIMEInfo.preferredAction = Ci.nsIMIMEInfo.saveToDisk;
- launcher.launchWithApplication(null, false);
- }
-}
-
-
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([HelperAppDlg]);
--- a/toolkit/components/downloads/test/unit/head_download_manager.js
+++ b/toolkit/components/downloads/test/unit/head_download_manager.js
@@ -9,163 +9,18 @@ var Ci = Components.interfaces;
var Cu = Components.utils;
var Cr = Components.results;
do_get_profile();
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://testing-common/httpd.js");
-Cu.import("resource://gre/modules/PlacesUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
- "resource://testing-common/PlacesTestUtils.jsm");
-
-var downloadUtils = { };
-XPCOMUtils.defineLazyServiceGetter(downloadUtils,
- "downloadManager",
- "@mozilla.org/download-manager;1",
- Ci.nsIDownloadManager);
function createURI(aObj)
{
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
return (aObj instanceof Ci.nsIFile) ? ios.newFileURI(aObj) :
ios.newURI(aObj, null, null);
}
-
-var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties);
-
-var provider = {
- getFile: function(prop, persistent) {
- persistent.value = true;
- if (prop == "DLoads") {
- var file = dirSvc.get("ProfD", Ci.nsILocalFile);
- file.append("downloads.rdf");
- return file;
- }
- print("*** Throwing trying to get " + prop);
- throw Cr.NS_ERROR_FAILURE;
- },
- QueryInterface: function(iid) {
- if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
- iid.equals(Ci.nsISupports)) {
- return this;
- }
- throw Cr.NS_ERROR_NO_INTERFACE;
- }
-};
-dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
-
-var gDownloadCount = 0;
-/**
- * Adds a download to the DM, and starts it.
- * @param server: a HttpServer used to serve the sourceURI
- * @param aParams (optional): an optional object which contains the function
- * parameters:
- * resultFileName: leaf node for the target file
- * targetFile: nsIFile for the target (overrides resultFileName)
- * sourceURI: the download source URI
- * downloadName: the display name of the download
- * runBeforeStart: a function to run before starting the download
- * isPrivate: whether the download is private or not
- */
-function addDownload(server, aParams)
-{
- if (!server)
- do_throw("Must provide a valid server.");
- const PORT = server.identity.primaryPort;
- if (!aParams)
- aParams = {};
- if (!("resultFileName" in aParams))
- aParams.resultFileName = "download.result";
- if (!("targetFile" in aParams)) {
- aParams.targetFile = dirSvc.get("ProfD", Ci.nsIFile);
- aParams.targetFile.append(aParams.resultFileName);
- }
- if (!("sourceURI" in aParams))
- aParams.sourceURI = "http://localhost:" + PORT + "/head_download_manager.js";
- if (!("downloadName" in aParams))
- aParams.downloadName = null;
- if (!("runBeforeStart" in aParams))
- aParams.runBeforeStart = function () {};
-
- const nsIWBP = Ci.nsIWebBrowserPersist;
- var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
- .createInstance(Ci.nsIWebBrowserPersist);
- persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
- nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
- nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
-
- // it is part of the active downloads the moment addDownload is called
- gDownloadCount++;
-
- let dm = downloadUtils.downloadManager;
- var dl = dm.addDownload(Ci.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOAD,
- createURI(aParams.sourceURI),
- createURI(aParams.targetFile), aParams.downloadName, null,
- Math.round(Date.now() * 1000), null, persist, aParams.isPrivate);
-
- // This will throw if it isn't found, and that would mean test failure, so no
- // try catch block
- if (!aParams.isPrivate)
- var test = dm.getDownload(dl.id);
-
- aParams.runBeforeStart.call(undefined, dl);
-
- persist.progressListener = dl.QueryInterface(Ci.nsIWebProgressListener);
- persist.savePrivacyAwareURI(dl.source, null, null, 0, null, null, dl.targetFile,
- aParams.isPrivate);
-
- return dl;
-}
-
-function getDownloadListener()
-{
- return {
- onDownloadStateChange: function(aState, aDownload)
- {
- if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_QUEUED)
- do_test_pending();
-
- if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED ||
- aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_CANCELED ||
- aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_FAILED) {
- gDownloadCount--;
- do_test_finished();
- }
-
- if (gDownloadCount == 0 && typeof httpserv != "undefined" && httpserv)
- {
- do_test_pending();
- httpserv.stop(do_test_finished);
- }
- },
- onStateChange: function(a, b, c, d, e) { },
- onProgressChange: function(a, b, c, d, e, f, g) { },
- onSecurityChange: function(a, b, c, d) { }
- };
-}
-
-XPCOMUtils.defineLazyGetter(this, "Services", function() {
- Cu.import("resource://gre/modules/Services.jsm");
- return Services;
-});
-
-// Disable alert service notifications
-Services.prefs.setBoolPref("browser.download.manager.showAlertOnComplete", false);
-
-do_register_cleanup(function() {
- Services.obs.notifyObservers(null, "quit-application", null);
-});
-
-function oldDownloadManagerDisabled() {
- try {
- // This method throws an exception if the old Download Manager is disabled.
- Services.downloads.activeDownloadCount;
- } catch (ex) {
- return true;
- }
- return false;
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_bug_382825.js
+++ /dev/null
@@ -1,54 +0,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/. */
-
-// This tests the retryDownload function of nsIDownloadManager. This function
-// was added in Bug 382825.
-
-const nsIDownloadManager = Ci.nsIDownloadManager;
-const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
-
-function test_retry_canceled()
-{
- var dl = addDownload(httpserv);
-
- // since we are going to be retrying a failed download, we need to inflate
- // this so it doesn't stop our server
- gDownloadCount++;
-
- dm.cancelDownload(dl.id);
-
- do_check_eq(nsIDownloadManager.DOWNLOAD_CANCELED, dl.state);
-
- // Our download object will no longer be updated.
- dm.retryDownload(dl.id);
-}
-
-function test_retry_bad()
-{
- try {
- dm.retryDownload(0);
- do_throw("Hey! We expect to get an exception with this!");
- } catch(e) {
- do_check_eq(Components.lastResult, Cr.NS_ERROR_NOT_AVAILABLE);
- }
-}
-
-var tests = [test_retry_canceled, test_retry_bad];
-
-var httpserv = null;
-function run_test()
-{
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- httpserv = new HttpServer();
- httpserv.registerDirectory("/", do_get_cwd());
- httpserv.start(-1);
-
- dm.addListener(getDownloadListener());
-
- for (var i = 0; i < tests.length; i++)
- tests[i]();
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_bug_384744.js
+++ /dev/null
@@ -1,17 +0,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/. */
-
-// This file tests Bug 384744 - or specifically that createInstance won't cause
-// a failure with the download manager. The old practice was bad because if
-// someone called createInstance before anyone called getService, getService
-// would fail, and we would have a non-functional download manager.
-
-function run_test()
-{
- var dmci = Cc["@mozilla.org/download-manager;1"].
- createInstance(Ci.nsIDownloadManager);
- var dmgs = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- do_check_eq(dmci, dmgs);
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_bug_395092.js
+++ /dev/null
@@ -1,68 +0,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/. */
-
-// This file tests Bug 395092 - specifically that dl-start event isn't
-// dispatched for resumed downloads.
-
-const nsIDownloadManager = Ci.nsIDownloadManager;
-const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
-
-var observer = {
- mCount: 0,
- id: 0,
- observe: function observe(aSubject, aTopic, aData)
- {
- print("observering " + aTopic);
- if ("dl-start" == aTopic) {
- var dl = aSubject.QueryInterface(Ci.nsIDownload);
- this.id = dl.id;
- dm.pauseDownload(this.id);
- this.mCount++;
- do_check_eq(1, this.mCount);
- } else if ("timer-callback" == aTopic) {
- dm.resumeDownload(this.id);
- }
- }
-};
-
-var httpserv = null;
-var timer = null;
-function run_test()
-{
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- httpserv = new HttpServer();
- httpserv.registerDirectory("/", do_get_cwd());
- httpserv.start(-1);
-
- // our download listener
- var listener = {
- onDownloadStateChange: function(aOldState, aDownload)
- {
- if (Ci.nsIDownloadManager.DOWNLOAD_PAUSED == aDownload.state) {
- // This is so hacky, but it let's the nsWebBrowserPersist catch up with
- // the script...
- timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
- timer.init(observer, 0, Ci.nsITimer.TYPE_ONE_SHOT);
- }
-
- if (Ci.nsIDownloadManager.DOWNLOAD_FINISHED == aDownload.state)
- do_test_finished();
- },
- onStateChange: function(a, b, c, d, e) { },
- onProgressChange: function(a, b, c, d, e, f, g) { },
- onSecurityChange: function(a, b, c, d) { }
- };
- dm.addListener(listener);
- dm.addListener(getDownloadListener());
-
- var os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- os.addObserver(observer, "dl-start", false);
-
- addDownload(httpserv);
- do_test_pending();
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_bug_401430.js
+++ /dev/null
@@ -1,117 +0,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/. */
-
-// This tests the "add to recent documents" functionality of the DM
-
-const nsIDownloadManager = Ci.nsIDownloadManager;
-const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
-
-// Make sure Unicode is supported:
-// U+00E3 : LATIN SMALL LETTER A WITH TILDE
-// U+041B : CYRILLIC CAPITAL LETTER EL
-// U+3056 : HIRAGANA LETTER ZA
-const resultFileName = "test\u00e3\u041b\u3056" + Date.now() + ".doc";
-
-// Milliseconds between polls.
-const POLL_REGISTRY_TIMEOUT = 200;
-// Max number of polls.
-const POLL_REGISTRY_MAX_LOOPS = 25;
-
-function checkResult() {
- // delete the saved file (this doesn't affect the "recent documents" list)
- var resultFile = do_get_file(resultFileName);
- resultFile.remove(false);
-
- // Need to poll RecentDocs value because the SHAddToRecentDocs call
- // doesn't update the registry immediately.
- do_timeout(POLL_REGISTRY_TIMEOUT, pollRecentDocs);
-}
-
-var gPollsCount = 0;
-function pollRecentDocs() {
- if (++gPollsCount > POLL_REGISTRY_MAX_LOOPS) {
- do_throw("Maximum time elapsed while polling RecentDocs.");
- do_test_finished();
- return;
- }
-
- if (checkRecentDocsFor(resultFileName)) {
- print("Document found in RecentDocs");
- do_test_finished();
- }
- else
- do_timeout(POLL_REGISTRY_TIMEOUT, pollRecentDocs);
-}
-
-function checkRecentDocsFor(aFileName) {
- var recentDocsKey = Cc["@mozilla.org/windows-registry-key;1"].
- createInstance(Ci.nsIWindowsRegKey);
- var recentDocsPath =
- "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RecentDocs";
- recentDocsKey.open(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
- recentDocsPath,
- Ci.nsIWindowsRegKey.ACCESS_READ);
- var count = recentDocsKey.valueCount;
- for (var i = 0; i < count; ++i) {
- var valueName = recentDocsKey.getValueName(i);
- var binValue = recentDocsKey.readBinaryValue(valueName);
-
- // "fields" in the data are separated by \0 wide characters, which are
- // returned as two \0 "bytes" by readBinaryValue. Use only the first field.
- var fileNameRaw = binValue.split("\0\0")[0];
-
- // Convert the filename from UTF-16LE.
- var fileName = "";
- for (var c = 0; c < fileNameRaw.length; c += 2)
- fileName += String.fromCharCode(fileNameRaw.charCodeAt(c) |
- fileNameRaw.charCodeAt(c+1) * 256);
-
- if (aFileName == fileName)
- return true;
- }
- return false;
-}
-
-var httpserv = null;
-function run_test()
-{
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- // This test functionality only implemented on Windows.
- // Is there a better way of doing this?
- var httpPH = Cc["@mozilla.org/network/protocol;1?name=http"].
- getService(Ci.nsIHttpProtocolHandler);
- if (httpPH.platform != "Windows")
- return;
-
- // Don't finish until the download is finished
- do_test_pending();
-
- httpserv = new HttpServer();
- httpserv.registerDirectory("/", do_get_cwd());
- httpserv.start(-1);
-
- var listener = {
- onDownloadStateChange: function test_401430_odsc(aState, aDownload) {
- if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED) {
- checkResult();
- }
- },
- onStateChange: function(a, b, c, d, e) { },
- onProgressChange: function(a, b, c, d, e, f, g) { },
- onSecurityChange: function(a, b, c, d) { }
- };
-
- dm.addListener(listener);
- dm.addListener(getDownloadListener());
-
- // need to save the file to the CWD, because the profile dir is in $TEMP,
- // and Windows apparently doesn't like putting things from $TEMP into
- // the recent files list.
- var dl = addDownload(httpserv,
- {resultFileName: resultFileName,
- targetFile: do_get_file(resultFileName, true)});
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_bug_406857.js
+++ /dev/null
@@ -1,78 +0,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 406857 to make sure a download's referrer doesn't disappear when
- * retrying the download.
- */
-
-function run_test()
-{
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- let db = dm.DBConnection;
- var httpserv = new HttpServer();
- httpserv.start(-1);
-
- let stmt = db.createStatement(
- "INSERT INTO moz_downloads (source, target, state, referrer) " +
- "VALUES (?1, ?2, ?3, ?4)");
-
- // Download from the test http server
- stmt.bindByIndex(0, "http://localhost:"+ httpserv.identity.primaryPort +
- "/httpd.js");
-
- // Download to a temp local file
- let file = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
- file.append("retry");
- file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o666);
- stmt.bindByIndex(1, Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService).newFileURI(file).spec);
-
- // Start it as canceled
- stmt.bindByIndex(2, dm.DOWNLOAD_CANCELED);
-
- // Add a referrer to make sure it doesn't disappear
- let referrer = "http://referrer.goes/here";
- stmt.bindByIndex(3, referrer);
-
- // Add it!
- stmt.execute();
- stmt.finalize();
-
- let listener = {
- onDownloadStateChange: function(aState, aDownload)
- {
- switch (aDownload.state) {
- case dm.DOWNLOAD_DOWNLOADING:
- do_check_eq(aDownload.referrer.spec, referrer);
- break;
- case dm.DOWNLOAD_FINISHED:
- do_check_eq(aDownload.referrer.spec, referrer);
-
- dm.removeListener(listener);
- try { file.remove(false); } catch(e) { /* stupid windows box */ }
- httpserv.stop(do_test_finished);
- break;
- case dm.DOWNLOAD_FAILED:
- case dm.DOWNLOAD_CANCELED:
- httpserv.stop(function () {});
- do_throw("Unexpected download state change received, state: " +
- aDownload.state);
- break;
- }
- }
- };
- dm.addListener(listener);
-
- // Retry the download, and wait.
- dm.retryDownload(1);
-
- do_test_pending();
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_bug_420230.js
+++ /dev/null
@@ -1,79 +0,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/. */
-
-// This tests data uri downloading of the DM in relation to the new security policy
-// checks put in place on windows. (bug 416683)
-
-const nsIDownloadManager = Ci.nsIDownloadManager;
-const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
-
-function run_test()
-{
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- // Don't finish until the download is finished
- do_test_pending();
-
- function addDownload() {
- const nsIWBP = Ci.nsIWebBrowserPersist;
- var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
- .createInstance(Ci.nsIWebBrowserPersist);
- persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
- nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
- nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
-
- // Download to a temp local file
- let file = dirSvc.get("ProfD", Ci.nsIFile);
- file.append("policychecktest.png");
- if (file.exists())
- file.remove(false);
- file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o666);
-
- gDownloadCount++;
-
- var dl = dm.addDownload(Ci.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOAD,
- createURI("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACGFjVEwAAAAEAAAAAHzNZtAAAAAaZmNUTAAAAAAAAAAQAAAAEAAAAAAAAAAAAPoD6AEBim0EngAAAfVJREFUOI2tke9LEwEYx/0vwwgpRKLoTRC+iAhXSFJYYEERbZjd1N1+5I+dW+laeh1rmkKzbbftpuvWvN020aSs5t0+vVgO5hy98QvfNw/P9/N94OnpOUvp1UO8sSrCSpmX0RL+mMHCeoUP6V0S29/JlX6g6vt0BQTiVRLf6qimTdq0SZdtFiIKzukgvvlFBHGWKWm1E3Cy2bVU5Pmbr4iSwtjrT8jqDr+A1S0TlxiiVqvx3+ZU2WbcM8dUvERuD5ImpHYhlDAIhRfbARPvd1BNm0yladW0SRoWLsHHhgnZGpQPoPoT0nvgFPztAOdSkYxpoZoWXwyLzZJFomQxLnhYzu5hHsJvCw5siCQN3O7JdsCzcIFMpRmKbdWRtTqK9gePL4gwG0XVKxwBa7kST168wjCMdsDjeY1Nw0LJH7GSa9o7JyOKPgZvDuH1z+CenMI14WFsWu78wsOAymrBaoVFKY5e0Bm4eh1Zs5A1i8ujEeR8g77hcCdgxJNEyTcXRX8IfVvn4sA13qUOkTUbWbPpv7+InG/Q65A6AXeFz63Fj8tLDDpGcc6s/Zs1Ws2TcoX+e6dccGt8vQU4Dpx0r0PigiOIkih2AoYm1gms7Z8alPON7s3H2sia3HiqcOVRlIEHES6NvKVvOMz5OxLnbs93bz4L/QVUgSoBF8urgQAAABpmY1RMAAAAAQAAAA8AAAAQAAAAAQAAAAAA+gPoAQGATZxOAAAB82ZkQVQAAAACKJGt0OFLE3Ecx3H/yzBCChlR9CQIH0SEKyQpTLCgiDbWum3u3Eydc6u5ll6HqU1otu3cbmpn5+22iSa1Su/27sFyYzJ8Ul/4PPnxefGBX0/P/zqtWmdiqYqwWOZFSie8ZDCXrvA+v0dm6xtF/TuKdkBXPLlcJfP1CMW0yZs2+bLNXFLGNT5LKJJAEKcJRFc4c9E9v8Oz118QozJjrz4iKbv8BFY2TdxijFqtxpmLubKNJzhDYFmnuA9ZE3J7EMsYxOKJNva+20UxbTYqzSimTdawcAsh1kwo1KB8CNUfkN8HlxBuY9f8DhumhWJafDYs1nWLjG7hEYIsFPYx6/DLgkMbklkDn8/fxk/j22xUmmBp8whJPUJWfxMMzSJMp1C0CsfAalHn8fOXGIbRxo8iKuuGhVw6ZrHYzMSMhCiGGLg5yER4Cp8/gNsbZGxc6vzth5MKK9tWC4rRZbRtDcfV60iqhaRaXB5JIpUa9A3FO/FwMItcapbEcAxtS+Oi4xpvc3Uk1UZSbfrvJ5BKDXqd0U58V/jUKn1YmGfAOYJravXvW6O16Jcq9N87tXzLk27hk/Lp9DqjXHDOImd2OvGgN83k6kFXJJUa3RdPbq1gcuOJzJXRFI4HSS4Nv6FvKM75O1HO3Y50X/zX+wPZgSoB2RWdYAAAABpmY1RMAAAAAwAAAA8AAAAPAAAAAQAAAAEA+gPoAQHbRhjBAAAB9GZkQVQAAAAEKJGt0P9LE3Ecx/H9l2GEFDKi6Jcg/CEiXCFJYYEFRbSx1vll52bqNrdyy/TTYbomNNt2upva2Xm7baJJWendnv2w3JgMf+oNr18+vB684ONy/a/Tq4eML1aRFsq8nDMIL5rMZCp8KOyS3fxO0fiBqu/TEU8sVcl+O0K1HAqWQ6HsMJNS8I5FCUVmkeQpRmPLnLnoS27z/M1X5JjC0OtPCHWHX8DyhoVPjlOr1ThzMV928AenGV0yKO5BzoL8LsSzJvHEbAsH3u+gWg5rlUZUyyFn2vikECsWrNegfADVn1DYA68UbmFvcps1y0a1bL6YNquGTdaw8UtB5tf3sA7htw0HDqRyJsPDIy38LLHFWqUBFjeOENoRivaHYCiKNDWHqlc4BtJFgycvXmGaZgs/jmismjZK6ZiFYiPj0wJZDtF7s4/x8CTDI6P4AkGGxkT7bz+cUFnesptQji2hb+m4r15HaDZCs7k8mEKU6nT3J9rxQDCHUmqU5HAcfVPnovsa7/KHCM1BaA4992cRpTpdnlg7vit9bpY+zifp9QzinUz/e6s3F0dEhZ57p5Zv+TNNfFI+nS5PjAueKEp2ux33BTJMpPc7IlGqd148uZV1ixtPFa48msP9IMWlgbd09yc4fyfGuduRzosul+sv1q4qAfNb7esAAAAaZmNUTAAAAAUAAAAQAAAADwAAAAAAAAABAPoD6AEBp98YvwAAAflmZEFUAAAABiiRrZHhSxNxGMf3X4YRUohE0ZsgfBERrpCkMMGCItqwdZvu3Ezdzq3cWnodpqbQbNvN3dTOztttE01qld7t04vlYM7Rmx74vvnxfD+fB34u1/8cvVJjYrGCsFDiRcogvGgyu1rmfW6P9NY3CsZ3VP2AjoDJpQrpr0eolkPOcsiVHGaTCp7xKKHIHII4zZi03A44bfYmdnj2+guipDDy6iOyustPYHnTwivGqFar/NOcLTmMBmcYWzIo7EPGguwexNImsfhcK8D3bhfVcsiXG1Eth4xp4xVCrFmwUYXSIVR+QG4fPEK4FeBJ7JC3bFTL5rNps27YpA2bUSHI/MY+Vg1+2XDoQDJj4vcHWgFP49vky43S4uYRsnaEov0mGIoiTKdQ9TLHwErB4PHzl5im2Qp4FNFYN22U4jELhUYmZmREMUTfzX4mwlP4A2N4fUFGxuX2X3g4qbK8bTfLorSEvq3Te/U6smYjazaXh5LIxTrdA/F2wGAwg1JsLIrhGPqWzsXea7zN1pA1B1lz6Lk/h1ys0+WW2gF3hU/NxQ/zCfrcQ3imVv6+1ZvmgFym594ZF9waXW0CTgqn0+WWuOCOoqR32gH9vlUmVw7OLMrFemfzyaxtWNx4onBlOEXvgySXBt/QPRDn/B2Jc7cjnc0ul+sPqZsqAeXgvCsAAAAASUVORK5CYII="),
- createURI(file), 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;
- }
-
- let listener = {
- onDownloadStateChange: function(aState, aDownload)
- {
- switch (aDownload.state) {
- case dm.DOWNLOAD_FAILED:
- case dm.DOWNLOAD_CANCELED:
- case dm.DOWNLOAD_DIRTY:
- case dm.DOWNLOAD_BLOCKED_POLICY:
- // Fail!
- if (aDownload.targetFile.exists())
- aDownload.targetFile.remove(false);
- dm.removeListener(this);
- do_throw("data: uri failed to download successfully");
- do_test_finished();
- break;
-
- case dm.DOWNLOAD_FINISHED:
- do_check_true(aDownload.targetFile.exists());
- aDownload.targetFile.remove(false);
- dm.removeListener(this);
- do_test_finished();
- break;
- }
- },
- onStateChange: function(a, b, c, d, e) { }
- };
-
- dm.addListener(listener);
- dm.addListener(getDownloadListener());
-
- addDownload();
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_cancel_download_files_removed.js
+++ /dev/null
@@ -1,147 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ */
-
-// This file tests Bug 593815 - specifically that downloaded files
-// are cleaned up correctly when a download is cancelled
-
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("resource://gre/modules/NetUtil.jsm");
-do_load_manifest("test_downloads.manifest");
-
-var httpserver = null;
-var currentTest = 0;
-
-function WindowContext() { }
-WindowContext.prototype = {
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIInterfaceRequestor]),
- getInterface: XPCOMUtils.generateQI([Ci.nsIURIContentListener,
- Ci.nsILoadGroup]),
-
- /* nsIURIContentListener */
- onStartURIOpen: function (uri) { },
- isPreferred: function (type, desiredtype) { return false; },
-
- /* nsILoadGroup */
- addRequest: function (request, context) { },
- removeRequest: function (request, context, status) { }
-};
-
-var DownloadListener = {
- set : null,
- init: function () {
- Services.obs.addObserver(this, "dl-start", true);
- Services.obs.addObserver(this, "dl-done", true);
- Services.obs.addObserver(this, "dl-cancel", true);
- Services.obs.addObserver(this, "dl-fail", true);
- },
-
- // check that relevant cancel operations have been performed
- // currently this just means removing the target file
- onCancel: function(aSubject, aTopic, aData) {
- let dl = aSubject.QueryInterface(Ci.nsIDownload);
- do_check_false(dl.targetFile.exists());
- runNextTest();
- },
-
- observe: function (aSubject, aTopic, aData) {
- switch(aTopic) {
- case "dl-start" :
- // cancel, pause, or resume the download
- // depending on parameters in this.set
- let dl = aSubject.QueryInterface(Ci.nsIDownload);
-
- if (this.set.doPause) {
- downloadUtils.downloadManager.pauseDownload(dl.id);
- }
-
- if (this.set.doResume) {
- downloadUtils.downloadManager.resumeDownload(dl.id);
- }
-
- downloadUtils.downloadManager.cancelDownload(dl.id);
- break;
- case "dl-cancel" :
- this.onCancel(aSubject, aTopic, aData);
- break;
- case "dl-fail" :
- do_throw("Download failed");
- break;
- case "dl-done" :
- do_throw("Download finished");
- break;
- }
- },
-
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
- Ci.nsISupportsWeakReference])
-}
-
-// loads the uri given in tests[currentTest]
-// finishes tests if there are no more test files listed
-function runNextTest()
-{
- if (currentTest == tests.length) {
- httpserver.stop(do_test_finished);
- return;
- }
-
- let set = DownloadListener.set = tests[currentTest];
- currentTest++;
- let uri = "http://localhost:" +
- httpserver.identity.primaryPort +
- set.serverPath;
- let channel = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
- let uriloader = Cc["@mozilla.org/uriloader;1"].getService(Ci.nsIURILoader);
- uriloader.openURI(channel, Ci.nsIURILoader.IS_CONTENT_PREFERRED,
- new WindowContext());
-}
-
-// sends the responses for the files. sends the same content twice if we resume
-// the download
-function getResponse(aSet) {
- return function(aMetadata, aResponse) {
- aResponse.setHeader("Content-Type", "text/plain", false);
- if (aMetadata.hasHeader("Range")) {
- var matches = aMetadata.getHeader("Range").match(/^\s*bytes=(\d+)?-(\d+)?\s*$/);
- aResponse.setStatusLine(aMetadata.httpVersion, 206, "Partial Content");
- aResponse.bodyOutputStream.write(aSet.data, aSet.data.length);
- return;
- }
- aResponse.setHeader("Accept-Ranges", "bytes", false);
- aResponse.setHeader("Content-Disposition", "attachment; filename=test.txt;", false);
- aResponse.bodyOutputStream.write(aSet.data, aSet.data.length);
- }
-}
-
-// files to be downloaded. For these tests, files will be cancelled either:
-// 1.) during the download
-// 2.) while they are paused
-// 3.) after they have been resumed
-var tests = [
- { serverPath: "/test1.html", data: "Test data 1" },
- { serverPath: "/test2.html", data: "Test data 2", doPause: true },
- { serverPath: "/test3.html", data: "Test data 3", doPause: true, doResume: true},
-];
-
-function run_test() {
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- // setup a download listener to run tests during and after the download
- DownloadListener.init();
- Services.prefs.setBoolPref("browser.download.manager.showWhenStarting", false);
-
- httpserver = new HttpServer();
- httpserver.start(-1);
- do_test_pending();
-
- // setup files to be download, each with the same suggested filename
- // from the server, but with different contents
- for(let i = 0; i < tests.length; i++) {
- let set = tests[i];
- httpserver.registerPathHandler(set.serverPath, getResponse(set));
- }
-
- runNextTest(); // start downloading the first file
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_download_manager.js
+++ /dev/null
@@ -1,135 +0,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/. */
-
-// This file tests the download manager backend
-
-const nsIDownloadManager = Ci.nsIDownloadManager;
-const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
-
-function test_get_download_empty_queue()
-{
- try {
- dm.getDownload(0);
- do_throw("Hey! We expect to get an excpetion with this!");
- } catch(e) {
- do_check_eq(Components.lastResult, Cr.NS_ERROR_NOT_AVAILABLE);
- }
-}
-
-function test_connection()
-{
- print("*** DOWNLOAD MANAGER TEST - test_connection");
- var ds = dm.DBConnection;
-
- do_check_true(ds.connectionReady);
-
- do_check_true(ds.tableExists("moz_downloads"));
-}
-
-function test_count_empty_queue()
-{
- print("*** DOWNLOAD MANAGER TEST - test_count_empty_queue");
- do_check_eq(0, dm.activeDownloadCount);
-
- do_check_false(dm.activeDownloads.hasMoreElements());
-}
-
-function test_canCleanUp_empty_queue()
-{
- print("*** DOWNLOAD MANAGER TEST - test_canCleanUp_empty_queue");
- do_check_false(dm.canCleanUp);
-}
-
-function test_pauseDownload_empty_queue()
-{
- print("*** DOWNLOAD MANAGER TEST - test_pauseDownload_empty_queue");
- try {
- dm.pauseDownload(0);
- do_throw("This should not be reached");
- } catch (e) {
- do_check_eq(Cr.NS_ERROR_FAILURE, e.result);
- }
-}
-
-function test_resumeDownload_empty_queue()
-{
- print("*** DOWNLOAD MANAGER TEST - test_resumeDownload_empty_queue");
- try {
- dm.resumeDownload(0);
- do_throw("This should not be reached");
- } catch (e) {
- do_check_eq(Cr.NS_ERROR_FAILURE, e.result);
- }
-}
-
-function test_addDownload_normal()
-{
- print("*** DOWNLOAD MANAGER TEST - Testing normal download adding");
- addDownload(httpserv);
-}
-
-function test_addDownload_cancel()
-{
- print("*** DOWNLOAD MANAGER TEST - Testing download cancel");
- var dl = addDownload(httpserv);
-
- dm.cancelDownload(dl.id);
-
- do_check_eq(nsIDownloadManager.DOWNLOAD_CANCELED, dl.state);
-}
-
-// This test is actually ran by the observer
-function test_dm_getDownload(aDl)
-{
- // this will get it from the database
- var dl = dm.getDownload(aDl.id);
-
- do_check_eq(aDl.displayName, dl.displayName);
-}
-
-var tests = [test_get_download_empty_queue, test_connection,
- test_count_empty_queue, test_canCleanUp_empty_queue,
- test_pauseDownload_empty_queue, test_resumeDownload_empty_queue,
- test_addDownload_normal, test_addDownload_cancel];
-
-var httpserv = null;
-function run_test()
-{
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- httpserv = new HttpServer();
- httpserv.registerDirectory("/", do_get_cwd());
- httpserv.start(-1);
-
- // our download listener
- var listener = {
- // this listener checks to ensure activeDownloadCount is correct.
- onDownloadStateChange: function(aState, aDownload)
- {
- do_check_eq(gDownloadCount, dm.activeDownloadCount);
- },
- onStateChange: function(a, b, c, d, e) { },
- onProgressChange: function(a, b, c, d, e, f, g) { },
- onSecurityChange: function(a, b, c, d) { }
- };
- dm.addListener(listener);
- dm.addListener(getDownloadListener());
-
- var observer = {
- observe: function(aSubject, aTopic, aData) {
- var dl = aSubject.QueryInterface(Ci.nsIDownload);
- do_check_eq(nsIDownloadManager.DOWNLOAD_CANCELED, dl.state);
- do_check_true(dm.canCleanUp);
- test_dm_getDownload(dl);
- }
- };
- var os = Cc["@mozilla.org/observer-service;1"]
- .getService(Ci.nsIObserverService);
- os.addObserver(observer, "dl-cancel", false);
-
- for (var i = 0; i < tests.length; i++)
- tests[i]();
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_download_samename.js
+++ /dev/null
@@ -1,170 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ */
-
-// This file tests Bug 593815 - specifically that after downloading two files
-// with the same name, the download manager still points to the correct files
-
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("resource://gre/modules/NetUtil.jsm");
-do_load_manifest("test_downloads.manifest");
-
-var httpserver = null;
-var currentTest = 0;
-
-function WindowContext() { }
-WindowContext.prototype = {
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIInterfaceRequestor]),
- getInterface: XPCOMUtils.generateQI([Ci.nsIURIContentListener,
- Ci.nsILoadGroup]),
-
- /* nsIURIContentListener */
- onStartURIOpen: function (uri) { },
- isPreferred: function (type, desiredtype) { return false; },
-
- /* nsILoadGroup */
- addRequest: function (request, context) { },
- removeRequest: function (request, context, status) { }
-};
-
-var DownloadListener = {
- set: null,
- prevFiles : [],
-
- init: function () {
- Services.obs.addObserver(this, "dl-start", true);
- Services.obs.addObserver(this, "dl-done", true);
- },
-
- observe: function (aSubject, aTopic, aData) {
-
- if (aTopic == "dl-start") {
- // pause the download if requested
- if (this.set.doPause) {
- let dl = aSubject.QueryInterface(Ci.nsIDownload);
- // Don't pause immediately, otherwise the external helper app handler
- // won't be able to assign a permanent file name.
- do_execute_soon(function() {
- downloadUtils.downloadManager.pauseDownload(dl.id);
- do_timeout(1000, function() {
- downloadUtils.downloadManager.resumeDownload(dl.id);
- });
- });
- }
- } else if (aTopic == "dl-done") {
- // check that no two files have the same filename in the download manager
- let file = aSubject.QueryInterface(Ci.nsIDownload).targetFile;
- for (let prevFile of this.prevFiles) {
- do_check_neq(file.leafName, prevFile.leafName);
- }
- this.prevFiles.push(file);
-
- // get the contents of the file
- let fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
- fis.init(file, -1, -1, 0);
- var cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
- cstream.init(fis, "UTF-8", 0, 0);
-
- let val = "";
- let str = {};
- let read = 0;
- do {
- read = cstream.readString(0xffffffff, str);
- val += str.value;
- } while (read != 0);
- cstream.close();
-
- // check if the file contents match the expected ones
- if (this.set.doPause) {
- do_check_eq(val, this.set.data + this.set.data); // files that have been paused have the same data twice
- } else {
- do_check_eq(val, this.set.data);
- }
- runNextTest(); // download the next file
- }
- },
-
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
- Ci.nsISupportsWeakReference])
-}
-
-/*
- Each test will download a file from the server.
-*/
-function runNextTest()
-{
- if (currentTest == tests.length) {
- for (var file of DownloadListener.prevFiles) {
- try {
- file.remove(false);
- } catch (ex) {
- try {
- do_report_unexpected_exception(ex, "while removing " + file.path);
- } catch (ex) {
- if (ex != Components.results.NS_ERROR_ABORT)
- throw ex;
- /* swallow */
- }
- }
- }
- httpserver.stop(do_test_finished);
- return;
- }
- let set = DownloadListener.set = tests[currentTest];
- currentTest++;
- let uri = "http://localhost:" +
- httpserver.identity.primaryPort +
- set.serverURL;
- let channel = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
- let uriloader = Cc["@mozilla.org/uriloader;1"].getService(Ci.nsIURILoader);
- uriloader.openURI(channel, Ci.nsIURILoader.IS_CONTENT_PREFERRED,
- new WindowContext());
-}
-
-// sends the responses for the files. sends the same content twice if we resume
-// the download
-function getResponse(aSet) {
- return function(aMetadata, aResponse) {
- aResponse.setHeader("Content-Type", "text/plain", false);
- if (aMetadata.hasHeader("Range")) {
- var matches = aMetadata.getHeader("Range").match(/^\s*bytes=(\d+)?-(\d+)?\s*$/);
- aResponse.setStatusLine(aMetadata.httpVersion, 206, "Partial Content");
- aResponse.bodyOutputStream.write(aSet.data, aSet.data.length);
- return;
- }
- aResponse.setHeader("Accept-Ranges", "bytes", false);
- aResponse.setHeader("Content-Disposition", "attachment; filename=test.txt;", false);
- aResponse.bodyOutputStream.write(aSet.data, aSet.data.length);
- }
-}
-
-// files to be downloaded. All files will have the same suggested filename, but
-// should contain different data. doPause will cause the download to pause and resume
-// itself
-var tests = [
- { serverURL: "/test1.html", data: "Test data 1", doPause: false },
- { serverURL: "/test2.html", data: "Test data 2", doPause: false },
- { serverURL: "/test3.html", data: "Test data 3", doPause: true }
-];
-
-function run_test() {
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- // setup a download listener to run tests after each download finished
- DownloadListener.init();
- Services.prefs.setBoolPref("browser.download.manager.showWhenStarting", false);
-
- httpserver = new HttpServer();
- httpserver.start(-1);
- do_test_pending();
-
- // setup files to be download, each with the same suggested filename
- // from the server, but with different contents
- for(let i = 0; i < tests.length; i++) {
- let set = tests[i];
- httpserver.registerPathHandler(set.serverURL, getResponse(set));
- }
-
- runNextTest(); // start downloading the first file
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_downloads.manifest
+++ /dev/null
@@ -1,2 +0,0 @@
-component 49456eda-4dc4-4d1a-b8e8-0b94749bf99e downloads_manifest.js
-contract @mozilla.org/helperapplauncherdialog;1 49456eda-4dc4-4d1a-b8e8-0b94749bf99e
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_guid.js
+++ /dev/null
@@ -1,32 +0,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/. */
-
-const dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
-
-function run_test()
-{
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- let server = new HttpServer();
- server.start(-1);
- let dl = addDownload(server);
- do_test_pending();
-
- do_print(dl.guid);
- do_check_true(/^[a-zA-Z0-9\-_]{12}$/.test(dl.guid));
-
- dm.getDownloadByGUID(dl.guid, function(status, result) {
- do_check_eq(dl, result, "should get back some download as requested");
- dl.cancel();
-
- dm.getDownloadByGUID("nonexistent", function(status, result) {
- do_check_eq(result, null, "should get back no download");
- do_check_eq(Components.results.NS_ERROR_NOT_AVAILABLE, status,
- "should pass NS_ERROR_NOT_AVAILABLE on failure");
- do_test_finished();
- });
- });
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_history_expiration.js
+++ /dev/null
@@ -1,126 +0,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 251337 to make sure old downloads are expired and removed.
- * Make sure bug 431346 and bug 431597 don't cause crashes when batching.
- */
-
-/**
- * Returns a PRTime in the past usable to add expirable visits.
- *
- * @note Expiration ignores any visit added in the last 7 days, but it's
- * better be safe against DST issues, by going back one day more.
- */
-function getExpirablePRTime() {
- let dateObj = new Date();
- // Normalize to midnight
- dateObj.setHours(0);
- dateObj.setMinutes(0);
- dateObj.setSeconds(0);
- dateObj.setMilliseconds(0);
- dateObj = new Date(dateObj.getTime() - 8 * 86400000);
- return dateObj.getTime() * 1000;
-}
-
-function run_test()
-{
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- run_next_test();
-}
-
-add_task(function* test_execute()
-{
- // Like the code, we check to see if nav-history-service exists
- // (i.e MOZ_PLACES is enabled), so that we don't run this test if it doesn't.
- if (!("@mozilla.org/browser/nav-history-service;1" in Cc))
- return;
-
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- let db = dm.DBConnection;
-
- // Empty any old downloads
- db.executeSimpleSQL("DELETE FROM moz_downloads");
-
- let stmt = db.createStatement(
- "INSERT INTO moz_downloads (id, source, target, state, guid) " +
- "VALUES (?1, ?2, ?3, ?4, ?5)");
-
- let iosvc = Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService);
- let theId = 1337;
- let theURI = iosvc.newURI("http://expireme/please", null, null);
- let theGUID = "a1bcD23eF4g5";
-
- try {
- // Add a download from the URI
- stmt.bindByIndex(0, theId);
- stmt.bindByIndex(1, theURI.spec);
-
- // Give a dummy file name
- let file = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
- file.append("expireTest");
- stmt.bindByIndex(2, Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService).newFileURI(file).spec);
-
- // Give it some state
- stmt.bindByIndex(3, dm.DOWNLOAD_FINISHED);
-
- stmt.bindByIndex(4, theGUID);
-
- // Add it!
- stmt.execute();
- }
- finally {
- stmt.reset();
- stmt.finalize();
- }
-
- // Add an expirable visit to this download.
- yield PlacesTestUtils.addVisits({
- uri: theURI, visitDate: getExpirablePRTime(),
- transition: PlacesUtils.history.TRANSITION_DOWNLOAD
- });
-
- // Get the download manager as history observer and batch expirations
- let histobs = dm.QueryInterface(Ci.nsINavHistoryObserver);
- histobs.onBeginUpdateBatch();
-
- // Look for the removed download notification
- let obs = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const kRemoveTopic = "download-manager-remove-download-guid";
- let testObs = {
- observe: function(aSubject, aTopic, aData) {
- if (aTopic != kRemoveTopic)
- return;
-
- // Make sure the removed/expired download was the one we added
- let id = aSubject.QueryInterface(Ci.nsISupportsCString);
- do_check_eq(id.data, theGUID);
-
- // We're done!
- histobs.onEndUpdateBatch();
- obs.removeObserver(testObs, kRemoveTopic);
- do_test_finished();
- }
- };
- obs.addObserver(testObs, kRemoveTopic, false);
-
- // Set expiration stuff to 0 to make the download expire
- Services.prefs.setIntPref("places.history.expiration.max_pages", 0);
-
- // Force a history expiration.
- let expire = Cc["@mozilla.org/places/expiration;1"].getService(Ci.nsIObserver);
- expire.observe(null, "places-debug-start-expiration", -1);
-
- // Expiration happens on a timeout, about 3.5s after we set the pref
- do_test_pending();
-});
-
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_offline_support.js
+++ /dev/null
@@ -1,159 +0,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 437415 by making sure the download manager responds to offline and
- * online notifications by pausing and resuming downloads.
- */
-
-/**
- * Used to indicate if we should error out or not. See bug 431745 for more
- * details.
- */
-var doNotError = false;
-
-const nsIF = Ci.nsIFile;
-const nsIDM = Ci.nsIDownloadManager;
-const nsIWBP = Ci.nsIWebBrowserPersist;
-const nsIWPL = Ci.nsIWebProgressListener;
-const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDM);
-if (!oldDownloadManagerDisabled()) {
- dm.cleanUp();
-}
-
-function setOnlineState(aOnline)
-{
- // We do not actually set the offline state because that introduces some neat
- // conditions when being called within a listener. We do dispatch the right
- // observer topics though, so this tests just the download manager.
- let topic = aOnline ?
- "network:offline-status-changed" :
- "network:offline-about-to-go-offline";
- let state = aOnline ? "online" : "offline";
- Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService).
- notifyObservers(null, topic, state);
-}
-
-function run_test()
-{
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- /**
- * 1. Create data for http server to send
- */
- // data starts at 10 bytes
- let data = "1234567890";
- // data * 10^4 = 100,000 bytes (actually 101,111 bytes with newline)
- for (let i = 0; i < 4; i++)
- data = [data,data,data,data,data,data,data,data,data,data,"\n"].join("");
-
- /**
- * 2. Start the http server that can handle resume
- */
- let httpserv = new HttpServer();
- let didResumeServer = false;
- httpserv.registerPathHandler("/resume", function(meta, resp) {
- let body = data;
- resp.setHeader("Content-Type", "text/html", false);
- if (meta.hasHeader("Range")) {
- // track that we resumed for testing
- didResumeServer = true;
- // Syntax: bytes=[from]-[to] (we don't support multiple ranges)
- let matches = meta.getHeader("Range").match(/^\s*bytes=(\d+)?-(\d+)?\s*$/);
- let from = (matches[1] === undefined) ? 0 : matches[1];
- let to = (matches[2] === undefined) ? data.length - 1 : matches[2];
- if (from >= data.length) {
- resp.setStatusLine(meta.httpVersion, 416, "Start pos too high");
- resp.setHeader("Content-Range", "*/" + data.length);
- dump("Returning early - from >= data.length. Not an error (bug 431745)\n");
- doNotError = true;
- return;
- }
- body = body.substring(from, to + 1);
- // always respond to successful range requests with 206
- resp.setStatusLine(meta.httpVersion, 206, "Partial Content");
- resp.setHeader("Content-Range", from + "-" + to + "/" + data.length);
- }
- resp.bodyOutputStream.write(body, body.length);
- });
- httpserv.start(-1);
-
- /**
- * 3. Perform various actions for certain download states
- */
- let didPause = false;
- let didResumeDownload = false;
- dm.addListener({
- onDownloadStateChange: function(a, aDl) {
- if (aDl.state == nsIDM.DOWNLOAD_DOWNLOADING && !didPause) {
- /**
- * (1) queued -> downloading = pause the download by going offline
- */
- setOnlineState(false);
- } else if (aDl.state == nsIDM.DOWNLOAD_PAUSED) {
- /**
- * (2) downloading -> paused
- */
- didPause = true;
- } else if (aDl.state == nsIDM.DOWNLOAD_FINISHED) {
- /**
- * (4) downloading (resumed) -> finished = check tests
- */
- // did we pause at all?
- do_check_true(didPause);
- // did we real-resume and not fake-resume?
- do_check_true(didResumeDownload);
- // extra real-resume check for the server
- do_check_true(didResumeServer);
-
- httpserv.stop(do_test_finished);
- aDl.targetFile.remove(false);
- }
- else if (aDl.state == nsIDM.DOWNLOAD_FAILED) {
- // this is only ok if we are not supposed to fail
- do_check_true(doNotError);
- httpserv.stop(do_test_finished);
- }
- },
- onStateChange: function(a, b, aState, d, aDl) {
- if ((aState & nsIWPL.STATE_STOP) && didPause && !didResumeServer &&
- !didResumeDownload) {
- /**
- * (3) paused -> stopped = resume the download by coming online
- */
- setOnlineState(true);
- didResumeDownload = true;
- }
- },
- onProgressChange: function(a, b, c, d, e, f, g) { },
- onSecurityChange: function(a, b, c, d) { }
- });
- dm.addListener(getDownloadListener());
-
- /**
- * 4. Start the download
- */
- let destFile = dirSvc.get("ProfD", nsIF);
- destFile.append("offline_online");
- if (destFile.exists())
- destFile.remove(false);
- let 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;
- let dl = dm.addDownload(nsIDM.DOWNLOAD_TYPE_DOWNLOAD,
- createURI("http://localhost:" +
- httpserv.identity.primaryPort + "/resume"),
- createURI(destFile), null, null,
- Math.round(Date.now() * 1000), null, persist, false);
- persist.progressListener = dl.QueryInterface(nsIWPL);
- persist.saveURI(dl.source, null, null, 0, null, null, dl.targetFile, null);
-
- // Mark as pending, so clear this when we actually finish the download
- do_test_pending();
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_private_resume.js
+++ /dev/null
@@ -1,118 +0,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/. */
-
-// Public request gets times=0 cookie, completes
-// Private request gets times=1 cookie, canceled
-// Private resumed request sends times=1 cookie, completes
-
-function run_test() {
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- // Allow all cookies.
- Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
-
- do_test_pending();
- let httpserv = new HttpServer();
-
- let times = 0;
- httpserv.registerPathHandler("/head_download_manager.js", function (meta, response) {
- response.setHeader("Content-Type", "text/plain", false);
- response.setStatusLine("1.1", !meta.hasHeader('range') ? 200 : 206);
-
- // Set a cookie if none is sent with the request. Public and private requests
- // should therefore receive different cookies, so we can tell if the resumed
- // request is actually treated as private or not.
- if (!meta.hasHeader('Cookie')) {
- do_check_true(times == 0 || times == 1);
- response.setHeader('Set-Cookie', 'times=' + times++);
- } else {
- do_check_eq(times, 2);
- do_check_eq(meta.getHeader('Cookie'), 'times=1');
- }
- let full = "";
- let body = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; //60
- for (var i = 0; i < 1000; i++) {
- full += body;
- }
- response.write(full);
- });
- httpserv.start(-1);
-
- let state = 0;
-
- let listener = {
- onDownloadStateChange: function(aState, aDownload) {
- switch (aDownload.state) {
- case downloadUtils.downloadManager.DOWNLOAD_DOWNLOADING:
- // We only care about the private download
- if (state != 1)
- break;
-
- state++;
- do_check_true(aDownload.resumable);
-
- aDownload.pause();
- do_check_eq(aDownload.state, downloadUtils.downloadManager.DOWNLOAD_PAUSED);
-
- do_execute_soon(function() {
- aDownload.resume();
- });
- break;
-
- case downloadUtils.downloadManager.DOWNLOAD_FINISHED:
- if (state == 0) {
- do_execute_soon(function() {
- // Perform an identical request but in private mode.
- // It should receive a different cookie than the
- // public request.
-
- state++;
-
- addDownload(httpserv, {
- isPrivate: true,
- sourceURI: downloadCSource,
- downloadName: downloadCName + "!!!",
- runBeforeStart: function (aDownload) {
- // Check that dl is retrievable
- do_check_eq(downloadUtils.downloadManager.activePrivateDownloadCount, 1);
- }
- });
- });
- } else if (state == 2) {
- // We're done here.
- do_execute_soon(function() {
- httpserv.stop(do_test_finished);
- });
- }
- 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) { }
- };
-
- downloadUtils.downloadManager.addPrivacyAwareListener(listener);
-
- const downloadCSource = "http://localhost:" +
- httpserv.identity.primaryPort +
- "/head_download_manager.js";
- const downloadCName = "download-C";
-
- // First a public download that completes without interruption.
- let dl = addDownload(httpserv, {
- isPrivate: false,
- sourceURI: downloadCSource,
- downloadName: downloadCName,
- runBeforeStart: function (aDownload) {
- // Check that dl is retrievable
- do_check_eq(downloadUtils.downloadManager.activeDownloadCount, 1);
- }
- });
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_privatebrowsing.js
+++ /dev/null
@@ -1,298 +0,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 download manager's interaction with the private browsing service.
-
- An overview of what this test does follows:
-
- * Create a download (Download-A) with specific details.
- * Check that Download-A is retrievable.
- * Enter private browsing mode.
- * Check that Download-A is not accessible.
- * Create another download (Download-B) with specific and different details.
- * Check that Download-B is retrievable.
- * Exit private browsing mode.
- * Check that Download-A is retrievable.
- * Check that Download-B is not accessible.
- * Create a new download (Download-C) with specific details.
- Start it and enter private browsing mode immediately after.
- * Check that Download-C has been paused.
- * Exit the private browsing mode.
- * Verify that Download-C resumes and finishes correctly now.
-**/
-
-Components.utils.import("resource://gre/modules/Services.jsm");
-
-this.__defineGetter__("dm", function() {
- delete this.dm;
- return this.dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
-});
-
-/**
- * Try to see if an active download is available using the |activeDownloads|
- * property.
- */
-function is_active_download_available(aGUID, aSrc, aDst, aName, aPrivate) {
- let enumerator = aPrivate ? dm.activePrivateDownloads : dm.activeDownloads;
- while (enumerator.hasMoreElements()) {
- let download = enumerator.getNext();
- if (download.guid == aGUID &&
- download.source.spec == aSrc &&
- download.targetFile.path == aDst.path &&
- download.displayName == aName &&
- download.isPrivate == aPrivate)
- return true;
- }
- return false;
-}
-
-function expect_download_present(aGUID, aSrc, aDst, aName, aPrivate) {
- is_download_available(aGUID, aSrc, aDst, aName, aPrivate, true);
-}
-
-function expect_download_absent(aGUID, aSrc, aDst, aName, aPrivate) {
- is_download_available(aGUID, aSrc, aDst, aName, aPrivate, false);
-}
-
-/**
- * Try to see if a download is available using the |getDownloadByGUID| method. The
- * download can both be active or inactive.
- */
-function is_download_available(aGUID, aSrc, aDst, aName, aPrivate, present) {
- do_test_pending();
- dm.getDownloadByGUID(aGUID, function(status, download) {
- if (!present) {
- do_check_eq(download, null);
- } else {
- do_check_neq(download, null);
- do_check_eq(download.guid, aGUID);
- do_check_eq(download.source.spec, aSrc);
- do_check_eq(download.targetFile.path, aDst.path);
- do_check_eq(download.displayName, aName);
- do_check_eq(download.isPrivate, aPrivate);
- }
- do_test_finished();
- });
-}
-
-function run_test() {
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- let prefBranch = Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefBranch);
-
- do_test_pending();
- let httpserv = new HttpServer();
- httpserv.registerDirectory("/", do_get_cwd());
- httpserv.start(-1);
-
- let tmpDir = do_get_tempdir();
- const nsIWBP = Ci.nsIWebBrowserPersist;
-
- // make sure we're starting with an empty DB
- do_check_eq(dm.activeDownloadCount, 0);
- do_check_eq(dm.activePrivateDownloadCount, 0);
-
- let listener = {
- phase: 1,
- handledC: false,
- onDownloadStateChange: function(aState, aDownload)
- {
- switch (aDownload.state) {
- case dm.DOWNLOAD_FAILED:
- case dm.DOWNLOAD_CANCELED:
- case dm.DOWNLOAD_DIRTY:
- case dm.DOWNLOAD_BLOCKED_POLICY:
- // Fail!
- if (aDownload.targetFile.exists())
- aDownload.targetFile.remove(false);
- dm.removeListener(this);
- do_throw("Download failed (name: " + aDownload.displayName + ", state: " + aDownload.state + ")");
- do_test_finished();
- break;
-
- // We need to wait until Download-C has started, because otherwise it
- // won't be resumable, so the private browsing mode won't correctly pause it.
- case dm.DOWNLOAD_DOWNLOADING:
- if (aDownload.guid == downloadC && !this.handledC && this.phase == 2) {
- // Sanity check: Download-C must be resumable
- do_check_true(dlC.resumable);
-
- // Check that Download-A is accessible
- expect_download_present(downloadA, downloadASource,
- fileA, downloadAName, false);
-
- // Check that Download-B is not accessible
- expect_download_absent(downloadB, downloadBSource,
- fileB, downloadBName, true);
-
- // Check that Download-C is accessible
- expect_download_present(downloadC, downloadCSource,
- fileC, downloadCName, false);
-
- // only perform these checks the first time that Download-C is started
- this.handledC = true;
- }
- break;
-
- case dm.DOWNLOAD_FINISHED:
- do_check_true(aDownload.targetFile.exists());
- aDownload.targetFile.remove(false);
- this.onDownloadFinished();
- break;
- }
- },
- onStateChange: function(a, b, c, d, e) { },
- onProgressChange: function(a, b, c, d, e, f, g) { },
- onSecurityChange: function(a, b, c, d) { },
- onDownloadFinished: function () {
- switch (this.phase) {
- case 1: {
- do_check_eq(dm.activeDownloadCount, 0);
-
- // Create Download-B
- let dlB = addDownload(httpserv, {
- isPrivate: true,
- targetFile: fileB,
- sourceURI: downloadBSource,
- downloadName: downloadBName,
- runBeforeStart: function (aDownload) {
- // Check that Download-B is retrievable
- do_check_eq(dm.activePrivateDownloadCount, 1);
- do_check_eq(dm.activeDownloadCount, 0);
- do_check_true(is_active_download_available(aDownload.guid,
- downloadBSource, fileB, downloadBName, true));
- expect_download_present(aDownload.guid,
- downloadBSource, fileB, downloadBName, true);
- }
- });
- downloadB = dlB.guid;
-
- // wait for Download-B to finish
- ++this.phase;
- }
- break;
-
- case 2: {
- do_check_eq(dm.activeDownloadCount, 0);
-
- // Simulate last private browsing context triggering cleanup
- Services.obs.notifyObservers(null, "last-pb-context-exited", null);
-
- // Create Download-C
- dlC = addDownload(httpserv, {
- isPrivate: false,
- targetFile: fileC,
- sourceURI: downloadCSource,
- downloadName: downloadCName,
- runBeforeStart: function (aDownload) {
- // Check that Download-C is retrievable
- do_check_eq(dm.activePrivateDownloadCount, 0);
- do_check_true(is_active_download_available(aDownload.guid,
- downloadCSource, fileC, downloadCName, false));
- expect_download_present(aDownload.guid,
- downloadCSource, fileC, downloadCName, false);
- }
- });
- downloadC = dlC.guid;
-
- // wait for Download-C to finish
- ++this.phase;
-
- // Check that Download-A is accessible
- expect_download_present(downloadA, downloadASource,
- fileA, downloadAName, false);
-
- // Check that Download-B is not accessible
- expect_download_absent(downloadB, downloadBSource,
- fileB, downloadBName, true);
- }
- break;
-
- case 3: {
- do_check_eq(dm.activePrivateDownloadCount, 0);
-
- // Check that Download-A is accessible
- expect_download_present(downloadA, downloadASource,
- fileA, downloadAName, false);
-
- // Check that Download-B is not accessible
- expect_download_absent(downloadB, downloadBSource,
- fileB, downloadBName, true);
-
- // Check that Download-C is accessible
- expect_download_present(downloadC, downloadCSource,
- fileC, downloadCName, false);
-
- // cleanup
- dm.removeListener(this);
- httpserv.stop(do_test_finished);
- }
- break;
-
- default:
- do_throw("Unexpected phase: " + this.phase);
- break;
- }
- }
- };
-
- dm.addPrivacyAwareListener(listener);
- dm.addPrivacyAwareListener(getDownloadListener());
-
- // properties of Download-A
- let downloadA = -1;
- const downloadASource = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9gKHhQaLFEVkXsAAAAIdEVYdENvbW1lbnQA9syWvwAABXZJREFUaN7VmnuIVUUcxz/3uma5ZJJmrZGVuZWupGSZsVNwTRYJYk8vRzd6o0kglgpm9q/ZEhlBUEssUpTtqMixl6LlURtDwyzCWmLxkZZL6qZRi/nc/tjf2Ybjufd6797HOrDM7NzfmfP9zfzm9zxwkbdEIRYxyhsCTAYmAWOBkcAwYBBwFugEDgN7gd3AdmCTtn5HWRkwynsamA7U5bnEBqBFW395SRkwylsIzAWqnOnvgTVAG3AIOA4cAwYAlwFDgZuAUcB4YApQIc+2A29p6zcWlQGjvEeBJUC1TO0BmoAPtfXbc1yrH/AwMB+YKNNtwGJt/VUFZ8Ao713gOfn3O2CBtv7mAt2hUcAi4BmZatLWn10QBozyRgArgFoRixe09d8vhkYxypsKfAwMBrYBDdr6B/JmwChvNLBWRCYA6rX1/y6mWjTKqwQ+BVIiUvXa+q3p6JNZdj4E3wJMKTZ4AG39TuA+oFnevVaw5MaAiE01sEJbf4a2/rlSGSdt/S5gJrAqxJATA3Jha4GdwFPlsLDChBZbUSuYst8BUZUr5cKOyVU9FuFODAZagWuAaVEVG3cCS6SfWW7wchLHgcci2OIZEAtbDWzR1l/dVxw2bf1N4X0QjD2tIkI7V/oF7qQyqa40a58Rd6EVWA+8Z3VwNI4wwxqIs/e7OHnNVgdbY2gWAQ8JxsbzTkAcsyog0NbfeYGbUwFcBdwLvAq0KpNK5bHJlcDNwBPAFmVS7yiTSkZOYQ+wGqgSrOeJ0HTpmzO9yeogEf6JozZOrCfisK1VJjUihzWSwNXiRhwTktnA8zGPNkewdjMg/nwdcBr45EK3zerglNXBj1YHDSKjAJdHRTDLGl1WB4etDpYDs5yfZsWQfwUcAeoEc88JTA4JemFtX3fG+cYH651xdcxlPgd84WIOGZgk/Te9UBa7nfF1ea7hXvR/09BsdzGHDIyV/ucya8ypzvjrNDS7XMyhGh0p/S+9ePlYZ3zwQh9SJpUAhgD3A8tk+i/g5TSP7HcxhwwMk/5ILxiY74w3ZgGdziYclQiv0epgXxqaDhG1YS4DlY5hIofd6w/cAiwUxwvgH+CNPDdhKHAnMAHYl8YqnzXKOxFirsj1DVksagcw3epgfzY7EFmzUkRwLjADWKVM6k2rg3lplhgQNWSd0g/KkZ8zAtoCrwCjrQ6+zHVTrA46rQ52iD35SKZfVCZVH+OdDgT6hZjDEzgs4G9Md3Tpdq8IbZnjfc6RqNBtwx3MPSewV/pRfcD5dFX5HTG/17iYkxEjNIG+1S6NmRvvYk5GrFtdHwBd44x/i/l9sos5ZGCT9DcY5Y0pMwOuPVkXucBXSqzegzkpurVDgmeAhlIjViY1UJnUXcqkWkSNIq710qgZEA20Icxsu3agRURojlHeEm39E0UE3JWF5FfgEauDQ87uJ5yIseW8gEZS3O2iTp8s8SGcpDujvU4CmRqrg2hU+IBY/XY3HZ+ICepfk8VGauuf7AuqyCivQtRrNfCSm4aPxp2Nko8cLoz0lTZPwLdFawhxeaHFYYbCKK+2D+z+bU4+aHHW1KJkvppEvNYY5VWVOSv3mSibprjCRyLDw1Z07i5gkrb+6RKDvwTYDNwNbNPWV3F0mbLTDXIfbges5O1LBf4K4FsB35bJNiUzpPMOAPWywETgJ6O860sA/lpxE8bxf4EjbZUm1xLTn8CD2vpbiwA8IdpmKdCfQpSYIi9wi3yfA89q6/9RIPC3Ah9IOAmFLPJFXuSWWbskenpbW39HnsZpGvC4k04pXpk1xmK7he6DdKckNwI/AAejJSkJBWvorn/dI35XaQvdMYxk+tTgEHBKsgeDRa6jrTyfGsQwUraPPS769h+G3Ox+KOb9iAAAAABJRU5ErkJggg==";
- const downloadADest = "download-file-A";
- const downloadAName = "download-A";
-
- // properties of Download-B
- let downloadB = -1;
- const downloadBSource = "data:application/octet-stream;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9gKHhQaLFEVkXsAAAAIdEVYdENvbW1lbnQA9syWvwAABXZJREFUaN7VmnuIVUUcxz/3uma5ZJJmrZGVuZWupGSZsVNwTRYJYk8vRzd6o0kglgpm9q/ZEhlBUEssUpTtqMixl6LlURtDwyzCWmLxkZZL6qZRi/nc/tjf2Ybjufd6797HOrDM7NzfmfP9zfzm9zxwkbdEIRYxyhsCTAYmAWOBkcAwYBBwFugEDgN7gd3AdmCTtn5HWRkwynsamA7U5bnEBqBFW395SRkwylsIzAWqnOnvgTVAG3AIOA4cAwYAlwFDgZuAUcB4YApQIc+2A29p6zcWlQGjvEeBJUC1TO0BmoAPtfXbc1yrH/AwMB+YKNNtwGJt/VUFZ8Ao713gOfn3O2CBtv7mAt2hUcAi4BmZatLWn10QBozyRgArgFoRixe09d8vhkYxypsKfAwMBrYBDdr6B/JmwChvNLBWRCYA6rX1/y6mWjTKqwQ+BVIiUvXa+q3p6JNZdj4E3wJMKTZ4AG39TuA+oFnevVaw5MaAiE01sEJbf4a2/rlSGSdt/S5gJrAqxJATA3Jha4GdwFPlsLDChBZbUSuYst8BUZUr5cKOyVU9FuFODAZagWuAaVEVG3cCS6SfWW7wchLHgcci2OIZEAtbDWzR1l/dVxw2bf1N4X0QjD2tIkI7V/oF7qQyqa40a58Rd6EVWA+8Z3VwNI4wwxqIs/e7OHnNVgdbY2gWAQ8JxsbzTkAcsyog0NbfeYGbUwFcBdwLvAq0KpNK5bHJlcDNwBPAFmVS7yiTSkZOYQ+wGqgSrOeJ0HTpmzO9yeogEf6JozZOrCfisK1VJjUihzWSwNXiRhwTktnA8zGPNkewdjMg/nwdcBr45EK3zerglNXBj1YHDSKjAJdHRTDLGl1WB4etDpYDs5yfZsWQfwUcAeoEc88JTA4JemFtX3fG+cYH651xdcxlPgd84WIOGZgk/Te9UBa7nfF1ea7hXvR/09BsdzGHDIyV/ucya8ypzvjrNDS7XMyhGh0p/S+9ePlYZ3zwQh9SJpUAhgD3A8tk+i/g5TSP7HcxhwwMk/5ILxiY74w3ZgGdziYclQiv0epgXxqaDhG1YS4DlY5hIofd6w/cAiwUxwvgH+CNPDdhKHAnMAHYl8YqnzXKOxFirsj1DVksagcw3epgfzY7EFmzUkRwLjADWKVM6k2rg3lplhgQNWSd0g/KkZ8zAtoCrwCjrQ6+zHVTrA46rQ52iD35SKZfVCZVH+OdDgT6hZjDEzgs4G9Md3Tpdq8IbZnjfc6RqNBtwx3MPSewV/pRfcD5dFX5HTG/17iYkxEjNIG+1S6NmRvvYk5GrFtdHwBd44x/i/l9sos5ZGCT9DcY5Y0pMwOuPVkXucBXSqzegzkpurVDgmeAhlIjViY1UJnUXcqkWkSNIq710qgZEA20Icxsu3agRURojlHeEm39E0UE3JWF5FfgEauDQ87uJ5yIseW8gEZS3O2iTp8s8SGcpDujvU4CmRqrg2hU+IBY/XY3HZ+ICepfk8VGauuf7AuqyCivQtRrNfCSm4aPxp2Nko8cLoz0lTZPwLdFawhxeaHFYYbCKK+2D+z+bU4+aHHW1KJkvppEvNYY5VWVOSv3mSibprjCRyLDw1Z07i5gkrb+6RKDvwTYDNwNbNPWV3F0mbLTDXIfbges5O1LBf4K4FsB35bJNiUzpPMOAPWywETgJ6O860sA/lpxE8bxf4EjbZUm1xLTn8CD2vpbiwA8IdpmKdCfQpSYIi9wi3yfA89q6/9RIPC3Ah9IOAmFLPJFXuSWWbskenpbW39HnsZpGvC4k04pXpk1xmK7he6DdKckNwI/AAejJSkJBWvorn/dI35XaQvdMYxk+tTgEHBKsgeDRa6jrTyfGsQwUraPPS769h+G3Ox+KOb9iAAAAABJRU5ErkJggg==";
- const downloadBDest = "download-file-B";
- const downloadBName = "download-B";
-
- // properties of Download-C
- let downloadC = -1;
- const downloadCSource = "http://localhost:" +
- httpserv.identity.primaryPort +
- "/head_download_manager.js";
- const downloadCDest = "download-file-C";
- const downloadCName = "download-C";
-
- // Create all target files
- let fileA = tmpDir.clone();
- fileA.append(downloadADest);
- fileA.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o666);
- let fileB = tmpDir.clone();
- fileB.append(downloadBDest);
- fileB.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o666);
- let fileC = tmpDir.clone();
- fileC.append(downloadCDest);
- fileC.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o666);
-
- // use js closures to access dlC
- let dlC;
-
- // Create Download-A
- let dlA = addDownload(httpserv, {
- isPrivate: false,
- targetFile: fileA,
- sourceURI: downloadASource,
- downloadName: downloadAName,
- runBeforeStart: function (aDownload) {
- // Check that Download-A is retrievable
- do_check_eq(dm.activePrivateDownloadCount, 0);
- do_check_true(is_active_download_available(aDownload.guid, downloadASource, fileA, downloadAName, false));
- expect_download_present(aDownload.guid, downloadASource, fileA, downloadAName, false);
- }
- });
- downloadA = dlA.guid;
-
- // wait for Download-A to finish
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_privatebrowsing_cancel.js
+++ /dev/null
@@ -1,252 +0,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/. */
-
-/**
- Make sure that the download manager service is given a chance to cancel the
- private browsing mode transition.
-**/
-
-Components.utils.import("resource://testing-common/MockRegistrar.jsm");
-
-var Cm = Components.manager;
-
-var promptService = {
- _buttonChoice: 0,
- _called: false,
- wasCalled: function() {
- let called = this._called;
- this._called = false;
- return called;
- },
- sayCancel: function() {
- this._buttonChoice = 1;
- this._called = false;
- },
- sayProceed: function() {
- this._buttonChoice = 0;
- this._called = false;
- },
- QueryInterface: function(aIID) {
- if (aIID.equals(Ci.nsIPromptService) ||
- aIID.equals(Ci.nsISupports)) {
- return this;
- }
- throw Cr.NS_ERROR_NO_INTERFACE;
- },
- confirmEx: function(parent, title, text, buttonFlags,
- button0Title, button1Title, button2Title,
- checkMsg, checkState) {
- this._called = true;
- return this._buttonChoice;
- }
-};
-
-var mockCID =
- MockRegistrar.register("@mozilla.org/embedcomp/prompt-service;1",
- promptService);
-
-this.__defineGetter__("dm", function() {
- delete this.dm;
- return this.dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
-});
-
-function trigger_pb_cleanup(expected)
-{
- var obs = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
- var cancel = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
- cancel.data = false;
- obs.notifyObservers(cancel, "last-pb-context-exiting", null);
- do_check_eq(expected, cancel.data);
- if (!expected)
- obs.notifyObservers(cancel, "last-pb-context-exited", null);
-}
-
-function run_test() {
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- function finishTest() {
- // Cancel Download-G
- dlG.cancel();
- dlG.remove();
- dm.cleanUp();
- dm.cleanUpPrivate();
- do_check_eq(dm.activeDownloadCount, 0);
- do_check_eq(dm.activePrivateDownloadCount, 0);
-
- dm.removeListener(listener);
- httpserv.stop(do_test_finished);
-
- // Unregister the mock so we do not leak
- MockRegistrar.unregister(mockCID);
- }
-
- do_test_pending();
- let httpserv = new HttpServer();
- httpserv.registerDirectory("/file/", do_get_cwd());
- httpserv.registerPathHandler("/noresume", function (meta, response) {
- response.setHeader("Content-Type", "text/html", false);
- response.setHeader("Accept-Ranges", "none", false);
- response.write("foo");
- });
- httpserv.start(-1);
-
- let tmpDir = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).
- get("TmpD", Ci.nsIFile);
-
- // make sure we're starting with an empty DB
- do_check_eq(dm.activeDownloadCount, 0);
-
- let listener = {
- onDownloadStateChange: function(aState, aDownload)
- {
- switch (aDownload.state) {
- case dm.DOWNLOAD_QUEUED:
- case dm.DOWNLOAD_DOWNLOADING:
- if (aDownload.targetFile.equals(dlD.targetFile)) {
- // Sanity check: Download-D must not be resumable
- do_check_false(dlD.resumable);
-
- // Cancel the transition
- promptService.sayCancel();
- trigger_pb_cleanup(true);
- do_check_true(promptService.wasCalled());
- do_check_eq(dm.activePrivateDownloadCount, 1);
-
- promptService.sayProceed();
- trigger_pb_cleanup(false);
- do_check_true(promptService.wasCalled());
- do_check_eq(dm.activePrivateDownloadCount, 0);
- do_check_eq(dlD.state, dm.DOWNLOAD_CANCELED);
-
- // Create Download-E
- dlE = addDownload(httpserv, {
- isPrivate: true,
- targetFile: fileE,
- sourceURI: downloadESource,
- downloadName: downloadEName
- });
-
- // Wait for Download-E to start
- } else if (aDownload.targetFile.equals(dlE.targetFile)) {
- // Sanity check: Download-E must be resumable
- do_check_true(dlE.resumable);
-
- promptService.sayCancel();
- trigger_pb_cleanup(true);
- do_check_true(promptService.wasCalled());
- do_check_eq(dm.activePrivateDownloadCount, 1);
-
- promptService.sayProceed();
- trigger_pb_cleanup(false);
- do_check_true(promptService.wasCalled());
- do_check_eq(dm.activePrivateDownloadCount, 0);
- do_check_eq(dlE.state, dm.DOWNLOAD_CANCELED);
-
- // Create Download-F
- dlF = addDownload(httpserv, {
- isPrivate: true,
- targetFile: fileF,
- sourceURI: downloadFSource,
- downloadName: downloadFName
- });
-
- // Wait for Download-F to start
- } else if (aDownload.targetFile.equals(dlF.targetFile)) {
- // Sanity check: Download-F must be resumable
- do_check_true(dlF.resumable);
- dlF.pause();
-
- } else if (aDownload.targetFile.equals(dlG.targetFile)) {
- // Sanity check: Download-G must not be resumable
- do_check_false(dlG.resumable);
-
- promptService.sayCancel();
- trigger_pb_cleanup(false);
- do_check_false(promptService.wasCalled());
- do_check_eq(dm.activeDownloadCount, 1);
- do_check_eq(dlG.state, dm.DOWNLOAD_DOWNLOADING);
- finishTest();
- }
- break;
-
- case dm.DOWNLOAD_PAUSED:
- if (aDownload.targetFile.equals(dlF.targetFile)) {
- promptService.sayProceed();
- trigger_pb_cleanup(false);
- do_check_true(promptService.wasCalled());
- do_check_eq(dm.activePrivateDownloadCount, 0);
- do_check_eq(dlF.state, dm.DOWNLOAD_CANCELED);
-
- // Create Download-G
- dlG = addDownload(httpserv, {
- isPrivate: false,
- targetFile: fileG,
- sourceURI: downloadGSource,
- downloadName: downloadGName
- });
-
- // Wait for Download-G to start
- }
- break;
- }
- },
- onStateChange: function(a, b, c, d, e) { },
- onProgressChange: function(a, b, c, d, e, f, g) { },
- onSecurityChange: function(a, b, c, d) { }
- };
-
- dm.addPrivacyAwareListener(listener);
-
- const PORT = httpserv.identity.primaryPort;
-
- // properties of Download-D
- const downloadDSource = "http://localhost:" + PORT + "/noresume";
- const downloadDDest = "download-file-D";
- const downloadDName = "download-D";
-
- // properties of Download-E
- const downloadESource = "http://localhost:" + PORT + "/file/head_download_manager.js";
- const downloadEDest = "download-file-E";
- const downloadEName = "download-E";
-
- // properties of Download-F
- const downloadFSource = "http://localhost:" + PORT + "/file/head_download_manager.js";
- const downloadFDest = "download-file-F";
- const downloadFName = "download-F";
-
- // properties of Download-G
- const downloadGSource = "http://localhost:" + PORT + "/noresume";
- const downloadGDest = "download-file-G";
- const downloadGName = "download-G";
-
- // Create all target files
- let fileD = tmpDir.clone();
- fileD.append(downloadDDest);
- fileD.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o666);
- let fileE = tmpDir.clone();
- fileE.append(downloadEDest);
- fileE.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o666);
- let fileF = tmpDir.clone();
- fileF.append(downloadFDest);
- fileF.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o666);
- let fileG = tmpDir.clone();
- fileG.append(downloadGDest);
- fileG.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o666);
-
- // Create Download-D
- let dlD = addDownload(httpserv, {
- isPrivate: true,
- targetFile: fileD,
- sourceURI: downloadDSource,
- downloadName: downloadDName
- });
-
- let dlE, dlF, dlG;
-
- // wait for Download-D to start
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_removeDownloadsByTimeframe.js
+++ /dev/null
@@ -1,166 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
- * vim: sw=2 ts=2 sts=2
- * 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 added with bug 462964 to test the behavior of the new API that was added
- * to remove downloads by a given time frame.
- */
-
-////////////////////////////////////////////////////////////////////////////////
-//// Constants
-
-var dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
-
-const START_TIME = Date.now() * 1000;
-const END_TIME = START_TIME + (60 * 1000000); // one minute range
-
-const DOWNLOAD_FINISHED = Ci.nsIDownloadManager.DOWNLOAD_FINISHED;
-const DOWNLOAD_DOWNLOADING = Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING;
-
-const REMOVED_TOPIC = "download-manager-remove-download";
-
-////////////////////////////////////////////////////////////////////////////////
-//// Utility Functions
-
-/**
- * Adds a download to the database.
- *
- * @param aStartTimeInRange
- * Indicates if the new download's start time should be in range.
- * @param aEndTimeInRange
- * Indicates if the new download's end time should be in range.
- * @returns the inserted id.
- */
-var id = 1;
-function add_download_to_db(aStartTimeInRange, aEndTimeInRange, aState)
-{
- let db = dm.DBConnection;
- let stmt = db.createStatement(
- "INSERT INTO moz_downloads (id, startTime, endTime, state) " +
- "VALUES (:id, :startTime, :endTime, :state)"
- );
- stmt.params.id = id;
- stmt.params.startTime = aStartTimeInRange ? START_TIME + 1 : START_TIME - 1;
- stmt.params.endTime = aEndTimeInRange ? END_TIME - 1 : END_TIME + 1;
- stmt.params.state = aState;
- stmt.execute();
- stmt.finalize();
-
- return id++;
-}
-
-/**
- * Checks to see the downloads with the specified id exist or not.
- *
- * @param aIDs
- * The ids of the downloads to check.
- * @param aExpected
- * True if we expect the download to exist, false if we do not.
- */
-function check_existence(aIDs, aExpected)
-{
- let db = dm.DBConnection;
- let stmt = db.createStatement(
- "SELECT * " +
- "FROM moz_downloads " +
- "WHERE id = :id"
- );
-
- let checkFunc = aExpected ? do_check_true : do_check_false;
- for (let i = 0; i < aIDs.length; i++) {
- stmt.params.id = aIDs[i];
- checkFunc(stmt.executeStep());
- stmt.reset();
- }
- stmt.finalize();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//// Test Functions
-
-function test_download_start_in_range()
-{
- let id = add_download_to_db(true, false, DOWNLOAD_FINISHED);
- dm.removeDownloadsByTimeframe(START_TIME, END_TIME);
- check_existence([id], false);
-}
-
-function test_download_end_in_range()
-{
- let id = add_download_to_db(false, true, DOWNLOAD_FINISHED);
- dm.removeDownloadsByTimeframe(START_TIME, END_TIME);
- check_existence([id], true);
-}
-
-function test_multiple_downloads_in_range()
-{
- let ids = [];
- ids.push(add_download_to_db(true, false, DOWNLOAD_FINISHED));
- ids.push(add_download_to_db(true, false, DOWNLOAD_FINISHED));
- dm.removeDownloadsByTimeframe(START_TIME, END_TIME);
- check_existence(ids, false);
-}
-
-function test_no_downloads_in_range()
-{
- let ids = [];
- ids.push(add_download_to_db(false, true, DOWNLOAD_FINISHED));
- ids.push(add_download_to_db(false, true, DOWNLOAD_FINISHED));
- dm.removeDownloadsByTimeframe(START_TIME, END_TIME);
- check_existence(ids, true);
-}
-
-function test_active_download_in_range()
-{
- let id = add_download_to_db(true, false, DOWNLOAD_DOWNLOADING);
- dm.removeDownloadsByTimeframe(START_TIME, END_TIME);
- check_existence([id], true);
-}
-
-function test_observer_dispatched()
-{
- let observer = {
- notified: false,
- observe: function(aSubject, aTopic, aData)
- {
- this.notified = true;
- do_check_eq(aSubject, null);
- do_check_eq(aTopic, REMOVED_TOPIC);
- do_check_eq(aData, null);
- }
- };
- let os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- os.addObserver(observer, REMOVED_TOPIC, false);
-
- add_download_to_db(true, false, DOWNLOAD_FINISHED);
- dm.removeDownloadsByTimeframe(START_TIME, END_TIME);
- do_check_true(observer.notified);
-
- os.removeObserver(observer, REMOVED_TOPIC);
-}
-
-var tests = [
- test_download_start_in_range,
- test_download_end_in_range,
- test_multiple_downloads_in_range,
- test_no_downloads_in_range,
- test_active_download_in_range,
- test_observer_dispatched,
-];
-
-function run_test()
-{
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- for (let i = 0; i < tests.length; i++) {
- dm.cleanUp();
- tests[i]();
- }
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_resume.js
+++ /dev/null
@@ -1,138 +0,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 download resume to do real-resume instead of stalling-the-channel
- * resume. Also test bug 395537 for resuming files that are deleted before
- * they're resumed. Bug 398216 is checked by making sure the reported progress
- * and file size are updated for finished downloads.
- */
-
-const nsIF = Ci.nsIFile;
-const nsIDM = Ci.nsIDownloadManager;
-const nsIWBP = Ci.nsIWebBrowserPersist;
-const nsIWPL = Ci.nsIWebProgressListener;
-const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDM);
-
-function run_test()
-{
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- /**
- * 1. Create data for http server to send
- */
- // data starts at 10 bytes
- var data = "1234567890";
- // data * 10^4 = 100,000 bytes (actually 101,111 bytes with newline)
- for (var i = 0; i < 4; i++) {
- data = [data,data,data,data,data,data,data,data,data,data,"\n"].join("");
- }
-
- /**
- * 2. Start the http server that can handle resume
- */
- var httpserv = new HttpServer();
- var didResumeServer = false;
- httpserv.registerPathHandler("/resume", function(meta, resp) {
- var body = data;
- resp.setHeader("Content-Type", "text/html", false);
- if (meta.hasHeader("Range")) {
- // track that we resumed for testing
- didResumeServer = true;
- // Syntax: bytes=[from]-[to] (we don't support multiple ranges)
- var matches = meta.getHeader("Range").match(/^\s*bytes=(\d+)?-(\d+)?\s*$/);
- var from = (matches[1] === undefined) ? 0 : matches[1];
- var to = (matches[2] === undefined) ? data.length - 1 : matches[2];
- if (from >= data.length) {
- resp.setStatusLine(meta.httpVersion, 416, "Start pos too high");
- resp.setHeader("Content-Range", "*/" + data.length, false);
- return;
- }
- body = body.substring(from, to + 1);
- // always respond to successful range requests with 206
- resp.setStatusLine(meta.httpVersion, 206, "Partial Content");
- resp.setHeader("Content-Range", from + "-" + to + "/" + data.length, false);
- }
- resp.bodyOutputStream.write(body, body.length);
- });
- httpserv.start(-1);
-
- /**
- * 3. Perform various actions for certain download states
- */
- var didPause = false;
- var didResumeDownload = false;
- dm.addListener({
- onDownloadStateChange: function(a, aDl) {
- if (aDl.state == nsIDM.DOWNLOAD_DOWNLOADING && !didPause) {
- /**
- * (1) queued -> downloading = pause the download
- */
- dm.pauseDownload(aDl.id);
- } else if (aDl.state == nsIDM.DOWNLOAD_PAUSED) {
- /**
- * (2) downloading -> paused = remove the file
- */
- didPause = true;
- // Test bug 395537 by removing the file before we actually resume
- aDl.targetFile.remove(false);
- } else if (aDl.state == nsIDM.DOWNLOAD_FINISHED) {
- /**
- * (4) downloading (resumed) -> finished = check tests
- */
- // did we pause at all?
- do_check_true(didPause);
- // did we real-resume and not fake-resume?
- do_check_true(didResumeDownload);
- // extra real-resume check for the server
- do_check_true(didResumeServer);
- // did we download the whole file?
- do_check_eq(data.length, aDl.targetFile.fileSize);
- // extra sanity checks on size (test bug 398216)
- do_check_eq(data.length, aDl.amountTransferred);
- do_check_eq(data.length, aDl.size);
-
- httpserv.stop(do_test_finished);
- }
- },
- onStateChange: function(a, b, aState, d, aDl) {
- if ((aState & nsIWPL.STATE_STOP) && didPause && !didResumeServer &&
- !didResumeDownload) {
- /**
- * (3) paused -> stopped = resume the download
- */
- dm.resumeDownload(aDl.id);
- didResumeDownload = true;
- }
- },
- onProgressChange: function(a, b, c, d, e, f, g) { },
- onSecurityChange: function(a, b, c, d) { }
- });
- dm.addListener(getDownloadListener());
-
- /**
- * 4. Start the download
- */
- var destFile = dirSvc.get("ProfD", nsIF);
- destFile.append("resumed");
- if (destFile.exists())
- destFile.remove(false);
- 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 dl = dm.addDownload(nsIDM.DOWNLOAD_TYPE_DOWNLOAD,
- createURI("http://localhost:" +
- httpserv.identity.primaryPort + "/resume"),
- createURI(destFile), null, null,
- Math.round(Date.now() * 1000), null, persist, false);
- persist.progressListener = dl.QueryInterface(nsIWPL);
- persist.saveURI(dl.source, null, null, 0, null, null, dl.targetFile, null);
-
- // Mark as pending, so clear this when we actually finish the download
- do_test_pending();
-}
deleted file mode 100644
--- a/toolkit/components/downloads/test/unit/test_sleep_wake.js
+++ /dev/null
@@ -1,159 +0,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 335418 by making sure the download manager responds to sleep and
- * wake notifications by pausing and resuming downloads.
- */
-
-/**
- * Used to indicate if we should error out or not. See bug 431745 for more
- * details.
- */
-var doNotError = false;
-
-const nsIF = Ci.nsIFile;
-const nsIDM = Ci.nsIDownloadManager;
-const nsIWBP = Ci.nsIWebBrowserPersist;
-const nsIWPL = Ci.nsIWebProgressListener;
-const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDM);
-if (!oldDownloadManagerDisabled()) {
- dm.cleanUp();
-}
-
-function notify(aTopic)
-{
- Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService).
- notifyObservers(null, aTopic, null);
-}
-
-function run_test()
-{
- if (oldDownloadManagerDisabled()) {
- return;
- }
-
- /**
- * 0. Speed up the resume on wake delay from 10 seconds
- */
- Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefBranch).
- setIntPref("browser.download.manager.resumeOnWakeDelay", 1000);
-
- /**
- * 1. Create data for http server to send
- */
- // data starts at 10 bytes
- let data = "1234567890";
- // data * 10^4 = 100,000 bytes (actually 101,111 bytes with newline)
- for (let i = 0; i < 4; i++)
- data = [data,data,data,data,data,data,data,data,data,data,"\n"].join("");
-
- /**
- * 2. Start the http server that can handle resume
- */
- let httpserv = new HttpServer();
- let didResumeServer = false;
- httpserv.registerPathHandler("/resume", function(meta, resp) {
- let body = data;
- resp.setHeader("Content-Type", "text/html", false);
- if (meta.hasHeader("Range")) {
- // track that we resumed for testing
- didResumeServer = true;
- // Syntax: bytes=[from]-[to] (we don't support multiple ranges)
- let matches = meta.getHeader("Range").match(/^\s*bytes=(\d+)?-(\d+)?\s*$/);
- let from = (matches[1] === undefined) ? 0 : matches[1];
- let to = (matches[2] === undefined) ? data.length - 1 : matches[2];
- if (from >= data.length) {
- resp.setStatusLine(meta.httpVersion, 416, "Start pos too high");
- resp.setHeader("Content-Range", "*/" + data.length);
- dump("Returning early - from >= data.length. Not an error (bug 431745)\n");
- doNotError = true;
- return;
- }
- body = body.substring(from, to + 1);
- // always respond to successful range requests with 206
- resp.setStatusLine(meta.httpVersion, 206, "Partial Content");
- resp.setHeader("Content-Range", from + "-" + to + "/" + data.length);
- }
- resp.bodyOutputStream.write(body, body.length);
- });
- httpserv.start(-1);
-
- /**
- * 3. Perform various actions for certain download states
- */
- let didPause = false;
- let didResumeDownload = false;
- dm.addListener({
- onDownloadStateChange: function(a, aDl) {
- if (aDl.state == nsIDM.DOWNLOAD_DOWNLOADING && !didPause) {
- /**
- * (1) queued -> downloading = pause the download with sleep
- */
- notify("sleep_notification");
- } else if (aDl.state == nsIDM.DOWNLOAD_PAUSED) {
- /**
- * (2) downloading -> paused
- */
- didPause = true;
- } else if (aDl.state == nsIDM.DOWNLOAD_FINISHED) {
- /**
- * (4) downloading (resumed) -> finished = check tests
- */
- // did we pause at all?
- do_check_true(didPause);
- // did we real-resume and not fake-resume?
- do_check_true(didResumeDownload);
- // extra real-resume check for the server
- do_check_true(didResumeServer);
-
- aDl.targetFile.remove(false);
- httpserv.stop(do_test_finished);
- }
- else if (aDl.state == nsIDM.DOWNLOAD_FAILED) {
- // this is only ok if we are not supposed to fail
- do_check_true(doNotError);
- httpserv.stop(do_test_finished);
- }
- },
- onStateChange: function(a, b, aState, d, aDl) {
- if ((aState & nsIWPL.STATE_STOP) && didPause && !didResumeServer &&
- !didResumeDownload) {
- /**
- * (3) paused -> stopped = resume the download by waking
- */
- notify("wake_notification");
- didResumeDownload = true;
- }
- },
- onProgressChange: function(a, b, c, d, e, f, g) { },
- onSecurityChange: function(a, b, c, d) { }
- });
- dm.addListener(getDownloadListener());
-
- /**
- * 4. Start the download
- */
- let destFile = dirSvc.get("ProfD", nsIF);
- destFile.append("sleep_wake");
- if (destFile.exists())
- destFile.remove(false);
- let 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;
- let dl = dm.addDownload(nsIDM.DOWNLOAD_TYPE_DOWNLOAD,
- createURI("http://localhost:" +
- httpserv.identity.primaryPort + "/resume"),
- createURI(destFile), null, null,
- Math.round(Date.now() * 1000), null, persist, false);
- persist.progressListener = dl.QueryInterface(nsIWPL);
- persist.saveURI(dl.source, null, null, 0, null, null, dl.targetFile, null);
-
- // Mark as pending, so clear this when we actually finish the download
- do_test_pending();
-}
--- a/toolkit/components/downloads/test/unit/xpcshell.ini
+++ b/toolkit/components/downloads/test/unit/xpcshell.ini
@@ -1,40 +1,14 @@
[DEFAULT]
head = head_download_manager.js
tail = tail_download_manager.js
skip-if = toolkit == 'android' || toolkit == 'gonk'
support-files =
- downloads_manifest.js
- test_downloads.manifest
data/digest.chunk
data/block_digest.chunk
data/signed_win.exe
[test_app_rep.js]
[test_app_rep_windows.js]
skip-if = os != "win"
[test_app_rep_maclinux.js]
skip-if = os == "win"
-[test_bug_382825.js]
-[test_bug_384744.js]
-[test_bug_395092.js]
-[test_bug_401430.js]
-[test_bug_406857.js]
-[test_bug_420230.js]
-[test_cancel_download_files_removed.js]
-# Bug 676989: test hangs consistently on Android
-# Bug 907732: thunderbird still uses legacy downloads manager.
-skip-if = (os == "android" || buildapp == '../mail')
-[test_download_manager.js]
-[test_download_samename.js]
-# Bug 676989: test hangs consistently on Android
-# Bug 907732: thunderbird still uses legacy downloads manager.
-skip-if = (os == "android" || buildapp == '../mail')
-[test_guid.js]
-[test_history_expiration.js]
-[test_offline_support.js]
-[test_private_resume.js]
-[test_privatebrowsing.js]
-[test_privatebrowsing_cancel.js]
-[test_removeDownloadsByTimeframe.js]
-[test_resume.js]
-[test_sleep_wake.js]
--- a/toolkit/mozapps/downloads/tests/chrome/chrome.ini
+++ b/toolkit/mozapps/downloads/tests/chrome/chrome.ini
@@ -1,40 +1,10 @@
[DEFAULT]
skip-if = buildapp == 'b2g' || os == 'android'
support-files =
unknownContentType_dialog_layout_data.pif
unknownContentType_dialog_layout_data.pif^headers^
unknownContentType_dialog_layout_data.txt
unknownContentType_dialog_layout_data.txt^headers^
- utils.js
-[test_backspace_key_removes.xul]
-skip-if = toolkit != 'cocoa'
-[test_basic_functionality.xul]
-[test_bug_412360.xul]
-[test_bug_429247.xul]
-[test_bug_462172.xul]
-[test_cleanup_search.xul]
-[test_clear_button_disabled.xul]
-[test_close_download_manager.xul]
-[test_close_on_last_window.xul]
-[test_delete_key_removes.xul]
-[test_destinationURI_annotation.xul]
-[test_esc_key_closes_clears.xul]
-[test_multi_select.xul]
-[test_multiword_search.xul]
-[test_pause_button_state.xul]
-[test_removeDownload_updates_ui.xul]
-[test_retention_is_0_closes.xul]
-disabled = temporarily disabled test (bug 483200)
-[test_search_clearlist.xul]
-[test_search_keys.xul]
-[test_select_all.xul]
-[test_space_key_pauses_resumes.xul]
-[test_taskbarprogress_downloadstates.xul]
-skip-if = os != 'win' && toolkit != 'cocoa'
-[test_taskbarprogress_service.xul]
-# disabled for very frequent orange--bug 630567
-skip-if = os != 'win' || true
-[test_ui_stays_open_on_alert_clickback.xul]
[test_unknownContentType_delayedbutton.xul]
[test_unknownContentType_dialog_layout.xul]
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_backspace_key_removes.xul
+++ /dev/null
@@ -1,176 +0,0 @@
-<?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/. -->
-<!--
- * 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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-var dmFile = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
-dmFile.append("dm-ui-test.file");
-dmFile.createUnique(Ci.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: 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 dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- 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 (var dl of DownloadData) {
- for (var prop in dl)
- stmt.params[prop] = dl[prop];
-
- stmt.execute();
- }
- stmt.finalize();
-
- // See if the DM is already open, and if it is, close it!
- var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- var win = wm.getMostRecentWindow("Download:Manager");
- if (win)
- win.close();
-
- let os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testObs = {
- observe: function(aSubject, aTopic, aData)
- {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- SimpleTest.waitForFocus(function () { deleteDownload(aSubject) }, aSubject);
- }
- };
-
- function deleteDownload(win) {
- let doc = win.document;
-
- let stmt = db.createStatement("SELECT COUNT(*) FROM moz_downloads");
- try {
- stmt.executeStep();
- let richlistbox = doc.getElementById("downloadView");
- richlistbox.selectedIndex = 0;
- is(stmt.getInt32(0), richlistbox.children.length,
- "The database and the number of downloads display matches");
- stmt.reset();
-
- let len = DownloadData.length;
- for (let i = 0; i < len; i++) {
- synthesizeKey("VK_BACK_SPACE", {}, 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);
- 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
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_basic_functionality.xul
+++ /dev/null
@@ -1,219 +0,0 @@
-<?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/. -->
-<!--
- * 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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-var dmFile = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
-dmFile.append("dm-ui-test.file");
-dmFile.createUnique(Ci.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: 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_numberOfRichlistitems(aWin)
-{
- var doc = aWin.document;
- var richlistbox = doc.getElementById("downloadView");
- is(richlistbox.children.length, DownloadData.length,
- "There is the correct number of richlistitems");
-}
-
-function test_properDownloadData(aWin)
-{
- // This also tests the ordering of the display
- var doc = aWin.document;
- var richlistbox = doc.getElementById("downloadView");
- for (var i = 0; i < richlistbox.children.length; i++) {
- var elm = richlistbox.children[i];
- is(elm.getAttribute("target"), DownloadData[i].name,
- "Download names match up");
- is(elm.getAttribute("state"), DownloadData[i].state,
- "Download states match up");
- is(elm.getAttribute("file"), DownloadData[i].target,
- "Download targets match up");
- is(elm.getAttribute("uri"), DownloadData[i].source,
- "Download sources match up");
- }
-}
-
-var testFuncs = [
- test_numberOfRichlistitems
- , test_properDownloadData
-];
-
-function test()
-{
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- 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 (var dl of DownloadData) {
- for (var prop in dl)
- stmt.params[prop] = dl[prop];
-
- stmt.execute();
- }
- stmt.finalize();
-
- // See if the DM is already open, and if it is, close it!
- var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- var win = wm.getMostRecentWindow("Download:Manager");
- if (win)
- win.close();
-
- let os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testObs = {
- observe: function(aSubject, aTopic, aData)
- {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
- win.focus();
-
- // Now we can run our tests
- for (let t of 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
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_bug_412360.xul
+++ /dev/null
@@ -1,175 +0,0 @@
-<?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/. -->
-<!--
- * This tests bug 412360, which caused problems when trying to save javascript
- * URIs. This is not an xpcshell unit test because it triggers an assertion,
- * which causes xpcshell test cases to fail.
--->
-
-<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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-
-let didFail = false;
-var file;
-
-let prefBranch = Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefBranch);
-
-let factory = {
- createInstance: function(aOuter, aIid) {
- if (aOuter != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- return promptService.QueryInterface(aIid);
- }
-};
-
-let promptService = {
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIPromptService]),
- alert: function() {
- ok(didFail, "javascript: uri failed and showed a message");
- file.remove(false);
-
- cleanUpFactory();
- SimpleTest.finish();
- }
-};
-
-Components.manager.QueryInterface(Ci.nsIComponentRegistrar).
-registerFactory(Components.ID("{6cc9c9fe-bc0b-432b-a410-253ef8bcc699}"),
- "PromptService", "@mozilla.org/embedcomp/prompt-service;1",
- factory
-);
-
-function cleanUpFactory() {
- // Unregister the factory so we do not leak
- Components.manager.QueryInterface(Ci.nsIComponentRegistrar).
- unregisterFactory(
- Components.ID("{6cc9c9fe-bc0b-432b-a410-253ef8bcc699}"),
- factory
- );
-}
-
-function test()
-{
- var dmui = getDMUI();
- if (!dmui) {
- cleanUpFactory();
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- let db = dm.DBConnection;
-
- // Empty any old downloads
- db.executeSimpleSQL("DELETE FROM moz_downloads");
-
- let stmt = db.createStatement(
- "INSERT INTO moz_downloads (source, target, state, endTime) " +
- "VALUES (?1, ?2, ?3, ?4)");
-
- try {
- // Saving javascript URIs doesn't work
- stmt.bindByIndex(0, "javascript:5");
-
- // Download to a temp local file
- file = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
- file.append("javascriptURI");
- file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
- stmt.bindByIndex(1, Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService).newFileURI(file).spec);
-
- // Start it as canceled
- stmt.bindByIndex(2, dm.DOWNLOAD_CANCELED);
-
- stmt.bindByIndex(3, Date.now() * 1000);
-
- // Add it!
- stmt.execute();
- }
- finally {
- stmt.finalize();
- }
-
- let listener = {
- onDownloadStateChange: function(aState, aDownload)
- {
- switch (aDownload.state) {
- case dm.DOWNLOAD_FAILED:
- // Remember that we failed for the prompt service
- didFail = true;
-
- ok(true, "javascript: uri failed instead of getting stuck");
- dm.removeListener(listener);
- break;
- }
- }
- };
- dm.addListener(listener);
-
- // Close the UI if necessary
- let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- let win = wm.getMostRecentWindow("Download:Manager");
- if (win) win.close();
-
-
- let os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testObs = {
- observe: function(aSubject, aTopic, aData)
- {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- os.removeObserver(testObs, DLMGR_UI_DONE);
-
- SimpleTest.waitForFocus(function () {
- let win = aSubject;
-
- // Down arrow to select the download
- synthesizeKey("VK_DOWN", {}, win);
-
- // Enter key to retry the download
- synthesizeKey("VK_RETURN", {}, win);
- }, aSubject);
- }
- };
-
- // Register with the observer service
- os.addObserver(testObs, DLMGR_UI_DONE, false);
-
- // Show the Download Manager UI
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_bug_429247.xul
+++ /dev/null
@@ -1,144 +0,0 @@
-<?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 429247 to make sure clicking on whitespace in the Download
- * Manager doesn't run the default action on the selected download.
--->
-
-<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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-function test()
-{
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
- let dmFile = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
- dmFile.append("dm-ui-test.file");
- dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
- let gTestPath = ios.newFileURI(dmFile).spec;
-
- // Data to populate the download manager with
- 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
- }
-
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- let db = dm.DBConnection;
-
- // Empty any old downloads
- db.executeSimpleSQL("DELETE FROM moz_downloads");
-
- let 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 prop in DownloadData)
- stmt.params[prop] = DownloadData[prop];
-
- stmt.execute();
- stmt.finalize();
-
- // Close the UI if necessary
- let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- let win = wm.getMostRecentWindow("Download:Manager");
- if (win) win.close();
-
- let obs = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testObs = {
- observe: function(aSubject, aTopic, aData) {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
- win.focus();
- let $ = aId => win.document.getElementById(aId);
- let downloadView = $("downloadView");
-
- // Default test/check for invocations
- let invokeCount = 0;
- let counter = () => invokeCount++;
-
- // Array of tests that consist of the download manager
- // function to temporarily replace, method to use in its place, value to
- // use when checking correctness
- let defaultForSelectedTest = ["doDefaultForSelected", counter, counter];
-
- // All the expected results
- let allExpected = [0, "The default action was not performed"];
-
- // Select the first download
- downloadView.selectedIndex = 0;
-
- let [func, test, value] = defaultForSelectedTest;
- // Make a copy of the original function and replace it with a test
- let copy = win[func];
- win[func] = test;
-
- // Get the offsetY of the whitespace under the download
- let downloadItem = downloadView.getItemAtIndex(0);
- let boxOffset = downloadItem.boxObject.height + 1;
- // The last download in the download manager + 1 is whitespace
- synthesizeMouse(downloadItem, 0, boxOffset, {clickCount: 2}, win);
-
- // Make sure the value is as expected
- let [correct, message] = allExpected;
- ok(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
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_bug_462172.xul
+++ /dev/null
@@ -1,174 +0,0 @@
-<?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/. -->
-<!--
- * Assure download manager can load valid list item as
- * "application/moz-x-file"
-
-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
-close window
-
--->
-<window title="Mozilla Bug 462172"
- xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- onload="test();">
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
- <script type="application/javascript">
- <![CDATA[
-
- /** Test for Bug 462172 **/
-var missingFileElid;
-var realFileElid;
-const kFiller = "notApplicable";
-const kFillerURL = "https://bugzilla.mozilla.org/show_bug.cgi?id=462172"
-var realFile = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("CurWorkD", Ci.nsIFile);
-var missingFile = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("CurWorkD", Ci.nsIFile);
-
-var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-
-realFile.append(kFiller);
-realFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
-var realFilePath = ios.newFileURI(realFile).spec;
-
-missingFile.append(kFiller);
-missingFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
-var missingFilePath = ios.newFileURI(missingFile).spec;
-missingFile.remove(false);
-
-// Dummy data for our files.
-// 'source' field must be in form of an 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 compareStrFunc(actualData, expectedData) {
- return expectedData === actualData;
-}
-
-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,
- eqTest : compareStrFunc },
- { type : "text/plain",
- data : realFilePath,
- eqTest : compareStrFunc }
-]];
-var dragMissingFile = [[
- { type :"application/x-moz-file",
- data : missingFile,
- eqTest : compareFunc },
- { type : "text/uri-list",
- data : missingFilePath,
- eqTest : compareStrFunc },
- { type : "text/plain",
- data : missingFilePath,
- eqTest : compareStrFunc }
-]];
-
-function test() {
-
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- // load files into db
- var dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- var db = dm.DBConnection;
-
- var stmt = db.createStatement(
- "INSERT INTO moz_downloads ( name, source, target, state)" +
- "VALUES (:name, :source, :target, :state)");
- for (var dl of DownloadData) {
- for (var prop in dl)
- stmt.params[prop] = dl[prop];
- stmt.execute();
- if (dl.target == missingFilePath)
- missingFileElid = "dl" + db.lastInsertRowID;
- else if (dl.target == realFilePath)
- realFileElid = "dl" + db.lastInsertRowID;
- }
- stmt.finalize();
-
- // See if the DM is already open, and if it is, close it!
- var win = getDMWindow();
- if (win) win.close();
-
- var os = 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;
-
- var win = aSubject.QueryInterface(Ci.nsIDOMWindow);
- win.focus();
-
- // Now we can run our tests
- var result = synthesizeDragStart(win.document.getElementById(realFileElid), dragRealFile, win);
- is(result, null, "Checking for Real file match");
- result = synthesizeDragStart(win.document.getElementById(missingFileElid), dragMissingFile, win);
- isnot(result, null, "Drag start did not return item for missing file");
-
- // Done.
- win.close();
- realFile.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
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_cleanup_search.xul
+++ /dev/null
@@ -1,149 +0,0 @@
-<?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 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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-function test()
-{
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- let db = dm.DBConnection;
-
- // Empty any old downloads
- db.executeSimpleSQL("DELETE FROM moz_downloads");
-
- // Make a file name for the downloads
- let file = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
- file.append("cleanUp");
- let filePath = Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService).newFileURI(file).spec;
-
- let 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
- let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- let win = wm.getMostRecentWindow("Download:Manager");
- if (win) win.close();
-
- let obs = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testPhase = 0;
- let testObs = {
- observe: function(aSubject, aTopic, aData) {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
- win.focus();
- let $ = aId => win.document.getElementById(aId);
- let downloadView = $("downloadView");
- let searchbox = $("searchbox");
- let clearList = $("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.itemCount, 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.itemCount, 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.itemCount, 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
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_clear_button_disabled.xul
+++ /dev/null
@@ -1,149 +0,0 @@
-<?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/. -->
-<!--
- * 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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
-
- <![CDATA[
-
-let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-let dmFile = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
-dmFile.append("dm-ui-test.file");
-dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
-let 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: Ci.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: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING,
- currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
-];
-
-function runTest()
-{
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- setCleanState();
- populateDM(DoneDownloadData);
-
- let obs = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testPhase = 0;
- let testObs = {
- observe: function(aSubject, aTopic, aData) {
- let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
- win.focus();
- let doc = win.document;
- let searchbox = doc.getElementById("searchbox");
- let 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
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- populateDM(ActiveDownloadData);
- 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);
- setCleanState();
- SimpleTest.finish();
-
- break;
- }
- }
- };
-
- obs.addObserver(testObs, DLMGR_UI_DONE, false);
-
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_close_download_manager.xul
+++ /dev/null
@@ -1,101 +0,0 @@
-<?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/. -->
-<!--
- * 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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
-
- <![CDATA[
-
-const dmui = getDMUI();
-
-function testCloseDMWithEscKey(aWin)
-{
- function dmWindowClosedListener() {
- aWin.removeEventListener("unload", dmWindowClosedListener, false);
- ok(!dmui.visible, "DMUI closes with ESC key");
- dmui.show();
- }
- aWin.addEventListener("unload", dmWindowClosedListener, false);
-
- synthesizeKey("VK_ESCAPE", { }, aWin);
-}
-
-function testCloseDMWithAccelKey(aWin)
-{
- function dmWindowClosedListener() {
- aWin.removeEventListener("unload", dmWindowClosedListener, false);
- ok(!dmui.visible, "DMUI closes with accel + w");
- setCleanState();
- SimpleTest.finish();
- }
- aWin.addEventListener("unload", dmWindowClosedListener, false);
-
- synthesizeKey("w", { accelKey: true }, aWin);
-}
-
-function runTest()
-{
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- // Close the DM UI if it is already open
- let dm_win = getDMWindow();
- if (dm_win) dm_win.close();
-
- let testPhase = 0;
- // Specify an observer that will be notified when the dm has been rendered on screen
- let obs = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- let testObs = {
- observe: function(aSubject, aTopic, aData) {
- SimpleTest.waitForFocus(function () { closeDM(aSubject) }, aSubject);
- }
- };
-
- function closeDM(win) {
- switch(testPhase++) {
- case 0:
- testCloseDMWithEscKey(win);
- break;
- case 1:
- obs.removeObserver(testObs, DLMGR_UI_DONE);
- testCloseDMWithAccelKey(win);
- }
- }
- obs.addObserver(testObs, DLMGR_UI_DONE, false);
-
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_close_on_last_window.xul
+++ /dev/null
@@ -1,221 +0,0 @@
-<?xml version="1.0"?>
-<!--
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
-
-/**
- * Bug 544356 - This tests that the Download Manager is closed
- * when the last browser window is closed, if there are no active
- * downloads.
- */
--->
-
-<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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-const DLMGR_UI_DONE = "download-manager-ui-done";
-
-Components.utils.import("resource://gre/modules/Services.jsm");
-
-let gGen, dm, dmui, chromeWindow, testCleanup;
-
-function test()
-{
- if (testSetup()) {
- SimpleTest.waitForExplicitFinish();
-
- SimpleTest.requestFlakyTimeout(
- "This test uses non-zero timeout values because it needs to check the condition " +
- "that -nothing happened-, so there are no events or observers to watch and rely on. " +
- "The alternative way to test it would be too tied to the actual implementation to " +
- "be useful. The test is not unstable; see detailed explanation in bug 544356 comment 57."
- );
-
- //Start test
- gGen = doTest();
- gGen.next();
- }
-}
-
-function doTest()
-{
- let browserWindow1 = openBrowserWindow(continueTest);
- yield;
- let browserWindow2 = openBrowserWindow(continueTest);
- yield;
- openDownloadManager(continueTest);
- yield;
- let DMWindow = Services.wm.getMostRecentWindow("Download:Manager");
-
- addCloseListener([browserWindow1, browserWindow2]);
- browserWindow1.BrowserTryToCloseWindow();
-
- yield;
-
- // Wait for a moment and make sure the Download Manager didn't close,
- // because there's still one browser window
- setTimeout(continueTest, 500); yield;
- ok(dmui.visible, "Download Manager wasn't closed");
-
- let download = addDownload();
- // The download listener will pause the download and continue the test
- yield;
-
- browserWindow2.BrowserTryToCloseWindow();
- yield;
-
- // Wait for a moment and make sure the Download Manager didn't close,
- // because there's one active download
- setTimeout(continueTest, 500); yield;
- ok(dmui.visible, "Download Manager wasn't closed");
-
- dm.cancelDownload(download.id);
- dm.removeDownload(download.id);
-
- let browserWindow3 = openBrowserWindow(continueTest);
- yield;
-
- // Prepare to close last window
- ok(dmui.visible, "Download Manager wasn't closed");
-
- let isMac = /Mac/.test(navigator.platform);
- addCloseListener(isMac ? [browserWindow3] : [browserWindow3, DMWindow]);
- browserWindow3.BrowserTryToCloseWindow();
- if (isMac) {
- // Manually continue the test after a moment to make sure the Download Manager
- // didn't close
- setTimeout(continueTest, 500);
- }
- yield; yield;
-
- // Finally we reach the case where the Download Manager should have been closed
- if (isMac) {
- ok(dmui.visible, "Download Manager wasn't closed");
- DMWindow.close();
- } else {
- ok (!dmui.visible, "Download Manager was closed");
- }
-
- testCleanup();
- SimpleTest.finish();
- yield;
-}
-
-function continueTest()
-{
- SimpleTest.executeSoon(function() {
- gGen.next();
- });
-}
-
-function testSetup()
-{
- chromeWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
- getInterface(Components.interfaces.nsIWebNavigation).
- QueryInterface(Components.interfaces.nsIDocShellTreeItem).
- rootTreeItem.
- QueryInterface(Components.interfaces.nsIInterfaceRequestor).
- getInterface(Components.interfaces.nsIDOMWindow);
-
- dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return false;
- }
-
- dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
-
- // Change the window type so this one doesn't count as a browser window
- let oldWinType = chromeWindow.document.documentElement.getAttribute("windowtype");
- chromeWindow.document.documentElement.setAttribute("windowtype", "navigator:testrunner");
-
- downloadListener = {
-
- onDownloadStateChange: function(aState, aDownload)
- {
- if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_PAUSED) {
- continueTest();
- } else if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING) {
- dm.pauseDownload(aDownload.id);
- }
- },
-
- onStateChange: function() { },
- onProgressChange: function() { },
- onSecurityChange: function() { }
- };
-
- dm.addListener(downloadListener);
-
- testCleanup = function() {
- dm.removeListener(downloadListener);
- chromeWindow.document.documentElement.setAttribute("windowtype", oldWinType);
- };
-
- return true;
-}
-
-function openBrowserWindow(callback)
-{
- let browserWindow = openDialog(chromeWindow.location, "_blank",
- "chrome,all,dialog=no", "about:blank");
-
- let helperFunc = function() {
- callback();
- browserWindow.removeEventListener("load", helperFunc, false);
- }
-
- browserWindow.addEventListener("load", helperFunc, false);
-
- return browserWindow;
-}
-
-function openDownloadManager(callback)
-{
- let testObs = {
- observe: function(aSubject, aTopic, aData) {
- if (aTopic != DLMGR_UI_DONE) {
- return;
- }
-
- callback();
- Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
- }
- };
-
- Services.obs.addObserver(testObs, DLMGR_UI_DONE, false);
-
- dmui.show();
-}
-
-function addCloseListener(aWins)
-{
- aWins.forEach(function(win) {
- let listener = function() {
- win.removeEventListener("unload", listener, false);
- continueTest();
- };
- win.addEventListener("unload", listener, false);
- });
-}
-
- ]]>
- </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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_delete_key_removes.xul
+++ /dev/null
@@ -1,182 +0,0 @@
-<?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/. -->
-<!--
- * This test ensures that the delete key removes a download. This was added by
- * bug 411172. SimpleTest.waitForFocus(function () { closeDM(aSubject) }, aSubject);
- }
- };
-
- function closeDM(win) {
-
- */
--->
-
-<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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-var dmFile = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
-dmFile.append("dm-ui-test.file");
-dmFile.createUnique(Ci.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: 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 dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- 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 (var dl of DownloadData) {
- for (var prop in dl)
- stmt.params[prop] = dl[prop];
-
- stmt.execute();
- }
- stmt.finalize();
-
- // See if the DM is already open, and if it is, close it!
- var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- var win = wm.getMostRecentWindow("Download:Manager");
- if (win)
- win.close();
-
- let os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testObs = {
- observe: function(aSubject, aTopic, aData)
- {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- SimpleTest.waitForFocus(function () { deleteDownload(aSubject) }, aSubject);
- }
- };
-
- function deleteDownload(win) {
- let doc = win.document;
-
- let stmt = db.createStatement("SELECT COUNT(*) FROM moz_downloads");
- try {
- stmt.executeStep();
- let richlistbox = doc.getElementById("downloadView");
- richlistbox.selectedIndex = 0;
- is(stmt.getInt32(0), richlistbox.children.length,
- "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);
- 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
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_destinationURI_annotation.xul
+++ /dev/null
@@ -1,204 +0,0 @@
-<?xml version="1.0"?>
-<!--
-/* Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ */
-
-/**
- * Bug 701607 - This test verifies that the destinationFileName and destinationFileURI
- * annotations are set even for files that didn't have custom file names chosen, e.g.
- * through the unknownContentType window.
- */
--->
-
-<window title="Test destinationFileURI annotation"
- xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- onload="init()">
-
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-const UCT_URI = "chrome://mozapps/content/downloads/unknownContentType.xul";
-
-// This file will trigger the simple UI, where only the Save and Cancel buttons are available
-const DOWNLOAD_URI = "http://mochi.test:8888/chrome/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif";
-const FILE_NAME = "unknownContentType_dialog_layout_data.pif";
-
-let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]
- .getService(Ci.nsIWindowWatcher);
-
-let dm = Cc["@mozilla.org/download-manager;1"]
- .getService(Ci.nsIDownloadManager);
-
-let os = Cc["@mozilla.org/observer-service;1"]
- .getService(Ci.nsIObserverService);
-
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
-Components.utils.import("resource://testing-common/PlacesTestUtils.jsm");
-
-let checkDestination = false,
- checkFileName = false;
-
-SimpleTest.waitForExplicitFinish();
-
-let annoObserver = {
- onPageAnnotationSet: function AO_onPageAnnotationSet(aPage, aName){
- if (aPage.spec == DOWNLOAD_URI) {
- let value = PlacesUtils.annotations.getPageAnnotation(aPage, aName);
- switch (aName) {
- case "downloads/destinationFileURI":
- checkDestination = true;
- ok(value.indexOf(FILE_NAME) != -1, "file destination was set correctly");
- break;
-
- case "downloads/destinationFileName":
- checkFileName = true;
- ok(value == FILE_NAME, "file name was set correctly");
- break;
- }
- }
- },
- onItemAnnotationSet: function() {},
- onPageAnnotationRemoved: function() {},
- onItemAnnotationRemoved: function() {}
-}
-
-let TestFinisher = {
- _dmuiDone: false,
- _callback: null,
-
- observe: function(aSubject, aTopic, aData) {
- os.removeObserver(TestFinisher, "download-manager-ui-done");
-
- if (this._callback) {
- SimpleTest.executeSoon(this._callback);
- this._callback = null;
- } else {
- this._dmuiDone = true;
- }
- },
-
- waitForDMUIDone: function(callback) {
- if (this._dmuiDone) {
- SimpleTest.executeSoon(callback);
- } else {
- this._callback = callback;
- }
- }
-};
-
-os.addObserver(TestFinisher, "download-manager-ui-done", false);
-
-let downloadListener = {
-
- onDownloadStateChange: function(aState, aDownload) {
- if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED) {
- is(aDownload.source.spec, DOWNLOAD_URI, "file was downloaded");
- dm.removeDownload(aDownload.id);
-
- try {
- aDownload.targetFile.remove(false);
- } catch (ex) {}
-
- TestFinisher.waitForDMUIDone(endTest);
-
- }
- },
-
- onStateChange: function() {},
- onProgressChange: function() {},
- onSecurityChange: function() {}
-};
-
-function init() {
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- SimpleTest.finish();
- return;
- }
-
- // Ensure that the download manager callbacks always use the window UI instead
- // of the panel in the browser's window.
- Services.prefs.setBoolPref("browser.download.useToolkitUI", true);
-
- // Check if the file we're trying to download already exists in the destination
- // folder, and if so, remove it first to ensure that the test works properly.
- let fileToDownload = dm.userDownloadsDirectory.clone();
- fileToDownload.append(FILE_NAME);
- if (fileToDownload.exists()) {
- fileToDownload.remove(false);
- info("File to download had to be removed as it already existed.");
- }
-
- ww.registerNotification(windowObserver);
- PlacesUtils.annotations.addObserver(annoObserver, false);
- dm.addListener(downloadListener);
-
- let frame = document.getElementById("testframe");
- frame.setAttribute("src", DOWNLOAD_URI);
-}
-
-let windowObserver = {
- observe: function(aSubject, aTopic, aData) {
- if (aTopic != "domwindowopened") {
- return;
- }
-
- let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
-
- win.addEventListener("load", function onLoad(event) {
- win.removeEventListener("load", onLoad, false);
-
- if (win.location == UCT_URI) {
- ww.unregisterNotification(windowObserver);
- SimpleTest.executeSoon(function() {
- win.document.documentElement._fireButtonEvent("accept");
- win.close();
- win = null;
- });
- }
- }, false);
- }
-};
-
-function endTest() {
- ok(checkDestination, "file destination was set");
- ok(checkFileName, "file name was set");
-
- PlacesUtils.annotations.removeObserver(annoObserver);
- dm.removeListener(downloadListener);
-
- ww = null;
- PlacesUtils = null;
- dm = null;
- os = null;
-
- Cc["@mozilla.org/appshell/window-mediator;1"]
- .getService(Ci.nsIWindowMediator)
- .getMostRecentWindow("Download:Manager")
- .close();
-
- Services.prefs.clearUserPref("browser.download.useToolkitUI");
-
- PlacesTestUtils.clearHistory().then(SimpleTest.finish);
-}
-
- ]]>
- </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>
-
- <iframe xmlns="http://www.w3.org/1999/xhtml"
- id="testframe">
- </iframe>
-</window>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_esc_key_closes_clears.xul
+++ /dev/null
@@ -1,95 +0,0 @@
-<?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/. -->
-<!--
- * This test ensures that the escape key closes the download manager. This test
- * was added in bug 416303.
--->
-
-<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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-const DLMGR_UI_DONE = "download-manager-ui-done";
-
-let os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
-
-function test()
-{
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- // Close the UI if necessary
- let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- let win = wm.getMostRecentWindow("Download:Manager");
- if (win) win.close();
-
- // Register with the observer service
- os.addObserver(testObs, DLMGR_UI_DONE, false);
-
- // Show the Download Manager UI
- dmui.show();
-
- SimpleTest.waitForExplicitFinish();
-}
-
-let testObs = {
- observe: function(aSubject, aTopic, aData)
- {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- SimpleTest.waitForFocus(function () { continueTest(aSubject) }, aSubject);
- }
-};
-
-function continueTest(win)
-{
- // Put in a value to clear out
- let search = win.document.getElementById("searchbox");
- search.focus();
- search.value = "download manager escape test";
-
- // Send the escape key to the download manager UI window
- let sendEscape = () => synthesizeKey("VK_ESCAPE", {}, win);
-
- // Escape from search box
- sendEscape();
- is(win.closed, false,
- "Escape doesn't close the window when in the search box");
- is(search.value, "", "Escape correctly emptied the search box");
-
- // Escape from list (escape from search box moves focus to list)
- sendEscape();
- is(win.closed, true,
- "Previous escape moved focus to list and now escape closed the window");
-
- os.removeObserver(testObs, DLMGR_UI_DONE);
- SimpleTest.finish();
-};
-
- ]]>
- </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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_multi_select.xul
+++ /dev/null
@@ -1,212 +0,0 @@
-<?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 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"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-function test()
-{
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- let db = dm.DBConnection;
-
- // Empty any old downloads
- db.executeSimpleSQL("DELETE FROM moz_downloads");
-
- let 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 = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
- file.append(site);
- let fileSpec = Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService).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
- let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- let win = wm.getMostRecentWindow("Download:Manager");
- if (win) win.close();
-
- let obs = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testPhase = 0;
- let testObs = {
- observe: function(aSubject, aTopic, aData) {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- SimpleTest.waitForFocus(function () { continueTest(aSubject) }, aSubject);
- }
- };
-
- function getLoadContext() {
- return window.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIWebNavigation)
- .QueryInterface(Ci.nsILoadContext);
- }
-
- function continueTest(win) {
- let $ = aId => win.document.getElementById(aId);
- let downloadView = $("downloadView");
-
- // Default test/check for invocations
- let invokeCount = 0;
- let counter = () => invokeCount++;
-
- // Accessors for returning a value for various properties
- let getItems = () => downloadView.itemCount;
- let getSelected = () => downloadView.selectedCount;
- let getClipboard = function() {
- let clip = Cc["@mozilla.org/widget/clipboard;1"].
- getService(Ci.nsIClipboard);
- let trans = Cc["@mozilla.org/widget/transferable;1"].
- createInstance(Ci.nsITransferable);
- trans.init(getLoadContext());
- trans.addDataFlavor("text/unicode");
- clip.getData(trans, clip.kGlobalClipboard);
- let str = {};
- let strLen = {};
- trans.getTransferData("text/unicode", str, strLen);
- return str.value.QueryInterface(Ci.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
- let 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", "openReferrer", counter, counter],
- ["copyLocation", null, null, getClipboard],
- ["removeFromList", null, null, getItems],
- ["selectAll", null, null, getSelected],
- ];
-
- // All the expected results for both single and double selections
- let 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: [1, "Retried one download"],
- openReferrer: [1, "Opened one referrer"],
- copyLocation: ["http://ed.agadak.net/file", "Copied one location"],
- removeFromList: [3, "Removed one downloads, 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: [2, "Retried both downloads"],
- openReferrer: [2, "Opened both referrers"],
- copyLocation: ["http://mozilla.org/file\nhttp://mozilla.com/file", "Copied both locations"],
- removeFromList: [1, "Removed both downloads, remaining 1"],
- selectAll: [1, "Selected the 1 remaining download"],
- },
- };
-
- // Run two tests: single selected, double selected
- for (let whichTest of ["single", "double"]) {
- let expected = allExpected[whichTest];
-
- // Select the first download
- downloadView.selectedIndex = 0;
-
- // Select 2 downloads for double
- if (whichTest == "double")
- synthesizeKey("VK_DOWN", { shiftKey: true }, win);
-
- 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
- $("menuitem_" + command).doCommand();
-
- // Make sure the value is as expected
- let [correct, message] = expected[command];
- ok(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
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_multiword_search.xul
+++ /dev/null
@@ -1,150 +0,0 @@
-<?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 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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-function test()
-{
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- let db = dm.DBConnection;
-
- // Empty any old downloads
- db.executeSimpleSQL("DELETE FROM moz_downloads");
-
- // Make a file name for the downloads
- let file = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
- file.append("multiWord");
- let filePath = Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService).newFileURI(file).spec;
-
- let 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
- let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- let win = wm.getMostRecentWindow("Download:Manager");
- if (win) win.close();
-
- let obs = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testPhase = -1;
- let testObs = {
- observe: function(aSubject, aTopic, aData) {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
- win.focus();
- let $ = aId => win.document.getElementById(aId);
- let downloadView = $("downloadView");
- let searchbox = $("searchbox");
-
- let search = function(aTerms) {
- searchbox.value = aTerms;
- searchbox.doCommand();
- };
-
- let testResults = function(aExpected) {
- is(downloadView.itemCount, 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 104 GB august 2");
-
- break;
- case 1:
- // Done populating the two items
- testResults(2);
-
- // Do partial word matches including the site
- search("Agadak.net aug 2 downl 104");
-
- 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, false);
-
- // Show the Download Manager UI
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_pause_button_state.xul
+++ /dev/null
@@ -1,144 +0,0 @@
-<?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/. -->
-<!--
- * This tests bug 410289. Specifically, it tests that the pause button is
- * active for resumable downloads, and inactive for non-resumable ones.
--->
-
-<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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-var dmFile = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
-dmFile.append("dm-ui-test.file");
-dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
-var gTestPath = ios.newFileURI(dmFile).spec;
-
-const DownloadData = [
- { name: "Firefox 2.0.0.11.dmg",
- source: "http://mozilla-mirror.naist.jp//firefox/releases/2.0.0.11/mac/en-US/Firefox%202.0.0.11.dmg",
- target: gTestPath,
- startTime: 1200185939538521,
- endTime: 1200185939538521,
- entityID: "%22216c12-1116bd8-440070d5d2700%22/17918936/Thu, 29 Nov 2007 01:15:40 GMT",
- state: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING,
- currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
- { name: "Firefox 2.0.0.11.dmg",
- source: "http://mozilla-mirror.naist.jp//firefox/releases/2.0.0.11/mac/en-US/Firefox%202.0.0.11.dmg",
- target: gTestPath,
- startTime: 1200185939538520,
- endTime: 1200185939538520,
- entityID: "",
- state: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING,
- currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
-];
-
-function test()
-{
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- 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, entityID) " +
- "VALUES (:name, :source, :target, :startTime, :endTime, :state, " +
- ":currBytes, :maxBytes, :preferredAction, :autoResume, :entityID)");
- for (var dl of DownloadData) {
- for (var prop in dl)
- stmt.params[prop] = dl[prop];
-
- stmt.execute();
- }
- stmt.finalize();
-
- // See if the DM is already open, and if it is, close it!
- var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- var win = wm.getMostRecentWindow("Download:Manager");
- if (win)
- win.close();
-
- let os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testObs = {
- observe: function(aSubject, aTopic, aData)
- {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
- win.focus();
- let doc = win.document;
-
- let richlistbox = doc.getElementById("downloadView");
- for (let i = 0; i < DownloadData.length; i++) {
- let dl = richlistbox.children[i];
- let buttons = dl.buttons;
- for (let j = 0; j < buttons.length; j++) {
- let button = buttons[j];
- if ("cmd_pause" == button.getAttribute("cmd")) {
- let id = dl.getAttribute("dlid");
-
- // check if it should be disabled or not
- let resumable = dm.getDownload(id).resumable;
- is(DownloadData[i].entityID ? true : false, resumable,
- "Pause button is properly disabled");
-
- // also check if tooltip text was updated
- if (!resumable) {
- let sb = doc.getElementById("downloadStrings");
- is(button.getAttribute("tooltiptext"), sb.getString("cannotPause"),
- "Pause button has proper text");
- }
- }
- }
- }
-
- 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
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_removeDownload_updates_ui.xul
+++ /dev/null
@@ -1,128 +0,0 @@
-<?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 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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-var dmFile = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
-dmFile.append("dm-ui-test.file");
-dmFile.createUnique(Ci.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: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
- currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
-];
-
-function test()
-{
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- 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 (var dl of DownloadData) {
- for (var prop in dl)
- stmt.params[prop] = dl[prop];
-
- stmt.execute();
- }
- stmt.finalize();
-
- // See if the DM is already open, and if it is, close it!
- var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- var win = wm.getMostRecentWindow("Download:Manager");
- if (win)
- win.close();
-
- let os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testObs = {
- observe: function(aSubject, aTopic, aData)
- {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
- win.focus();
- let doc = win.document;
-
- // Note: This also tests the ordering of the display
- let stmt = db.createStatement("SELECT id FROM moz_downloads");
- let id = -1;
- try {
- stmt.executeStep();
- id = stmt.getInt64(0);
- }
- finally {
- stmt.reset();
- stmt.finalize();
- }
-
- dm.removeDownload(id);
- let richlistbox = doc.getElementById("downloadView");
- is(richlistbox.children.length, 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
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_retention_is_0_closes.xul
+++ /dev/null
@@ -1,175 +0,0 @@
-<?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/. -->
-<!--
- * This tests that the download manager UI closes upon download completion when
- * browser.download.manager.retention is set to 0. This test was added in bug
- * 413093.
--->
-
-<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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-function setPref(aDoTest)
-{
- let prefs = Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefBranch);
-
- // If we're testing, set retention to auto-remove and auto-close
- prefs.setIntPref("browser.download.manager.retention", aDoTest ? 0 : 2);
- prefs.setBoolPref("browser.download.manager.closeWhenDone", aDoTest);
-}
-
-function bug413093obs()
-{
- this.mDownload = null;
- this.wasPaused = false;
-}
-bug413093obs.prototype = {
- observe: function(aSubject, aTopic, aData)
- {
- if ("domwindowopened" == aTopic) {
- // If we opened before we were paused, we need to set up our proper state
- // We also should not try to resume (we weren't paused!)
- if (!this.wasPaused) {
- dump("domwindowopened callback - not pausing or resuming\n");
- this.wasPaused = true;
- return;
- }
-
- dump("domwindowopened callback - resuming download\n");
-
- // Resume the download now that UI is up and running
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- dm.resumeDownload(this.mDownload.id);
- }
- else if("domwindowclosed" == aTopic) {
- let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
- getService(Ci.nsIWindowWatcher);
- ww.unregisterNotification(this);
-
- // Let the UI finish doing whatever it needs to do
- SimpleTest.executeSoon(function() {
- setPref(false);
-
- let dmui = Cc["@mozilla.org/download-manager-ui;1"].
- getService(Ci.nsIDownloadManagerUI);
- ok(!dmui.visible, "Download Manager UI is not showing");
-
- // reset the changed config values to default value
- let prefs = Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefService);
- prefs.clearUserPref("browser.download.manager.retention");
- prefs.clearUserPref("browser.download.manager.closeWhenDone");
-
- SimpleTest.finish();
- });
- }
- },
-
- onDownloadStateChange: function(aOldState, aDownload)
- {
- if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING &&
- !this.wasPaused) {
- dump("onDownloadStateChange - pausing download\n");
- this.wasPaused = true;
-
- // Pause the download until the UI shows up
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- dm.pauseDownload(aDownload.id);
- }
-
- if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED) {
- aDownload.targetFile.remove(false);
-
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- dm.removeListener(this);
-
- // If this test is going to pass, we'll get a domwindowclosed notification
- }
- },
- onStateChange: function(a, b, c, d, e) { },
- onProgressChange: function(a, b, c, d, e, f, g) { },
- onSecurityChange: function(a, b, c, d) { },
-};
-function test()
-{
- function addDownload() {
- function createURI(aObj) {
- let ios = Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService);
- return (aObj instanceof Ci.nsIFile) ? ios.newFileURI(aObj) :
- ios.newURI(aObj, null, null);
- }
-
- const nsIWBP = Ci.nsIWebBrowserPersist;
- let persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
- .createInstance(Ci.nsIWebBrowserPersist);
- persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
- nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
- nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
-
- let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties);
- let destFile = dirSvc.get("ProfD", Ci.nsIFile);
- destFile.append("download.result");
- if (destFile.exists())
- destFile.remove(false);
-
- let src = createURI("http://example.com/httpd.js");
- let target = createURI(destFile);
- let tr = Cc["@mozilla.org/transfer;1"].createInstance(Ci.nsITransfer);
- tr.init(src, target, "test download", null, Math.round(Date.now() * 1000),
- null, persist, false);
- persist.progressListener = tr;
- persist.saveURI(src, null, null, 0, null, null, destFile);
- }
-
- // First, we clear out the database
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
-
- // See if the DM is already open, and if it is, close it!
- let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- let win = wm.getMostRecentWindow("Download:Manager");
- if (win)
- win.close();
-
- let obs = new bug413093obs();
- dm.addListener(obs);
- setPref(true);
-
- // Start the test when the download manager window loads
- let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
- getService(Ci.nsIWindowWatcher);
- ww.registerNotification(obs);
-
- addDownload();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_search_clearlist.xul
+++ /dev/null
@@ -1,145 +0,0 @@
-<?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 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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-function test()
-{
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- let db = dm.DBConnection;
-
- // Empty any old downloads
- db.executeSimpleSQL("DELETE FROM moz_downloads");
-
- // Make a file name for the downloads
- let file = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
- file.append("cleanUp");
- let filePath = Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService).newFileURI(file).spec;
-
- let 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
- let sites = [];
- for (let i = 0; i < 50; i++)
- sites.push("i-hate.clear-list-" + i);
-
- // Add one download that matches the search
- let 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
- let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- let win = wm.getMostRecentWindow("Download:Manager");
- if (win) win.close();
-
- let obs = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testPhase = 0;
- let testObs = {
- observe: function(aSubject, aTopic, aData) {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
- win.focus();
- let $ = aId => win.document.getElementById(aId);
- let downloadView = $("downloadView");
- let searchbox = $("searchbox");
- let clearList = $("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.itemCount, 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.itemCount, 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
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_search_keys.xul
+++ /dev/null
@@ -1,103 +0,0 @@
-<?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/. -->
-<!--
- * 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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-function test_meta_k(aWin)
-{
- let doc = aWin.document;
- let searchbox = doc.getElementById("searchbox");
- let richlistbox = doc.getElementById("downloadView");
-
- // Enusre the serachbox is not focused
- richlistbox.focus();
-
- // Dispatch the right key combination
- synthesizeKey("k", {accelKey: true}, aWin);
-
- ok(searchbox.hasAttribute("focused"), "Searchbox is focused");
-}
-
-let testFuncs = [
- test_meta_k,
-]
-
-function test()
-{
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
-
- // See if the DM is already open, and if it is, close it!
- let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- let win = wm.getMostRecentWindow("Download:Manager");
- if (win)
- win.close();
-
- let os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let 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();
- 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
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_select_all.xul
+++ /dev/null
@@ -1,122 +0,0 @@
-<?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 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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-function test()
-{
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- let db = dm.DBConnection;
-
- // Empty any old downloads
- db.executeSimpleSQL("DELETE FROM moz_downloads");
-
- // Make a file name for the downloads
- let file = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
- file.append("selectAll");
- let filePath = Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService).newFileURI(file).spec;
-
- let stmt = db.createStatement(
- "INSERT INTO moz_downloads (target, source, state) " +
- "VALUES (?1, ?2, ?3)");
-
- let 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
- let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- let win = wm.getMostRecentWindow("Download:Manager");
- if (win) win.close();
-
- let obs = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testObs = {
- observe: function(aSubject, aTopic, aData) {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- SimpleTest.waitForFocus(function () { checkSelectAndRemove(aSubject) }, aSubject);
- }
- };
-
- var checkSelectAndRemove = function(win)
- {
- let $ = aId => win.document.getElementById(aId);
- let downloadView = $("downloadView");
- is(downloadView.itemCount, sites.length, "All downloads displayed");
-
- // Select all downloads
- let isMac = navigator.platform.search("Mac") == 0;
- synthesizeKey("a", { metaKey: isMac, ctrlKey: !isMac }, win);
- is(downloadView.selectedCount, sites.length, "All downloads selected");
-
- // Delete all downloads
- synthesizeKey("VK_DELETE", {}, win);
- is(downloadView.itemCount, 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
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_space_key_pauses_resumes.xul
+++ /dev/null
@@ -1,174 +0,0 @@
-<?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/. -->
-<!--
- * 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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-function bug413985obs(aWin)
-{
- this.mWin = aWin;
- this.wasPaused = false;
- this.wasResumed = false;
- this.timer = null; // timer declared here to prevent premature GC
-}
-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 == Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING &&
- !this.wasPaused) {
- this.wasPaused = true;
- // dispatch a space keypress to pause the download
- synthesizeKey(" ", {}, this.mWin);
- }
-
- if (aDownload.state == Ci.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...
- this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
- this.timer.init(this, 0, Ci.nsITimer.TYPE_ONE_SHOT);
- }
-
- if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED) {
- ok(this.wasPaused && this.wasResumed,
- "The download was paused, and then resumed to completion");
- aDownload.targetFile.remove(false);
-
- var dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.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 dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- var dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
-
- function addDownload() {
- function createURI(aObj) {
- var ios = Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService);
- return (aObj instanceof Ci.nsIFile) ? ios.newFileURI(aObj) :
- ios.newURI(aObj, null, null);
- }
-
- const nsIWBP = Ci.nsIWebBrowserPersist;
- var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
- .createInstance(Ci.nsIWebBrowserPersist);
- persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
- nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
- nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
-
- var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties);
- var destFile = 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);
-
- var privacyContext = window.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIWebNavigation)
- .QueryInterface(Ci.nsILoadContext);
-
- persist.progressListener = dl.QueryInterface(Ci.nsIWebProgressListener);
- persist.saveURI(dl.source, null, null, 0, null, null, dl.targetFile, privacyContext);
-
- 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 = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- var win = wm.getMostRecentWindow("Download:Manager");
- if (win)
- win.close();
-
- let os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testObs = {
- observe: function(aSubject, aTopic, aData)
- {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- SimpleTest.waitForFocus(function () { continueTest(aSubject) }, aSubject);
- }
- };
-
- var continueTest = function(win)
- {
- let doc = win.document;
- dm.addListener(new bug413985obs(win));
-
- let dl = addDownload();
- // we need to focus the download as well
- doc.getElementById("downloadView").selectedIndex = 0;
- os.removeObserver(testObs, DLMGR_UI_DONE);
- };
-
- // Register with the observer service
- os.addObserver(testObs, DLMGR_UI_DONE, false);
-
- // Show the Download Manager UI
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_taskbarprogress_downloadstates.xul
+++ /dev/null
@@ -1,243 +0,0 @@
-<?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/. -->
-<!--
- * This tests that the Windows 7 Taskbar Progress is correctly updated when
- * the download state changes.
--->
-
-<window title="Win7 Taskbar Progress"
- xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- onload="test();">
-
- <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"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-const kTaskbarID = "@mozilla.org/windows-taskbar;1";
-const DOWNLOAD_MANAGER_URL = "chrome://mozapps/content/downloads/downloads.xul";
-const DLMGR_UI_DONE = "download-manager-ui-done";
-
-var Cu = Components.utils;
-const nsITP = Ci.nsITaskbarProgress;
-
-let DownloadTaskbarProgress, dm;
-let downloadA, downloadB, gGen;
-
-let testState = {
- activeDownloadCount: 0,
- pausedDownloadCount: 0,
- finishedDownloadCount: 0,
-
- regularStateTested: false,
- pausedStateTested: false,
- noDownloadsStateTested: false
-}
-
-function continueTest() {
- SimpleTest.executeSoon(function(){
- gGen.next();
- });
-}
-
-let wasPaused = {};
-
-let downloadListener = {
-
- onStateChange: function(a, b, c, d, e) {
- checkCorrectState();
- },
-
- onDownloadStateChange: function(aState, aDownload)
- {
-
- if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_PAUSED) {
- wasPaused[aDownload.id] = true;
- testState.pausedDownloadCount++;
- testState.activeDownloadCount--;
-
- continueTest();
- }
-
- if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED) {
- testState.activeDownloadCount--;
- testState.finishedDownloadCount++;
- aDownload.targetFile.remove(false);
-
- SimpleTest.executeSoon(checkCorrectState);
- if(testState.finishedDownloadCount == 2) {
- SimpleTest.executeSoon(finishTest);
- }
-
- }
-
- if (aDownload.state == Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING) {
- if (!wasPaused[aDownload.id])
- dm.pauseDownload(aDownload.id);
- continueTest();
- }
-
- },
-
- onProgressChange: function(a, b, c, d, e, f, g) { },
- onSecurityChange: function(a, b, c, d) { }
-};
-
-function testSteps() {
-
- // Step 1 - Add downloads and pause
-
- testState.activeDownloadCount++;
- downloadA = addDownload();
- yield; // added
- yield; // paused
-
- testState.activeDownloadCount++;
- downloadB = addDownload();
- yield; // added
- yield; // paused
-
- // Step 2 - Resume downloads
-
- testState.activeDownloadCount++;
- testState.pausedDownloadCount--;
- dm.resumeDownload(downloadA.id);
- yield;
-
- testState.activeDownloadCount++;
- testState.pausedDownloadCount--;
- dm.resumeDownload(downloadB.id);
- yield;
-
- yield;
-}
-
-function finishTest() {
- ok(testState.regularStateTested, "Tests went through regular download state");
- ok(testState.pausedStateTested, "Tests went through paused download state");
- ok(testState.noDownloadsStateTested, "Tests went through finished downloads state");
- dm.removeListener(downloadListener);
- gGen.close();
- SimpleTest.finish();
-}
-
-function checkCorrectState() {
-
- if(testState.activeDownloadCount < 0 || testState.pausedDownloadCount < 0) {
- ok(false, "There shouldn't be negative download counts");
- SimpleTest.finish();
- }
-
- let taskbarState = DownloadTaskbarProgress.taskbarState;
-
- if (testState.activeDownloadCount) {
- //There's at least one active download
- ok(taskbarState == nsITP.STATE_NORMAL || taskbarState == nsITP.STATE_INDETERMINATE, "Correct downloading state");
- testState.regularStateTested = true;
- } else if (testState.pausedDownloadCount) {
- //There are no active downloads but there are paused ones
- ok(taskbarState == nsITP.STATE_PAUSED, "Correct paused state");
- testState.pausedStateTested = true;
- } else {
- //No more downloads
- ok(taskbarState == nsITP.STATE_NO_PROGRESS, "Correct finished downloads state");
- testState.noDownloadsStateTested = true;
- }
-
-}
-
-function test() {
- testSetup();
-}
-
-function testSetup()
-{
- //Test setup
- let dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- let isWin = /Win/.test(navigator.platform);
- if (isWin) {
- let isWin7OrHigher = false;
- try {
- let version = Cc["@mozilla.org/system-info;1"]
- .getService(Ci.nsIPropertyBag2)
- .getProperty("version");
- isWin7OrHigher = (parseFloat(version) >= 6.1);
- } catch (ex) { }
-
- if (!isWin7OrHigher) {
- ok(true, "This test only runs on Windows 7 or higher");
- return;
- }
- }
-
- let tempScope = {};
- Cu.import("resource://gre/modules/DownloadTaskbarProgress.jsm", tempScope);
- Cu.import("resource://gre/modules/Services.jsm");
-
- DownloadTaskbarProgress = tempScope.DownloadTaskbarProgress;
- isnot(DownloadTaskbarProgress, null, "Download taskbar progress service exists");
- DownloadTaskbarProgress.init();
-
- if (isWin) {
- let TaskbarService = Cc[kTaskbarID].getService(Ci.nsIWinTaskbar);
- is(TaskbarService.available, true, "Taskbar Service is available");
- }
-
- dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
-
- // 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!
- let win = Services.wm.getMostRecentWindow("Download:Manager");
- if (win) {
- win.close();
- }
- let os = Services.obs;
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- gGen = testSteps();
- dm.addListener(downloadListener);
-
- let testObs = {
- observe: function(aSubject, aTopic, aData)
- {
- if (aTopic != DLMGR_UI_DONE) {
- return;
- }
- os.removeObserver(testObs, DLMGR_UI_DONE);
- continueTest();
- }
- };
-
- // Register with the observer service
- os.addObserver(testObs, DLMGR_UI_DONE, false);
-
- // Show the Download Manager UI
- dmui.show();
-
- 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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_taskbarprogress_service.xul
+++ /dev/null
@@ -1,193 +0,0 @@
-<?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/. -->
-<!--
- * This tests that the Windows 7 Taskbar Progress is correctly updated when
- * windows are opened and closed.
--->
-
-<window title="Win7 Taskbar Progress"
- xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- onload="test();">
-
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-const kTaskbarID = "@mozilla.org/windows-taskbar;1";
-const DOWNLOAD_MANAGER_URL = "chrome://mozapps/content/downloads/downloads.xul";
-const DLMGR_UI_DONE = "download-manager-ui-done";
-
-Components.utils.import("resource://gre/modules/Services.jsm");
-
-let DownloadTaskbarProgress, TaskbarService, observerService, wwatch, chromeWindow;
-let gGen = null;
-
-function test() {
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- let isWin7OrHigher = false;
- try {
- let version = Cc["@mozilla.org/system-info;1"]
- .getService(Ci.nsIPropertyBag2)
- .getProperty("version");
- isWin7OrHigher = (parseFloat(version) >= 6.1);
- } catch (ex) { }
-
- if (!isWin7OrHigher) {
- ok(true, "This test only runs on Windows 7 or higher");
- return;
- }
-
- SimpleTest.waitForExplicitFinish();
- gGen = doTest();
- gGen.next();
-}
-
-function continueTest() {
- gGen.next();
-}
-
-function doTest() {
- // Ensure that the download manager callbacks always use the window UI instead
- // of the panel in the browser's window.
- Services.prefs.setBoolPref("browser.download.useToolkitUI", true);
-
- let tempScope = {};
- Components.utils.import("resource://gre/modules/DownloadTaskbarProgress.jsm", tempScope);
-
- DownloadTaskbarProgress = tempScope.DownloadTaskbarProgress;
- TaskbarService = Cc[kTaskbarID].getService(Ci.nsIWinTaskbar);
-
- observerService = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
-
- wwatch = Cc["@mozilla.org/embedcomp/window-watcher;1"].
- getService(Ci.nsIWindowWatcher);
-
- isnot(DownloadTaskbarProgress, null, "Download taskbar progress service exists");
- is(TaskbarService.available, true, "Taskbar Service is available");
-
- let DMWindow = getDMWindow();
- if (DMWindow)
- DMWindow.close();
-
- //Manually call onBrowserWindowLoad because this is delayed in 10sec
- chromeWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
- getInterface(Components.interfaces.nsIWebNavigation).
- QueryInterface(Components.interfaces.nsIDocShellTreeItem).
- rootTreeItem.
- QueryInterface(Components.interfaces.nsIInterfaceRequestor).
- getInterface(Components.interfaces.nsIDOMWindow);
-
- DownloadTaskbarProgress.onBrowserWindowLoad(chromeWindow);
-
- is(DownloadTaskbarProgress.activeWindowIsDownloadWindow, false,
- "DownloadTaskbarProgress window is not the Download window");
-
- checkActiveTaskbar(false, window);
- openDownloadManager(continueTest);
- yield;
-
- let DMWindow = getDMWindow();
-
- ok(DMWindow, "Download Manager window was opened");
- checkActiveTaskbar(true, DMWindow);
-
- DMWindow.close();
- setTimeout(continueTest, 100);
- yield;
-
- checkActiveTaskbar(false, window);
-
- let browserWindow = openBrowserWindow(continueTest);
- yield;
-
- ok(browserWindow, "Browser window was opened");
- DownloadTaskbarProgress.onBrowserWindowLoad(browserWindow);
-
- // The owner window should not have changed, since our
- // original window still exists
- checkActiveTaskbar(false, window);
-
- Services.prefs.clearUserPref("browser.download.useToolkitUI");
-
- browserWindow.close();
- SimpleTest.finish();
- yield;
-}
-
-function checkActiveTaskbar(isDownloadManager, ownerWindow) {
-
- isnot(DownloadTaskbarProgress.activeTaskbarProgress, null, "DownloadTaskbarProgress has an active taskbar");
-
- is(DownloadTaskbarProgress.activeWindowIsDownloadWindow, isDownloadManager,
- "The active taskbar progress " + (isDownloadManager ? "is" : "is not") + " the Download Manager");
-
- if (ownerWindow) {
- let ownerWindowDocShell = ownerWindow.QueryInterface(Ci.nsIInterfaceRequestor).
- getInterface(Ci.nsIWebNavigation).
- QueryInterface(Ci.nsIDocShellTreeItem).treeOwner.
- QueryInterface(Ci.nsIInterfaceRequestor).
- getInterface(Ci.nsIXULWindow).docShell;
-
- let windowTaskbarProgress = TaskbarService.getTaskbarProgress(ownerWindowDocShell);
-
- is(DownloadTaskbarProgress.activeTaskbarProgress, windowTaskbarProgress,
- "DownloadTaskbarProgress has the expected taskbar as active");
- }
-
-}
-
-function openBrowserWindow(callback) {
-
- let browserWindow = openDialog(chromeWindow.location, "_blank",
- "chrome,all,dialog=no", "about:blank");
-
- let helperFunc = function() {
- callback();
- browserWindow.removeEventListener("load", helperFunc, false);
- }
-
- browserWindow.addEventListener("load", helperFunc, false);
-
- return browserWindow;
-}
-
-function openDownloadManager(callback) {
-
- let testObs = {
- observe: function(aSubject, aTopic, aData) {
- if (aTopic != DLMGR_UI_DONE) {
- return;
- }
-
- callback();
- observerService.removeObserver(testObs, DLMGR_UI_DONE);
- }
- };
-
- observerService.addObserver(testObs, DLMGR_UI_DONE, false);
-
- Cc["@mozilla.org/download-manager-ui;1"].
- getService(Ci.nsIDownloadManagerUI).show();
-
-}
- ]]>
- </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>
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/test_ui_stays_open_on_alert_clickback.xul
+++ /dev/null
@@ -1,100 +0,0 @@
-<?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 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/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
-
- <script type="application/javascript">
- <![CDATA[
-
-Components.utils.import("resource://gre/modules/Services.jsm");
-
-function test()
-{
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- return;
- }
-
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
-
- // Empty any old downloads
- dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
-
- function setClose(aVal) {
- Services.prefs.setBoolPref("browser.download.manager.closeWhenDone", aVal);
- }
-
- // Close the UI if necessary
- let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator);
- let win = wm.getMostRecentWindow("Download:Manager");
- if (win) win.close();
-
- // Ensure that the download manager callbacks always use the window UI instead
- // of the panel in the browser's window.
- Services.prefs.setBoolPref("browser.download.useToolkitUI", true);
-
- let os = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
- const DLMGR_UI_DONE = "download-manager-ui-done";
-
- let testObs = {
- observe: function(aSubject, aTopic, aData)
- {
- if (aTopic != DLMGR_UI_DONE)
- return;
-
- let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
- win.focus();
-
- // 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
- ok(dmui.visible, "Download Manager stays open on alert click");
-
- win.close();
- setClose(false);
- os.removeObserver(testObs, DLMGR_UI_DONE);
-
- Services.prefs.clearUserPref("browser.download.manager.closeWhenDone");
- Services.prefs.clearUserPref("browser.download.useToolkitUI");
-
- 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(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>
--- a/toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_delayedbutton.xul
+++ b/toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_delayedbutton.xul
@@ -9,23 +9,23 @@
-->
<window title="Unknown Content Type Dialog Test"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="doTest()">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
<script type="application/javascript"><![CDATA[
- Components.utils.import("resource://gre/modules/Services.jsm");
- Components.utils.import("resource://gre/modules/Task.jsm");
- Components.utils.import("resource://gre/modules/Promise.jsm");
+ const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+ Cu.import("resource://gre/modules/Services.jsm");
+ Cu.import("resource://gre/modules/Task.jsm");
+ Cu.import("resource://gre/modules/Promise.jsm");
const UCT_URI = "chrome://mozapps/content/downloads/unknownContentType.xul";
const LOAD_URI = "http://mochi.test:8888/chrome/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt";
const DIALOG_DELAY = Services.prefs.getIntPref("security.dialog_enable_delay") + 200;
let UCTObserver = {
opened: Promise.defer(),
--- a/toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_dialog_layout.xul
+++ b/toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_dialog_layout.xul
@@ -9,21 +9,20 @@
-->
<window title="Unknown Content Type Dialog Test"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="init()">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
- <script type="application/javascript"
- src="utils.js"/>
<script type="application/javascript">
<![CDATA[
+const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
const UCT_URI = "chrome://mozapps/content/downloads/unknownContentType.xul";
let testIndex = -1;
let tests = [
{ // This URL will trigger the simple UI, where only the Save an Cancel buttons are available
url: "http://mochi.test:8888/chrome/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif",
elements: {
@@ -63,23 +62,16 @@ let windowObserver = {
SimpleTest.executeSoon(function() {
checkWindow(win);
});
}, false);
}
};
function init() {
- var dmui = getDMUI();
- if (!dmui) {
- todo(false, "skip test for toolkit download manager UI");
- SimpleTest.finish();
- return;
- }
-
ww.registerNotification(windowObserver);
loadNextTest();
}
function loadNextTest() {
if (!tests[++testIndex]) {
ww.unregisterNotification(windowObserver);
SimpleTest.finish();
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/utils.js
+++ /dev/null
@@ -1,148 +0,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/. */
-
-/**
- * Provides utility functions for the download manager chrome tests.
- */
-
-var Cc = Components.classes;
-var Ci = Components.interfaces;
-var Cr = Components.results;
-
-Components.utils.import("resource://gre/modules/Services.jsm");
-
-/**
- * Returns the toolkit implementation of the download manager UI service.
- * If the toolkit implementation of the service can't be found (e.g. because
- * SeaMonkey doesn't package that version but an own implementation that calls
- * different UI), then returns false (see bug 483781).
- *
- * @returns toolkit's nsIDownloadManagerUI implementation or false if not found
- */
-function getDMUI()
-{
- try {
- // This method throws an exception if the old Download Manager is disabled.
- Services.downloads.activeDownloadCount;
- } catch (ex) {
- return false;
- }
- if (Components.classesByID["{7dfdf0d1-aff6-4a34-bad1-d0fe74601642}"])
- return Components.classesByID["{7dfdf0d1-aff6-4a34-bad1-d0fe74601642}"].
- getService(Ci.nsIDownloadManagerUI);
- return false;
-}
-
-/**
- * Adds a live download to the download manager.
- *
- * @param [optional] aName
- * The name that will be assigned to the downloaded file.
- * @returns an instance of nsIDownload.
- */
-function addDownload(aName) {
- function createURI(aObj) {
- let ios = Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService);
- return (aObj instanceof Ci.nsIFile) ? ios.newFileURI(aObj) :
- ios.newURI(aObj, null, null);
- }
-
- function randomString() {
- let chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
- let string_length = 8;
- let randomstring = "";
- for (let i=0; i<string_length; i++) {
- let rnum = Math.floor(Math.random() * chars.length);
- randomstring += chars.substring(rnum, rnum+1);
- }
- return randomstring;
- }
-
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- const nsIWBP = Ci.nsIWebBrowserPersist;
- let persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
- .createInstance(Ci.nsIWebBrowserPersist);
- persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
- nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
- nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
- let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties);
- let dmFile = dirSvc.get("TmpD", Ci.nsIFile);
- dmFile.append(aName || ("dm-test-file-" + randomString()));
- if (dmFile.exists())
- throw "Download file already exists";
-
- let dl = dm.addDownload(Ci.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOAD,
- createURI("http://example.com/httpd.js"),
- createURI(dmFile), null, null,
- Math.round(Date.now() * 1000), null, persist, false);
-
- let privacyContext = window.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIWebNavigation)
- .QueryInterface(Ci.nsILoadContext);
-
- persist.progressListener = dl.QueryInterface(Ci.nsIWebProgressListener);
- persist.saveURI(dl.source, null, null, 0, null, null, dl.targetFile, privacyContext);
-
- return dl;
- }
-
-/**
- * Used to populate the dm with dummy download data.
- *
- * @param aDownloadData
- * An array that contains the dummy download data to be added to the DM.
- * Expected fields are:
- * name, source, target, startTime, endTime, state, currBytes,
- * maxBytes, preferredAction, and autoResume
- */
-function populateDM(DownloadData)
-{
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
- let db = dm.DBConnection;
-
- let 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 in dl)
- stmt.params[prop] = dl[prop];
-
- stmt.execute();
- }
- stmt.finalize();
-}
-
-/**
- * Returns an instance to the download manager window
- *
- * @return an instance of nsIDOMWindow
- */
-function getDMWindow()
-{
- return Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator).
- getMostRecentWindow("Download:Manager");
-}
-
-/**
- * Establishes a clean state to run a test in by removing everything from the
- * database and ensuring that the download manager's window is not open.
- */
-function setCleanState()
-{
- let dm = Cc["@mozilla.org/download-manager;1"].
- getService(Ci.nsIDownloadManager);
-
- // Clean the dm
- dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
-
- let win = getDMWindow();
- if (win) win.close();
-}