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-07-21 20:07:55 +04:00
|
|
|
<input id='d' type='file' accept="image/*, audio/* ">
|
|
|
|
<input id='e' type='file' accept=" image/*,video/*">
|
|
|
|
<input id='f' type='file' accept="audio/*,video/*">
|
|
|
|
<input id='g' type='file' accept="image/*, audio/* ,video/*">
|
|
|
|
<input id='h' type='file' accept="foo/baz,image/*,bogus/duh">
|
|
|
|
<input id='i' type='file' accept="mime/type;parameter,video/*">
|
2010-10-08 14:13:08 +04:00
|
|
|
<input id='j' type='file' accept="audio/*, audio/*, audio/*">
|
2010-07-21 20:07:55 +04:00
|
|
|
<input id='z' type='file' accept="i/am,a,pathological,;,,,,test/case">
|
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");
|
|
|
|
|
2010-08-27 19:49:10 +04:00
|
|
|
// 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);
|
|
|
|
|
2010-05-20 06:28:08 +04:00
|
|
|
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)
|
|
|
|
{
|
2010-08-27 19:49:10 +04:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
2010-05-20 06:28:08 +04:00
|
|
|
this._obs.notifyObservers(null, "TEST_FILEPICKER_APPENDFILTERS", val);
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function() {},
|
|
|
|
|
|
|
|
show: function()
|
|
|
|
{
|
2010-08-27 19:49:10 +04:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
2010-05-20 06:28:08 +04:00
|
|
|
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-21 20:07:55 +04:00
|
|
|
var testData = [["a", FilePickerService.prototype.filterImages, 1],
|
|
|
|
["b", FilePickerService.prototype.filterAudio, 1],
|
|
|
|
["c", FilePickerService.prototype.filterVideo, 1],
|
2010-10-08 14:13:08 +04:00
|
|
|
["d", 0, 0],
|
|
|
|
["e", 0, 0],
|
|
|
|
["f", 0, 0],
|
|
|
|
["g", 0, 0],
|
2010-07-21 20:07:55 +04:00
|
|
|
["h", FilePickerService.prototype.filterImages, 1],
|
|
|
|
["i", FilePickerService.prototype.filterVideo, 1],
|
2010-10-08 14:13:08 +04:00
|
|
|
["j", FilePickerService.prototype.filterAudio, 1],
|
2010-07-21 20:07:55 +04:00
|
|
|
["z", 0, 0]];
|
|
|
|
|
|
|
|
testData.forEach(function (datum) {
|
|
|
|
document.getElementById(datum[0]).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-21 20:07:55 +04:00
|
|
|
});
|
2010-05-20 06:28:08 +04:00
|
|
|
|
2010-07-17 11:00:28 +04:00
|
|
|
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],
|
2010-07-21 20:07:55 +04:00
|
|
|
"Correct filters should have been added");
|
|
|
|
is(observer.filterIndex, testData[currentTest][2],
|
|
|
|
"File picker should show the correct filter index");
|
2010-05-20 06:28:08 +04:00
|
|
|
|
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);
|
2010-08-27 19:49:10 +04:00
|
|
|
|
|
|
|
pbi.setBoolPref("dom.disable_open_during_load", oldAllow);
|
2010-07-17 11:00:28 +04:00
|
|
|
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>
|