summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/downloads
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2020-04-14 21:49:04 +0200
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-04-14 21:49:04 +0200
commit39dac57259cff8b61db0b22cb2ad0a8adb02692e (patch)
tree52a026cc8c22793eb17fd0f5e22adce1ae08a1dd /toolkit/mozapps/downloads
parenta1cce3b2b00bbd9f4983013ddd8934a7bccb9e99 (diff)
parentc2d9ab62f3d097c9e0e00184cab1f546554f5eaa (diff)
downloadUXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.tar
UXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.tar.gz
UXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.tar.lz
UXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.tar.xz
UXP-39dac57259cff8b61db0b22cb2ad0a8adb02692e.zip
Merge branch 'redwood' into 28.9-platform
Diffstat (limited to 'toolkit/mozapps/downloads')
-rw-r--r--toolkit/mozapps/downloads/DownloadTaskbarProgress.jsm68
-rw-r--r--toolkit/mozapps/downloads/content/downloads.js30
-rw-r--r--toolkit/mozapps/downloads/jar.mn2
-rw-r--r--toolkit/mozapps/downloads/moz.build13
-rw-r--r--toolkit/mozapps/downloads/nsHelperAppDlg.js238
-rw-r--r--toolkit/mozapps/downloads/tests/chrome/.eslintrc.js7
-rw-r--r--toolkit/mozapps/downloads/tests/chrome/chrome.ini10
-rw-r--r--toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_delayedbutton.xul117
-rw-r--r--toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_dialog_layout.xul108
-rw-r--r--toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif1
-rw-r--r--toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif^headers^1
-rw-r--r--toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt1
-rw-r--r--toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt^headers^2
-rw-r--r--toolkit/mozapps/downloads/tests/moz.build8
-rw-r--r--toolkit/mozapps/downloads/tests/unit/.eslintrc.js7
-rw-r--r--toolkit/mozapps/downloads/tests/unit/head_downloads.js5
-rw-r--r--toolkit/mozapps/downloads/tests/unit/test_DownloadPaths.js131
-rw-r--r--toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js237
-rw-r--r--toolkit/mozapps/downloads/tests/unit/test_lowMinutes.js55
-rw-r--r--toolkit/mozapps/downloads/tests/unit/test_syncedDownloadUtils.js26
-rw-r--r--toolkit/mozapps/downloads/tests/unit/test_unspecified_arguments.js25
-rw-r--r--toolkit/mozapps/downloads/tests/unit/xpcshell.ini10
22 files changed, 175 insertions, 927 deletions
diff --git a/toolkit/mozapps/downloads/DownloadTaskbarProgress.jsm b/toolkit/mozapps/downloads/DownloadTaskbarProgress.jsm
index bccbeda56..e015ded2a 100644
--- a/toolkit/mozapps/downloads/DownloadTaskbarProgress.jsm
+++ b/toolkit/mozapps/downloads/DownloadTaskbarProgress.jsm
@@ -16,7 +16,6 @@ const Cu = Components.utils;
const Cr = Components.results;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-Cu.import("resource://gre/modules/AppConstants.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Services",
"resource://gre/modules/Services.jsm");
@@ -177,33 +176,33 @@ var DownloadTaskbarProgressUpdater =
*/
_setActiveWindow: function DTPU_setActiveWindow(aWindow, aIsDownloadWindow)
{
- if (AppConstants.platform == "win") {
- // Clear out the taskbar for the old active window. (If there was no active
- // window, this is a no-op.)
- this._clearTaskbar();
-
- this._activeWindowIsDownloadWindow = aIsDownloadWindow;
- if (aWindow) {
- // Get the taskbar progress for this window
- let docShell = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).
- getInterface(Ci.nsIWebNavigation).
- QueryInterface(Ci.nsIDocShellTreeItem).treeOwner.
- QueryInterface(Ci.nsIInterfaceRequestor).
- getInterface(Ci.nsIXULWindow).docShell;
- let taskbarProgress = this._taskbar.getTaskbarProgress(docShell);
- this._activeTaskbarProgress = taskbarProgress;
-
- this._updateTaskbar();
- // _onActiveWindowUnload is idempotent, so we don't need to check whether
- // we've already set this before or not.
- aWindow.addEventListener("unload", function () {
- DownloadTaskbarProgressUpdater._onActiveWindowUnload(taskbarProgress);
- }, false);
- }
- else {
- this._activeTaskbarProgress = null;
- }
+#ifdef XP_WIN
+ // Clear out the taskbar for the old active window. (If there was no active
+ // window, this is a no-op.)
+ this._clearTaskbar();
+
+ this._activeWindowIsDownloadWindow = aIsDownloadWindow;
+ if (aWindow) {
+ // Get the taskbar progress for this window
+ let docShell = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIWebNavigation).
+ QueryInterface(Ci.nsIDocShellTreeItem).treeOwner.
+ QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIXULWindow).docShell;
+ let taskbarProgress = this._taskbar.getTaskbarProgress(docShell);
+ this._activeTaskbarProgress = taskbarProgress;
+
+ this._updateTaskbar();
+ // _onActiveWindowUnload is idempotent, so we don't need to check whether
+ // we've already set this before or not.
+ aWindow.addEventListener("unload", function () {
+ DownloadTaskbarProgressUpdater._onActiveWindowUnload(taskbarProgress);
+ }, false);
+ }
+ else {
+ this._activeTaskbarProgress = null;
}
+#endif
},
// / Current state displayed on the active window's taskbar item
@@ -213,14 +212,15 @@ var DownloadTaskbarProgressUpdater =
_shouldSetState: function DTPU_shouldSetState()
{
- if (AppConstants.platform == "win") {
- // If the active window is not the download manager window, set the state
- // only if it is normal or indeterminate.
- return this._activeWindowIsDownloadWindow ||
- (this._taskbarState == Ci.nsITaskbarProgress.STATE_NORMAL ||
- this._taskbarState == Ci.nsITaskbarProgress.STATE_INDETERMINATE);
- }
+#ifdef XP_WIN
+ // If the active window is not the download manager window, set the state
+ // only if it is normal or indeterminate.
+ return this._activeWindowIsDownloadWindow ||
+ (this._taskbarState == Ci.nsITaskbarProgress.STATE_NORMAL ||
+ this._taskbarState == Ci.nsITaskbarProgress.STATE_INDETERMINATE);
+#else
return true;
+#endif
},
/**
diff --git a/toolkit/mozapps/downloads/content/downloads.js b/toolkit/mozapps/downloads/content/downloads.js
index 2fdb19a74..66230592f 100644
--- a/toolkit/mozapps/downloads/content/downloads.js
+++ b/toolkit/mozapps/downloads/content/downloads.js
@@ -19,7 +19,6 @@ var Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/DownloadUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/AppConstants.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
"resource://gre/modules/PluralForm.jsm");
@@ -253,18 +252,18 @@ function openDownload(aDownload)
dontAsk = !pref.getBoolPref(PREF_BDM_CONFIRMOPENEXE);
} catch (e) { }
- if (AppConstants.platform == "win") {
- // On Vista and above, we rely on native security prompting for
- // downloaded content unless it's disabled.
- try {
- var sysInfo = Cc["@mozilla.org/system-info;1"].
- getService(Ci.nsIPropertyBag2);
- if (parseFloat(sysInfo.getProperty("version")) >= 6 &&
- pref.getBoolPref(PREF_BDM_SCANWHENDONE)) {
- dontAsk = true;
- }
- } catch (ex) { }
- }
+#ifdef XP_WIN
+ // On Vista and above, we rely on native security prompting for
+ // downloaded content unless it's disabled.
+ try {
+ var sysInfo = Cc["@mozilla.org/system-info;1"].
+ getService(Ci.nsIPropertyBag2);
+ if (parseFloat(sysInfo.getProperty("version")) >= 6 &&
+ pref.getBoolPref(PREF_BDM_SCANWHENDONE)) {
+ dontAsk = true;
+ }
+ } catch (ex) { }
+#endif
if (!dontAsk) {
var strings = document.getElementById("downloadStrings");
@@ -478,10 +477,11 @@ var gDownloadObserver = {
removeFromView(dl);
break;
case "browser-lastwindow-close-granted":
- if (AppConstants.platform != "macosx" &&
- gDownloadManager.activeDownloadCount == 0) {
+#ifndef XP_MACOSX
+ if (gDownloadManager.activeDownloadCount == 0) {
setTimeout(gCloseDownloadManager, 0);
}
+#endif
break;
}
}
diff --git a/toolkit/mozapps/downloads/jar.mn b/toolkit/mozapps/downloads/jar.mn
index eb761b0d9..29a3d0ee2 100644
--- a/toolkit/mozapps/downloads/jar.mn
+++ b/toolkit/mozapps/downloads/jar.mn
@@ -6,7 +6,7 @@ toolkit.jar:
% content mozapps %content/mozapps/
* content/mozapps/downloads/unknownContentType.xul (content/unknownContentType.xul)
* content/mozapps/downloads/downloads.xul (content/downloads.xul)
- content/mozapps/downloads/downloads.js (content/downloads.js)
+* content/mozapps/downloads/downloads.js (content/downloads.js)
content/mozapps/downloads/DownloadProgressListener.js (content/DownloadProgressListener.js)
content/mozapps/downloads/downloads.css (content/downloads.css)
content/mozapps/downloads/download.xml (content/download.xml)
diff --git a/toolkit/mozapps/downloads/moz.build b/toolkit/mozapps/downloads/moz.build
index 1850ea7de..48741710a 100644
--- a/toolkit/mozapps/downloads/moz.build
+++ b/toolkit/mozapps/downloads/moz.build
@@ -4,21 +4,16 @@
# 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_DIRS += ['tests']
+EXTRA_COMPONENTS += ['nsHelperAppDlg.manifest']
-EXTRA_COMPONENTS += [
- 'nsHelperAppDlg.manifest',
-]
-
-EXTRA_PP_COMPONENTS += [
- 'nsHelperAppDlg.js',
-]
+EXTRA_PP_COMPONENTS += ['nsHelperAppDlg.js']
EXTRA_JS_MODULES += [
'DownloadLastDir.jsm',
'DownloadPaths.jsm',
- 'DownloadTaskbarProgress.jsm',
'DownloadUtils.jsm',
]
+EXTRA_PP_JS_MODULES += ['DownloadTaskbarProgress.jsm']
+
JAR_MANIFESTS += ['jar.mn'] \ No newline at end of file
diff --git a/toolkit/mozapps/downloads/nsHelperAppDlg.js b/toolkit/mozapps/downloads/nsHelperAppDlg.js
index 27c0fede0..90d38c90b 100644
--- a/toolkit/mozapps/downloads/nsHelperAppDlg.js
+++ b/toolkit/mozapps/downloads/nsHelperAppDlg.js
@@ -4,7 +4,6 @@
const {utils: Cu, interfaces: Ci, classes: Cc, results: Cr} = Components;
Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "EnableDelayHelper",
"resource://gre/modules/SharedPromptUtils.jsm");
@@ -408,22 +407,22 @@ nsUnknownContentTypeDialog.prototype = {
// is now caught properly in the caller of validateLeafName.
var createdFile = DownloadPaths.createNiceUniqueFile(aLocalFolder);
- if (AppConstants.platform == "win") {
- let ext;
- try {
- // We can fail here if there's no primary extension set
- ext = "." + this.mLauncher.MIMEInfo.primaryExtension;
- } catch (e) { }
-
- // Append a file extension if it's an executable that doesn't have one
- // but make sure we actually have an extension to add
- let leaf = createdFile.leafName;
- if (ext && leaf.slice(-ext.length) != ext && createdFile.isExecutable()) {
- createdFile.remove(false);
- aLocalFolder.leafName = leaf + ext;
- createdFile = DownloadPaths.createNiceUniqueFile(aLocalFolder);
- }
+#ifdef XP_WIN
+ let ext;
+ try {
+ // We can fail here if there's no primary extension set
+ ext = "." + this.mLauncher.MIMEInfo.primaryExtension;
+ } catch (e) { }
+
+ // Append a file extension if it's an executable that doesn't have one
+ // but make sure we actually have an extension to add
+ let leaf = createdFile.leafName;
+ if (ext && leaf.slice(-ext.length) != ext && createdFile.isExecutable()) {
+ createdFile.remove(false);
+ aLocalFolder.leafName = leaf + ext;
+ createdFile = DownloadPaths.createNiceUniqueFile(aLocalFolder);
}
+#endif
return createdFile;
},
@@ -640,21 +639,22 @@ nsUnknownContentTypeDialog.prototype = {
// Returns true if opening the default application makes sense.
openWithDefaultOK: function() {
// The checking is different on Windows...
- if (AppConstants.platform == "win") {
- // Windows presents some special cases.
- // We need to prevent use of "system default" when the file is
- // executable (so the user doesn't launch nasty programs downloaded
- // from the web), and, enable use of "system default" if it isn't
- // executable (because we will prompt the user for the default app
- // in that case).
-
- // Default is Ok if the file isn't executable (and vice-versa).
- return !this.mLauncher.targetFileIsExecutable;
- }
+#ifdef XP_WIN
+ // Windows presents some special cases.
+ // We need to prevent use of "system default" when the file is
+ // executable (so the user doesn't launch nasty programs downloaded
+ // from the web), and, enable use of "system default" if it isn't
+ // executable (because we will prompt the user for the default app
+ // in that case).
+
+ // Default is Ok if the file isn't executable (and vice-versa).
+ return !this.mLauncher.targetFileIsExecutable;
+#else
// On other platforms, default is Ok if there is a default app.
// Note that nsIMIMEInfo providers need to ensure that this holds true
// on each platform.
return this.mLauncher.MIMEInfo.hasDefaultHandler;
+#endif
},
// Set "default" application description field.
@@ -675,10 +675,11 @@ nsUnknownContentTypeDialog.prototype = {
// getPath:
getPath: function (aFile) {
- if (AppConstants.platform == "macosx") {
+#ifdef XP_MACOSX
return aFile.leafName || aFile.path;
- }
+#else
return aFile.path;
+#endif
},
// initAppAndSaveToDiskValues:
@@ -980,19 +981,20 @@ nsUnknownContentTypeDialog.prototype = {
// Retrieve the pretty description from the file
getFileDisplayName: function getFileDisplayName(file)
{
- if (AppConstants.platform == "win") {
- if (file instanceof Components.interfaces.nsILocalFileWin) {
- try {
- return file.getVersionInfoField("FileDescription");
- } catch (e) {}
- }
- } else if (AppConstants.platform == "macosx") {
- if (file instanceof Components.interfaces.nsILocalFileMac) {
- try {
- return file.bundleDisplayName;
- } catch (e) {}
- }
+#ifdef XP_WIN
+ if (file instanceof Components.interfaces.nsILocalFileWin) {
+ try {
+ return file.getVersionInfoField("FileDescription");
+ } catch (e) {}
+ }
+#elifdef XP_MACOSX
+ if (file instanceof Components.interfaces.nsILocalFileMac) {
+ try {
+ return file.bundleDisplayName;
+ } catch (e) {}
}
+#endif
+
return file.leafName;
},
@@ -1006,10 +1008,13 @@ nsUnknownContentTypeDialog.prototype = {
var otherHandler = this.dialogElement("otherHandler");
otherHandler.removeAttribute("hidden");
otherHandler.setAttribute("path", this.getPath(this.chosenApp.executable));
- if (AppConstants.platform == "win")
- otherHandler.label = this.getFileDisplayName(this.chosenApp.executable);
- else
- otherHandler.label = this.chosenApp.name;
+
+#ifdef XP_WIN
+ otherHandler.label = this.getFileDisplayName(this.chosenApp.executable);
+#else
+ otherHandler.label = this.chosenApp.name;
+#endif
+
this.dialogElement("openHandler").selectedIndex = 1;
this.dialogElement("openHandler").setAttribute("lastSelectedItemID", "otherHandler");
@@ -1025,85 +1030,84 @@ nsUnknownContentTypeDialog.prototype = {
},
// chooseApp: Open file picker and prompt user for application.
chooseApp: function() {
- if (AppConstants.platform == "win") {
- // Protect against the lack of an extension
- var fileExtension = "";
- try {
- fileExtension = this.mLauncher.MIMEInfo.primaryExtension;
- } catch(ex) {
- }
+#ifdef XP_WIN
+ // Protect against the lack of an extension
+ var fileExtension = "";
+ try {
+ fileExtension = this.mLauncher.MIMEInfo.primaryExtension;
+ } catch(ex) {
+ }
- // Try to use the pretty description of the type, if one is available.
- var typeString = this.mLauncher.MIMEInfo.description;
-
- if (!typeString) {
- // If there is none, use the extension to
- // identify the file, e.g. "ZIP file"
- if (fileExtension) {
- typeString =
- this.dialogElement("strings").
- getFormattedString("fileType", [fileExtension.toUpperCase()]);
- } else {
- // If we can't even do that, just give up and show the MIME type.
- typeString = this.mLauncher.MIMEInfo.MIMEType;
- }
+ // Try to use the pretty description of the type, if one is available.
+ var typeString = this.mLauncher.MIMEInfo.description;
+
+ if (!typeString) {
+ // If there is none, use the extension to
+ // identify the file, e.g. "ZIP file"
+ if (fileExtension) {
+ typeString =
+ this.dialogElement("strings").
+ getFormattedString("fileType", [fileExtension.toUpperCase()]);
+ } else {
+ // If we can't even do that, just give up and show the MIME type.
+ typeString = this.mLauncher.MIMEInfo.MIMEType;
}
+ }
- var params = {};
- params.title =
- this.dialogElement("strings").getString("chooseAppFilePickerTitle");
- params.description = typeString;
- params.filename = this.mLauncher.suggestedFileName;
- params.mimeInfo = this.mLauncher.MIMEInfo;
- params.handlerApp = null;
-
- this.mDialog.openDialog("chrome://global/content/appPicker.xul", null,
- "chrome,modal,centerscreen,titlebar,dialog=yes",
- params);
-
- if (params.handlerApp &&
- params.handlerApp.executable &&
- params.handlerApp.executable.isFile()) {
- // Remember the file they chose to run.
- this.chosenApp = params.handlerApp;
- }
+ var params = {};
+ params.title =
+ this.dialogElement("strings").getString("chooseAppFilePickerTitle");
+ params.description = typeString;
+ params.filename = this.mLauncher.suggestedFileName;
+ params.mimeInfo = this.mLauncher.MIMEInfo;
+ params.handlerApp = null;
+
+ this.mDialog.openDialog("chrome://global/content/appPicker.xul", null,
+ "chrome,modal,centerscreen,titlebar,dialog=yes",
+ params);
+
+ if (params.handlerApp &&
+ params.handlerApp.executable &&
+ params.handlerApp.executable.isFile()) {
+ // Remember the file they chose to run.
+ this.chosenApp = params.handlerApp;
}
- else {
+#else // XP_WIN
#if MOZ_WIDGET_GTK == 3
- var nsIApplicationChooser = Components.interfaces.nsIApplicationChooser;
- var appChooser = Components.classes["@mozilla.org/applicationchooser;1"]
- .createInstance(nsIApplicationChooser);
- appChooser.init(this.mDialog, this.dialogElement("strings").getString("chooseAppFilePickerTitle"));
- var contentTypeDialogObj = this;
- let appChooserCallback = function appChooserCallback_done(aResult) {
- if (aResult) {
- contentTypeDialogObj.chosenApp = aResult.QueryInterface(Components.interfaces.nsILocalHandlerApp);
- }
- contentTypeDialogObj.finishChooseApp();
- };
- appChooser.open(this.mLauncher.MIMEInfo.MIMEType, appChooserCallback);
- // The finishChooseApp is called from appChooserCallback
- return;
-#else
- var nsIFilePicker = Components.interfaces.nsIFilePicker;
- var fp = Components.classes["@mozilla.org/filepicker;1"]
- .createInstance(nsIFilePicker);
- fp.init(this.mDialog,
- this.dialogElement("strings").getString("chooseAppFilePickerTitle"),
- nsIFilePicker.modeOpen);
-
- fp.appendFilters(nsIFilePicker.filterApps);
-
- if (fp.show() == nsIFilePicker.returnOK && fp.file) {
- // Remember the file they chose to run.
- var localHandlerApp =
- Components.classes["@mozilla.org/uriloader/local-handler-app;1"].
- createInstance(Components.interfaces.nsILocalHandlerApp);
- localHandlerApp.executable = fp.file;
- this.chosenApp = localHandlerApp;
+ var nsIApplicationChooser = Components.interfaces.nsIApplicationChooser;
+ var appChooser = Components.classes["@mozilla.org/applicationchooser;1"]
+ .createInstance(nsIApplicationChooser);
+ appChooser.init(this.mDialog, this.dialogElement("strings").getString("chooseAppFilePickerTitle"));
+ var contentTypeDialogObj = this;
+ let appChooserCallback = function appChooserCallback_done(aResult) {
+ if (aResult) {
+ contentTypeDialogObj.chosenApp = aResult.QueryInterface(Components.interfaces.nsILocalHandlerApp);
}
-#endif // MOZ_WIDGET_GTK == 3
+ contentTypeDialogObj.finishChooseApp();
+ };
+ appChooser.open(this.mLauncher.MIMEInfo.MIMEType, appChooserCallback);
+ // The finishChooseApp is called from appChooserCallback
+ return;
+#else // MOZ_WIDGET_GTK == 3
+ var nsIFilePicker = Components.interfaces.nsIFilePicker;
+ var fp = Components.classes["@mozilla.org/filepicker;1"]
+ .createInstance(nsIFilePicker);
+ fp.init(this.mDialog,
+ this.dialogElement("strings").getString("chooseAppFilePickerTitle"),
+ nsIFilePicker.modeOpen);
+
+ fp.appendFilters(nsIFilePicker.filterApps);
+
+ if (fp.show() == nsIFilePicker.returnOK && fp.file) {
+ // Remember the file they chose to run.
+ var localHandlerApp =
+ Components.classes["@mozilla.org/uriloader/local-handler-app;1"].
+ createInstance(Components.interfaces.nsILocalHandlerApp);
+ localHandlerApp.executable = fp.file;
+ this.chosenApp = localHandlerApp;
}
+#endif // MOZ_WIDGET_GTK == 3
+#endif // XP_WIN
this.finishChooseApp();
},
diff --git a/toolkit/mozapps/downloads/tests/chrome/.eslintrc.js b/toolkit/mozapps/downloads/tests/chrome/.eslintrc.js
deleted file mode 100644
index 8c0f4f574..000000000
--- a/toolkit/mozapps/downloads/tests/chrome/.eslintrc.js
+++ /dev/null
@@ -1,7 +0,0 @@
-"use strict";
-
-module.exports = {
- "extends": [
- "../../../../../testing/mochitest/chrome.eslintrc.js"
- ]
-};
diff --git a/toolkit/mozapps/downloads/tests/chrome/chrome.ini b/toolkit/mozapps/downloads/tests/chrome/chrome.ini
deleted file mode 100644
index b5a29cb45..000000000
--- a/toolkit/mozapps/downloads/tests/chrome/chrome.ini
+++ /dev/null
@@ -1,10 +0,0 @@
-[DEFAULT]
-skip-if = 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^
-
-[test_unknownContentType_delayedbutton.xul]
-[test_unknownContentType_dialog_layout.xul]
diff --git a/toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_delayedbutton.xul b/toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_delayedbutton.xul
deleted file mode 100644
index 9bbec0f92..000000000
--- a/toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_delayedbutton.xul
+++ /dev/null
@@ -1,117 +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/. -->
-<!--
- * The unknownContentType popup can have two different layouts depending on
- * whether a helper application can be selected or not.
- * This tests that both layouts have correct collapsed elements.
--->
-
-<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"><![CDATA[
- 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(),
- closed: Promise.defer(),
-
- observe: function(aSubject, aTopic, aData) {
- let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
-
- switch (aTopic) {
- case "domwindowopened":
- win.addEventListener("load", function onLoad(event) {
- win.removeEventListener("load", onLoad, false);
-
- // Let the dialog initialize
- SimpleTest.executeSoon(function() {
- UCTObserver.opened.resolve(win);
- });
- }, false);
- break;
-
- case "domwindowclosed":
- if (win.location == UCT_URI) {
- this.closed.resolve();
- }
- break;
- }
- }
- };
-
- Services.ww.registerNotification(UCTObserver);
- SimpleTest.waitForExplicitFinish();
- SimpleTest.requestFlakyTimeout("This test is testing a timing-based feature, so it really needs to wait a certain amount of time to verify that the feature worked.");
-
- function waitDelay(delay) {
- return new Promise((resolve, reject) => {
- window.setTimeout(resolve, delay);
- });
- }
-
- function doTest() {
- Task.spawn(function test_aboutCrashed() {
- let frame = document.getElementById("testframe");
- frame.setAttribute("src", LOAD_URI);
-
- let uctWindow = yield UCTObserver.opened.promise;
- let ok = uctWindow.document.documentElement.getButton("accept");
-
- SimpleTest.is(ok.disabled, true, "button started disabled");
-
- yield waitDelay(DIALOG_DELAY);
-
- SimpleTest.is(ok.disabled, false, "button was enabled");
-
- focusOutOfDialog = SimpleTest.promiseFocus(window);
- window.focus();
- yield focusOutOfDialog;
-
- SimpleTest.is(ok.disabled, true, "button was disabled");
-
- focusOnDialog = SimpleTest.promiseFocus(uctWindow);
- uctWindow.focus();
- yield focusOnDialog;
-
- SimpleTest.is(ok.disabled, true, "button remained disabled");
-
- yield waitDelay(DIALOG_DELAY);
- SimpleTest.is(ok.disabled, false, "button re-enabled after delay");
-
- uctWindow.document.documentElement.cancelDialog();
- yield UCTObserver.closed.promise;
-
- Services.ww.unregisterNotification(UCTObserver);
- uctWindow = null;
- UCTObserver = null;
- 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>
diff --git a/toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_dialog_layout.xul b/toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_dialog_layout.xul
deleted file mode 100644
index 1210b908d..000000000
--- a/toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_dialog_layout.xul
+++ /dev/null
@@ -1,108 +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/. -->
-<!--
- * The unknownContentType popup can have two different layouts depending on
- * whether a helper application can be selected or not.
- * This tests that both layouts have correct collapsed elements.
--->
-
-<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">
- <![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: {
- basicBox: { collapsed: false },
- normalBox: { collapsed: true }
- }
- },
- { // This URL will trigger the full UI
- url: "http://mochi.test:8888/chrome/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt",
- elements: {
- basicBox: { collapsed: true },
- normalBox: { collapsed: false }
- }
- }
-];
-
-let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
- getService(Ci.nsIWindowWatcher);
-
-SimpleTest.waitForExplicitFinish();
-
-let windowObserver = {
- observe: function(aSubject, aTopic, aData) {
- let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
-
- if (aTopic == "domwindowclosed") {
- if (win.location == UCT_URI)
- loadNextTest();
- return;
- }
-
- // domwindowopened
- win.addEventListener("load", function onLoad(event) {
- win.removeEventListener("load", onLoad, false);
-
- // Let the dialog initialize
- SimpleTest.executeSoon(function() {
- checkWindow(win);
- });
- }, false);
- }
-};
-
-function init() {
- ww.registerNotification(windowObserver);
- loadNextTest();
-}
-
-function loadNextTest() {
- if (!tests[++testIndex]) {
- ww.unregisterNotification(windowObserver);
- SimpleTest.finish();
- return;
- }
- let frame = document.getElementById("testframe");
- frame.setAttribute("src", tests[testIndex].url);
-}
-
-function checkWindow(win) {
- for (let [id, props] of Object.entries(tests[testIndex].elements)) {
- let elem = win.dialog.dialogElement(id);
- for (let [prop, value] of Object.entries(props)) {
- is(elem[prop], value,
- "Element with id " + id + " has property " +
- prop + " set to " + value);
- }
- }
- win.document.documentElement.cancelDialog();
-}
-
- ]]>
- </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>
diff --git a/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif b/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif
deleted file mode 100644
index 9353d1312..000000000
--- a/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif
+++ /dev/null
@@ -1 +0,0 @@
-Dummy content for unknownContentType_dialog_layout_data.pif
diff --git a/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif^headers^ b/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif^headers^
deleted file mode 100644
index 09b22facc..000000000
--- a/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif^headers^
+++ /dev/null
@@ -1 +0,0 @@
-Content-Type: application/octet-stream
diff --git a/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt b/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt
deleted file mode 100644
index 77e719559..000000000
--- a/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt
+++ /dev/null
@@ -1 +0,0 @@
-Dummy content for unknownContentType_dialog_layout_data.txt
diff --git a/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt^headers^ b/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt^headers^
deleted file mode 100644
index 2a3c472e2..000000000
--- a/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt^headers^
+++ /dev/null
@@ -1,2 +0,0 @@
-Content-Type: text/plain
-Content-Disposition: attachment
diff --git a/toolkit/mozapps/downloads/tests/moz.build b/toolkit/mozapps/downloads/tests/moz.build
deleted file mode 100644
index a4b1efb9a..000000000
--- a/toolkit/mozapps/downloads/tests/moz.build
+++ /dev/null
@@ -1,8 +0,0 @@
-# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
-# vim: set filetype=python:
-# 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/.
-
-XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
-MOCHITEST_CHROME_MANIFESTS += ['chrome/chrome.ini']
diff --git a/toolkit/mozapps/downloads/tests/unit/.eslintrc.js b/toolkit/mozapps/downloads/tests/unit/.eslintrc.js
deleted file mode 100644
index d35787cd2..000000000
--- a/toolkit/mozapps/downloads/tests/unit/.eslintrc.js
+++ /dev/null
@@ -1,7 +0,0 @@
-"use strict";
-
-module.exports = {
- "extends": [
- "../../../../../testing/xpcshell/xpcshell.eslintrc.js"
- ]
-};
diff --git a/toolkit/mozapps/downloads/tests/unit/head_downloads.js b/toolkit/mozapps/downloads/tests/unit/head_downloads.js
deleted file mode 100644
index 4f199e5cf..000000000
--- a/toolkit/mozapps/downloads/tests/unit/head_downloads.js
+++ /dev/null
@@ -1,5 +0,0 @@
-Components.utils.import("resource://gre/modules/Services.jsm");
-
-do_register_cleanup(function() {
- Services.obs.notifyObservers(null, "quit-application", null);
-});
diff --git a/toolkit/mozapps/downloads/tests/unit/test_DownloadPaths.js b/toolkit/mozapps/downloads/tests/unit/test_DownloadPaths.js
deleted file mode 100644
index 77249169d..000000000
--- a/toolkit/mozapps/downloads/tests/unit/test_DownloadPaths.js
+++ /dev/null
@@ -1,131 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */
-/* ***** BEGIN LICENSE BLOCK *****
- *
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- *
- * ***** END LICENSE BLOCK ***** */
-
-/**
- * Tests for the "DownloadPaths.jsm" JavaScript module.
- */
-
-var Cc = Components.classes;
-var Ci = Components.interfaces;
-var Cu = Components.utils;
-var Cr = Components.results;
-
-Cu.import("resource://gre/modules/DownloadPaths.jsm");
-
-/**
- * Provides a temporary save directory.
- *
- * @returns nsIFile pointing to the new or existing directory.
- */
-function createTemporarySaveDirectory()
-{
- var saveDir = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
- saveDir.append("testsavedir");
- if (!saveDir.exists()) {
- saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
- }
- return saveDir;
-}
-
-function testSplitBaseNameAndExtension(aLeafName, [aBase, aExt])
-{
- var [base, ext] = DownloadPaths.splitBaseNameAndExtension(aLeafName);
- do_check_eq(base, aBase);
- do_check_eq(ext, aExt);
-
- // If we modify the base name and concatenate it with the extension again,
- // another roundtrip through the function should give a consistent result.
- // The only exception is when we introduce an extension in a file name that
- // didn't have one or that ended with one of the special cases like ".gz". If
- // we avoid using a dot and we introduce at least another special character,
- // the results are always consistent.
- [base, ext] = DownloadPaths.splitBaseNameAndExtension("(" + base + ")" + ext);
- do_check_eq(base, "(" + aBase + ")");
- do_check_eq(ext, aExt);
-}
-
-function testCreateNiceUniqueFile(aTempFile, aExpectedLeafName)
-{
- var createdFile = DownloadPaths.createNiceUniqueFile(aTempFile);
- do_check_eq(createdFile.leafName, aExpectedLeafName);
-}
-
-function run_test()
-{
- // Usual file names.
- testSplitBaseNameAndExtension("base", ["base", ""]);
- testSplitBaseNameAndExtension("base.ext", ["base", ".ext"]);
- testSplitBaseNameAndExtension("base.application", ["base", ".application"]);
- testSplitBaseNameAndExtension("base.x.Z", ["base", ".x.Z"]);
- testSplitBaseNameAndExtension("base.ext.Z", ["base", ".ext.Z"]);
- testSplitBaseNameAndExtension("base.ext.gz", ["base", ".ext.gz"]);
- testSplitBaseNameAndExtension("base.ext.Bz2", ["base", ".ext.Bz2"]);
- testSplitBaseNameAndExtension("base..ext", ["base.", ".ext"]);
- testSplitBaseNameAndExtension("base..Z", ["base.", ".Z"]);
- testSplitBaseNameAndExtension("base. .Z", ["base. ", ".Z"]);
- testSplitBaseNameAndExtension("base.base.Bz2", ["base.base", ".Bz2"]);
- testSplitBaseNameAndExtension("base .ext", ["base ", ".ext"]);
-
- // Corner cases. A name ending with a dot technically has no extension, but
- // we consider the ending dot separately from the base name so that modifying
- // the latter never results in an extension being introduced accidentally.
- // Names beginning with a dot are hidden files on Unix-like platforms and if
- // their name doesn't contain another dot they should have no extension, but
- // on Windows the whole name is considered as an extension.
- testSplitBaseNameAndExtension("base.", ["base", "."]);
- testSplitBaseNameAndExtension(".ext", ["", ".ext"]);
-
- // Unusual file names (not recommended as input to the function).
- testSplitBaseNameAndExtension("base. ", ["base", ". "]);
- testSplitBaseNameAndExtension("base ", ["base ", ""]);
- testSplitBaseNameAndExtension("", ["", ""]);
- testSplitBaseNameAndExtension(" ", [" ", ""]);
- testSplitBaseNameAndExtension(" . ", [" ", ". "]);
- testSplitBaseNameAndExtension(" .. ", [" .", ". "]);
- testSplitBaseNameAndExtension(" .ext", [" ", ".ext"]);
- testSplitBaseNameAndExtension(" .ext. ", [" .ext", ". "]);
- testSplitBaseNameAndExtension(" .ext.gz ", [" .ext", ".gz "]);
-
- var destDir = createTemporarySaveDirectory();
- try {
- // Single extension.
- var tempFile = destDir.clone();
- tempFile.append("test.txt");
- testCreateNiceUniqueFile(tempFile, "test.txt");
- testCreateNiceUniqueFile(tempFile, "test(1).txt");
- testCreateNiceUniqueFile(tempFile, "test(2).txt");
-
- // Double extension.
- tempFile.leafName = "test.tar.gz";
- testCreateNiceUniqueFile(tempFile, "test.tar.gz");
- testCreateNiceUniqueFile(tempFile, "test(1).tar.gz");
- testCreateNiceUniqueFile(tempFile, "test(2).tar.gz");
-
- // Test automatic shortening of long file names. We don't know exactly how
- // many characters are removed, because it depends on the name of the folder
- // where the file is located.
- tempFile.leafName = new Array(256).join("T") + ".txt";
- var newFile = DownloadPaths.createNiceUniqueFile(tempFile);
- do_check_true(newFile.leafName.length < tempFile.leafName.length);
- do_check_eq(newFile.leafName.slice(-4), ".txt");
-
- // Creating a valid file name from an invalid one is not always possible.
- tempFile.append("file-under-long-directory.txt");
- try {
- DownloadPaths.createNiceUniqueFile(tempFile);
- do_throw("Exception expected with a long parent directory name.")
- } catch (e) {
- // An exception is expected, but we don't know which one exactly.
- }
- } finally {
- // Clean up the temporary directory.
- destDir.remove(true);
- }
-}
diff --git a/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js b/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js
deleted file mode 100644
index 11e7776a7..000000000
--- a/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js
+++ /dev/null
@@ -1,237 +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 Cu = Components.utils;
-Cu.import("resource://gre/modules/DownloadUtils.jsm");
-
-const gDecimalSymbol = Number(5.4).toLocaleString().match(/\D/);
-function _(str) {
- return str.replace(/\./g, gDecimalSymbol);
-}
-
-function testConvertByteUnits(aBytes, aValue, aUnit)
-{
- let [value, unit] = DownloadUtils.convertByteUnits(aBytes);
- do_check_eq(value, aValue);
- do_check_eq(unit, aUnit);
-}
-
-function testTransferTotal(aCurrBytes, aMaxBytes, aTransfer)
-{
- let transfer = DownloadUtils.getTransferTotal(aCurrBytes, aMaxBytes);
- do_check_eq(transfer, aTransfer);
-}
-
-// Get the em-dash character because typing it directly here doesn't work :(
-var gDash = DownloadUtils.getDownloadStatus(0)[0].match(/remaining (.) 0 bytes/)[1];
-
-var gVals = [0, 100, 2345, 55555, 982341, 23194134, 1482, 58, 9921949201, 13498132, Infinity];
-
-function testStatus(aFunc, aCurr, aMore, aRate, aTest)
-{
- dump("Status Test: " + [aCurr, aMore, aRate, aTest] + "\n");
- let curr = gVals[aCurr];
- let max = curr + gVals[aMore];
- let speed = gVals[aRate];
-
- let [status, last] = aFunc(curr, max, speed);
-
- if (0) {
- dump("testStatus(" + aCurr + ", " + aMore + ", " + aRate + ", [\"" +
- status.replace(gDash, "--") + "\", " + last.toFixed(3) + "]);\n");
- }
-
- // Make sure the status text matches
- do_check_eq(status, _(aTest[0].replace(/--/, gDash)));
-
- // Make sure the lastSeconds matches
- if (last == Infinity)
- do_check_eq(last, aTest[1]);
- else
- do_check_true(Math.abs(last - aTest[1]) < .1);
-}
-
-function testURI(aURI, aDisp, aHost)
-{
- dump("URI Test: " + [aURI, aDisp, aHost] + "\n");
-
- let [disp, host] = DownloadUtils.getURIHost(aURI);
-
- // Make sure we have the right display host and full host
- do_check_eq(disp, aDisp);
- do_check_eq(host, aHost);
-}
-
-
-function testGetReadableDates(aDate, aCompactValue)
-{
- const now = new Date(2000, 11, 31, 11, 59, 59);
-
- let [dateCompact] = DownloadUtils.getReadableDates(aDate, now);
- do_check_eq(dateCompact, aCompactValue);
-}
-
-function testAllGetReadableDates()
-{
- // This test cannot depend on the current date and time, or the date format.
- // It depends on being run with the English localization, however.
- const today_11_30 = new Date(2000, 11, 31, 11, 30, 15);
- const today_12_30 = new Date(2000, 11, 31, 12, 30, 15);
- const yesterday_11_30 = new Date(2000, 11, 30, 11, 30, 15);
- const yesterday_12_30 = new Date(2000, 11, 30, 12, 30, 15);
- const twodaysago = new Date(2000, 11, 29, 11, 30, 15);
- const sixdaysago = new Date(2000, 11, 25, 11, 30, 15);
- const sevendaysago = new Date(2000, 11, 24, 11, 30, 15);
-
- // TODO: Remove Intl fallback when bug 1215247 is fixed.
- const locale = typeof Intl === "undefined"
- ? undefined
- : Components.classes["@mozilla.org/chrome/chrome-registry;1"]
- .getService(Components.interfaces.nsIXULChromeRegistry)
- .getSelectedLocale("global", true);
-
- let dts = Components.classes["@mozilla.org/intl/scriptabledateformat;1"].
- getService(Components.interfaces.nsIScriptableDateFormat);
-
- testGetReadableDates(today_11_30, dts.FormatTime("", dts.timeFormatNoSeconds,
- 11, 30, 0));
- testGetReadableDates(today_12_30, dts.FormatTime("", dts.timeFormatNoSeconds,
- 12, 30, 0));
- testGetReadableDates(yesterday_11_30, "Yesterday");
- testGetReadableDates(yesterday_12_30, "Yesterday");
- testGetReadableDates(twodaysago,
- typeof Intl === "undefined"
- ? twodaysago.toLocaleFormat("%A")
- : twodaysago.toLocaleDateString(locale, { weekday: "long" }));
- testGetReadableDates(sixdaysago,
- typeof Intl === "undefined"
- ? sixdaysago.toLocaleFormat("%A")
- : sixdaysago.toLocaleDateString(locale, { weekday: "long" }));
- testGetReadableDates(sevendaysago,
- (typeof Intl === "undefined"
- ? sevendaysago.toLocaleFormat("%B")
- : sevendaysago.toLocaleDateString(locale, { month: "long" })) + " " +
- sevendaysago.getDate().toString().padStart(2, "0"));
-
- let [, dateTimeFull] = DownloadUtils.getReadableDates(today_11_30);
- do_check_eq(dateTimeFull, dts.FormatDateTime("", dts.dateFormatLong,
- dts.timeFormatNoSeconds,
- 2000, 12, 31, 11, 30, 0));
-}
-
-function run_test()
-{
- testConvertByteUnits(-1, "-1", "bytes");
- testConvertByteUnits(1, _("1"), "bytes");
- testConvertByteUnits(42, _("42"), "bytes");
- testConvertByteUnits(123, _("123"), "bytes");
- testConvertByteUnits(1024, _("1.0"), "KB");
- testConvertByteUnits(8888, _("8.7"), "KB");
- testConvertByteUnits(59283, _("57.9"), "KB");
- testConvertByteUnits(640000, _("625"), "KB");
- testConvertByteUnits(1048576, _("1.0"), "MB");
- testConvertByteUnits(307232768, _("293"), "MB");
- testConvertByteUnits(1073741824, _("1.0"), "GB");
-
- testTransferTotal(1, 1, _("1 of 1 bytes"));
- testTransferTotal(234, 4924, _("234 bytes of 4.8 KB"));
- testTransferTotal(94923, 233923, _("92.7 of 228 KB"));
- testTransferTotal(4924, 94923, _("4.8 of 92.7 KB"));
- testTransferTotal(2342, 294960345, _("2.3 KB of 281 MB"));
- testTransferTotal(234, undefined, _("234 bytes"));
- testTransferTotal(4889023, undefined, _("4.7 MB"));
-
- if (0) {
- // Help find some interesting test cases
- let r = () => Math.floor(Math.random() * 10);
- for (let i = 0; i < 100; i++) {
- testStatus(r(), r(), r());
- }
- }
-
- // First, test with rates, via getDownloadStatus...
- let statusFunc = DownloadUtils.getDownloadStatus.bind(DownloadUtils);
-
- testStatus(statusFunc, 2, 1, 7, ["A few seconds remaining -- 2.3 of 2.4 KB (58 bytes/sec)", 1.724]);
- testStatus(statusFunc, 1, 2, 6, ["A few seconds remaining -- 100 bytes of 2.4 KB (1.4 KB/sec)", 1.582]);
- testStatus(statusFunc, 4, 3, 9, ["A few seconds remaining -- 959 KB of 1.0 MB (12.9 MB/sec)", 0.004]);
- testStatus(statusFunc, 2, 3, 8, ["A few seconds remaining -- 2.3 of 56.5 KB (9.2 GB/sec)", 0.000]);
-
- testStatus(statusFunc, 8, 4, 3, ["17 seconds remaining -- 9.2 of 9.2 GB (54.3 KB/sec)", 17.682]);
- testStatus(statusFunc, 1, 3, 2, ["23 seconds remaining -- 100 bytes of 54.4 KB (2.3 KB/sec)", 23.691]);
- testStatus(statusFunc, 9, 3, 2, ["23 seconds remaining -- 12.9 of 12.9 MB (2.3 KB/sec)", 23.691]);
- testStatus(statusFunc, 5, 6, 7, ["25 seconds remaining -- 22.1 of 22.1 MB (58 bytes/sec)", 25.552]);
-
- testStatus(statusFunc, 3, 9, 3, ["4 minutes remaining -- 54.3 KB of 12.9 MB (54.3 KB/sec)", 242.969]);
- testStatus(statusFunc, 2, 3, 1, ["9 minutes remaining -- 2.3 of 56.5 KB (100 bytes/sec)", 555.550]);
- testStatus(statusFunc, 4, 3, 7, ["15 minutes remaining -- 959 KB of 1.0 MB (58 bytes/sec)", 957.845]);
- testStatus(statusFunc, 5, 3, 7, ["15 minutes remaining -- 22.1 of 22.2 MB (58 bytes/sec)", 957.845]);
-
- testStatus(statusFunc, 1, 9, 2, ["1 hour, 35 minutes remaining -- 100 bytes of 12.9 MB (2.3 KB/sec)", 5756.133]);
- testStatus(statusFunc, 2, 9, 6, ["2 hours, 31 minutes remaining -- 2.3 KB of 12.9 MB (1.4 KB/sec)", 9108.051]);
- testStatus(statusFunc, 2, 4, 1, ["2 hours, 43 minutes remaining -- 2.3 of 962 KB (100 bytes/sec)", 9823.410]);
- testStatus(statusFunc, 6, 4, 7, ["4 hours, 42 minutes remaining -- 1.4 of 961 KB (58 bytes/sec)", 16936.914]);
-
- testStatus(statusFunc, 6, 9, 1, ["1 day, 13 hours remaining -- 1.4 KB of 12.9 MB (100 bytes/sec)", 134981.320]);
- testStatus(statusFunc, 3, 8, 3, ["2 days, 1 hour remaining -- 54.3 KB of 9.2 GB (54.3 KB/sec)", 178596.872]);
- testStatus(statusFunc, 1, 8, 6, ["77 days, 11 hours remaining -- 100 bytes of 9.2 GB (1.4 KB/sec)", 6694972.470]);
- testStatus(statusFunc, 6, 8, 7, ["1979 days, 22 hours remaining -- 1.4 KB of 9.2 GB (58 bytes/sec)", 171068089.672]);
-
- testStatus(statusFunc, 0, 0, 5, ["Unknown time remaining -- 0 of 0 bytes (22.1 MB/sec)", Infinity]);
- testStatus(statusFunc, 0, 6, 0, ["Unknown time remaining -- 0 bytes of 1.4 KB (0 bytes/sec)", Infinity]);
- testStatus(statusFunc, 6, 6, 0, ["Unknown time remaining -- 1.4 of 2.9 KB (0 bytes/sec)", Infinity]);
- testStatus(statusFunc, 8, 5, 0, ["Unknown time remaining -- 9.2 of 9.3 GB (0 bytes/sec)", Infinity]);
-
- // With rate equal to Infinity
- testStatus(statusFunc, 0, 0, 10, ["Unknown time remaining -- 0 of 0 bytes (Really fast)", Infinity]);
- testStatus(statusFunc, 1, 2, 10, ["A few seconds remaining -- 100 bytes of 2.4 KB (Really fast)", 0]);
-
- // Now test without rates, via getDownloadStatusNoRate.
- statusFunc = DownloadUtils.getDownloadStatusNoRate.bind(DownloadUtils);
-
- testStatus(statusFunc, 2, 1, 7, ["A few seconds remaining -- 2.3 of 2.4 KB", 1.724]);
- testStatus(statusFunc, 1, 2, 6, ["A few seconds remaining -- 100 bytes of 2.4 KB", 1.582]);
- testStatus(statusFunc, 4, 3, 9, ["A few seconds remaining -- 959 KB of 1.0 MB", 0.004]);
- testStatus(statusFunc, 2, 3, 8, ["A few seconds remaining -- 2.3 of 56.5 KB", 0.000]);
-
- testStatus(statusFunc, 8, 4, 3, ["17 seconds remaining -- 9.2 of 9.2 GB", 17.682]);
- testStatus(statusFunc, 1, 3, 2, ["23 seconds remaining -- 100 bytes of 54.4 KB", 23.691]);
- testStatus(statusFunc, 9, 3, 2, ["23 seconds remaining -- 12.9 of 12.9 MB", 23.691]);
- testStatus(statusFunc, 5, 6, 7, ["25 seconds remaining -- 22.1 of 22.1 MB", 25.552]);
-
- testStatus(statusFunc, 3, 9, 3, ["4 minutes remaining -- 54.3 KB of 12.9 MB", 242.969]);
- testStatus(statusFunc, 2, 3, 1, ["9 minutes remaining -- 2.3 of 56.5 KB", 555.550]);
- testStatus(statusFunc, 4, 3, 7, ["15 minutes remaining -- 959 KB of 1.0 MB", 957.845]);
- testStatus(statusFunc, 5, 3, 7, ["15 minutes remaining -- 22.1 of 22.2 MB", 957.845]);
-
- testStatus(statusFunc, 1, 9, 2, ["1 hour, 35 minutes remaining -- 100 bytes of 12.9 MB", 5756.133]);
- testStatus(statusFunc, 2, 9, 6, ["2 hours, 31 minutes remaining -- 2.3 KB of 12.9 MB", 9108.051]);
- testStatus(statusFunc, 2, 4, 1, ["2 hours, 43 minutes remaining -- 2.3 of 962 KB", 9823.410]);
- testStatus(statusFunc, 6, 4, 7, ["4 hours, 42 minutes remaining -- 1.4 of 961 KB", 16936.914]);
-
- testStatus(statusFunc, 6, 9, 1, ["1 day, 13 hours remaining -- 1.4 KB of 12.9 MB", 134981.320]);
- testStatus(statusFunc, 3, 8, 3, ["2 days, 1 hour remaining -- 54.3 KB of 9.2 GB", 178596.872]);
- testStatus(statusFunc, 1, 8, 6, ["77 days, 11 hours remaining -- 100 bytes of 9.2 GB", 6694972.470]);
- testStatus(statusFunc, 6, 8, 7, ["1979 days, 22 hours remaining -- 1.4 KB of 9.2 GB", 171068089.672]);
-
- testStatus(statusFunc, 0, 0, 5, ["Unknown time remaining -- 0 of 0 bytes", Infinity]);
- testStatus(statusFunc, 0, 6, 0, ["Unknown time remaining -- 0 bytes of 1.4 KB", Infinity]);
- testStatus(statusFunc, 6, 6, 0, ["Unknown time remaining -- 1.4 of 2.9 KB", Infinity]);
- testStatus(statusFunc, 8, 5, 0, ["Unknown time remaining -- 9.2 of 9.3 GB", Infinity]);
-
- testURI("http://www.mozilla.org/", "mozilla.org", "www.mozilla.org");
- testURI("http://www.city.mikasa.hokkaido.jp/", "city.mikasa.hokkaido.jp", "www.city.mikasa.hokkaido.jp");
- testURI("data:text/html,Hello World", "data resource", "data resource");
- testURI("jar:http://www.mozilla.com/file!/magic", "mozilla.com", "www.mozilla.com");
- testURI("file:///C:/Cool/Stuff/", "local file", "local file");
- // Don't test for moz-icon if we don't have a protocol handler for it (e.g. b2g):
- if ("@mozilla.org/network/protocol;1?name=moz-icon" in Components.classes) {
- testURI("moz-icon:file:///test.extension", "local file", "local file");
- testURI("moz-icon://.extension", "moz-icon resource", "moz-icon resource");
- }
- testURI("about:config", "about resource", "about resource");
- testURI("invalid.uri", "", "");
-
- testAllGetReadableDates();
-}
diff --git a/toolkit/mozapps/downloads/tests/unit/test_lowMinutes.js b/toolkit/mozapps/downloads/tests/unit/test_lowMinutes.js
deleted file mode 100644
index 75eff3370..000000000
--- a/toolkit/mozapps/downloads/tests/unit/test_lowMinutes.js
+++ /dev/null
@@ -1,55 +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 448344 to make sure when we're in low minutes, we show both minutes
- * and seconds; but continue to show only minutes when we have plenty.
- */
-
-Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
-
-/**
- * Print some debug message to the console. All arguments will be printed,
- * separated by spaces.
- *
- * @param [arg0, arg1, arg2, ...]
- * Any number of arguments to print out
- * @usage _("Hello World") -> prints "Hello World"
- * @usage _(1, 2, 3) -> prints "1 2 3"
- */
-var _ = function(some, debug, text, to) {
- print(Array.slice(arguments).join(" "));
-};
-
-_("Make an array of time lefts and expected string to be shown for that time");
-var expectedTimes = [
- [1.1, "A few seconds remaining", "under 4sec -> few"],
- [2.5, "A few seconds remaining", "under 4sec -> few"],
- [3.9, "A few seconds remaining", "under 4sec -> few"],
- [5.3, "5 seconds remaining", "truncate seconds"],
- [1.1 * 60, "1 minute, 6 seconds remaining", "under 4min -> show sec"],
- [2.5 * 60, "2 minutes, 30 seconds remaining", "under 4min -> show sec"],
- [3.9 * 60, "3 minutes, 54 seconds remaining", "under 4min -> show sec"],
- [5.3 * 60, "5 minutes remaining", "over 4min -> only show min"],
- [1.1 * 3600, "1 hour, 6 minutes remaining", "over 1hr -> show min/sec"],
- [2.5 * 3600, "2 hours, 30 minutes remaining", "over 1hr -> show min/sec"],
- [3.9 * 3600, "3 hours, 54 minutes remaining", "over 1hr -> show min/sec"],
- [5.3 * 3600, "5 hours, 18 minutes remaining", "over 1hr -> show min/sec"],
-];
-_(expectedTimes.join("\n"));
-
-function run_test()
-{
- expectedTimes.forEach(function([time, expectStatus, comment]) {
- _("Running test with time", time);
- _("Test comment:", comment);
- let [status, last] = DownloadUtils.getTimeLeft(time);
-
- _("Got status:", status, "last:", last);
- _("Expecting..", expectStatus);
- do_check_eq(status, expectStatus);
-
- _();
- });
-}
diff --git a/toolkit/mozapps/downloads/tests/unit/test_syncedDownloadUtils.js b/toolkit/mozapps/downloads/tests/unit/test_syncedDownloadUtils.js
deleted file mode 100644
index 86d810a9b..000000000
--- a/toolkit/mozapps/downloads/tests/unit/test_syncedDownloadUtils.js
+++ /dev/null
@@ -1,26 +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 420482 by making sure multiple consumers of DownloadUtils gets the
- * same time remaining time if they provide the same time left but a different
- * "last time".
- */
-
-var Cu = Components.utils;
-Cu.import("resource://gre/modules/DownloadUtils.jsm");
-
-function run_test()
-{
- // Simulate having multiple downloads requesting time left
- let downloadTimes = {};
- for (let time of [1, 30, 60, 3456, 9999])
- downloadTimes[time] = DownloadUtils.getTimeLeft(time)[0];
-
- // Pretend we're a download status bar also asking for a time left, but we're
- // using a different "last sec". We need to make sure we get the same time.
- let lastSec = 314;
- for (let [time, text] of Object.entries(downloadTimes))
- do_check_eq(DownloadUtils.getTimeLeft(time, lastSec)[0], text);
-}
diff --git a/toolkit/mozapps/downloads/tests/unit/test_unspecified_arguments.js b/toolkit/mozapps/downloads/tests/unit/test_unspecified_arguments.js
deleted file mode 100644
index 02e27c92c..000000000
--- a/toolkit/mozapps/downloads/tests/unit/test_unspecified_arguments.js
+++ /dev/null
@@ -1,25 +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 passing null and nothing to various variable-arg DownloadUtils
- * methods provide the same result.
- */
-
-var Cu = Components.utils;
-Cu.import("resource://gre/modules/DownloadUtils.jsm");
-
-function run_test()
-{
- do_check_eq(DownloadUtils.getDownloadStatus(1000, null, null, null) + "",
- DownloadUtils.getDownloadStatus(1000) + "");
- do_check_eq(DownloadUtils.getDownloadStatus(1000, null, null) + "",
- DownloadUtils.getDownloadStatus(1000, null) + "");
-
- do_check_eq(DownloadUtils.getTransferTotal(1000, null) + "",
- DownloadUtils.getTransferTotal(1000) + "");
-
- do_check_eq(DownloadUtils.getTimeLeft(1000, null) + "",
- DownloadUtils.getTimeLeft(1000) + "");
-}
diff --git a/toolkit/mozapps/downloads/tests/unit/xpcshell.ini b/toolkit/mozapps/downloads/tests/unit/xpcshell.ini
deleted file mode 100644
index 877816ef6..000000000
--- a/toolkit/mozapps/downloads/tests/unit/xpcshell.ini
+++ /dev/null
@@ -1,10 +0,0 @@
-[DEFAULT]
-head = head_downloads.js
-tail =
-skip-if = toolkit == 'android'
-
-[test_DownloadPaths.js]
-[test_DownloadUtils.js]
-[test_lowMinutes.js]
-[test_syncedDownloadUtils.js]
-[test_unspecified_arguments.js]