OLD | NEW |
| (Empty) |
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | |
2 <html> | |
3 <head> | |
4 <script src="../../resources/js-test.js"></script> | |
5 </head> | |
6 <body> | |
7 <script type="text/javascript"> | |
8 description('Tests that the speech button ignores programmatic click events.'); | |
9 | |
10 function sendClick(useEventSender) { | |
11 var input = document.getElementById('speechInput'); | |
12 var clientX = input.offsetWidth - 4; | |
13 var clientY = input.offsetHeight / 2; | |
14 var pageX = input.offsetLeft + clientX; | |
15 var pageY = input.offsetTop + clientY; | |
16 if (useEventSender) { | |
17 eventSender.mouseMoveTo(pageX, pageY); | |
18 eventSender.mouseDown(); | |
19 eventSender.mouseUp(); | |
20 } else { | |
21 var event = document.createEvent("MouseEvents"); | |
22 event.initMouseEvent('click', true, true, window, 1, pageX, pageY, clien
tX, clientY, | |
23 false, false, false, false, 0, document); | |
24 input.dispatchEvent(event); | |
25 } | |
26 } | |
27 | |
28 function setupDispatchEventTest() { | |
29 document.getElementById('speechInput').onwebkitspeechchange = function() { | |
30 testFailed('speech button accepted a programmatic click and fired onChan
ge event.'); | |
31 finishJSTest(); | |
32 }; | |
33 setTimeout(function() { | |
34 testPassed('speech button ignored the programmatic click event.'); | |
35 finishJSTest(); | |
36 }, 1000); | |
37 sendClick(false); | |
38 } | |
39 | |
40 // In this test, we first send a click via the eventSender interface which is av
ailable only | |
41 // within our test environment. This mimics a real user input event and hence th
e speech button | |
42 // should treat it normally. We'll be receiving the mock recognition result and
verify that. | |
43 // Next we send a generated click event via the dispatchEvent interface which is
available | |
44 // for any web page to use. The speech button should identify that this is not a
real user | |
45 // input event and not process it. | |
46 function run() { | |
47 if (window.testRunner && window.eventSender) { | |
48 // Running in DRT, test the eventSender case. | |
49 testRunner.addMockSpeechInputResult('Pictures of the moon', 1.0, ''); | |
50 document.getElementById('speechInput').onwebkitspeechchange = function()
{ | |
51 shouldBeEqualToString('document.getElementById("speechInput").value'
, 'Pictures of the moon'); | |
52 | |
53 // The speech button is still in the processing state and does not a
ccept clicks. So ask for | |
54 // a callback once it has processed pending events before sending a
programmatic click. | |
55 setTimeout(setupDispatchEventTest, 0); | |
56 }; | |
57 sendClick(true); | |
58 } else { | |
59 setupDispatchEventTest(); | |
60 } | |
61 } | |
62 | |
63 window.onload = run; | |
64 window.jsTestIsAsync = true; | |
65 </script> | |
66 <input id='speechInput' x-webkit-speech> | |
67 </body> | |
68 </html> | |
OLD | NEW |