2010-05-20 06:28:08 +04:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=377624
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 377624</title>
|
|
|
|
<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>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
</head>
|
|
|
|
<body onload="runTests();">
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=377624">Mozilla Bug 377624</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content">
|
2010-07-17 11:00:28 +04:00
|
|
|
<input id='a' type='file' accept="image/*">
|
|
|
|
<input id='b' type='file' accept="audio/*">
|
|
|
|
<input id='c' type='file' accept="video/*">
|
2010-05-20 06:28:08 +04:00
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script type="application/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 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);
|
2010-06-25 19:34:10 +04:00
|
|
|
const CUSTOM_FILE_PICKER_ID = Components.ID("d63dee33-fb6d-4547-a8d1-c12197655cce");
|
2010-05-20 06:28:08 +04:00
|
|
|
const FILE_PICKER_DESCRIPTION = "File Picker Test Service";
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
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,
|
2010-07-17 11:00:28 +04:00
|
|
|
filterAllowURLs: 128,
|
|
|
|
filterAudio: 256,
|
|
|
|
filterVideo: 512,
|
2010-05-20 06:28:08 +04:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
this._obs.notifyObservers(null, "TEST_FILEPICKER_APPENDFILTERS", val);
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function() {},
|
|
|
|
|
|
|
|
show: function()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-17 11:00:28 +04:00
|
|
|
document.getElementById('a').addEventListener("focus", function (aEvent) {
|
|
|
|
aEvent.target.removeEventListener("focus", arguments.callee, false);
|
|
|
|
synthesizeKey('VK_SPACE', {});
|
|
|
|
}, false);
|
|
|
|
document.getElementById('b').addEventListener("focus", function (aEvent) {
|
|
|
|
aEvent.target.removeEventListener("focus", arguments.callee, false);
|
|
|
|
synthesizeKey('VK_SPACE', {});
|
|
|
|
}, false);
|
|
|
|
document.getElementById('c').addEventListener("focus", function (aEvent) {
|
2010-05-20 06:28:08 +04:00
|
|
|
aEvent.target.removeEventListener("focus", arguments.callee, false);
|
|
|
|
synthesizeKey('VK_SPACE', {});
|
|
|
|
}, false);
|
|
|
|
|
2010-07-17 11:00:28 +04:00
|
|
|
var testData = [["a", FilePickerService.prototype.filterImages],
|
|
|
|
["b", FilePickerService.prototype.filterAudio],
|
|
|
|
["c", FilePickerService.prototype.filterVideo]];
|
|
|
|
var currentTest = 0;
|
|
|
|
|
|
|
|
function launchNextTest(aObserver)
|
2010-05-20 06:28:08 +04:00
|
|
|
{
|
2010-07-17 11:00:28 +04:00
|
|
|
aObserver.shown = false;
|
|
|
|
aObserver.appendFilterCalled = false;
|
|
|
|
aObserver.filters = [];
|
|
|
|
aObserver.filterIndex = 0;
|
|
|
|
|
|
|
|
document.getElementById(testData[currentTest][0]).focus();
|
|
|
|
}
|
2010-05-20 06:28:08 +04:00
|
|
|
|
2010-07-17 11:00:28 +04:00
|
|
|
function runTests()
|
|
|
|
{
|
2010-05-20 06:28:08 +04:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
|
2010-06-25 19:34:10 +04:00
|
|
|
Cm.registerFactory(CUSTOM_FILE_PICKER_ID,
|
2010-05-20 06:28:08 +04:00
|
|
|
FILE_PICKER_DESCRIPTION,
|
|
|
|
FILE_PICKER_CID,
|
|
|
|
factory);
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
2010-07-17 11:00:28 +04:00
|
|
|
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");
|
2010-05-20 06:28:08 +04:00
|
|
|
is(observer.filters[0], FilePickerService.prototype.filterAll +
|
2010-07-17 11:00:28 +04:00
|
|
|
testData[currentTest][1],
|
|
|
|
"Incorrect filters have been added");
|
2010-05-20 06:28:08 +04:00
|
|
|
is(observer.filterIndex, 1,
|
|
|
|
"File picker should show the second filter index (first is zero)");
|
|
|
|
|
2010-07-17 11:00:28 +04:00
|
|
|
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);
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
} else {
|
|
|
|
launchNextTest(observer);
|
|
|
|
}
|
2010-05-20 06:28:08 +04:00
|
|
|
} );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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|.
|
2010-07-17 11:00:28 +04:00
|
|
|
launchNextTest(observer);
|
2010-05-20 06:28:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|