blob: b22df27458e694ab44ca6b965276e1dd1a18af0b [file] [log] [blame]
<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true, shouldHandleRunOpenPanel=false, shouldPresentPopovers=false ] -->
<html>
<head>
<meta name="viewport" content="width=device-width">
<script src="../../../resources/js-test.js"></script>
<script src="../../../resources/ui-helper.js"></script>
</head>
<body>
<div id="description"></div>
<input id="testInput" type="file">
<div id="console"></div>
<script>
description("Basic testing for the File Upload Panel on iOS.");
jsTestIsAsync = true;
function getFileUploadPickerMenuItemsScript()
{
return `
(function() {
return JSON.stringify(uiController.contentsOfUserInterfaceItem('fileUploadPanelMenu'));
})();`
}
function dismissFilePickerScript()
{
return `
(function() {
uiController.dismissFilePicker(function() {
uiController.uiScriptComplete();
});
})();`
}
function getFileUploadPickerMenuItems()
{
return new Promise((resolve) => {
testRunner.runUIScript(getFileUploadPickerMenuItemsScript(), function(result) {
resolve(JSON.parse(result).fileUploadPanelMenu);
});
});
}
function dismissFilePicker()
{
const uiScript = `uiController.dismissFilePicker(() => uiController.uiScriptComplete())`;
return new Promise(resolve => testRunner.runUIScript(uiScript, resolve));
}
function runAcceptTest(accept, expectedMenuItems)
{
return new Promise((resolve) => {
debug("* accept = " + accept);
testInput.accept = accept;
UIHelper.activateElement(testInput).then(() => {
getFileUploadPickerMenuItems().then((_items) => {
items = _items;
shouldBeTrue("areArraysEqual(items, " + expectedMenuItems + ")");
debug("");
dismissFilePicker().then(() => { resolve(); });
});
});
});
}
async function runTests()
{
document.getElementById("console").style = "display: none";
await runAcceptTest("", '["Photo Library", "Take Photo or Video", "Browse"]');
await runAcceptTest("image/*", '["Photo Library", "Take Photo", "Browse"]');
await runAcceptTest("video/*", '["Photo Library", "Take Video", "Browse"]');
await runAcceptTest("image/*, video/*", '["Photo Library", "Take Photo or Video", "Browse"]');
await runAcceptTest(".PNG, .GIF", '["Photo Library", "Take Photo", "Browse"]');
await runAcceptTest(".PNG, .GIF, .MOV", '["Photo Library", "Take Photo or Video", "Browse"]');
await runAcceptTest("audio/*", '["Browse"]');
await runAcceptTest(".TXT", '["Browse"]');
await runAcceptTest(".PDF", '["Browse"]');
await runAcceptTest(".PDF, .TXT", '["Browse"]');
document.getElementById("console").style = "";
finishJSTest();
}
onload = runTests;
</script>
</body>
</html>