Chromium Code Reviews| Index: chrome/browser/ui/webui/app_list/start_page_browsertest.js |
| diff --git a/chrome/browser/ui/webui/app_list/start_page_browsertest.js b/chrome/browser/ui/webui/app_list/start_page_browsertest.js |
| index 1fb89fb4723978ff38cc74ca474152de0bb06ff6..c745ba663a912ef8d66df8f107a23df4734d82a8 100644 |
| --- a/chrome/browser/ui/webui/app_list/start_page_browsertest.js |
| +++ b/chrome/browser/ui/webui/app_list/start_page_browsertest.js |
| @@ -9,6 +9,24 @@ |
| **/ |
| function AppListStartPageWebUITest() {} |
| +/** |
| + * Mock of audioContext. |
| + * @constructor |
| + */ |
| +function mockAudioContext() { |
| + this.sampleRate = 44100; /* some dummy number */ |
| +} |
| + |
| +mockAudioContext.prototype = { |
| + createMediaStreamSource: function(stream) { |
| + return {connect: function(audioProc) {}}; |
| + }, |
| + createScriptProcessor: function(bufSize, channels, channels) { |
| + return {connect: function(destination) {}, |
| + disconnect: function() {}}; |
| + } |
| +}; |
| + |
| AppListStartPageWebUITest.prototype = { |
| __proto__: testing.Test.prototype, |
| @@ -31,18 +49,83 @@ AppListStartPageWebUITest.prototype = { |
| 'appId': 'app_id_2', |
| 'textTitle': 'app 2', |
| 'iconUrl': 'icon_url_2' |
| - }, |
| + } |
| ], |
| + /** |
| + * Placeholder for mock speech recognizer. |
| + */ |
| + speechRecognizer: null, |
| + |
| + /** |
| + * Sends the speech recognition result. |
| + * |
| + * @param {string} result The testing result. |
| + * @param {boolean} isFinal Whether the result is final or not. |
| + */ |
| + sendSpeechResult: function(result, isFinal) { |
| + var speechEvent = new Event('test'); |
| + var transcript = [{transcript: result}]; |
|
xiyuan
2014/02/13 01:56:17
You probably don't need the enclosing [] and can c
Jun Mukai
2014/02/13 02:15:25
the speech result data is a bit tricky, but isFina
xiyuan
2014/02/13 02:27:16
Thanks for the explanation.
|
| + transcript.isFinal = isFinal; |
| + speechEvent.results = [transcript]; |
| + this.speechRecognizer.onresult(speechEvent); |
| + }, |
| + |
| + /** |
| + * Registers the webkitSpeechRecognition mock for test. |
| + * @private |
| + */ |
| + registerMockSpeechRecognition_: function() { |
| + var owner = this; |
| + function mockSpeechRecognition() { |
| + this.inSpeech_ = false; |
| + owner.speechRecognizer = this; |
| + } |
| + |
| + mockSpeechRecognition.prototype = { |
| + start: function() { |
| + this.onstart(); |
| + }, |
| + |
| + abort: function() { |
| + if (this.inSpeech_) |
| + this.onspeechend(); |
| + this.onerror(new Error()); |
| + this.onend(); |
| + } |
| + }, |
| + |
| + window.webkitSpeechRecognition = mockSpeechRecognition; |
| + }, |
| + |
| + /** |
| + * Mock of webkitGetUserMedia for start page. |
| + * |
| + * @private |
| + * @param {object} constraint The constraint parameter. |
| + * @param {Function} success The success callback. |
| + * @param {Function} error The error callback. |
| + */ |
| + mockGetUserMedia_: function(constraint, success, error) { |
| + assertTrue(constraint.audio); |
| + assertNotEquals(null, error, 'error callback must not be null'); |
| + success(); |
| + }, |
| + |
| /** @override */ |
| preLoad: function() { |
| this.makeAndRegisterMockHandler( |
| - ['initialize', 'launchApp', 'setSpeechRecognitionState']); |
| + ['initialize', 'launchApp', |
| + 'setSpeechRecognitionState', 'speechResult']); |
|
xiyuan
2014/02/13 01:56:17
nit: Reformat to one string per line.
Jun Mukai
2014/02/13 02:15:25
Done.
|
| this.mockHandler.stubs().initialize().will(callFunction(function() { |
| appList.startPage.setRecommendedApps(this.recommendedApps_); |
| }.bind(this))); |
| this.mockHandler.stubs().launchApp(ANYTHING); |
| this.mockHandler.expects(once()).setSpeechRecognitionState('READY'); |
| + |
| + this.registerMockSpeechRecognition_(); |
| + window.webkitAudioContext = mockAudioContext; |
| + navigator.webkitGetUserMedia = this.mockGetUserMedia_.bind(this); |
| } |
| }; |
| @@ -65,3 +148,34 @@ TEST_F('AppListStartPageWebUITest', 'ClickToLaunch', function() { |
| cr.dispatchSimpleEvent(recommendedApp.children[i], 'click'); |
| } |
| }); |
| + |
| +TEST_F('AppListStartPageWebUITest', 'SpeechRecognitionState', function() { |
| + appList.startPage.onAppListShown(); |
| + this.mockHandler.expects(once()).setSpeechRecognitionState('RECOGNIZING'); |
| + appList.startPage.toggleSpeechRecognition(); |
|
xiyuan
2014/02/13 01:56:17
Think you need to
Mock4JS.verifyAllMocks();
M
Jun Mukai
2014/02/13 02:15:25
Done.
|
| + |
| + this.mockHandler.expects(once()).setSpeechRecognitionState('READY'); |
| + appList.startPage.toggleSpeechRecognition(); |
| + |
| + this.mockHandler.expects(once()).setSpeechRecognitionState('RECOGNIZING'); |
| + appList.startPage.toggleSpeechRecognition(); |
| + |
| + this.mockHandler.expects(once()).setSpeechRecognitionState('STOPPING'); |
| + appList.startPage.onAppListHidden(); |
| +}); |
| + |
| +TEST_F('AppListStartPageWebUITest', 'SpeechRecognition', function() { |
| + appList.startPage.onAppListShown(); |
| + this.mockHandler.expects(once()).setSpeechRecognitionState('RECOGNIZING'); |
| + appList.startPage.toggleSpeechRecognition(); |
| + |
| + this.mockHandler.expects(once()).setSpeechRecognitionState('IN_SPEECH'); |
| + this.speechRecognizer.onspeechstart(); |
| + |
| + this.mockHandler.expects(once()).speechResult('test,false'); |
| + this.sendSpeechResult('test', false); |
| + |
| + this.mockHandler.expects(once()).speechResult('test,true'); |
| + this.mockHandler.expects(once()).setSpeechRecognitionState('READY'); |
| + this.sendSpeechResult('test', true); |
| +}); |