1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
4 <script src="../js/resources/js-test-pre.js"></script>
7 <script type="text/javascript">
8 description('Tests that the speech button ignores programmatic click events.');
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;
17 eventSender.mouseMoveTo(pageX, pageY);
18 eventSender.mouseDown();
19 eventSender.mouseUp();
21 var event = document.createEvent("MouseEvents");
22 event.initMouseEvent('click', true, true, window, 1, pageX, pageY, clientX, clientY,
23 false, false, false, false, 0, document);
24 input.dispatchEvent(event);
28 function setupDispatchEventTest() {
29 document.getElementById('speechInput').onwebkitspeechchange = function() {
30 testFailed('speech button accepted a programmatic click and fired onChange event.');
33 setTimeout(function() {
34 testPassed('speech button ignored the programmatic click event.');
40 // In this test, we first send a click via the eventSender interface which is available only
41 // within our test environment. This mimics a real user input event and hence the 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.
47 if (window.layoutTestController && window.eventSender) {
48 // Running in DRT, test the eventSender case.
49 layoutTestController.addMockSpeechInputResult('Pictures of the moon', 1.0, '');
50 document.getElementById('speechInput').onwebkitspeechchange = function() {
51 shouldBeEqualToString('document.getElementById("speechInput").value', 'Pictures of the moon');
53 // The speech button is still in the processing state and does not accept clicks. So ask for
54 // a callback once it has processed pending events before sending a programmatic click.
55 setTimeout(setupDispatchEventTest, 0);
59 setupDispatchEventTest();
64 window.jsTestIsAsync = true;
66 <script src="../js/resources/js-test-post.js"></script>
67 <input id='speechInput' x-webkit-speech>