зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1261842 - Update browser_privatebrowsing_downloadLastDir_toggle.js to use add_task and BrowserTestUtils. r=jdm
MozReview-Commit-ID: 6S64VvZpwDf --HG-- extra : rebase_source : cf1014d4f5fe9be2c79091da0e91d0e79e585d23 extra : source : 20eb3987a721a2c0a312868cf52dbf2f43563236
This commit is contained in:
Родитель
462c1e5074
Коммит
ee080acac2
|
@ -1,16 +1,12 @@
|
|||
/* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
let FileUtils =
|
||||
Cu.import("resource://gre/modules/FileUtils.jsm", {}).FileUtils;
|
||||
let DownloadLastDir =
|
||||
Cu.import("resource://gre/modules/DownloadLastDir.jsm", {}).DownloadLastDir;
|
||||
Cu.import("resource://gre/modules/FileUtils.jsm");
|
||||
Cu.import("resource://gre/modules/DownloadLastDir.jsm");
|
||||
|
||||
/**
|
||||
* Tests how the browser remembers the last download folder
|
||||
* from download to download, with a particular emphasis
|
||||
* on how it behaves when private browsing windows open.
|
||||
*/
|
||||
add_task(function* test_downloads_last_dir_toggle() {
|
||||
let tmpDir = FileUtils.getDir("TmpD", [], true);
|
||||
let dir1 = newDirectory();
|
||||
|
||||
|
@ -19,79 +15,91 @@ function test() {
|
|||
dir1.remove(true);
|
||||
});
|
||||
|
||||
function testOnWindow(aPrivate, aCallback) {
|
||||
whenNewWindowLoaded({private: aPrivate}, function(win) {
|
||||
let gDownloadLastDir = new DownloadLastDir(win);
|
||||
aCallback(win, gDownloadLastDir);
|
||||
gDownloadLastDir.cleanupPrivateFile();
|
||||
win.close();
|
||||
});
|
||||
}
|
||||
let win = yield BrowserTestUtils.openNewBrowserWindow();
|
||||
let gDownloadLastDir = new DownloadLastDir(win);
|
||||
is(typeof gDownloadLastDir, "object",
|
||||
"gDownloadLastDir should be a valid object");
|
||||
is(gDownloadLastDir.file, null,
|
||||
"gDownloadLastDir.file should be null to start with");
|
||||
|
||||
function checkDownloadLastDirInit(aWin, gDownloadLastDir, aCallback) {
|
||||
is(typeof gDownloadLastDir, "object",
|
||||
"gDownloadLastDir should be a valid object");
|
||||
is(gDownloadLastDir.file, null,
|
||||
"gDownloadLastDir.file should be null to start with");
|
||||
gDownloadLastDir.file = tmpDir;
|
||||
is(gDownloadLastDir.file.path, tmpDir.path,
|
||||
"LastDir should point to the temporary directory");
|
||||
isnot(gDownloadLastDir.file, tmpDir,
|
||||
"gDownloadLastDir.file should not be pointing to the tmpDir");
|
||||
|
||||
gDownloadLastDir.file = tmpDir;
|
||||
is(gDownloadLastDir.file.path, tmpDir.path,
|
||||
"LastDir should point to the temporary directory");
|
||||
isnot(gDownloadLastDir.file, tmpDir,
|
||||
"gDownloadLastDir.file should not be pointing to the tmpDir");
|
||||
gDownloadLastDir.file = 1; // not an nsIFile
|
||||
is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null");
|
||||
|
||||
gDownloadLastDir.file = 1; // not an nsIFile
|
||||
is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null");
|
||||
gDownloadLastDir.file = tmpDir;
|
||||
clearHistory();
|
||||
is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null");
|
||||
|
||||
gDownloadLastDir.file = tmpDir;
|
||||
clearHistory();
|
||||
is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null");
|
||||
gDownloadLastDir.file = tmpDir;
|
||||
yield BrowserTestUtils.closeWindow(win);
|
||||
|
||||
gDownloadLastDir.file = tmpDir;
|
||||
aCallback();
|
||||
}
|
||||
info("Opening the first private window");
|
||||
yield testHelper({ private: true, expectedDir: tmpDir });
|
||||
info("Opening a non-private window");
|
||||
yield testHelper({ private: false, expectedDir: tmpDir });
|
||||
info("Opening a private window and setting download directory");
|
||||
yield testHelper({ private: true, setDir: dir1, expectedDir: dir1 });
|
||||
info("Opening a non-private window and checking download directory");
|
||||
yield testHelper({ private: false, expectedDir: tmpDir });
|
||||
info("Opening private window and clearing history");
|
||||
yield testHelper({ private: true, clearHistory: true, expectedDir: null });
|
||||
info("Opening a non-private window and checking download directory");
|
||||
yield testHelper({ private: true, expectedDir: null });
|
||||
});
|
||||
|
||||
function checkDownloadLastDir(aWin, gDownloadLastDir, aLastDir, aUpdate, aCallback) {
|
||||
if (aUpdate)
|
||||
gDownloadLastDir.file = aLastDir;
|
||||
is(gDownloadLastDir.file.path, aLastDir.path,
|
||||
"gDownloadLastDir should point to the expected last directory");
|
||||
isnot(gDownloadLastDir.file, aLastDir,
|
||||
"gDownloadLastDir.file should not be pointing to the last directory");
|
||||
aCallback();
|
||||
}
|
||||
/**
|
||||
* Opens a new window and performs some test actions on it based
|
||||
* on the options object that have been passed in.
|
||||
*
|
||||
* @param options (Object)
|
||||
* An object with the following properties:
|
||||
*
|
||||
* clearHistory (bool, optional):
|
||||
* Whether or not to simulate clearing session history.
|
||||
* Defaults to false.
|
||||
*
|
||||
* setDir (nsIFile, optional):
|
||||
* An nsIFile for setting the last download directory.
|
||||
* If not set, the load download directory is not changed.
|
||||
*
|
||||
* expectedDir (nsIFile, expectedDir):
|
||||
* An nsIFile for what we expect the last download directory
|
||||
* should be. The nsIFile is not compared directly - only
|
||||
* paths are compared. If expectedDir is not set, then the
|
||||
* last download directory is expected to be null.
|
||||
*
|
||||
* @returns Promise
|
||||
*/
|
||||
function testHelper(options) {
|
||||
return new Task.spawn(function() {
|
||||
let win = yield BrowserTestUtils.openNewBrowserWindow(options);
|
||||
let gDownloadLastDir = new DownloadLastDir(win);
|
||||
|
||||
function checkDownloadLastDirNull(aWin, gDownloadLastDir, aCallback) {
|
||||
is(gDownloadLastDir.file, null, "gDownloadLastDir should be null");
|
||||
aCallback();
|
||||
}
|
||||
if (options.clearHistory) {
|
||||
clearHistory();
|
||||
}
|
||||
|
||||
testOnWindow(false, function(win, downloadDir) {
|
||||
checkDownloadLastDirInit(win, downloadDir, function() {
|
||||
testOnWindow(true, function(win, downloadDir) {
|
||||
checkDownloadLastDir(win, downloadDir, tmpDir, false, function() {
|
||||
testOnWindow(false, function(win, downloadDir) {
|
||||
checkDownloadLastDir(win, downloadDir, tmpDir, false, function() {
|
||||
testOnWindow(true, function(win, downloadDir) {
|
||||
checkDownloadLastDir(win, downloadDir, dir1, true, function() {
|
||||
testOnWindow(false, function(win, downloadDir) {
|
||||
checkDownloadLastDir(win, downloadDir, tmpDir, false, function() {
|
||||
testOnWindow(true, function(win, downloadDir) {
|
||||
clearHistory();
|
||||
checkDownloadLastDirNull(win, downloadDir, function() {
|
||||
testOnWindow(false, function(win, downloadDir) {
|
||||
checkDownloadLastDirNull(win, downloadDir, finish);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
if (options.setDir) {
|
||||
gDownloadLastDir.file = options.setDir;
|
||||
}
|
||||
|
||||
let expectedDir = options.expectedDir;
|
||||
|
||||
if (expectedDir) {
|
||||
is(gDownloadLastDir.file.path, expectedDir.path,
|
||||
"gDownloadLastDir should point to the expected last directory");
|
||||
isnot(gDownloadLastDir.file, expectedDir,
|
||||
"gDownloadLastDir.file should not be pointing to the last directory");
|
||||
} else {
|
||||
is(gDownloadLastDir.file, null, "gDownloadLastDir should be null");
|
||||
}
|
||||
|
||||
gDownloadLastDir.cleanupPrivateFile();
|
||||
yield BrowserTestUtils.closeWindow(win);
|
||||
});
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче