зеркало из https://github.com/mozilla/gecko-dev.git
Bug 668154 - Use the same mock file picker for all mochitests and xpcshell tests r=jmaher
This commit is contained in:
Родитель
fa3cd9704a
Коммит
4450e4f1ab
|
@ -8,7 +8,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=500885
|
|||
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/mockObjects.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
|
||||
</head>
|
||||
|
@ -19,41 +18,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=500885
|
|||
</div>
|
||||
<script type="text/javascript">
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
var MockFilePicker = SpecialPowers.MockFilePicker;
|
||||
MockFilePicker.reset();
|
||||
MockFilePicker.returnValue = MockFilePicker.returnOK;
|
||||
|
||||
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() {
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
},
|
||||
get files() {
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
},
|
||||
show: function MFP_show() {
|
||||
return Ci.nsIFilePicker.returnOK;
|
||||
}
|
||||
};
|
||||
|
||||
var mockFilePickerRegisterer =
|
||||
new MockObjectRegisterer("@mozilla.org/filepicker;1",MockFilePicker);
|
||||
var wu = SpecialPowers.DOMWindowUtils;
|
||||
|
||||
function test() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var wu = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindowUtils);
|
||||
|
||||
|
||||
mockFilePickerRegisterer.register();
|
||||
try {
|
||||
var domActivateEvents;
|
||||
var fileInput = document.getElementById("file");
|
||||
|
@ -76,17 +47,10 @@ function test() {
|
|||
is(domActivateEvents, 1, "click on button should only fire 1 DOMActivate event");
|
||||
|
||||
} finally {
|
||||
SimpleTest.executeSoon(unregister);
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
function unregister()
|
||||
{
|
||||
mockFilePickerRegisterer.unregister();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
setTimeout(test, 0);
|
||||
|
|
|
@ -8,7 +8,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=592802
|
|||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/mockObjects.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -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();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
|
|
@ -1,72 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/mockObjects.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<input id="target" type="file" />
|
||||
<script type="text/javascript">
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
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,
|
||||
get file() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var f = window.parent.dirs[window.parent.index].clone();
|
||||
f.append("aFile.txt");
|
||||
return f;
|
||||
},
|
||||
get fileURL() {
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
},
|
||||
get files() {
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
},
|
||||
show: function MFP_show() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
if (this.displayDirectory)
|
||||
window.parent.postMessage(this.displayDirectory.path, "*");
|
||||
else
|
||||
window.parent.postMessage("", "*");
|
||||
mockFilePickerRegisterer.unregister();
|
||||
return Ci.nsIFilePicker.returnOK;
|
||||
}
|
||||
};
|
||||
|
||||
var mockFilePickerRegisterer =
|
||||
new MockObjectRegisterer("@mozilla.org/filepicker;1",MockFilePicker);
|
||||
|
||||
function test() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var wu = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindowUtils);
|
||||
|
||||
var fileInput = document.getElementById("target");
|
||||
var rect = fileInput.getBoundingClientRect();
|
||||
|
||||
mockFilePickerRegisterer.register();
|
||||
try {
|
||||
wu.sendMouseEvent("mousedown", rect.left + 5, rect.top + 5, 0, 1, 0);
|
||||
wu.sendMouseEvent("mouseup", rect.left + 5, rect.top + 5, 0, 1, 0);
|
||||
} catch (e) {
|
||||
Cu.reportError(e);
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
setTimeout(test, 0);
|
||||
var fileInput = document.getElementById("target");
|
||||
fileInput.click();
|
||||
};
|
||||
|
||||
</script>
|
||||
|
|
|
@ -8,7 +8,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=36619
|
|||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/mockObjects.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
|
@ -8,6 +8,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=536567
|
|||
<script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=536567">Mozilla Bug 536567</a>
|
||||
|
@ -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();
|
||||
|
|
|
@ -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 <geoff@darktrojan.net>.
|
||||
* 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;
|
||||
}
|
||||
};
|
|
@ -28,3 +28,5 @@ mochikit.jar:
|
|||
|
||||
content/MochiKit/packed.js (MochiKit/packed.js)
|
||||
|
||||
% resource mochikit %modules/
|
||||
modules/MockFilePicker.jsm (MockFilePicker.jsm)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -34,6 +34,9 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
Components.utils.import("resource://mochikit/MockFilePicker.jsm");
|
||||
MockFilePicker.reset();
|
||||
|
||||
/**
|
||||
* Test for bug 471962 <https://bugzilla.mozilla.org/show_bug.cgi?id=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,
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -56,7 +56,6 @@ void(function (scriptScope) {
|
|||
"testRunner.js",
|
||||
|
||||
// To be included after the files above.
|
||||
"mockFilePicker.js",
|
||||
"mockTransferForContinuing.js",
|
||||
"toolkitFunctions.js",
|
||||
];
|
||||
|
|
|
@ -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 <http://www.amadzone.org/>.
|
||||
* 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);
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
])
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче