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

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: fix 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 | « chrome/browser/resources/app_list/speech_manager.js ('k') | 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 // Each result contains a list of alternatives and 'isFinal' flag.
69 var speechResult = [{transcript: result}];
70 speechResult.isFinal = isFinal;
71 speechEvent.results = [speechResult];
72 this.speechRecognizer.onresult(speechEvent);
73 },
74
75 /**
76 * Registers the webkitSpeechRecognition mock for test.
77 * @private
78 */
79 registerMockSpeechRecognition_: function() {
80 var owner = this;
81 function mockSpeechRecognition() {
82 this.inSpeech_ = false;
83 owner.speechRecognizer = this;
84 }
85
86 mockSpeechRecognition.prototype = {
87 start: function() {
88 this.onstart();
89 },
90
91 abort: function() {
92 if (this.inSpeech_)
93 this.onspeechend();
94 this.onerror(new Error());
95 this.onend();
96 }
34 }, 97 },
35 ], 98
99 window.webkitSpeechRecognition = mockSpeechRecognition;
100 },
101
102 /**
103 * Mock of webkitGetUserMedia for start page.
104 *
105 * @private
106 * @param {object} constraint The constraint parameter.
107 * @param {Function} success The success callback.
108 * @param {Function} error The error callback.
109 */
110 mockGetUserMedia_: function(constraint, success, error) {
111 assertTrue(constraint.audio);
112 assertNotEquals(null, error, 'error callback must not be null');
113 success();
114 },
36 115
37 /** @override */ 116 /** @override */
38 preLoad: function() { 117 preLoad: function() {
39 this.makeAndRegisterMockHandler( 118 this.makeAndRegisterMockHandler(['initialize',
40 ['initialize', 'launchApp', 'setSpeechRecognitionState']); 119 'launchApp',
120 'setSpeechRecognitionState',
121 'speechResult']);
41 this.mockHandler.stubs().initialize().will(callFunction(function() { 122 this.mockHandler.stubs().initialize().will(callFunction(function() {
42 appList.startPage.setRecommendedApps(this.recommendedApps_); 123 appList.startPage.setRecommendedApps(this.recommendedApps_);
43 }.bind(this))); 124 }.bind(this)));
44 this.mockHandler.stubs().launchApp(ANYTHING); 125 this.mockHandler.stubs().launchApp(ANYTHING);
45 this.mockHandler.expects(once()).setSpeechRecognitionState('READY'); 126 this.mockHandler.expects(once()).setSpeechRecognitionState('READY');
127
128 this.registerMockSpeechRecognition_();
129 window.webkitAudioContext = mockAudioContext;
130 navigator.webkitGetUserMedia = this.mockGetUserMedia_.bind(this);
46 } 131 }
47 }; 132 };
48 133
49 TEST_F('AppListStartPageWebUITest', 'Basic', function() { 134 TEST_F('AppListStartPageWebUITest', 'Basic', function() {
50 assertEquals(this.browsePreload, document.location.href); 135 assertEquals(this.browsePreload, document.location.href);
51 136
52 var recommendedApp = $('start-page').querySelector('.recommended-apps'); 137 var recommendedApp = $('start-page').querySelector('.recommended-apps');
53 assertEquals(this.recommendedApps_.length, recommendedApp.childElementCount); 138 assertEquals(this.recommendedApps_.length, recommendedApp.childElementCount);
54 for (var i = 0; i < recommendedApp.childElementCount; ++i) { 139 for (var i = 0; i < recommendedApp.childElementCount; ++i) {
55 assertEquals(this.recommendedApps_[i].appId, 140 assertEquals(this.recommendedApps_[i].appId,
56 recommendedApp.children[i].appId); 141 recommendedApp.children[i].appId);
57 } 142 }
58 }); 143 });
59 144
60 TEST_F('AppListStartPageWebUITest', 'ClickToLaunch', function() { 145 TEST_F('AppListStartPageWebUITest', 'ClickToLaunch', function() {
61 var recommendedApp = $('start-page').querySelector('.recommended-apps'); 146 var recommendedApp = $('start-page').querySelector('.recommended-apps');
62 for (var i = 0; i < recommendedApp.childElementCount; ++i) { 147 for (var i = 0; i < recommendedApp.childElementCount; ++i) {
63 this.mockHandler.expects(once()).launchApp( 148 this.mockHandler.expects(once()).launchApp(
64 [this.recommendedApps_[i].appId]); 149 [this.recommendedApps_[i].appId]);
65 cr.dispatchSimpleEvent(recommendedApp.children[i], 'click'); 150 cr.dispatchSimpleEvent(recommendedApp.children[i], 'click');
66 } 151 }
67 }); 152 });
153
154 TEST_F('AppListStartPageWebUITest', 'SpeechRecognitionState', function() {
155 appList.startPage.onAppListShown();
156 this.mockHandler.expects(once()).setSpeechRecognitionState('RECOGNIZING');
157 appList.startPage.toggleSpeechRecognition();
158 Mock4JS.verifyAllMocks();
159 Mock4JS.clearMocksToVerify();
160
161 this.mockHandler.expects(once()).setSpeechRecognitionState('READY');
162 appList.startPage.toggleSpeechRecognition();
163 Mock4JS.verifyAllMocks();
164 Mock4JS.clearMocksToVerify();
165
166 this.mockHandler.expects(once()).setSpeechRecognitionState('RECOGNIZING');
167 appList.startPage.toggleSpeechRecognition();
168 Mock4JS.verifyAllMocks();
169 Mock4JS.clearMocksToVerify();
170
171 this.mockHandler.expects(once()).setSpeechRecognitionState('STOPPING');
172 this.mockHandler.expects(once()).setSpeechRecognitionState('READY');
173 appList.startPage.onAppListHidden();
174 });
175
176 TEST_F('AppListStartPageWebUITest', 'SpeechRecognition', function() {
177 appList.startPage.onAppListShown();
178 this.mockHandler.expects(once()).setSpeechRecognitionState('RECOGNIZING');
179 appList.startPage.toggleSpeechRecognition();
180 Mock4JS.verifyAllMocks();
181 Mock4JS.clearMocksToVerify();
182
183 this.mockHandler.expects(once()).setSpeechRecognitionState('IN_SPEECH');
184 this.speechRecognizer.onspeechstart();
185 Mock4JS.verifyAllMocks();
186 Mock4JS.clearMocksToVerify();
187
188 this.mockHandler.expects(once()).speechResult('test,false');
189 this.sendSpeechResult('test', false);
190 Mock4JS.verifyAllMocks();
191 Mock4JS.clearMocksToVerify();
192
193 this.mockHandler.expects(once()).speechResult('test,true');
194 this.mockHandler.expects(once()).setSpeechRecognitionState('READY');
195 this.sendSpeechResult('test', true);
196 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/app_list/speech_manager.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698