зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1661365. Test. r=Gijs
Depends on D94268 Differential Revision: https://phabricator.services.mozilla.com/D94269
This commit is contained in:
Родитель
62ea0c2a23
Коммит
3f7cec1751
|
@ -774,7 +774,7 @@ add_task(async function test_empty_progress_tryToKeepPartialData() {
|
|||
add_task(async function test_empty_noprogress() {
|
||||
let sourcePath = "/test_empty_noprogress.txt";
|
||||
let sourceUrl = httpUrl("test_empty_noprogress.txt");
|
||||
let deferRequestReceived = Promise.defer();
|
||||
let deferRequestReceived = PromiseUtils.defer();
|
||||
|
||||
// Register an interruptible handler that notifies us when the request occurs.
|
||||
function cleanup() {
|
||||
|
@ -903,7 +903,7 @@ add_task(async function test_cancel_midway() {
|
|||
}
|
||||
|
||||
// Cancel the download after receiving the first part of the response.
|
||||
let deferCancel = Promise.defer();
|
||||
let deferCancel = PromiseUtils.defer();
|
||||
let onchange = function() {
|
||||
if (!download.stopped && !download.canceled && download.progress == 50) {
|
||||
// Cancel the download immediately during the notification.
|
||||
|
@ -1084,7 +1084,7 @@ add_task(async function test_cancel_midway_restart_tryToKeepPartialData() {
|
|||
|
||||
// The second time, we'll request and obtain the second part of the response,
|
||||
// but we still stop when half of the remaining progress is reached.
|
||||
let deferMidway = Promise.defer();
|
||||
let deferMidway = PromiseUtils.defer();
|
||||
download.onchange = function() {
|
||||
if (
|
||||
!download.stopped &&
|
||||
|
|
|
@ -9,11 +9,6 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
// Globals
|
||||
|
||||
var { AppConstants } = ChromeUtils.import(
|
||||
"resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
var { Integration } = ChromeUtils.import(
|
||||
"resource://gre/modules/Integration.jsm"
|
||||
);
|
||||
|
@ -21,68 +16,22 @@ var { XPCOMUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"DownloadPaths",
|
||||
"resource://gre/modules/DownloadPaths.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"Downloads",
|
||||
"resource://gre/modules/Downloads.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"FileUtils",
|
||||
"resource://gre/modules/FileUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"HttpServer",
|
||||
"resource://testing-common/httpd.js"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"NetUtil",
|
||||
"resource://gre/modules/NetUtil.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"PlacesUtils",
|
||||
"resource://gre/modules/PlacesUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"Promise",
|
||||
"resource://gre/modules/Promise.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"Services",
|
||||
"resource://gre/modules/Services.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"E10SUtils",
|
||||
"resource://gre/modules/E10SUtils.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"FileTestUtils",
|
||||
"resource://testing-common/FileTestUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"MockRegistrar",
|
||||
"resource://testing-common/MockRegistrar.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"TestUtils",
|
||||
"resource://testing-common/TestUtils.jsm"
|
||||
);
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
AppConstants: "resource://gre/modules/AppConstants.jsm",
|
||||
DownloadPaths: "resource://gre/modules/DownloadPaths.jsm",
|
||||
Downloads: "resource://gre/modules/Downloads.jsm",
|
||||
E10SUtils: "resource://gre/modules/E10SUtils.jsm",
|
||||
FileTestUtils: "resource://testing-common/FileTestUtils.jsm",
|
||||
FileUtils: "resource://gre/modules/FileUtils.jsm",
|
||||
HttpServer: "resource://testing-common/httpd.js",
|
||||
MockRegistrar: "resource://testing-common/MockRegistrar.jsm",
|
||||
NetUtil: "resource://gre/modules/NetUtil.jsm",
|
||||
OS: "resource://gre/modules/osfile.jsm",
|
||||
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
|
||||
PromiseUtils: "resource://gre/modules/PromiseUtils.jsm",
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
TestUtils: "resource://testing-common/TestUtils.jsm",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this,
|
||||
|
@ -224,6 +173,18 @@ function getTempFile(leafName) {
|
|||
return FileTestUtils.getTempFile(leafName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for file existence.
|
||||
* @param {string} path The file path.
|
||||
*/
|
||||
async function fileExists(path) {
|
||||
try {
|
||||
return (await IOUtils.stat(path)).type == "regular";
|
||||
} catch (ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for pending events to be processed.
|
||||
*
|
||||
|
@ -692,7 +653,7 @@ function startFakeServer() {
|
|||
/**
|
||||
* This is an internal reference that should not be used directly by tests.
|
||||
*/
|
||||
var _gDeferResponses = Promise.defer();
|
||||
var _gDeferResponses = PromiseUtils.defer();
|
||||
|
||||
/**
|
||||
* Ensures that all the interruptible requests started after this function is
|
||||
|
@ -720,7 +681,7 @@ function mustInterruptResponses() {
|
|||
_gDeferResponses.resolve();
|
||||
|
||||
info("Interruptible responses will be blocked midway.");
|
||||
_gDeferResponses = Promise.defer();
|
||||
_gDeferResponses = PromiseUtils.defer();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -310,7 +310,7 @@ add_task(async function test_history_expiration() {
|
|||
let downloadOne = await promiseNewDownload();
|
||||
let downloadTwo = await promiseNewDownload(httpUrl("interruptible.txt"));
|
||||
|
||||
let deferred = Promise.defer();
|
||||
let deferred = PromiseUtils.defer();
|
||||
let removeNotifications = 0;
|
||||
let downloadView = {
|
||||
onDownloadRemoved(aDownload) {
|
||||
|
@ -357,7 +357,7 @@ add_task(async function test_history_clear() {
|
|||
await list.add(downloadOne);
|
||||
await list.add(downloadTwo);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
let deferred = PromiseUtils.defer();
|
||||
let removeNotifications = 0;
|
||||
let downloadView = {
|
||||
onDownloadRemoved(aDownload) {
|
||||
|
@ -392,7 +392,7 @@ add_task(async function test_removeFinished() {
|
|||
await list.add(downloadThree);
|
||||
await list.add(downloadFour);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
let deferred = PromiseUtils.defer();
|
||||
let removeNotifications = 0;
|
||||
let downloadView = {
|
||||
onDownloadRemoved(aDownload) {
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
add_task(async function() {
|
||||
info("Get a file without extension");
|
||||
let noExtFile = getTempFile("test_bug_1661365");
|
||||
Assert.ok(!noExtFile.leafName.includes("."), "Sanity check the filename");
|
||||
info("Create an exe file with the same name");
|
||||
await IOUtils.remove(noExtFile.path + ".exe", { ignoreAbsent: true });
|
||||
let exeFile = new FileUtils.File(noExtFile.path + ".exe");
|
||||
exeFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
|
||||
Assert.ok(await fileExists(exeFile.path), "Sanity check the exe exists.");
|
||||
Assert.equal(
|
||||
exeFile.leafName,
|
||||
noExtFile.leafName + ".exe",
|
||||
"Sanity check the file names."
|
||||
);
|
||||
registerCleanupFunction(async function() {
|
||||
await IOUtils.remove(noExtFile.path, { ignoreAbsent: true });
|
||||
await IOUtils.remove(exeFile.path, { ignoreAbsent: true });
|
||||
});
|
||||
|
||||
info("Download to the no-extension file");
|
||||
let download = await Downloads.createDownload({
|
||||
source: httpUrl("source.txt"),
|
||||
target: noExtFile,
|
||||
});
|
||||
await download.start();
|
||||
|
||||
Assert.ok(
|
||||
await fileExists(download.target.path),
|
||||
"The file should have been created."
|
||||
);
|
||||
Assert.ok(await fileExists(exeFile.path), "Sanity check the exe exists.");
|
||||
|
||||
info("Launch should open the containing folder");
|
||||
let promiseShowInFolder = waitForDirectoryShown();
|
||||
download.launch();
|
||||
Assert.equal(await promiseShowInFolder, noExtFile.path);
|
||||
});
|
||||
|
||||
/**
|
||||
* Waits for an attempt to show the directory where a file is located, and
|
||||
* returns the path of the file.
|
||||
*/
|
||||
function waitForDirectoryShown() {
|
||||
return new Promise(resolve => {
|
||||
let waitFn = base => ({
|
||||
showContainingDirectory(path) {
|
||||
Integration.downloads.unregister(waitFn);
|
||||
resolve(path);
|
||||
return Promise.resolve();
|
||||
},
|
||||
});
|
||||
Integration.downloads.register(waitFn);
|
||||
});
|
||||
}
|
|
@ -7,6 +7,8 @@ skip-if = toolkit == 'android'
|
|||
support-files =
|
||||
common_test_Download.js
|
||||
|
||||
[test_Download_noext_win.js]
|
||||
run-if = os == "win" # Windows-specific test.
|
||||
[test_DownloadCore.js]
|
||||
[test_DownloadHistory.js]
|
||||
[test_DownloadHistory_initialization.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче