Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: chrome/browser/ui/webui/app_list/start_page_browsertest.js

Issue 159973004: Adds speech recognition test case to AppListStartPageWebUITest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * TestFixture for kiosk app settings WebUI testing. 6 * TestFixture for kiosk app settings WebUI testing.
7 * @extends {testing.Test} 7 * @extends {testing.Test}
8 * @constructor 8 * @constructor
9 **/ 9 **/
10 function AppListStartPageWebUITest() {} 10 function AppListStartPageWebUITest() {}
11 11
12 /**
13 * Mock of audioContext.
14 * @constructor
15 */
16 function mockAudioContext() {
17 this.sampleRate = 44100; /* some dummy number */
18 }
19
20 mockAudioContext.prototype = {
21 createMediaStreamSource: function(stream) {
22 return {connect: function(audioProc) {}};
23 },
24 createScriptProcessor: function(bufSize, channels, channels) {
25 return {connect: function(destination) {},
26 disconnect: function() {}};
27 }
28 };
29
12 AppListStartPageWebUITest.prototype = { 30 AppListStartPageWebUITest.prototype = {
13 __proto__: testing.Test.prototype, 31 __proto__: testing.Test.prototype,
14 32
15 /** 33 /**
16 * Browser to app launcher start page. 34 * Browser to app launcher start page.
17 */ 35 */
18 browsePreload: 'chrome://app-list/', 36 browsePreload: 'chrome://app-list/',
19 37
20 /** 38 /**
21 * Recommend apps data. 39 * Recommend apps data.
22 * @private 40 * @private
23 */ 41 */
24 recommendedApps_: [ 42 recommendedApps_: [
25 { 43 {
26 'appId': 'app_id_1', 44 'appId': 'app_id_1',
27 'textTitle': 'app 1', 45 'textTitle': 'app 1',
28 'iconUrl': 'icon_url_1' 46 'iconUrl': 'icon_url_1'
29 }, 47 },
30 { 48 {
31 'appId': 'app_id_2', 49 'appId': 'app_id_2',
32 'textTitle': 'app 2', 50 'textTitle': 'app 2',
33 'iconUrl': 'icon_url_2' 51 'iconUrl': 'icon_url_2'
52 }
53 ],
54
55 /**
56 * Placeholder for mock speech recognizer.
57 */
58 speechRecognizer: null,
59
60 /**
61 * Sends the speech recognition result.
62 *
63 * @param {string} result The testing result.
64 * @param {boolean} isFinal Whether the result is final or not.
65 */
66 sendSpeechResult: function(result, isFinal) {
67 var speechEvent = new Event('test');
68 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.
69 transcript.isFinal = isFinal;
70 speechEvent.results = [transcript];
71 this.speechRecognizer.onresult(speechEvent);
72 },
73
74 /**
75 * Registers the webkitSpeechRecognition mock for test.
76 * @private
77 */
78 registerMockSpeechRecognition_: function() {
79 var owner = this;
80 function mockSpeechRecognition() {
81 this.inSpeech_ = false;
82 owner.speechRecognizer = this;
83 }
84
85 mockSpeechRecognition.prototype = {
86 start: function() {
87 this.onstart();
88 },
89
90 abort: function() {
91 if (this.inSpeech_)
92 this.onspeechend();
93 this.onerror(new Error());
94 this.onend();
95 }
34 }, 96 },
35 ], 97
98 window.webkitSpeechRecognition = mockSpeechRecognition;
99 },
100
101 /**
102 * Mock of webkitGetUserMedia for start page.
103 *
104 * @private
105 * @param {object} constraint The constraint parameter.
106 * @param {Function} success The success callback.
107 * @param {Function} error The error callback.
108 */
109 mockGetUserMedia_: function(constraint, success, error) {
110 assertTrue(constraint.audio);
111 assertNotEquals(null, error, 'error callback must not be null');
112 success();
113 },
36 114
37 /** @override */ 115 /** @override */
38 preLoad: function() { 116 preLoad: function() {
39 this.makeAndRegisterMockHandler( 117 this.makeAndRegisterMockHandler(
40 ['initialize', 'launchApp', 'setSpeechRecognitionState']); 118 ['initialize', 'launchApp',
119 '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.
41 this.mockHandler.stubs().initialize().will(callFunction(function() { 120 this.mockHandler.stubs().initialize().will(callFunction(function() {
42 appList.startPage.setRecommendedApps(this.recommendedApps_); 121 appList.startPage.setRecommendedApps(this.recommendedApps_);
43 }.bind(this))); 122 }.bind(this)));
44 this.mockHandler.stubs().launchApp(ANYTHING); 123 this.mockHandler.stubs().launchApp(ANYTHING);
45 this.mockHandler.expects(once()).setSpeechRecognitionState('READY'); 124 this.mockHandler.expects(once()).setSpeechRecognitionState('READY');
125
126 this.registerMockSpeechRecognition_();
127 window.webkitAudioContext = mockAudioContext;
128 navigator.webkitGetUserMedia = this.mockGetUserMedia_.bind(this);
46 } 129 }
47 }; 130 };
48 131
49 TEST_F('AppListStartPageWebUITest', 'Basic', function() { 132 TEST_F('AppListStartPageWebUITest', 'Basic', function() {
50 assertEquals(this.browsePreload, document.location.href); 133 assertEquals(this.browsePreload, document.location.href);
51 134
52 var recommendedApp = $('start-page').querySelector('.recommended-apps'); 135 var recommendedApp = $('start-page').querySelector('.recommended-apps');
53 assertEquals(this.recommendedApps_.length, recommendedApp.childElementCount); 136 assertEquals(this.recommendedApps_.length, recommendedApp.childElementCount);
54 for (var i = 0; i < recommendedApp.childElementCount; ++i) { 137 for (var i = 0; i < recommendedApp.childElementCount; ++i) {
55 assertEquals(this.recommendedApps_[i].appId, 138 assertEquals(this.recommendedApps_[i].appId,
56 recommendedApp.children[i].appId); 139 recommendedApp.children[i].appId);
57 } 140 }
58 }); 141 });
59 142
60 TEST_F('AppListStartPageWebUITest', 'ClickToLaunch', function() { 143 TEST_F('AppListStartPageWebUITest', 'ClickToLaunch', function() {
61 var recommendedApp = $('start-page').querySelector('.recommended-apps'); 144 var recommendedApp = $('start-page').querySelector('.recommended-apps');
62 for (var i = 0; i < recommendedApp.childElementCount; ++i) { 145 for (var i = 0; i < recommendedApp.childElementCount; ++i) {
63 this.mockHandler.expects(once()).launchApp( 146 this.mockHandler.expects(once()).launchApp(
64 [this.recommendedApps_[i].appId]); 147 [this.recommendedApps_[i].appId]);
65 cr.dispatchSimpleEvent(recommendedApp.children[i], 'click'); 148 cr.dispatchSimpleEvent(recommendedApp.children[i], 'click');
66 } 149 }
67 }); 150 });
151
152 TEST_F('AppListStartPageWebUITest', 'SpeechRecognitionState', function() {
153 appList.startPage.onAppListShown();
154 this.mockHandler.expects(once()).setSpeechRecognitionState('RECOGNIZING');
155 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.
156
157 this.mockHandler.expects(once()).setSpeechRecognitionState('READY');
158 appList.startPage.toggleSpeechRecognition();
159
160 this.mockHandler.expects(once()).setSpeechRecognitionState('RECOGNIZING');
161 appList.startPage.toggleSpeechRecognition();
162
163 this.mockHandler.expects(once()).setSpeechRecognitionState('STOPPING');
164 appList.startPage.onAppListHidden();
165 });
166
167 TEST_F('AppListStartPageWebUITest', 'SpeechRecognition', function() {
168 appList.startPage.onAppListShown();
169 this.mockHandler.expects(once()).setSpeechRecognitionState('RECOGNIZING');
170 appList.startPage.toggleSpeechRecognition();
171
172 this.mockHandler.expects(once()).setSpeechRecognitionState('IN_SPEECH');
173 this.speechRecognizer.onspeechstart();
174
175 this.mockHandler.expects(once()).speechResult('test,false');
176 this.sendSpeechResult('test', false);
177
178 this.mockHandler.expects(once()).speechResult('test,true');
179 this.mockHandler.expects(once()).setSpeechRecognitionState('READY');
180 this.sendSpeechResult('test', true);
181 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698