diff --git a/content/html/content/test/test_bug500885.html b/content/html/content/test/test_bug500885.html
index 1b76f25dadf..5ff60f27f2f 100644
--- a/content/html/content/test/test_bug500885.html
+++ b/content/html/content/test/test_bug500885.html
@@ -8,7 +8,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=500885
-
@@ -19,41 +18,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=500885
-
@@ -27,125 +26,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=592802
SimpleTest.waitForExplicitFinish();
-netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-
-function simpleEnumerator(items)
-{
- this._items = items;
- this._nextIndex = 0;
-}
-
-simpleEnumerator.prototype = {
- QueryInterface: function(aIID)
- {
- if (Ci.nsISimpleEnumerator.equals(aIID) ||
- Ci.nsISupports.equals(aIID)) {
- return this;
- }
-
- throw Cr.NS_ERROR_NO_INTERFACE;
- },
-
- hasMoreElements: function()
- {
- return this._nextIndex < this._items.length;
- },
-
- getNext: function()
- {
- if (!this.hasMoreElements()) {
- throw Cr.NS_ERROR_FAILURE;
- }
-
- return this._items[this._nextIndex++];
- }
-};
-
-function MockFilePicker()
-{
-}
-
-MockFilePicker.prototype = {
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
-
- // Constants
- returnOK: 0, // the user hits OK (select a file)
- returnCancel: 1, // the user cancel the file selection
- returnReplace: 2, // the user replace the selection
-
- // Properties
- defaultExtension: "",
- defaultString: "",
- get displayDirectory() { return null; },
- set displayDirectory(val) { },
- get fileURL() { return null; },
- filterIndex: 0,
-
- get file() {
- netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
- var fileName = "592808_file";
- var fileData = "file content";
-
- var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
- .getService(Components.interfaces.nsIProperties);
- var testFile = dirSvc.get("ProfD", Components.interfaces.nsIFile);
- testFile.append(fileName);
- var outStream = Components.
- classes["@mozilla.org/network/file-output-stream;1"].
- createInstance(Components.interfaces.nsIFileOutputStream);
- outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
- 0666, 0);
- outStream.write(fileData, fileData.length);
- outStream.close();
-
- return testFile;
- },
-
- get files() {
- netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
- var fileName = "592808_file";
- var fileData = "file content";
-
- var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
- .getService(Components.interfaces.nsIProperties);
- var testFile = dirSvc.get("ProfD", Components.interfaces.nsIFile);
- testFile.append(fileName);
- var outStream = Components.
- classes["@mozilla.org/network/file-output-stream;1"].
- createInstance(Components.interfaces.nsIFileOutputStream);
- outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
- 0666, 0);
- outStream.write(fileData, fileData.length);
- outStream.close();
-
- return new simpleEnumerator([testFile]);
- },
-
- appendFilter: function(val) {},
-
- appendFilters: function(val) {},
-
- init: function() {},
-
- show: function()
- {
- if (firstFilePickerShow) {
- firstFilePickerShow = false;
- return this.returnCancel;
- } else {
- return this.returnOK;
- }
- }
-};
-
-var mockFilePickerRegisterer =
- new MockObjectRegisterer("@mozilla.org/filepicker;1",MockFilePicker);
-
-mockFilePickerRegisterer.register();
+var MockFilePicker = SpecialPowers.MockFilePicker;
+MockFilePicker.reset();
var testData = [
/* visibility | display | multiple */
@@ -160,26 +42,27 @@ var testData = [
var testCounter = 0;
var testNb = testData.length;
-var firstFilePickerShow = true;
-
function finished()
{
- mockFilePickerRegisterer.unregister();
-
SimpleTest.finish();
}
SimpleTest.waitForFocus(function() {
// mockFilePicker will simulate a cancel for the first time the file picker will be shown.
+ MockFilePicker.returnValue = MockFilePicker.returnCancel;
+
var b2 = document.getElementById('b2');
b2.focus(); // Be sure the element is visible.
document.getElementById('b2').addEventListener("change", function(aEvent) {
aEvent.target.removeEventListener("change", arguments.callee, false);
ok(false, "When cancel is received, change should not fire");
}, false);
- synthesizeMouse(b2, 2, 2, {});
+ b2.click();
// Now, we can launch tests when file picker isn't canceled.
+ MockFilePicker.useAnyFile();
+ MockFilePicker.returnValue = MockFilePicker.returnOK;
+
var b = document.getElementById('b');
b.focus(); // Be sure the element is visible.
@@ -200,12 +83,12 @@ SimpleTest.waitForFocus(function() {
a.multiple = data[2];
SimpleTest.executeSoon(function() {
- synthesizeMouse(b, 2, 2, {});
+ b.click();
});
}
}, false);
- synthesizeMouse(b, 2, 2, {});
+ b.click();
});
diff --git a/layout/forms/test/bug536567_subframe.html b/layout/forms/test/bug536567_subframe.html
index 13348fa03bb..c1271becf06 100644
--- a/layout/forms/test/bug536567_subframe.html
+++ b/layout/forms/test/bug536567_subframe.html
@@ -1,72 +1,12 @@
-
-
-
-
diff --git a/layout/forms/test/test_bug36619.html b/layout/forms/test/test_bug36619.html
index 4caed05bb8c..9f675c912fd 100644
--- a/layout/forms/test/test_bug36619.html
+++ b/layout/forms/test/test_bug36619.html
@@ -8,7 +8,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=36619
-
@@ -25,76 +24,29 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=36619
SimpleTest.waitForExplicitFinish();
-netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-
-function MockFilePicker()
-{
-}
-
-MockFilePicker.prototype = {
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
-
- // properties
- defaultExtension: "",
- defaultString: "",
- get displayDirectory() { return null; },
- set displayDirectory(val) { },
- file: null,
- get files() { return null; },
- get fileURL() { return null; },
- filterIndex: 0,
-
- // methods
- appendFilter: function(val)
- {
- },
-
- appendFilters: function(val)
- {
- },
-
- init: function() {
- },
-
- show: function()
- {
- shown = true;
- }
-};
-
-var mockFilePickerRegisterer =
- new MockObjectRegisterer("@mozilla.org/filepicker;1",MockFilePicker);
-
-mockFilePickerRegisterer.register();
+var MockFilePicker = SpecialPowers.MockFilePicker;
+MockFilePicker.reset();
// enable popups the first time
-var pbi = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch2);
-var oldAllow = pbi.getBoolPref("dom.disable_open_during_load");
-var oldShowBar = pbi.getBoolPref("privacy.popups.showBrowserMessage");
-pbi.setBoolPref("dom.disable_open_during_load", true);
-pbi.setBoolPref("privacy.popups.showBrowserMessage", false);
-
-var shown = false;
+var oldAllow = SpecialPowers.getBoolPref("dom.disable_open_during_load");
+var oldShowBar = SpecialPowers.getBoolPref("privacy.popups.showBrowserMessage");
+SpecialPowers.setBoolPref("dom.disable_open_during_load", true);
+SpecialPowers.setBoolPref("privacy.popups.showBrowserMessage", false);
function checkFirst()
{
- netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
- ok(shown, "File picker show method should have been called");
- shown = false;
+ ok(MockFilePicker.shown, "File picker show method should have been called");
document.getElementById("a").click();
setTimeout(finishTest, 1000);
}
function finishTest()
{
- netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
- ok(!shown, "File picker show method should not have been called");
+ MockFilePicker.reset();
+ ok(!MockFilePicker.shown, "File picker show method should not have been called");
- mockFilePickerRegisterer.unregister();
-
- pbi.setBoolPref("dom.disable_open_during_load", oldAllow);
- pbi.setBoolPref("privacy.popups.showBrowserMessage", oldShowBar);
+ SpecialPowers.setBoolPref("dom.disable_open_during_load", oldAllow);
+ SpecialPowers.setBoolPref("privacy.popups.showBrowserMessage", oldShowBar);
SimpleTest.finish();
}
diff --git a/layout/forms/test/test_bug377624.html b/layout/forms/test/test_bug377624.html
index b8efaab430a..17f36a65056 100644
--- a/layout/forms/test/test_bug377624.html
+++ b/layout/forms/test/test_bug377624.html
@@ -33,198 +33,78 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=377624
SimpleTest.waitForExplicitFinish();
-netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-const Cm = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
-const Cu = Components.utils;
-
-const FILE_PICKER_CID = "@mozilla.org/filepicker;1";
-const FILE_PICKER_ID = Components.ID(Cc[FILE_PICKER_CID].number);
-const CUSTOM_FILE_PICKER_ID = Components.ID("d63dee33-fb6d-4547-a8d1-c12197655cce");
-const FILE_PICKER_DESCRIPTION = "File Picker Test Service";
-
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+var MockFilePicker = SpecialPowers.MockFilePicker;
+MockFilePicker.reset();
// disable popups to make sure that the popup blocker does not interfere
// with manually opened file pickers.
-var pbi = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch2);
-var oldAllow = pbi.getBoolPref("dom.disable_open_during_load");
-pbi.setBoolPref("dom.disable_open_during_load", true);
+var oldAllow = SpecialPowers.getBoolPref("dom.disable_open_during_load");
+SpecialPowers.setBoolPref("dom.disable_open_during_load", false);
-function FilePickerService()
-{
-}
-
-FilePickerService.prototype = {
- _obs: Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService),
- 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,
- filterAllowURLs: 128,
- filterAudio: 256,
- filterVideo: 512,
-
- // properties
- defaultExtension: "",
- defaultString: "",
- get displayDirectory() { return null; },
- set displayDirectory(val) { },
- file: null,
- get files() { return null; },
- get fileURL() { return null; },
- filterIndex: 0,
-
- // methods
- appendFilter: function(val)
- {
- this._obs.notifyObservers(null, "TEST_FILEPICKER_APPENDFILTER", val);
- },
-
- appendFilters: function(val)
- {
- netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
- this._obs.notifyObservers(null, "TEST_FILEPICKER_APPENDFILTERS", val);
- },
-
- init: function() {},
-
- show: function()
- {
- netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
- this._obs.notifyObservers(null, "TEST_FILEPICKER_SHOW", this.filterIndex);
- return this.returnOK;
- }
-};
-
-factory = {
- createInstance: function(aOuter, aIid) {
- if (aOuter != null)
- throw Cr.NS_ERROR_NO_AGGREGATION;
- return new FilePickerService().QueryInterface(aIid);
- }
-};
-
-var testData = [["a", FilePickerService.prototype.filterImages, 1],
- ["b", FilePickerService.prototype.filterAudio, 1],
- ["c", FilePickerService.prototype.filterVideo, 1],
+var testData = [["a", MockFilePicker.filterImages, 1],
+ ["b", MockFilePicker.filterAudio, 1],
+ ["c", MockFilePicker.filterVideo, 1],
["d", 0, 0],
["e", 0, 0],
["f", 0, 0],
["g", 0, 0],
- ["h", FilePickerService.prototype.filterImages, 1],
- ["i", FilePickerService.prototype.filterVideo, 1],
- ["j", FilePickerService.prototype.filterAudio, 1],
+ ["h", MockFilePicker.filterImages, 1],
+ ["i", MockFilePicker.filterVideo, 1],
+ ["j", MockFilePicker.filterAudio, 1],
["z", 0, 0]];
-testData.forEach(function (datum) {
-document.getElementById(datum[0]).addEventListener("focus", function (aEvent) {
- aEvent.target.removeEventListener("focus", arguments.callee, false);
- synthesizeKey('VK_SPACE', {});
- }, false);
-});
-
var currentTest = 0;
+var appendFilterCalled;
+var filters;
+var filterIndex;
-function launchNextTest(aObserver)
+function launchNextTest()
{
- aObserver.shown = false;
- aObserver.appendFilterCalled = false;
- aObserver.filters = [];
- aObserver.filterIndex = 0;
+ MockFilePicker.shown = false;
+ appendFilterCalled = false;
+ filters = [];
+ filterIndex = 0;
- document.getElementById(testData[currentTest][0]).focus();
+ document.getElementById(testData[currentTest][0]).click();
}
function runTests()
{
- netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+ MockFilePicker.appendFilterCallback = function(filepicker, title, val)
+ {
+ this.appendFilterCalled = true;
+ };
+ MockFilePicker.appendFiltersCallback = function(filepicker, val)
+ {
+ filters.push(val);
+ };
+ MockFilePicker.showCallback = function(filepicker)
+ {
+ filterIndex = filepicker.filterIndex;
- Cm.registerFactory(CUSTOM_FILE_PICKER_ID,
- FILE_PICKER_DESCRIPTION,
- FILE_PICKER_CID,
- factory);
+ SimpleTest.executeSoon(function () {
+ ok(MockFilePicker.shown,
+ "File picker show method should have been called");
+ ok(!appendFilterCalled,
+ "appendFilter should not have been called");
+ is(filters.length, 1,
+ "appendFilters should have been called once");
+ is(filters[0], MockFilePicker.filterAll +
+ testData[currentTest][1],
+ "Correct filters should have been added");
+ is(filterIndex, testData[currentTest][2],
+ "File picker should show the correct filter index");
- var obs = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
-
- var observer = {
- observe: function(aSubject, aTopic, aData) {
- switch (aTopic) {
- case "TEST_FILEPICKER_APPENDFILTER":
- this.appendFilterCalled = true;
- break;
- case "TEST_FILEPICKER_APPENDFILTERS":
- this.filters.push(aData);
- break;
- case "TEST_FILEPICKER_SHOW":
- this.shown = true;
- this.filterIndex = aData;
-
- SimpleTest.executeSoon(function () {
- netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
- ok(observer.shown,
- "File picker show method should have been called");
- ok(!observer.appendFilterCalled,
- "appendFilter should not have been called");
- is(observer.filters.length, 1,
- "appendFilters should have been called once");
- is(observer.filters[0], FilePickerService.prototype.filterAll +
- testData[currentTest][1],
- "Correct filters should have been added");
- is(observer.filterIndex, testData[currentTest][2],
- "File picker should show the correct filter index");
-
- if (++currentTest == testData.length) {
- obs.removeObserver(observer, "TEST_FILEPICKER_APPENDFILTER", false);
- obs.removeObserver(observer, "TEST_FILEPICKER_APPENDFILTERS", false);
- obs.removeObserver(observer, "TEST_FILEPICKER_SHOW", false);
- Cm.unregisterFactory(CUSTOM_FILE_PICKER_ID, factory);
-
- Cm.registerFactory(FILE_PICKER_ID,
- "File Picker Service",
- FILE_PICKER_CID,
- null);
-
- pbi.setBoolPref("dom.disable_open_during_load", oldAllow);
- SimpleTest.finish();
- } else {
- launchNextTest(observer);
- }
- } );
- break;
+ if (++currentTest == testData.length) {
+ SpecialPowers.setBoolPref("dom.disable_open_during_load", oldAllow);
+ SimpleTest.finish();
+ } else {
+ launchNextTest();
}
- },
- shown: false,
- appendFilterCalled: false,
- filters: [],
- filterIndex: 0
+ } );
};
- obs.addObserver(observer, "TEST_FILEPICKER_APPENDFILTER", false);
- obs.addObserver(observer, "TEST_FILEPICKER_APPENDFILTERS", false);
- obs.addObserver(observer, "TEST_FILEPICKER_SHOW", false);
-
- // We are simulating a focus then a SPACE key press to open the file picker.
- // We were not able to do this with |synthesizeMouse|.
- launchNextTest(observer);
+ launchNextTest();
}
diff --git a/layout/forms/test/test_bug536567.html b/layout/forms/test/test_bug536567.html
index 16bfd49673b..8f0c04e1505 100644
--- a/layout/forms/test/test_bug536567.html
+++ b/layout/forms/test/test_bug536567.html
@@ -8,6 +8,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=536567
+
Mozilla Bug 536567
@@ -18,12 +19,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=536567
/** Test for Bug 536567 **/
-netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cm = Components.manager;
+Cu.import("resource://mochikit/MockFilePicker.jsm");
+MockFilePicker.reset();
+
var ioSvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var prefSvc = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
@@ -37,8 +40,6 @@ var homeDir = dirSvc.get("Desk", Ci.nsILocalFile);
prefSvc.setBoolPref("browser.privatebrowsing.keep_current_session", true);
function newDir() {
- netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
var dir = tmpDir.clone();
dir.append("testdir" + Math.floor(Math.random() * 10000));
dir.QueryInterface(Ci.nsILocalFile);
@@ -96,7 +97,6 @@ var tests = [
"pb off"
];
-var index;
var testIndex = 0;
var content = document.getElementById('content');
@@ -122,7 +122,9 @@ function runTest() {
testIndex++;
runTest();
} else {
- index = test[2];
+ var file = dirs[test[2]].clone();
+ file.append("file.file");
+ MockFilePicker.returnFiles = [file];
content.setAttribute ('src', domains[test[0]] + '/tests/layout/forms/test/bug536567_subframe.html');
}
}
@@ -136,13 +138,11 @@ function endTest() {
SimpleTest.finish();
}
-window.addEventListener("message", function(event) {
- netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
+MockFilePicker.showCallback = function(filepicker) {
var test = tests[testIndex];
var returned = -1;
for (var i = 0; i < dirs.length; i++) {
- if (dirs[i].path == event.data) {
+ if (dirs[i].path == MockFilePicker.displayDirectory.path) {
returned = i;
break;
}
@@ -152,10 +152,12 @@ window.addEventListener("message", function(event) {
} else {
is(returned, test[1], 'test ' + testIndex);
}
-
- testIndex++;
- runTest();
-}, false);
+
+ SimpleTest.executeSoon(function() {
+ testIndex++;
+ runTest();
+ });
+};
window.onload = function() {
SimpleTest.waitForExplicitFinish();
diff --git a/testing/mochitest/MockFilePicker.jsm b/testing/mochitest/MockFilePicker.jsm
new file mode 100644
index 00000000000..8d8dbae3e38
--- /dev/null
+++ b/testing/mochitest/MockFilePicker.jsm
@@ -0,0 +1,136 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.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 Mochitest Reusable Mock File Picker.
+ *
+ * The Initial Developer of the Original Code is
+ * Geoff Lankow .
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var EXPORTED_SYMBOLS = ["MockFilePicker"];
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cm = Components.manager;
+const Cu = Components.utils;
+
+const CONTRACT_ID = "@mozilla.org/filepicker;1";
+const CLASS_ID = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID();
+
+Cu.import("resource://gre/modules/FileUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
+
+var MockFilePickerFactory = {
+ createInstance: function(aOuter, aIID) {
+ if (aOuter)
+ throw Components.results.NS_ERROR_NO_AGGREGATION;
+ return new MockFilePickerInstance().QueryInterface(aIID);
+ },
+ lockFactory: function(aLock) {
+ throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+ },
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory])
+};
+
+var MockFilePicker = {
+ returnOK: Ci.nsIFilePicker.returnOK,
+ returnCancel: Ci.nsIFilePicker.returnCancel,
+ returnReplace: Ci.nsIFilePicker.returnReplace,
+
+ filterAll: Ci.nsIFilePicker.filterAll,
+ filterHTML: Ci.nsIFilePicker.filterHTML,
+ filterText: Ci.nsIFilePicker.filterText,
+ filterImages: Ci.nsIFilePicker.filterImages,
+ filterXML: Ci.nsIFilePicker.filterXML,
+ filterXUL: Ci.nsIFilePicker.filterXUL,
+ filterApps: Ci.nsIFilePicker.filterApps,
+ filterAllowURLs: Ci.nsIFilePicker.filterAllowURLs,
+ filterAudio: Ci.nsIFilePicker.filterAudio,
+ filterVideo: Ci.nsIFilePicker.filterVideo,
+
+ reset: function() {
+ this.appendFilterCallback = null;
+ this.appendFiltersCallback = null;
+ this.displayDirectory = null;
+ this.mode = null;
+ this.returnFiles = [];
+ this.returnValue = null;
+ this.showCallback = null;
+ this.shown = false;
+ if (!registrar.isCIDRegistered(CLASS_ID))
+ registrar.registerFactory(CLASS_ID, "", CONTRACT_ID, MockFilePickerFactory);
+ },
+
+ useAnyFile: function() {
+ var file = FileUtils.getFile("TmpD", ["testfile"]);
+ file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0644);
+ this.returnFiles = [file];
+ }
+};
+
+function MockFilePickerInstance() { };
+MockFilePickerInstance.prototype = {
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
+ init: function(aParent, aTitle, aMode) {
+ MockFilePicker.mode = aMode;
+ },
+ appendFilter: function(aTitle, aFilter) {
+ if (typeof MockFilePicker.appendFilterCallback == "function")
+ MockFilePicker.appendFilterCallback(this, aTitle, aFilter);
+ },
+ appendFilters: function(aFilterMask) {
+ if (typeof MockFilePicker.appendFiltersCallback == "function")
+ MockFilePicker.appendFiltersCallback(this, aFilterMask);
+ },
+ defaultString: "",
+ defaultExtension: "",
+ filterIndex: 0,
+ displayDirectory: null,
+ get file() {
+ if (MockFilePicker.returnFiles.length >= 1)
+ return MockFilePicker.returnFiles[0];
+ return null;
+ },
+ get fileURL() {
+ if (MockFilePicker.returnFiles.length >= 1)
+ return Services.io.newFileURI(MockFilePicker.returnFiles[0]);
+ return null;
+ },
+ get files() {
+ return {
+ index: 0,
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsISimpleEnumerator]),
+ hasMoreElements: function() {
+ return this.index < MockFilePicker.returnFiles.length;
+ },
+ getNext: function() {
+ return MockFilePicker.returnFiles[this.index++];
+ }
+ };
+ },
+ show: function() {
+ MockFilePicker.displayDirectory = this.displayDirectory;
+ MockFilePicker.shown = true;
+ if (typeof MockFilePicker.showCallback == "function")
+ MockFilePicker.showCallback(this);
+ return MockFilePicker.returnValue;
+ }
+};
diff --git a/testing/mochitest/jar.mn b/testing/mochitest/jar.mn
index 933a56792d8..ae7414f8d93 100644
--- a/testing/mochitest/jar.mn
+++ b/testing/mochitest/jar.mn
@@ -28,3 +28,5 @@ mochikit.jar:
content/MochiKit/packed.js (MochiKit/packed.js)
+% resource mochikit %modules/
+ modules/MockFilePicker.jsm (MockFilePicker.jsm)
diff --git a/testing/mochitest/specialpowers/content/specialpowers.js b/testing/mochitest/specialpowers/content/specialpowers.js
index 5baaa0806f6..21ad6da2634 100644
--- a/testing/mochitest/specialpowers/content/specialpowers.js
+++ b/testing/mochitest/specialpowers/content/specialpowers.js
@@ -38,8 +38,13 @@
* order to be used as a replacement for UniversalXPConnect
*/
-var Ci = Components.interfaces;
var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+
+var MockFilePicker;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
function SpecialPowers(window) {
this.window = window;
@@ -311,6 +316,12 @@ SpecialPowers.prototype = {
Components.classes["@mozilla.org/eventlistenerservice;1"].
getService(Components.interfaces.nsIEventListenerService).
removeSystemEventListener(target, type, listener, useCapture);
+ },
+
+ get MockFilePicker() {
+ if (!MockFilePicker)
+ Cu.import("resource://mochikit/MockFilePicker.jsm");
+ return MockFilePicker;
}
};
diff --git a/toolkit/content/tests/browser/browser_save_resend_postdata.js b/toolkit/content/tests/browser/browser_save_resend_postdata.js
index a14a7fe3fcb..22d19279008 100644
--- a/toolkit/content/tests/browser/browser_save_resend_postdata.js
+++ b/toolkit/content/tests/browser/browser_save_resend_postdata.js
@@ -34,6 +34,9 @@
*
* ***** END LICENSE BLOCK ***** */
+Components.utils.import("resource://mochikit/MockFilePicker.jsm");
+MockFilePicker.reset();
+
/**
* Test for bug 471962 :
* When saving an inner frame as file only, the POST data of the outer page is
@@ -110,10 +113,11 @@ function test() {
// Create the folder the page will be saved into.
var destDir = createTemporarySaveDirectory();
+ var file = destDir.clone();
+ file.append("no_default_file_name");
+ MockFilePicker.returnFiles = [file];
try {
// Call the appropriate save function defined in contentAreaUtils.js.
- mockFilePickerSettings.destDir = destDir;
- mockFilePickerSettings.filterIndex = 1; // kSaveAsType_URL
callSaveWithMockObjects(function() {
var docToSave = innerFrame.contentDocument;
// We call internalSave instead of saveDocument to bypass the history
@@ -130,7 +134,7 @@ function test() {
throw "Unexpected failure, the inner frame couldn't be saved!";
// Read the entire saved file.
- var fileContents = readShortFile(mockFilePickerResults.selectedFile);
+ var fileContents = readShortFile(file);
// Check if outer POST data is found (bug 471962).
ok(fileContents.indexOf("inputfield=outer") === -1,
diff --git a/toolkit/content/tests/browser/common/Makefile.in b/toolkit/content/tests/browser/common/Makefile.in
index b026931f32f..d935925dca4 100644
--- a/toolkit/content/tests/browser/common/Makefile.in
+++ b/toolkit/content/tests/browser/common/Makefile.in
@@ -47,7 +47,6 @@ include $(topsrcdir)/config/rules.mk
# If you add files here, add them to "_loadAll.js" too.
_COMMON_FILES = \
_loadAll.js \
- mockFilePicker.js \
mockObjects.js \
mockTransferForContinuing.js \
testRunner.js \
diff --git a/toolkit/content/tests/browser/common/_loadAll.js b/toolkit/content/tests/browser/common/_loadAll.js
index 91bf6d45988..e00e5a9fa9f 100644
--- a/toolkit/content/tests/browser/common/_loadAll.js
+++ b/toolkit/content/tests/browser/common/_loadAll.js
@@ -56,7 +56,6 @@ void(function (scriptScope) {
"testRunner.js",
// To be included after the files above.
- "mockFilePicker.js",
"mockTransferForContinuing.js",
"toolkitFunctions.js",
];
diff --git a/toolkit/content/tests/browser/common/mockFilePicker.js b/toolkit/content/tests/browser/common/mockFilePicker.js
deleted file mode 100644
index 8c0a0006fc7..00000000000
--- a/toolkit/content/tests/browser/common/mockFilePicker.js
+++ /dev/null
@@ -1,116 +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 Mozilla XUL Toolkit Testing Code.
- *
- * The Initial Developer of the Original Code is
- * Paolo Amadini .
- * 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 ***** */
-
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-
-var mockFilePickerSettings = {
- /**
- * File object pointing to the directory where the files will be saved.
- * The files will be saved with the default name, and will be overwritten
- * if they exist.
- */
- destDir: null,
-
- /**
- * Index of the filter to be returned by the file picker, or -1 to return
- * the filter proposed by the caller.
- */
- filterIndex: -1
-};
-
-var mockFilePickerResults = {
- /**
- * File object corresponding to the last automatically selected file.
- */
- selectedFile: null,
-
- /**
- * Index of the filter that was set on the file picker by the caller.
- */
- proposedFilterIndex: -1
-};
-
-/**
- * This file picker implementation uses the global settings defined in
- * mockFilePickerSettings, and updates the mockFilePickerResults object
- * when its "show" method is called.
- */
-function MockFilePicker() { };
-MockFilePicker.prototype = {
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
- init: function(aParent, aTitle, aMode) { },
- appendFilters: function(aFilterMask) { },
- appendFilter: function(aTitle, aFilter) { },
- defaultString: "",
- defaultExtension: "",
- filterIndex: 0,
- displayDirectory: null,
- file: null,
- get fileURL() {
- return Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService).newFileURI(this.file);
- },
- get files() {
- throw Cr.NS_ERROR_NOT_IMPLEMENTED;
- },
- show: function MFP_show() {
- // Select the destination file with the specified default file name. If the
- // default file name was never specified or was set to an empty string by
- // the caller, ensure that a fallback file name is used.
- this.file = mockFilePickerSettings.destDir.clone();
- this.file.append(this.defaultString || "no_default_file_name");
- // Store the current file picker settings for testing them later.
- mockFilePickerResults.selectedFile = this.file.clone();
- mockFilePickerResults.proposedFilterIndex = this.filterIndex;
- // Select a different file filter if required.
- if (mockFilePickerSettings.filterIndex != -1)
- this.filterIndex = mockFilePickerSettings.filterIndex;
- // Assume we overwrite the file if it exists.
- return (this.file.exists() ?
- Ci.nsIFilePicker.returnReplace :
- Ci.nsIFilePicker.returnOK);
- }
-};
-
-// Create an instance of a MockObjectRegisterer whose methods can be used to
-// temporarily replace the default "@mozilla.org/filepicker;1" object factory
-// with one that provides the mock implementation above. To activate the mock
-// object factory, call the "register" method. Starting from that moment, all
-// the file picker objects that are requested will be mock objects, until the
-// "unregister" method is called.
-var mockFilePickerRegisterer =
- new MockObjectRegisterer("@mozilla.org/filepicker;1",
- MockFilePicker);
diff --git a/toolkit/content/tests/browser/common/toolkitFunctions.js b/toolkit/content/tests/browser/common/toolkitFunctions.js
index 196be3c5abb..a8c4755abe4 100644
--- a/toolkit/content/tests/browser/common/toolkitFunctions.js
+++ b/toolkit/content/tests/browser/common/toolkitFunctions.js
@@ -64,18 +64,12 @@ function callSaveWithMockObjects(aSaveFunction) {
// ensure that, even in case of exceptions during the function's execution,
// the mock object factories are unregistered before proceeding with the other
// tests in the suite.
- mockFilePickerRegisterer.register();
+ mockTransferForContinuingRegisterer.register();
try {
- mockTransferForContinuingRegisterer.register();
- try {
- aSaveFunction();
- }
- finally {
- mockTransferForContinuingRegisterer.unregister();
- }
+ aSaveFunction();
}
finally {
- mockFilePickerRegisterer.unregister();
+ mockTransferForContinuingRegisterer.unregister();
}
}
diff --git a/toolkit/mozapps/downloads/tests/Makefile.in b/toolkit/mozapps/downloads/tests/Makefile.in
index f57fbf1bfd8..8e8ab412969 100644
--- a/toolkit/mozapps/downloads/tests/Makefile.in
+++ b/toolkit/mozapps/downloads/tests/Makefile.in
@@ -54,3 +54,6 @@ XPCSHELL_TESTS = \
DIRS += chrome
include $(topsrcdir)/config/rules.mk
+
+libs::
+ $(INSTALL) $(topsrcdir)/testing/mochitest/MockFilePicker.jsm $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit
diff --git a/toolkit/mozapps/downloads/tests/unit/test_privatebrowsing_downloadLastDir.js b/toolkit/mozapps/downloads/tests/unit/test_privatebrowsing_downloadLastDir.js
index 980c5d17bcd..060116bb585 100644
--- a/toolkit/mozapps/downloads/tests/unit/test_privatebrowsing_downloadLastDir.js
+++ b/toolkit/mozapps/downloads/tests/unit/test_privatebrowsing_downloadLastDir.js
@@ -40,11 +40,6 @@ const Ci = Components.interfaces;
const Cc = Components.classes;
const Cu = Components.utils;
const Cr = Components.results;
-const Cm = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
-
-const FILE_PICKER_CID = "@mozilla.org/filepicker;1";
-const FILE_PICKER_ID = Components.ID("fa71ce55-6524-4744-ba75-71a4c126cfa3");
-const FILE_PICKER_DESCRIPTION = "File Picker Test Service";
// Code borrowed from toolkit/components/downloadmgr/test/unit/head_download_manager.js
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
@@ -82,70 +77,14 @@ if (!profileDir) {
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/DownloadLastDir.jsm");
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-
let context = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIInterfaceRequestor]),
getInterface: XPCOMUtils.generateQI([Ci.nsIDOMWindowInternal])
};
-function FilePickerService() {
-}
-
-FilePickerService.prototype = {
- _obs: Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService),
- 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() {
- var 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);
- },
- show: function() {
- return this.returnOK;
- }
-};
-
-let factory = {
- createInstance: function(aOuter, aIid) {
- if (aOuter != null)
- throw Cr.NS_ERROR_NO_AGGREGATION;
- return new FilePickerService().QueryInterface(aIid);
- }
-};
+Cu.import("resource://test/MockFilePicker.jsm");
+MockFilePicker.reset();
+MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
function run_test()
{
@@ -158,19 +97,11 @@ function run_test()
return;
}
- //do_load_module("filepicker.js");
- Cm.registerFactory(FILE_PICKER_ID,
- FILE_PICKER_DESCRIPTION,
- FILE_PICKER_CID,
- factory);
-
let prefsService = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
QueryInterface(Ci.nsIPrefBranch);
prefsService.setBoolPref("browser.privatebrowsing.keep_current_session", true);
let prefs = prefsService.getBranch("browser.download.");
- let obs = Cc["@mozilla.org/observer-service;1"].
- getService(Ci.nsIObserverService);
let launcher = Cc["@mozilla.org/helperapplauncherdialog;1"].
getService(Ci.nsIHelperAppLauncherDialog);
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
@@ -195,32 +126,13 @@ function run_test()
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;
+ MockFilePicker.returnFiles = [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);
+ do_check_eq(MockFilePicker.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 be usable outside of the private browsing mode
@@ -228,12 +140,12 @@ function run_test()
pb.privateBrowsingEnabled = true;
do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
- observer.file = file2;
- observer.displayDirectory = null;
+ MockFilePicker.returnFiles = [file2];
+ MockFilePicker.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);
+ do_check_eq(MockFilePicker.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
@@ -242,12 +154,12 @@ function run_test()
pb.privateBrowsingEnabled = false;
// gDownloadLastDir should be cleared after leaving the private browsing mode
do_check_eq(gDownloadLastDir.file.path, dir1.path);
- observer.file = file3;
- observer.displayDirectory = null;
+ MockFilePicker.returnFiles = [file3];
+ MockFilePicker.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);
+ do_check_eq(MockFilePicker.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 be usable after leaving the private browsing mode
@@ -257,6 +169,4 @@ function run_test()
prefsService.clearUserPref("browser.privatebrowsing.keep_current_session");
[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);
}
diff --git a/toolkit/mozapps/extensions/test/browser/browser_bug567127.js b/toolkit/mozapps/extensions/test/browser/browser_bug567127.js
index bed62f04f23..6abdb5d77f5 100644
--- a/toolkit/mozapps/extensions/test/browser/browser_bug567127.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug567127.js
@@ -4,39 +4,11 @@
// Tests bug 567127 - Add install button to the add-ons manager
+Components.utils.import("resource://mochikit/MockFilePicker.jsm");
+MockFilePicker.reset();
-var gFilePickerFiles = [];
-var gMockFilePickerFactory;
-var gMockFilePickerFactoryCID;
var gManagerWindow;
-function MockFilePicker() { }
-
-MockFilePicker.prototype = {
- QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIFilePicker]),
- init: function(aParent, aTitle, aMode) { },
- appendFilters: function(aFilterMask) { },
- appendFilter: function(aTitle, aFilter) { },
- defaultString: "",
- defaultExtension: "",
- filterIndex: 0,
- displayDirectory: null,
- file: null,
- fileURL: null,
- get files() {
- var i = 0;
- return {
- getNext: function() gFilePickerFiles[i++],
- hasMoreElements: function() gFilePickerFiles.length > i
- };
- },
- show: function() {
- return gFilePickerFiles.length == 0 ?
- Components.interfaces.nsIFilePicker.returnCancel :
- Components.interfaces.nsIFilePicker.returnOK;
- }
-};
-
// This listens for the next opened window and checks it is of the right url.
// opencallback is called when the new window is fully loaded
// closecallback is called when the window is closed
@@ -120,14 +92,6 @@ function test_confirmation(aWindow, aExpectedURLs) {
function test() {
waitForExplicitFinish();
- gMockFilePickerFactoryCID = Components.ID("{4f595df2-9108-42c6-9910-0dc392a310c9}");
- gMockFilePickerFactory = XPCOMUtils._getFactory(MockFilePicker);
- var compReg = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- compReg.registerFactory(gMockFilePickerFactoryCID,
- "Mock FilePicker",
- "@mozilla.org/filepicker;1",
- gMockFilePickerFactory);
-
open_manager("addons://list/extension", function(aWindow) {
gManagerWindow = aWindow;
run_next_test();
@@ -135,9 +99,6 @@ function test() {
}
function end_test() {
- var compReg = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- compReg.unregisterFactory(gMockFilePickerFactoryCID,
- gMockFilePickerFactory);
close_manager(gManagerWindow, function() {
finish();
});
@@ -149,7 +110,7 @@ add_test(function() {
get_addon_file_url("browser_bug567127_1.xpi"),
get_addon_file_url("browser_bug567127_2.xpi")
];
- gFilePickerFiles = filePaths.map(function(aPath) aPath.file);
+ MockFilePicker.returnFiles = filePaths.map(function(aPath) aPath.file);
new WindowOpenListener(INSTALL_URI, function(aWindow) {
test_confirmation(aWindow, filePaths.map(function(aPath) aPath.spec));
diff --git a/toolkit/mozapps/extensions/test/browser/browser_inlinesettings.js b/toolkit/mozapps/extensions/test/browser/browser_inlinesettings.js
index 1421bbd0963..562ed5ce7e4 100644
--- a/toolkit/mozapps/extensions/test/browser/browser_inlinesettings.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_inlinesettings.js
@@ -10,6 +10,9 @@ var gProvider;
const SETTINGS_ROWS = 8;
+Components.utils.import("resource://mochikit/MockFilePicker.jsm");
+MockFilePicker.reset();
+
var observer = {
lastData: null,
observe: function(aSubject, aTopic, aData) {
@@ -201,8 +204,6 @@ add_test(function() {
is(Services.prefs.getCharPref("extensions.inlinesettings1.color"), "#FF9900", "Color pref should have been updated");
try {
- mockFilePickerFactory.register();
-
ok(!settings[6].hasAttribute("first-row"), "Not the first row");
var button = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "button");
input = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "input");
@@ -211,17 +212,17 @@ add_test(function() {
var profD = Services.dirsvc.get("ProfD", Ci.nsIFile);
var curProcD = Services.dirsvc.get("CurProcD", Ci.nsIFile);
- _returnFile = profD;
- _returnValue = Ci.nsIFilePicker.returnOK;
+ MockFilePicker.returnFiles = [profD];
+ MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
- is(_mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
+ is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
is(input.value, profD.path, "Label value should match file chosen");
is(Services.prefs.getCharPref("extensions.inlinesettings1.file"), profD.path, "File pref should match file chosen");
- _returnFile = curProcD;
- _returnValue = Ci.nsIFilePicker.returnCancel;
+ MockFilePicker.returnFiles = [curProcD];
+ MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
- is(_mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
+ is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
is(input.value, profD.path, "Label value should not have changed");
is(Services.prefs.getCharPref("extensions.inlinesettings1.file"), profD.path, "File pref should not have changed");
@@ -230,23 +231,21 @@ add_test(function() {
input = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "input");
is(input.value, "", "Label value should be empty");
- _returnFile = profD;
- _returnValue = Ci.nsIFilePicker.returnOK;
+ MockFilePicker.returnFiles = [profD];
+ MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
- is(_mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
+ is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
is(input.value, profD.path, "Label value should match file chosen");
is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should match file chosen");
- _returnFile = curProcD;
- _returnValue = Ci.nsIFilePicker.returnCancel;
+ MockFilePicker.returnFiles = [curProcD];
+ MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
- is(_mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
+ is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
is(input.value, profD.path, "Label value should not have changed");
is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should not have changed");
} finally {
- mockFilePickerFactory.unregister();
-
button = gManagerWindow.document.getElementById("detail-prefs-btn");
is_element_hidden(button, "Preferences button should not be visible");
@@ -398,60 +397,3 @@ add_test(function() {
});
});
});
-
-var _returnFile, _returnValue, _mode;
-
-function MockFilePicker() { };
-MockFilePicker.prototype = {
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
- init: function(aParent, aTitle, aMode) {
- _mode = aMode;
- },
- appendFilters: function(aFilterMask) { },
- appendFilter: function(aTitle, aFilter) { },
- defaultString: "",
- defaultExtension: "",
- filterIndex: 0,
- displayDirectory: null,
- get file() {
- return _returnFile;
- },
- get fileURL() {
- throw Cr.NS_ERROR_NOT_IMPLEMENTED;
- },
- get files() {
- throw Cr.NS_ERROR_NOT_IMPLEMENTED;
- },
- show: function() {
- return _returnValue;
- }
-};
-var mockFilePickerFactory = {
- registrar: Components.manager.QueryInterface(Ci.nsIComponentRegistrar),
- contractID: "@mozilla.org/filepicker;1",
- classID: Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID(),
-
- register: function() {
- this.registrar.registerFactory(this.classID, "", this.contractID, this);
- },
-
- unregister: function() {
- this.registrar.unregisterFactory(this.classID, this);
- },
-
- // nsIFactory
- createInstance: function(aOuter, aIID) {
- if (aOuter) {
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- }
- return new MockFilePicker().QueryInterface(aIID);
- },
-
- lockFactory: function(aLock) {
- throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
- },
-
- QueryInterface: XPCOMUtils.generateQI([
- Ci.nsIFactory
- ])
-};