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

Side by Side Diff: extensions/test/data/api_test/audio/test.js

Issue 2605983002: Simplify logic behind chrome.audio.setActiveDevices (Closed)
Patch Set: . Created 3 years, 11 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
« no previous file with comments | « extensions/common/api/audio.idl ('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 * Asserts that device property values match properties in |expectedProperties|. 6 * Asserts that device property values match properties in |expectedProperties|.
7 * The method will *not* assert that the device contains *only* properties 7 * The method will *not* assert that the device contains *only* properties
8 * specified in expected properties. 8 * specified in expected properties.
9 * @param {Object} expectedProperties Expected device properties. 9 * @param {Object} expectedProperties Expected device properties.
10 * @param {Object} device Device object to test. 10 * @param {Object} device Device object to test.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 * expected devices used to assert devices match expectation. 49 * expected devices used to assert devices match expectation.
50 */ 50 */
51 function deviceListToExpectedDevicesMap(devices) { 51 function deviceListToExpectedDevicesMap(devices) {
52 var expectedDevicesMap = {}; 52 var expectedDevicesMap = {};
53 devices.forEach(function(device) { 53 devices.forEach(function(device) {
54 expectedDevicesMap[device.id] = device; 54 expectedDevicesMap[device.id] = device;
55 }); 55 });
56 return expectedDevicesMap; 56 return expectedDevicesMap;
57 } 57 }
58 58
59 function getActiveDeviceIds(deviceList) {
60 return deviceList
61 .filter(function(device) {return device.isActive;})
62 .map(function(device) {return device.id});
63 }
64
65 function getDevices(callback) {
66 chrome.audio.getInfo(chrome.test.callbackPass(callback));
67 }
68
59 chrome.test.runTests([ 69 chrome.test.runTests([
60 function getInfoTest() { 70 function getInfoTest() {
61 // Test output devices. Maps device ID -> tested device properties. 71 // Test output devices. Maps device ID -> tested device properties.
62 var kTestOutputDevices = { 72 var kTestOutputDevices = {
63 '30001': { 73 '30001': {
64 id: '30001', 74 id: '30001',
65 name: 'Jabra Speaker: Jabra Speaker 1' 75 name: 'Jabra Speaker: Jabra Speaker 1'
66 }, 76 },
67 '30002': { 77 '30002': {
68 id: '30002', 78 id: '30002',
(...skipping 14 matching lines...) Expand all
83 '40002': { 93 '40002': {
84 id: '40002', 94 id: '40002',
85 name: 'Jabra Mic: Jabra Mic 2' 95 name: 'Jabra Mic: Jabra Mic 2'
86 }, 96 },
87 '40003': { 97 '40003': {
88 id: '40003', 98 id: '40003',
89 name: 'Webcam Mic: Logitech Webcam' 99 name: 'Webcam Mic: Logitech Webcam'
90 } 100 }
91 }; 101 };
92 102
93 chrome.audio.getInfo( 103 getDevices(function(outputInfo, inputInfo) {
94 chrome.test.callbackPass(function(outputInfo, inputInfo) { 104 assertDevicesMatch(kTestOutputDevices, outputInfo);
95 assertDevicesMatch(kTestOutputDevices, outputInfo); 105 assertDevicesMatch(kTestInputDevices, inputInfo);
96 assertDevicesMatch(kTestInputDevices, inputInfo); 106 });
97 }));
98 }, 107 },
99 108
100 function setActiveDevicesTest() { 109 function deprecatedSetActiveDevicesTest() {
101 //Test output devices. Maps device ID -> tested device properties. 110 //Test output devices. Maps device ID -> tested device properties.
102 var kTestOutputDevices = { 111 var kTestOutputDevices = {
103 '30001': { 112 '30001': {
104 id: '30001', 113 id: '30001',
105 isActive: false 114 isActive: false
106 }, 115 },
107 '30002': { 116 '30002': {
108 id: '30002', 117 id: '30002',
109 isActive: false 118 isActive: false
110 }, 119 },
(...skipping 16 matching lines...) Expand all
127 '40003': { 136 '40003': {
128 id: '40003', 137 id: '40003',
129 isActive: false 138 isActive: false
130 } 139 }
131 }; 140 };
132 141
133 chrome.audio.setActiveDevices([ 142 chrome.audio.setActiveDevices([
134 '30003', 143 '30003',
135 '40002' 144 '40002'
136 ], chrome.test.callbackPass(function() { 145 ], chrome.test.callbackPass(function() {
137 chrome.audio.getInfo( 146 getDevices(function(outputInfo, inputInfo) {
138 chrome.test.callbackPass(function(outputInfo, inputInfo) { 147 assertDevicesMatch(kTestOutputDevices, outputInfo);
139 assertDevicesMatch(kTestOutputDevices, outputInfo); 148 assertDevicesMatch(kTestInputDevices, inputInfo);
140 assertDevicesMatch(kTestInputDevices, inputInfo); 149 });
141 }));
142 })); 150 }));
143 }, 151 },
144 152
145 function setPropertiesTest() { 153 function setPropertiesTest() {
146 chrome.audio.getInfo(function(originalOutputInfo, originalInputInfo) { 154 getDevices(function(originalOutputInfo, originalInputInfo) {
147 chrome.test.assertNoLastError();
148
149 var expectedInput = deviceListToExpectedDevicesMap(originalInputInfo); 155 var expectedInput = deviceListToExpectedDevicesMap(originalInputInfo);
150 // Update expected input devices with values that should be changed in 156 // Update expected input devices with values that should be changed in
151 // test. 157 // test.
152 var updatedInput = expectedInput['40002']; 158 var updatedInput = expectedInput['40002'];
153 chrome.test.assertFalse(updatedInput.isMuted); 159 chrome.test.assertFalse(updatedInput.isMuted);
154 chrome.test.assertFalse(updatedInput.gain === 55); 160 chrome.test.assertFalse(updatedInput.gain === 55);
155 updatedInput.isMuted = true; 161 updatedInput.isMuted = true;
156 updatedInput.gain = 55; 162 updatedInput.gain = 55;
157 163
158 var expectedOutput = deviceListToExpectedDevicesMap(originalOutputInfo); 164 var expectedOutput = deviceListToExpectedDevicesMap(originalOutputInfo);
159 // Update expected output devices with values that should be changed in 165 // Update expected output devices with values that should be changed in
160 // test. 166 // test.
161 var updatedOutput = expectedOutput['30001']; 167 var updatedOutput = expectedOutput['30001'];
162 chrome.test.assertFalse(updatedOutput.isMuted); 168 chrome.test.assertFalse(updatedOutput.isMuted);
163 chrome.test.assertFalse(updatedOutput.volume === 35); 169 chrome.test.assertFalse(updatedOutput.volume === 35);
164 updatedOutput.isMuted = true; 170 updatedOutput.isMuted = true;
165 updatedOutput.volume = 35; 171 updatedOutput.volume = 35;
166 172
167 chrome.audio.setProperties('30001', { 173 chrome.audio.setProperties('30001', {
168 isMuted: true, 174 isMuted: true,
169 volume: 35 175 volume: 35
170 }, chrome.test.callbackPass(function() { 176 }, chrome.test.callbackPass(function() {
171 chrome.audio.setProperties('40002', { 177 chrome.audio.setProperties('40002', {
172 isMuted: true, 178 isMuted: true,
173 gain: 55 179 gain: 55
174 }, chrome.test.callbackPass(function() { 180 }, chrome.test.callbackPass(function() {
175 chrome.audio.getInfo( 181 getDevices(
176 chrome.test.callbackPass(function(outputInfo, inputInfo) { 182 chrome.test.callbackPass(function(outputInfo, inputInfo) {
177 assertDevicesMatch(expectedInput, inputInfo); 183 assertDevicesMatch(expectedInput, inputInfo);
178 assertDevicesMatch(expectedOutput, outputInfo); 184 assertDevicesMatch(expectedOutput, outputInfo);
179 })); 185 }));
180 })); 186 }));
181 })); 187 }));
182 }); 188 });
183 }, 189 },
184 190
185 function setPropertiesInvalidValuesTest() { 191 function setPropertiesInvalidValuesTest() {
186 chrome.audio.getInfo(function(originalOutputInfo, originalInputInfo) { 192 getDevices(function(originalOutputInfo, originalInputInfo) {
187 chrome.test.assertNoLastError();
188 var expectedInput = deviceListToExpectedDevicesMap(originalInputInfo); 193 var expectedInput = deviceListToExpectedDevicesMap(originalInputInfo);
189 var expectedOutput = deviceListToExpectedDevicesMap(originalOutputInfo); 194 var expectedOutput = deviceListToExpectedDevicesMap(originalOutputInfo);
190 195
191 chrome.audio.setProperties('30001', { 196 chrome.audio.setProperties('30001', {
192 isMuted: true, 197 isMuted: true,
193 // Output device - should have volume set. 198 // Output device - should have volume set.
194 gain: 55 199 gain: 55
195 }, chrome.test.callbackFail('Could not set properties', function() { 200 }, chrome.test.callbackFail('Could not set properties', function() {
196 chrome.audio.setProperties('40002', { 201 chrome.audio.setProperties('40002', {
197 isMuted: true, 202 isMuted: true,
198 // Input device - should have gain set. 203 // Input device - should have gain set.
199 volume:55 204 volume:55
200 }, chrome.test.callbackFail('Could not set properties', function() { 205 }, chrome.test.callbackFail('Could not set properties', function() {
201 // Assert that device properties haven't changed. 206 // Assert that device properties haven't changed.
202 chrome.audio.getInfo( 207 getDevices(function(outputInfo, inputInfo) {
203 chrome.test.callbackPass(function(outputInfo, inputInfo) { 208 assertDevicesMatch(expectedOutput, outputInfo);
204 assertDevicesMatch(expectedOutput, outputInfo); 209 assertDevicesMatch(expectedInput, inputInfo);
205 assertDevicesMatch(expectedInput, inputInfo); 210 });
206 }));
207 })); 211 }));
208 })); 212 }));
209 }); 213 });
210 } 214 },
215
216 function setActiveDevicesTest() {
217 chrome.audio.setActiveDevices({
218 input: ['40002', '40003'],
219 output: ['30001']
220 }, chrome.test.callbackPass(function() {
221 getDevices(function(outputs, inputs) {
222 chrome.test.assertEq(
223 ['40002', '40003'], getActiveDeviceIds(inputs).sort());
224 chrome.test.assertEq(['30001'], getActiveDeviceIds(outputs));
225 });
226 }));
227 },
228
229 function setActiveDevicesOutputOnlyTest() {
230 getDevices(function(originalOutputs, originalInputs) {
231 var originalActiveInputs = getActiveDeviceIds(originalInputs);
232 chrome.test.assertTrue(originalActiveInputs.length > 0);
233
234 chrome.audio.setActiveDevices({
235 output: ['30003']
236 }, chrome.test.callbackPass(function() {
237 getDevices(function(outputs, inputs) {
238 chrome.test.assertEq(
239 originalActiveInputs.sort(), getActiveDeviceIds(inputs).sort());
240 chrome.test.assertEq(['30003'], getActiveDeviceIds(outputs));
241 });
242 }));
243 });
244 },
245
246 function setActiveDevicesFailInputTest() {
247 getDevices(function(originalOutputs, originalInputs) {
248 var originalActiveInputs = getActiveDeviceIds(originalInputs).sort();
249 chrome.test.assertTrue(originalActiveInputs.length > 0);
250
251 var originalActiveOutputs = getActiveDeviceIds(originalOutputs).sort();
252 chrome.test.assertTrue(originalActiveOutputs.length > 0);
253
254 chrome.audio.setActiveDevices({
255 input: ['0000000'], /* does not exist */
256 output: []
257 }, chrome.test.callbackFail('Failed to set active devices.', function() {
258 getDevices(function(outputs, inputs) {
259 chrome.test.assertEq(
260 originalActiveInputs, getActiveDeviceIds(inputs).sort());
261 chrome.test.assertEq(
262 originalActiveOutputs, getActiveDeviceIds(outputs).sort());
263 });
264 }));
265 });
266 },
267
268 function setActiveDevicesFailOutputTest() {
269 getDevices(function(originalOutputs, originalInputs) {
270 var originalActiveInputs = getActiveDeviceIds(originalInputs).sort();
271 chrome.test.assertTrue(originalActiveInputs.length > 0);
272
273 var originalActiveOutputs = getActiveDeviceIds(originalOutputs).sort();
274 chrome.test.assertTrue(originalActiveOutputs.length > 0);
275
276 chrome.audio.setActiveDevices({
277 input: [],
278 output: ['40001'] /* id is input node ID */
279 }, chrome.test.callbackFail('Failed to set active devices.', function() {
280 getDevices(function(outputs, inputs) {
281 chrome.test.assertEq(
282 originalActiveInputs, getActiveDeviceIds(inputs).sort());
283 chrome.test.assertEq(
284 originalActiveOutputs, getActiveDeviceIds(outputs).sort());
285 });
286 }));
287 });
288 },
289
290 function clearActiveDevicesTest() {
291 getDevices(function(originalOutputs, originalInputs) {
292 chrome.test.assertTrue(getActiveDeviceIds(originalInputs).length > 0);
293 chrome.test.assertTrue(getActiveDeviceIds(originalOutputs).length > 0);
294
295 chrome.audio.setActiveDevices({
296 input: [],
297 output: []
298 }, chrome.test.callbackPass(function() {
299 getDevices(function(outputs, inputs) {
300 chrome.test.assertEq([], getActiveDeviceIds(inputs));
301 chrome.test.assertEq([], getActiveDeviceIds(outputs));
302 });
303 }));
304 });
305 },
211 ]); 306 ]);
OLDNEW
« no previous file with comments | « extensions/common/api/audio.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698