Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / test / data / api_test / audio / test.js
blob6261cc44d9b513ea51ad1e3ade9b3d4b75b2b1e0
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 function verifyGetInfoOutput(outputs) {
6   chrome.test.assertEq("30001", outputs[0].id);
7   chrome.test.assertEq("Jabra Speaker: Jabra Speaker 1", outputs[0].name);
9   chrome.test.assertEq("30002", outputs[1].id);
10   chrome.test.assertEq("Jabra Speaker: Jabra Speaker 2", outputs[1].name);
12   chrome.test.assertEq("30003", outputs[2].id);
13   chrome.test.assertEq("HDMI output: HDA Intel MID", outputs[2].name);
16 function verifyGetInfoInput(inputs) {
17   chrome.test.assertEq("40001", inputs[0].id);
18   chrome.test.assertEq("Jabra Mic: Jabra Mic 1", inputs[0].name);
20   chrome.test.assertEq("40002", inputs[1].id);
21   chrome.test.assertEq("Jabra Mic: Jabra Mic 2", inputs[1].name);
23   chrome.test.assertEq("40003", inputs[2].id);
24   chrome.test.assertEq("Webcam Mic: Logitech Webcam", inputs[2].name);
27 function verifyActiveDevices(output_id, input_id) {
28   chrome.audio.getInfo(
29       chrome.test.callbackPass(function(outputInfo, inputInfo) {
30         var outputFound = false;
31         var inputFound = false;
32         for (var i = 0; i < outputInfo.length; ++i) {
33           if (outputInfo[i].isActive) {
34             chrome.test.assertTrue(outputInfo[i].id == output_id);
35             outputFound = true;
36           }
37         }
38         for (var i = 0; i < inputInfo.length; ++i) {
39           if (inputInfo[i].isActive) {
40             chrome.test.assertTrue(inputInfo[i].id == input_id);
41             inputFound = true;
42           }
43         }
44         chrome.test.assertTrue(outputFound);
45         chrome.test.assertTrue(inputFound);
46   }));
50 function verifyDeviceProperties(output_id, input_id,
51                                 output_props, input_props) {
52   chrome.audio.getInfo(
53       chrome.test.callbackPass(function(outputInfo, inputInfo) {
54         var outputFound = false;
55         var inputFound = false;
56         for (var i = 0; i < outputInfo.length; ++i) {
57           if (outputInfo[i].id == output_id) {
58             chrome.test.assertEq(output_props.volume, outputInfo[i].volume);
59             chrome.test.assertEq(output_props.isMuted, outputInfo[i].isMuted);
60             outputFound = true;
61           }
62         }
63         for (var i = 0; i < inputInfo.length; ++i) {
64           if (inputInfo[i].id == input_id) {
65             chrome.test.assertEq(input_props.gain, inputInfo[i].gain);
66             chrome.test.assertEq(input_props.isMuted, inputInfo[i].isMuted);
67             inputFound = true;
68           }
69         }
70         chrome.test.assertTrue(outputFound);
71         chrome.test.assertTrue(inputFound);
72   }));
76 function setActiveDevicesAndVerify(output_id, input_id) {
77   chrome.audio.setActiveDevices([output_id, input_id],
78       chrome.test.callbackPass(function() {
79         verifyActiveDevices(output_id, input_id);
80   }));
83 function setPropertiesAndVerify(outputInfo, inputInfo) {
84   var outputProps = new Object;
85   outputProps.isMuted = true;
86   outputProps.volume = 55;
87   chrome.audio.setProperties(outputInfo.id, outputProps,
88       chrome.test.callbackPass(function() {
89     // Once the output properties have been set, set input properties, then
90     // verify.
91     var inputProps = new Object;
92     inputProps.isMuted = true;
93     inputProps.gain = 35;
94     chrome.audio.setProperties(inputInfo.id, inputProps,
95         chrome.test.callbackPass(function() {
96           verifyDeviceProperties(outputInfo.id, inputInfo.id,
97                                  outputProps, inputProps);
98     }));
99   }));
102 chrome.test.runTests([
103   function getInfoTest() {
104     chrome.audio.getInfo(
105         chrome.test.callbackPass(function(outputInfo, inputInfo) {
106           verifyGetInfoOutput(outputInfo);
107           verifyGetInfoInput(inputInfo);
108     }));
109   },
111   function setActiveDevicesTest() {
112     chrome.audio.getInfo(
113         chrome.test.callbackPass(function(outputInfo, inputInfo) {
114           setActiveDevicesAndVerify(outputInfo[2].id, inputInfo[1].id);
115     }));
116   },
118   function setPropertiesTest() {
119     chrome.audio.getInfo(
120         chrome.test.callbackPass(function(outputInfo, inputInfo) {
121           setPropertiesAndVerify(outputInfo[0], inputInfo[1]);
122     }));
123   }