Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Speech JavaScript API: SpeechRecognition should hook up with ActiveDO…
…MObject more https://bugs.webkit.org/show_bug.cgi?id=89217 Reviewed by Adam Barth. Source/WebCore: Previously, the SpeechRecognition was kept alive while waiting for pending events by making the embedder hold a reference to the object. We should do this by using ActiveDOMObject's setPendingActivity() instead. Also, override ActiveDOMObject::stop() to get notified when the user leaves the page. Test: fast/speech/scripted/navigate-away.html * Modules/speech/SpeechRecognition.cpp: (WebCore::SpeechRecognition::start): (WebCore::SpeechRecognition::didEnd): (WebCore::SpeechRecognition::stop): (WebCore): * Modules/speech/SpeechRecognition.h: (SpeechRecognition): Tools: Add a method for checking whether the mock speech recognition was aborted. Also redo the way the mock posts tasks. Instead of posting them all at once, maintain an internal queue of task objects, and call postTask() for them once at the time. This means that for example when the page is navigated away and abort() is called, that call doesn't end up after a bunch of previously posted events on the event loop. * DumpRenderTree/chromium/LayoutTestController.cpp: (LayoutTestController::LayoutTestController): (LayoutTestController::wasMockSpeechRecognitionAborted): * DumpRenderTree/chromium/LayoutTestController.h: (LayoutTestController): * DumpRenderTree/chromium/MockWebSpeechRecognizer.cpp: (WebKit::ClientCallTask::ClientCallTask): (WebKit::ResultTask::ResultTask): (WebKit::NoMatchTask::NoMatchTask): (WebKit::ErrorTask::ErrorTask): (MockWebSpeechRecognizer::start): (MockWebSpeechRecognizer::abort): (MockWebSpeechRecognizer::setError): (MockWebSpeechRecognizer::MockWebSpeechRecognizer): (MockWebSpeechRecognizer::startTaskQueue): (MockWebSpeechRecognizer::StepTask::runIfValid): * DumpRenderTree/chromium/MockWebSpeechRecognizer.h: (MockWebSpeechRecognizer::hasBeenAborted): (MockWebSpeechRecognizer): (MockWebSpeechRecognizer::taskList): (Task): (MockWebSpeechRecognizer::Task::Task): (MockWebSpeechRecognizer::Task::~Task): (StepTask): (MockWebSpeechRecognizer::StepTask::StepTask): LayoutTests: Add a layout test to check that speech recognition gets aborted when navigating away from the page. * fast/speech/scripted/navigate-away-expected.txt: Added. * fast/speech/scripted/navigate-away-iframe-expected.txt: Added. * fast/speech/scripted/navigate-away-iframe.html: Added. * fast/speech/scripted/navigate-away.html: Added. Canonical link: https://commits.webkit.org/107503@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@120913 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
13 changed files
with
307 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
LayoutTests/fast/speech/scripted/navigate-away-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Test behaviour when navigating away from a page using the Speech JavaScript API | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
The iframe was loaded. | ||
PASS 'webkitSpeechRecognition' in self is true | ||
PASS webkitSpeechRecognition == null is false | ||
PASS testRunner.wasMockSpeechRecognitionAborted() is false | ||
iframe: Created SpeechRecognition | ||
iframe: calling start() | ||
iframe: onstart | ||
iframe: navigating away | ||
The iframe was navigated away. | ||
PASS testRunner.wasMockSpeechRecognitionAborted() is true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
1 change: 1 addition & 0 deletions
1
LayoutTests/fast/speech/scripted/navigate-away-iframe-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This file is meant to be used as part of the navigate-away.html test. |
48 changes: 48 additions & 0 deletions
48
LayoutTests/fast/speech/scripted/navigate-away-iframe.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<script src="../../js/resources/js-test-pre.js"></script> | ||
</head> | ||
<body id="body"> | ||
<script type="text/javascript"> | ||
|
||
function log(msg) { | ||
parent.postMessage(msg, '*'); | ||
} | ||
|
||
function setDefaultHandlers(r) { | ||
for (var prop in r) { | ||
if (prop.match('^on')) { | ||
r[prop] = function() { | ||
log('unexpected ' + event.type + ' event!'); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function run() { | ||
if (window.top == window.self) { | ||
// We are not in an iframe. | ||
document.getElementById('body').innerHTML = 'This file is meant to be used as part of the navigate-away.html test.'; | ||
return; | ||
} | ||
|
||
window.speechreco = new webkitSpeechRecognition(); | ||
log('Created SpeechRecognition'); | ||
setDefaultHandlers(speechreco); | ||
|
||
speechreco.onstart = function() { | ||
log('onstart'); | ||
log('navigating away'); | ||
window.location = 'data:text/html,Navigated away.'; | ||
}; | ||
|
||
log('calling start()'); | ||
speechreco.start(); | ||
} | ||
|
||
window.onload = run; | ||
</script> | ||
This iframe creates a speechreco object. | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<script src="../../js/resources/js-test-pre.js"></script> | ||
</head> | ||
<body> | ||
<script type="text/javascript"> | ||
description('Test behaviour when navigating away from a page using the Speech JavaScript API'); | ||
|
||
function run() { | ||
// Check availability of constructors. | ||
shouldBeTrue("'webkitSpeechRecognition' in self"); | ||
shouldBeFalse("webkitSpeechRecognition == null"); | ||
|
||
if (window.testRunner) | ||
shouldBeFalse("testRunner.wasMockSpeechRecognitionAborted()"); | ||
|
||
window.onmessage = function() { | ||
debug('iframe: ' + event.data); | ||
}; | ||
} | ||
|
||
window.iframeonloadcount = 0; | ||
function iframeonload() { | ||
++iframeonloadcount; | ||
|
||
if (iframeonloadcount === 1) { | ||
// The iframe has loaded for the first time. | ||
debug('The iframe was loaded.'); | ||
return; | ||
} | ||
|
||
debug('The iframe was navigated away.'); | ||
if (window.testRunner) | ||
shouldBeTrue("testRunner.wasMockSpeechRecognitionAborted()"); | ||
finishJSTest(); | ||
} | ||
|
||
window.onload = run; | ||
window.jsTestIsAsync = true; | ||
</script> | ||
<script src="../../js/resources/js-test-post.js"></script> | ||
<iframe id="iframe" src="navigate-away-iframe.html" onload="iframeonload()" > | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.