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.
6 * TestFixture for kiosk app settings WebUI testing.
7 * @extends {testing.Test}
10 function AppListStartPageWebUITest() {}
13 * Mock of audioContext.
16 function mockAudioContext() {
17 this.sampleRate = 44100; /* some dummy number */
20 mockAudioContext.prototype = {
21 createMediaStreamSource: function(stream) {
22 return {connect: function(audioProc) {},
23 disconnect: function() {}};
25 createScriptProcessor: function(bufSize, in_channels, out_channels) {
26 return {connect: function(destination) {},
27 disconnect: function() {}};
31 AppListStartPageWebUITest.prototype = {
32 __proto__: testing.Test.prototype,
35 * Browser to app launcher start page.
37 browsePreload: 'chrome://app-list/',
40 * Placeholder for mock speech recognizer.
42 speechRecognizer: null,
45 * Sends the speech recognition result.
47 * @param {string} result The testing result.
48 * @param {boolean} isFinal Whether the result is final or not.
50 sendSpeechResult: function(result, isFinal) {
51 var speechEvent = new Event('test');
52 // Each result contains a list of alternatives and 'isFinal' flag.
53 var speechResult = [{transcript: result}];
54 speechResult.isFinal = isFinal;
55 speechEvent.results = [speechResult];
56 this.speechRecognizer.onresult(speechEvent);
60 * Registers the webkitSpeechRecognition mock for test.
63 registerMockSpeechRecognition_: function() {
65 function mockSpeechRecognition() {
66 this.inSpeech_ = false;
67 owner.speechRecognizer = this;
70 mockSpeechRecognition.prototype = {
78 this.onerror(new Error());
83 window.webkitSpeechRecognition = mockSpeechRecognition;
87 * Mock of webkitGetUserMedia for start page.
90 * @param {object} constraint The constraint parameter.
91 * @param {Function} success The success callback.
92 * @param {Function} error The error callback.
94 mockGetUserMedia_: function(constraint, success, error) {
95 function getAudioTracks() {
97 assertTrue(constraint.audio);
98 assertNotEquals(null, error, 'error callback must not be null');
100 for (var i = 0; i < 2; ++i) {
101 audioTracks.push(this.audioTrackMocks[i].proxy());
103 success({getAudioTracks: function() { return audioTracks; }});
107 preLoad: function() {
108 this.makeAndRegisterMockHandler(['initialize',
110 'setSpeechRecognitionState',
112 this.mockHandler.stubs().initialize();
113 this.mockHandler.stubs().launchApp(ANYTHING);
115 this.registerMockSpeechRecognition_();
116 window.AudioContext = mockAudioContext;
117 navigator.webkitGetUserMedia = this.mockGetUserMedia_.bind(this);
118 this.audioTrackMocks = [mock(MediaStreamTrack), mock(MediaStreamTrack)];
122 TEST_F('AppListStartPageWebUITest', 'Basic', function() {
123 assertEquals(this.browsePreload, document.location.href);
126 TEST_F('AppListStartPageWebUITest', 'LoadDoodle', function() {
129 'transparent_large_image': {
132 'alt_text': 'Doodle alt text',
133 'target_url': '/target.html'
137 assertEquals(null, $('doodle'));
139 // Load the doodle with a target url and alt text.
140 appList.startPage.onAppListDoodleUpdated(doodleData,
141 'http://example.com/x/');
142 assertNotEquals(null, $('doodle'));
143 assertEquals('http://example.com/x/doodle.png', $('doodle_image').src);
144 assertEquals(doodleData.ddljson.alt_text, $('doodle_image').title);
145 assertEquals('http://example.com/target.html', $('doodle_link').href);
147 // Reload the doodle without a target url and alt text.
148 doodleData.ddljson.alt_text = undefined;
149 doodleData.ddljson.target_url = undefined;
150 appList.startPage.onAppListDoodleUpdated(doodleData,
151 'http://example.com/x/');
152 assertNotEquals(null, $('doodle'));
153 assertEquals('http://example.com/x/doodle.png', $('doodle_image').src);
154 assertEquals('', $('doodle_image').title);
155 assertEquals(null, $('doodle_link'));
158 appList.startPage.onAppListDoodleUpdated({},
159 'http://example.com/');
160 assertEquals(null, $('doodle'));