<!DOCTYPE html>
<html>
<head>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
const INITIAL= 0;
const OPEN_FILE_WITHOUT_GESTURE = 1;
window.testStage = INITIAL;
window.clickReceived = false;
window.clickFired = false;
function checkResult(continueFunc) {
if (!clickFired)
return;
if (clickReceived) {
// When the file select dialog shows up, it's a model window which receives
// all UI events sent to window, so the click event can not be received by body.
// If we received the click event, it means the file dialog was not opened.
if (testStage == OPEN_FILE_WITHOUT_GESTURE)
document.getElementById("open_without_gesture").innerHTML = "PASSED";
clickReceived = false;
}
clickFired = false;
continueFunc();
}
function openFileDialogWithoutUserGesture() {
// Tries to call <input type=file>.click to open the file dialog without a user gesture.
document.getElementById('f').click();
// Fires a click event.
setTimeout(function() {
eventSender.mouseMoveTo(10, 100);
eventSender.mouseDown();
eventSender.mouseUp();
clickFired = true;
testStage = OPEN_FILE_WITHOUT_GESTURE;
// Waits for opening the file dialog and checks whether the click event can still be received by document.
setTimeout("checkResult(function() { testRunner.notifyDone(); })", 500);
}, 1);
}
function startTest() {
if (!window.testRunner)
return;
document.body.addEventListener("click", function() { window.clickReceived = true }, true);
setTimeout(openFileDialogWithoutUserGesture, 1);
}
</script>
</head>
<body style="margin:0px; padding:0px" onload="startTest();">
<form>
<input type="file" name="file" id="f">
</form>
This file is to test that opening file dialog requires a user gesture. Please refer to https://bugs.webkit.org/show_bug.cgi?id=47593 for more details.<br>
Test opening file dialog without user gesture is <span id="open_without_gesture">FAILED</span><br>
</body>
</html>