Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / file / input-file-not-open-without-gesture.html
blob10341aa866ea8212b9eba7aae19c433c876a27f3
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script>
5 if (window.testRunner) {
6 testRunner.dumpAsText();
7 testRunner.waitUntilDone();
9 const INITIAL= 0;
10 const OPEN_FILE_WITHOUT_GESTURE = 1;
11 window.testStage = INITIAL;
12 window.clickReceived = false;
13 window.clickFired = false;
15 function checkResult(continueFunc) {
16 if (!clickFired)
17 return;
18 if (clickReceived) {
19 // When the file select dialog shows up, it's a model window which receives
20 // all UI events sent to window, so the click event can not be received by body.
21 // If we received the click event, it means the file dialog was not opened.
22 if (testStage == OPEN_FILE_WITHOUT_GESTURE)
23 document.getElementById("open_without_gesture").innerHTML = "PASSED";
24 clickReceived = false;
26 clickFired = false;
27 continueFunc();
30 function openFileDialogWithoutUserGesture() {
31 // Tries to call <input type=file>.click to open the file dialog without a user gesture.
32 document.getElementById('f').click();
33 // Fires a click event.
34 setTimeout(function() {
35 eventSender.mouseMoveTo(10, 100);
36 eventSender.mouseDown();
37 eventSender.mouseUp();
38 clickFired = true;
39 testStage = OPEN_FILE_WITHOUT_GESTURE;
40 // Waits for opening the file dialog and checks whether the click event can still be received by document.
41 setTimeout("checkResult(function() { testRunner.notifyDone(); })", 500);
42 }, 1);
45 function startTest() {
46 if (!window.testRunner)
47 return;
48 document.body.addEventListener("click", function() { window.clickReceived = true }, true);
49 setTimeout(openFileDialogWithoutUserGesture, 1);
51 </script>
52 </head>
53 <body style="margin:0px; padding:0px" onload="startTest();">
54 <form>
55 <input type="file" name="file" id="f">
56 </form>
57 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>
58 Test opening file dialog without user gesture is <span id="open_without_gesture">FAILED</span><br>
59 </body>
60 </html>