mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Marge backout of bug 464795
This commit is contained in:
commit
18650341da
@ -1,180 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is bug 464795 unit test.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ehsan Akhgari.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
|
||||
function loadUtilsScript() {
|
||||
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
|
||||
getService(Ci.mozIJSSubScriptLoader);
|
||||
loader.loadSubScript("chrome://global/content/contentAreaUtils.js");
|
||||
}
|
||||
|
||||
// Code borrowed from toolkit/components/downloadmgr/test/unit/head_download_manager.js
|
||||
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIProperties);
|
||||
var profileDir = null;
|
||||
try {
|
||||
profileDir = dirSvc.get("ProfD", Ci.nsIFile);
|
||||
} catch (e) { }
|
||||
if (!profileDir) {
|
||||
// Register our own provider for the profile directory.
|
||||
// It will simply return the current directory.
|
||||
var provider = {
|
||||
getFile: function(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == "ProfD") {
|
||||
return dirSvc.get("CurProcD", Ci.nsILocalFile);
|
||||
} else if (prop == "DLoads") {
|
||||
var file = dirSvc.get("CurProcD", 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.nsIDirectoryProvider) ||
|
||||
iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
}
|
||||
|
||||
let window = {};
|
||||
function run_test()
|
||||
{
|
||||
loadUtilsScript();
|
||||
|
||||
let prefs = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService).
|
||||
getBranch("browser.download.");
|
||||
let pb = Cc["@mozilla.org/privatebrowsing;1"].
|
||||
getService(Ci.nsIPrivateBrowsingService);
|
||||
let tmpDir = dirSvc.get("TmpD", Ci.nsILocalFile);
|
||||
function newDirectory() {
|
||||
let dir = tmpDir.clone();
|
||||
dir.append("testdir" + Math.floor(Math.random() * 10000));
|
||||
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
|
||||
return dir;
|
||||
}
|
||||
function newFileInDirectory(dir) {
|
||||
let file = dir.clone();
|
||||
file.append("testfile" + Math.floor(Math.random() * 10000));
|
||||
file.createUnique(Ci.nsIFile.DIRECTORY_FILE, 0600);
|
||||
return file;
|
||||
}
|
||||
let dir1 = newDirectory();
|
||||
let dir2 = newDirectory();
|
||||
let dir3 = newDirectory();
|
||||
let file1 = newFileInDirectory(dir1);
|
||||
let file2 = newFileInDirectory(dir2);
|
||||
let file3 = newFileInDirectory(dir3);
|
||||
|
||||
// overwrite makeFilePicker, as we don't want to create a real filepicker object
|
||||
let fp = {
|
||||
appendFilter: function() {},
|
||||
appendFilters: function() {},
|
||||
init: function() {},
|
||||
show: function() Ci.nsIFilePicker.returnOK,
|
||||
displayDirectory: null,
|
||||
file: file1
|
||||
};
|
||||
makeFilePicker = function() fp;
|
||||
|
||||
// Overwrite getStringBundle to return an object masquerading as an string bungle
|
||||
getStringBundle = function() {
|
||||
return {
|
||||
GetStringFromName: function() ""
|
||||
};
|
||||
}
|
||||
|
||||
// Overwrite validateFileName to validate everything
|
||||
validateFileName = function(foo) foo;
|
||||
|
||||
let params = {
|
||||
fpTitleKey: "test",
|
||||
fileInfo: new FileInfo("test.txt", "test.txt", "test", "txt", "http://mozilla.org/test.txt"),
|
||||
contentType: "text/plain",
|
||||
saveMode: SAVEMODE_FILEONLY,
|
||||
saveAsType: kSaveAsType_Complete,
|
||||
file: null
|
||||
};
|
||||
|
||||
prefs.setComplexValue("lastDir", Ci.nsILocalFile, tmpDir);
|
||||
|
||||
do_check_true(getTargetFile(params));
|
||||
// file picker should start with browser.download.lastDir
|
||||
do_check_eq(fp.displayDirectory.path, tmpDir.path);
|
||||
// browser.download.lastDir should be modified before entering the private browsing mode
|
||||
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
|
||||
// gDownloadLastDir should not be used outside of the private browsing mode
|
||||
do_check_eq(gDownloadLastDir.file, null);
|
||||
|
||||
pb.privateBrowsingEnabled = true;
|
||||
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
|
||||
fp.file = file2;
|
||||
fp.displayDirectory = null;
|
||||
do_check_true(getTargetFile(params));
|
||||
// file picker should start with browser.download.lastDir as set before entering the private browsing mode
|
||||
do_check_eq(fp.displayDirectory.path, dir1.path);
|
||||
// browser.download.lastDir should not be modified inside the private browsing mode
|
||||
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
|
||||
// but gDownloadLastDir should be modified
|
||||
do_check_eq(gDownloadLastDir.file.path, dir2.path);
|
||||
|
||||
pb.privateBrowsingEnabled = false;
|
||||
// gDownloadLastDir should be cleared after leaving the private browsing mode
|
||||
do_check_eq(gDownloadLastDir.file, null);
|
||||
fp.file = file3;
|
||||
fp.displayDirectory = null;
|
||||
do_check_true(getTargetFile(params));
|
||||
// file picker should start with browser.download.lastDir as set before entering the private browsing mode
|
||||
do_check_eq(fp.displayDirectory.path, dir1.path);
|
||||
// browser.download.lastDir should be modified after leaving the private browsing mode
|
||||
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir3.path);
|
||||
// gDownloadLastDir should not be used after leaving the private browsing mode
|
||||
do_check_eq(gDownloadLastDir.file, null);
|
||||
|
||||
// cleanup
|
||||
[dir1, dir2, dir3].forEach(function(dir) dir.remove(true));
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).unregisterProvider(provider);
|
||||
}
|
@ -62,9 +62,6 @@ let gDownloadLastDir = {
|
||||
return gDownloadLastDirFile;
|
||||
},
|
||||
set file(val) {
|
||||
if (val instanceof Components.interfaces.nsIFile)
|
||||
gDownloadLastDirFile = val.clone();
|
||||
else
|
||||
gDownloadLastDirFile = null;
|
||||
gDownloadLastDirFile = val;
|
||||
}
|
||||
};
|
||||
|
@ -1,98 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is bug 464795 unit test.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ehsan Akhgari.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
function FilePickerService() {
|
||||
let fileptr = Cc["@mozilla.org/supports-interface-pointer;1"].
|
||||
createInstance(Ci.nsISupportsInterfacePointer);
|
||||
this._obs.notifyObservers(fileptr, "TEST_FILEPICKER_GETFILE", "");
|
||||
this.file = fileptr.data.QueryInterface(fileptr.dataIID);
|
||||
}
|
||||
|
||||
FilePickerService.prototype = {
|
||||
_obs: Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService),
|
||||
classDescription: "File Picker Test Service",
|
||||
contractID: "@mozilla.org/filepicker;1",
|
||||
classID: Components.ID("{a070e4b7-65f3-45b3-96dd-1b682ff18588}"),
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
|
||||
|
||||
// constants
|
||||
modeOpen: 0,
|
||||
modeSave: 1,
|
||||
modeGetFolder: 2,
|
||||
modeOpenMultiple: 3,
|
||||
returnOK: 0,
|
||||
returnCancel: 1,
|
||||
returnReplace: 2,
|
||||
filterAll: 1,
|
||||
filterHTML: 2,
|
||||
filterText: 4,
|
||||
filterImages: 8,
|
||||
filterXML: 16,
|
||||
filterXUL: 32,
|
||||
filterApps: 64,
|
||||
|
||||
// properties
|
||||
defaultExtension: "",
|
||||
defaultString: "",
|
||||
get displayDirectory() { return null; },
|
||||
set displayDirectory(val) {
|
||||
this._obs.notifyObservers(val, "TEST_FILEPICKER_SETDISPLAYDIRECTORY", "");
|
||||
},
|
||||
file: null,
|
||||
get files() { return null; },
|
||||
get fileURL() { return null; },
|
||||
filterIndex: 0,
|
||||
|
||||
// methods
|
||||
appendFilter: function() {},
|
||||
appendFilters: function() {},
|
||||
init: function() {},
|
||||
show: function() {
|
||||
return this.returnOK;
|
||||
}
|
||||
};
|
||||
|
||||
function NSGetModule(compMgr, fileSpec)
|
||||
XPCOMUtils.generateModule([FilePickerService]);
|
@ -1,74 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is DownloadUtils Test Code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ehsan Akhgari <ehsan.akhgari@gmail.com>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
function run_test()
|
||||
{
|
||||
let Cc = Components.classes;
|
||||
let Ci = Components.interfaces;
|
||||
let Cu = Components.utils;
|
||||
Cu.import("resource://gre/modules/DownloadLastDir.jsm");
|
||||
|
||||
do_check_eq(typeof gDownloadLastDir, "object");
|
||||
do_check_eq(gDownloadLastDir.file, null);
|
||||
|
||||
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIProperties);
|
||||
let tmpDir = dirSvc.get("TmpD", Ci.nsILocalFile);
|
||||
|
||||
gDownloadLastDir.file = tmpDir;
|
||||
do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
|
||||
do_check_neq(gDownloadLastDir.file, tmpDir);
|
||||
|
||||
gDownloadLastDir.file = 1; // not an nsIFile
|
||||
do_check_eq(gDownloadLastDir.file, null);
|
||||
gDownloadLastDir.file = tmpDir;
|
||||
|
||||
let pb = Cc["@mozilla.org/privatebrowsing;1"].
|
||||
getService(Ci.nsIPrivateBrowsingService);
|
||||
pb.privateBrowsingEnabled = true;
|
||||
do_check_eq(gDownloadLastDir.file, null);
|
||||
|
||||
pb.privateBrowsingEnabled = false;
|
||||
do_check_eq(gDownloadLastDir.file, null);
|
||||
pb.privateBrowsingEnabled = true;
|
||||
|
||||
gDownloadLastDir.file = tmpDir;
|
||||
do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
|
||||
do_check_neq(gDownloadLastDir.file, tmpDir);
|
||||
|
||||
pb.privateBrowsingEnabled = false;
|
||||
do_check_eq(gDownloadLastDir.file, null);
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is bug 464795 unit test.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ehsan Akhgari.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cu = Components.utils;
|
||||
|
||||
// Code borrowed from toolkit/components/downloadmgr/test/unit/head_download_manager.js
|
||||
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIProperties);
|
||||
var profileDir = null;
|
||||
try {
|
||||
profileDir = dirSvc.get("ProfD", Ci.nsIFile);
|
||||
} catch (e) { }
|
||||
if (!profileDir) {
|
||||
// Register our own provider for the profile directory.
|
||||
// It will simply return the current directory.
|
||||
var provider = {
|
||||
getFile: function(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == "ProfD") {
|
||||
return dirSvc.get("CurProcD", Ci.nsILocalFile);
|
||||
} else if (prop == "DLoads") {
|
||||
var file = dirSvc.get("CurProcD", 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.nsIDirectoryProvider) ||
|
||||
iid.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
}
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/DownloadLastDir.jsm");
|
||||
|
||||
let context = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIInterfaceRequestor]),
|
||||
getInterface: XPCOMUtils.generateQI([Ci.nsIDOMWindowInternal])
|
||||
};
|
||||
|
||||
function run_test()
|
||||
{
|
||||
do_load_module("privatebrowsing_downloadLastDir_filepicker.js");
|
||||
|
||||
let prefs = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService).
|
||||
getBranch("browser.download.");
|
||||
let obs = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let pb = Cc["@mozilla.org/privatebrowsing;1"].
|
||||
getService(Ci.nsIPrivateBrowsingService);
|
||||
let launcher = Cc["@mozilla.org/helperapplauncherdialog;1"].
|
||||
getService(Ci.nsIHelperAppLauncherDialog);
|
||||
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIProperties);
|
||||
let tmpDir = dirSvc.get("TmpD", Ci.nsILocalFile);
|
||||
function newDirectory() {
|
||||
let dir = tmpDir.clone();
|
||||
dir.append("testdir" + Math.floor(Math.random() * 10000));
|
||||
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
|
||||
return dir;
|
||||
}
|
||||
function newFileInDirectory(dir) {
|
||||
let file = dir.clone();
|
||||
file.append("testfile" + Math.floor(Math.random() * 10000));
|
||||
file.createUnique(Ci.nsIFile.DIRECTORY_FILE, 0600);
|
||||
return file;
|
||||
}
|
||||
let dir1 = newDirectory();
|
||||
let dir2 = newDirectory();
|
||||
let dir3 = newDirectory();
|
||||
let file1 = newFileInDirectory(dir1);
|
||||
let file2 = newFileInDirectory(dir2);
|
||||
let file3 = newFileInDirectory(dir3);
|
||||
|
||||
let observer = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
switch (aTopic) {
|
||||
case "TEST_FILEPICKER_GETFILE":
|
||||
let fileptr = aSubject.QueryInterface(Ci.nsISupportsInterfacePointer);
|
||||
fileptr.data = this.file;
|
||||
fileptr.dataIID = Ci.nsILocalFile;
|
||||
break;
|
||||
case "TEST_FILEPICKER_SETDISPLAYDIRECTORY":
|
||||
this.displayDirectory = aSubject.QueryInterface(Ci.nsILocalFile);
|
||||
break;
|
||||
}
|
||||
},
|
||||
file: null,
|
||||
displayDirectory: null
|
||||
};
|
||||
obs.addObserver(observer, "TEST_FILEPICKER_GETFILE", false);
|
||||
obs.addObserver(observer, "TEST_FILEPICKER_SETDISPLAYDIRECTORY", false);
|
||||
|
||||
prefs.setComplexValue("lastDir", Ci.nsILocalFile, tmpDir);
|
||||
|
||||
observer.file = file1;
|
||||
let file = launcher.promptForSaveToFile(null, context, null, null, null);
|
||||
do_check_true(!!file);
|
||||
// file picker should start with browser.download.lastDir
|
||||
do_check_eq(observer.displayDirectory.path, tmpDir.path);
|
||||
// browser.download.lastDir should be modified before entering the private browsing mode
|
||||
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
|
||||
// gDownloadLastDir should not be used outside of the private browsing mode
|
||||
do_check_eq(gDownloadLastDir.file, null);
|
||||
|
||||
pb.privateBrowsingEnabled = true;
|
||||
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
|
||||
observer.file = file2;
|
||||
observer.displayDirectory = null;
|
||||
file = launcher.promptForSaveToFile(null, context, null, null, null);
|
||||
do_check_true(!!file);
|
||||
// file picker should start with browser.download.lastDir as set before entering the private browsing mode
|
||||
do_check_eq(observer.displayDirectory.path, dir1.path);
|
||||
// browser.download.lastDir should not be modified inside the private browsing mode
|
||||
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
|
||||
// but gDownloadLastDir should be modified
|
||||
do_check_eq(gDownloadLastDir.file.path, dir2.path);
|
||||
|
||||
pb.privateBrowsingEnabled = false;
|
||||
// gDownloadLastDir should be cleared after leaving the private browsing mode
|
||||
do_check_eq(gDownloadLastDir.file, null);
|
||||
observer.file = file3;
|
||||
observer.displayDirectory = null;
|
||||
file = launcher.promptForSaveToFile(null, context, null, null, null);
|
||||
do_check_true(!!file);
|
||||
// file picker should start with browser.download.lastDir as set before entering the private browsing mode
|
||||
do_check_eq(observer.displayDirectory.path, dir1.path);
|
||||
// browser.download.lastDir should be modified after leaving the private browsing mode
|
||||
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir3.path);
|
||||
// gDownloadLastDir should not be used after leaving the private browsing mode
|
||||
do_check_eq(gDownloadLastDir.file, null);
|
||||
|
||||
// cleanup
|
||||
[dir1, dir2, dir3].forEach(function(dir) dir.remove(true));
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).unregisterProvider(provider);
|
||||
obs.removeObserver(observer, "TEST_FILEPICKER_GETFILE", false);
|
||||
obs.removeObserver(observer, "TEST_FILEPICKER_SETDISPLAYDIRECTORY", false);
|
||||
}
|
Loading…
Reference in New Issue
Block a user