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 for enabling and disabling speech input via script.'); | |
9 | |
10 var speechInputCreatedByScript = false; | |
11 | |
12 function onWebkitSpeechChange() { | |
13 shouldBeEqualToString('document.getElementById("speechInput").value', 'Pictu
res of the moon'); | |
14 | |
15 // Disable speech input now, just to verify this doesn't result in any crash
es. | |
16 var input = document.getElementById('speechInput'); | |
17 input.removeAttribute('x-webkit-speech'); | |
18 | |
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(); | |
24 return; | |
25 } | |
26 | |
27 // If the test has only been done with a statically declared element, now re
peat 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(); | |
36 return; | |
37 } | |
38 | |
39 finishJSTest(); | |
40 } | |
41 | |
42 function testSetAttributeAndClick() { | |
43 // Enable speech input and test that clicking the speech button fills in moc
k speech-recognized text. | |
44 var input = document.getElementById('speechInput'); | |
45 input.setAttribute('x-webkit-speech', ''); | |
46 input.addEventListener('webkitspeechchange', onWebkitSpeechChange); | |
47 | |
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(); | |
53 } | |
54 | |
55 function run() { | |
56 if (!window.testRunner || !window.eventSender) | |
57 return; | |
58 | |
59 testRunner.addMockSpeechInputResult('Pictures of the moon', 1.0, ''); | |
60 | |
61 // Try disabling speech with an input tag which has the attribute set in HTM
L and | |
62 // verify that doesn't result in any crashes. | |
63 document.getElementById('inputWithAttribute').removeAttribute('x-webkit-spee
ch'); | |
64 | |
65 testSetAttributeAndClick(); | |
66 } | |
67 | |
68 window.onload = run; | |
69 window.jsTestIsAsync = true; | |
70 </script> | |
71 <input id='speechInput'> | |
72 <input id='inputWithAttribute' x-webkit-speech> | |
73 </body> | |
74 </html> | |
OLD | NEW |