blob: d0cd5e2e970c38b9d5dd0fd5d1a0cb10b9165179 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<script type="text/javascript">
description('Tests that the speech button ignores programmatic click events.');
function sendClick(useEventSender) {
var input = document.getElementById('speechInput');
var clientX = input.offsetWidth - 4;
var clientY = input.offsetHeight / 2;
var pageX = input.offsetLeft + clientX;
var pageY = input.offsetTop + clientY;
if (useEventSender) {
eventSender.mouseMoveTo(pageX, pageY);
eventSender.mouseDown();
eventSender.mouseUp();
} else {
var event = document.createEvent("MouseEvents");
event.initMouseEvent('click', true, true, window, 1, pageX, pageY, clientX, clientY,
false, false, false, false, 0, document);
input.dispatchEvent(event);
}
}
function setupDispatchEventTest() {
document.getElementById('speechInput').onwebkitspeechchange = function() {
testFailed('speech button accepted a programmatic click and fired onChange event.');
finishJSTest();
};
setTimeout(function() {
testPassed('speech button ignored the programmatic click event.');
finishJSTest();
}, 1000);
sendClick(false);
}
// In this test, we first send a click via the eventSender interface which is available only
// within our test environment. This mimics a real user input event and hence the speech button
// should treat it normally. We'll be receiving the mock recognition result and verify that.
// Next we send a generated click event via the dispatchEvent interface which is available
// for any web page to use. The speech button should identify that this is not a real user
// input event and not process it.
function run() {
if (window.testRunner && window.eventSender) {
// Running in DRT, test the eventSender case.
testRunner.addMockSpeechInputResult('Pictures of the moon', 1.0, '');
document.getElementById('speechInput').onwebkitspeechchange = function() {
shouldBeEqualToString('document.getElementById("speechInput").value', 'Pictures of the moon');
// The speech button is still in the processing state and does not accept clicks. So ask for
// a callback once it has processed pending events before sending a programmatic click.
setTimeout(setupDispatchEventTest, 0);
};
sendClick(true);
} else {
setupDispatchEventTest();
}
}
window.onload = run;
window.jsTestIsAsync = true;
</script>
<script src="../../resources/js-test-post.js"></script>
<input id='speechInput' x-webkit-speech>
</body>
</html>