NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / app_list / start_page_browsertest.js
blob93bee2b845839339f5d80e3193c63d749ccbdecb
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
3 // found in the LICENSE file.
5 /**
6 * TestFixture for kiosk app settings WebUI testing.
7 * @extends {testing.Test}
8 * @constructor
9 **/
10 function AppListStartPageWebUITest() {}
12 /**
13 * Mock of audioContext.
14 * @constructor
16 function mockAudioContext() {
17 this.sampleRate = 44100; /* some dummy number */
20 mockAudioContext.prototype = {
21 createMediaStreamSource: function(stream) {
22 return {connect: function(audioProc) {}};
24 createScriptProcessor: function(bufSize, channels, channels) {
25 return {connect: function(destination) {},
26 disconnect: function() {}};
30 AppListStartPageWebUITest.prototype = {
31 __proto__: testing.Test.prototype,
33 /**
34 * Browser to app launcher start page.
36 browsePreload: 'chrome://app-list/',
38 /**
39 * Recommend apps data.
40 * @private
42 recommendedApps_: [
44 'appId': 'app_id_1',
45 'textTitle': 'app 1',
46 'iconUrl': 'icon_url_1'
49 'appId': 'app_id_2',
50 'textTitle': 'app 2',
51 'iconUrl': 'icon_url_2'
55 /**
56 * Placeholder for mock speech recognizer.
58 speechRecognizer: null,
60 /**
61 * Sends the speech recognition result.
63 * @param {string} result The testing result.
64 * @param {boolean} isFinal Whether the result is final or not.
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);
75 /**
76 * Registers the webkitSpeechRecognition mock for test.
77 * @private
79 registerMockSpeechRecognition_: function() {
80 var owner = this;
81 function mockSpeechRecognition() {
82 this.inSpeech_ = false;
83 owner.speechRecognizer = this;
86 mockSpeechRecognition.prototype = {
87 start: function() {
88 this.onstart();
91 abort: function() {
92 if (this.inSpeech_)
93 this.onspeechend();
94 this.onerror(new Error());
95 this.onend();
99 window.webkitSpeechRecognition = mockSpeechRecognition;
103 * Mock of webkitGetUserMedia for start page.
105 * @private
106 * @param {object} constraint The constraint parameter.
107 * @param {Function} success The success callback.
108 * @param {Function} error The error callback.
110 mockGetUserMedia_: function(constraint, success, error) {
111 assertTrue(constraint.audio);
112 assertNotEquals(null, error, 'error callback must not be null');
113 success();
116 /** @override */
117 preLoad: function() {
118 this.makeAndRegisterMockHandler(['initialize',
119 'launchApp',
120 'setSpeechRecognitionState',
121 'speechResult']);
122 this.mockHandler.stubs().initialize().will(callFunction(function() {
123 appList.startPage.setRecommendedApps(this.recommendedApps_);
124 }.bind(this)));
125 this.mockHandler.stubs().launchApp(ANYTHING);
126 this.mockHandler.expects(once()).setSpeechRecognitionState('READY');
128 this.registerMockSpeechRecognition_();
129 window.webkitAudioContext = mockAudioContext;
130 navigator.webkitGetUserMedia = this.mockGetUserMedia_.bind(this);
134 TEST_F('AppListStartPageWebUITest', 'Basic', function() {
135 assertEquals(this.browsePreload, document.location.href);
137 var recommendedApp = $('start-page').querySelector('.recommended-apps');
138 assertEquals(this.recommendedApps_.length, recommendedApp.childElementCount);
139 for (var i = 0; i < recommendedApp.childElementCount; ++i) {
140 assertEquals(this.recommendedApps_[i].appId,
141 recommendedApp.children[i].appId);
145 TEST_F('AppListStartPageWebUITest', 'ClickToLaunch', function() {
146 var recommendedApp = $('start-page').querySelector('.recommended-apps');
147 for (var i = 0; i < recommendedApp.childElementCount; ++i) {
148 this.mockHandler.expects(once()).launchApp(
149 [this.recommendedApps_[i].appId]);
150 cr.dispatchSimpleEvent(recommendedApp.children[i], 'click');
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();
161 this.mockHandler.expects(once()).setSpeechRecognitionState('READY');
162 appList.startPage.toggleSpeechRecognition();
163 Mock4JS.verifyAllMocks();
164 Mock4JS.clearMocksToVerify();
166 this.mockHandler.expects(once()).setSpeechRecognitionState('RECOGNIZING');
167 appList.startPage.toggleSpeechRecognition();
168 Mock4JS.verifyAllMocks();
169 Mock4JS.clearMocksToVerify();
171 this.mockHandler.expects(once()).setSpeechRecognitionState('STOPPING');
172 this.mockHandler.expects(once()).setSpeechRecognitionState('READY');
173 appList.startPage.onAppListHidden();
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();
183 this.mockHandler.expects(once()).setSpeechRecognitionState('IN_SPEECH');
184 this.speechRecognizer.onspeechstart();
185 Mock4JS.verifyAllMocks();
186 Mock4JS.clearMocksToVerify();
188 this.mockHandler.expects(once()).speechResult('test,false');
189 this.sendSpeechResult('test', false);
190 Mock4JS.verifyAllMocks();
191 Mock4JS.clearMocksToVerify();
193 this.mockHandler.expects(once()).speechResult('test,true');
194 this.mockHandler.expects(once()).setSpeechRecognitionState('READY');
195 this.sendSpeechResult('test', true);