pjs/layout/forms/test/test_bug377624.html

214 строки
6.4 KiB
HTML
Исходник Обычный вид История

<!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">
<input id='a' type='file' accept="image/*">
<input id='b' type='file' accept="audio/*">
<input id='c' type='file' accept="video/*">
</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);
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");
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)
{
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);
}
};
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) {
aEvent.target.removeEventListener("focus", arguments.callee, false);
synthesizeKey('VK_SPACE', {});
}, false);
var testData = [["a", FilePickerService.prototype.filterImages],
["b", FilePickerService.prototype.filterAudio],
["c", FilePickerService.prototype.filterVideo]];
var currentTest = 0;
function launchNextTest(aObserver)
{
aObserver.shown = false;
aObserver.appendFilterCalled = false;
aObserver.filters = [];
aObserver.filterIndex = 0;
document.getElementById(testData[currentTest][0]).focus();
}
function runTests()
{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
Cm.registerFactory(CUSTOM_FILE_PICKER_ID,
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');
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],
"Incorrect filters have been added");
is(observer.filterIndex, 1,
"File picker should show the second filter index (first is zero)");
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);
}
} );
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|.
launchNextTest(observer);
}
</script>
</pre>
</body>
</html>