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 for enabling and disabling speech input via script.');
10 var speechInputCreatedByScript = false;
12 function onWebkitSpeechChange() {
13 shouldBeEqualToString('document.getElementById("speechInput").value', 'Pictures of the moon');
15 // Disable speech input now, just to verify this doesn't result in any crashes.
16 var input = document.getElementById('speechInput');
17 input.removeAttribute('x-webkit-speech');
19 // If the test has only been done with a type='text' field, repeat the same with a
20 // type='search' field since that takes a slightly different code path.
21 if (input.type != 'search') {
22 input.type = 'search';
23 testSetAttributeAndClick();
27 // If the test has only been done with a statically declared element, now repeat the same
28 // with a dynamically created/inserted element.
29 if (!speechInputCreatedByScript) {
30 document.body.removeChild(input);
31 input = document.createElement('input');
32 input.id = 'speechInput';
33 document.body.appendChild(input);
34 speechInputCreatedByScript = true;
35 testSetAttributeAndClick();
42 function testSetAttributeAndClick() {
43 // Enable speech input and test that clicking the speech button fills in mock speech-recognized text.
44 var input = document.getElementById('speechInput');
45 input.setAttribute('x-webkit-speech', '');
46 input.addEventListener('webkitspeechchange', onWebkitSpeechChange);
48 var x = input.offsetLeft + input.offsetWidth - 8;
49 var y = input.offsetTop + input.offsetHeight / 2;
50 eventSender.mouseMoveTo(x, y);
51 eventSender.mouseDown();
52 eventSender.mouseUp();
56 if (!window.layoutTestController || !window.eventSender)
59 layoutTestController.addMockSpeechInputResult('Pictures of the moon', 1.0, '');
61 // Try disabling speech with an input tag which has the attribute set in HTML and
62 // verify that doesn't result in any crashes.
63 document.getElementById('inputWithAttribute').removeAttribute('x-webkit-speech');
65 testSetAttributeAndClick();
69 window.jsTestIsAsync = true;
71 <script src="../js/resources/js-test-post.js"></script>
72 <input id='speechInput'>
73 <input id='inputWithAttribute' x-webkit-speech>