OLD | NEW |
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 // JavaScript for invoking methods on APIs used by Hangouts via the | 5 // JavaScript for invoking methods on APIs used by Hangouts via the |
6 // Hangout Services extension, and a JavaScript-based end-to-end test | 6 // Hangout Services extension, and a JavaScript-based end-to-end test |
7 // of the extension. | 7 // of the extension. |
8 | 8 |
9 // ID of the Hangout Services component extension. | 9 // ID of the Hangout Services component extension. |
10 var EXTENSION_ID = "nkeimhogjdpnpccoofpliimaahmaaome"; | 10 var EXTENSION_ID = "nkeimhogjdpnpccoofpliimaahmaaome"; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 // Will call |callback()| on completion. | 103 // Will call |callback()| on completion. |
104 function loggingDiscard(callback) { | 104 function loggingDiscard(callback) { |
105 sendMessage({'method': 'logging.discard'}, callback); | 105 sendMessage({'method': 'logging.discard'}, callback); |
106 } | 106 } |
107 | 107 |
108 // Will call |callback(sinkList)| on completion. | 108 // Will call |callback(sinkList)| on completion. |
109 function getSinks(callback) { | 109 function getSinks(callback) { |
110 sendMessage({'method': 'getSinks'}, callback); | 110 sendMessage({'method': 'getSinks'}, callback); |
111 } | 111 } |
112 | 112 |
113 // Will call |callback(activeSink)| on completion. | |
114 function getActiveSink(callback) { | |
115 sendMessage({'method': 'getActiveSink'}, callback); | |
116 } | |
117 | |
118 // Will call |callback()| on completion. | |
119 function setActiveSink(sinkId, callback) { | |
120 sendMessage({'method': 'setActiveSink', 'sinkId': sinkId}, callback); | |
121 } | |
122 | |
123 // Will call |callback(sinkId)| on completion. | 113 // Will call |callback(sinkId)| on completion. |
124 function getAssociatedSink(sourceId, callback) { | 114 function getAssociatedSink(sourceId, callback) { |
125 sendMessage({'method': 'getAssociatedSink', 'sourceId': sourceId}, | 115 sendMessage({'method': 'getAssociatedSink', 'sourceId': sourceId}, |
126 callback); | 116 callback); |
127 } | 117 } |
128 | 118 |
129 // Will call |callback()| on completion. If the extension you send to | 119 // Will call |callback()| on completion. If the extension you send to |
130 // is not loaded, the extension system will still call |callback()| | 120 // is not loaded, the extension system will still call |callback()| |
131 // but will set lastError. | 121 // but will set lastError. |
132 function isExtensionEnabled(callback) { | 122 function isExtensionEnabled(callback) { |
133 sendMessage({'method': 'isExtensionEnabled'}, callback); | 123 sendMessage({'method': 'isExtensionEnabled'}, callback); |
134 } | 124 } |
135 | 125 |
136 // | 126 // |
137 // Automated tests. | 127 // Automated tests. |
138 // | 128 // |
139 | 129 |
140 // Very micro test framework. Add all tests to |TESTS|. Each test must | 130 // Very micro test framework. Add all tests to |TESTS|. Each test must |
141 // call the passed-in callback eventually with a string indicating | 131 // call the passed-in callback eventually with a string indicating |
142 // results. Empty results indicate success. | 132 // results. Empty results indicate success. |
143 var TESTS = [ | 133 var TESTS = [ |
144 testCpuGetInfo, | 134 testCpuGetInfo, |
145 testLogging, | 135 testLogging, |
146 testLoggingSetMetaDataAfterStart, | 136 testLoggingSetMetaDataAfterStart, |
147 testDisabledLogging, | 137 testDisabledLogging, |
148 testDisabledLoggingButUpload, | 138 testDisabledLoggingButUpload, |
149 testDisabledLoggingWithStopAndUpload, | 139 testDisabledLoggingWithStopAndUpload, |
150 testEnabledLoggingButDiscard, | 140 testEnabledLoggingButDiscard, |
151 testGetSinks, | 141 testGetSinks, |
152 testGetActiveSink, | |
153 testSetActiveSink, | |
154 testGetAssociatedSink, | 142 testGetAssociatedSink, |
155 testIsExtensionEnabled, | 143 testIsExtensionEnabled, |
156 testSendingToInvalidExtension, | 144 testSendingToInvalidExtension, |
157 testStoreLog, | 145 testStoreLog, |
158 | 146 |
159 // Uncomment to manually test timeout logic. | 147 // Uncomment to manually test timeout logic. |
160 //testTimeout, | 148 //testTimeout, |
161 ]; | 149 ]; |
162 | 150 |
163 var TEST_TIMEOUT_MS = 3000; | 151 var TEST_TIMEOUT_MS = 3000; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 } | 311 } |
324 | 312 |
325 function testGetSinks(callback) { | 313 function testGetSinks(callback) { |
326 getSinks(function(sinks) { | 314 getSinks(function(sinks) { |
327 // Some bots may have no audio sinks installed, in which case we | 315 // Some bots may have no audio sinks installed, in which case we |
328 // will get an empty list here. | 316 // will get an empty list here. |
329 callback(''); | 317 callback(''); |
330 }); | 318 }); |
331 } | 319 } |
332 | 320 |
333 function testGetActiveSink(callback) { | |
334 getActiveSink(function(sinkId) { | |
335 if (sinkId == '') { | |
336 callback('Got empty sink ID.'); | |
337 } else { | |
338 callback(''); | |
339 } | |
340 }); | |
341 } | |
342 | |
343 function testSetActiveSink(callback) { | |
344 getSinks(function(sinks) { | |
345 for (var i = 0; i < sinks.length; ++i) { | |
346 setActiveSink(sinks[i].sinkId); | |
347 } | |
348 callback(''); | |
349 }); | |
350 } | |
351 | |
352 function testGetAssociatedSink(callback) { | 321 function testGetAssociatedSink(callback) { |
353 getAssociatedSink('noSuchSourceId', function(sinkId) { | 322 getAssociatedSink('noSuchSourceId', function(sinkId) { |
354 if (sinkId != '') { | 323 if (sinkId != '') { |
355 callback('Got non-empty sink ID for nonexistent source ID.'); | 324 callback('Got non-empty sink ID for nonexistent source ID.'); |
356 } else { | 325 } else { |
357 callback(''); | 326 callback(''); |
358 } | 327 } |
359 }); | 328 }); |
360 } | 329 } |
361 | 330 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 }); | 371 }); |
403 }); | 372 }); |
404 }); | 373 }); |
405 }); | 374 }); |
406 } | 375 } |
407 | 376 |
408 function testTimeout(callback) { | 377 function testTimeout(callback) { |
409 // Never call the callback. Used for manually testing that the | 378 // Never call the callback. Used for manually testing that the |
410 // timeout logic of the test framework is correct. | 379 // timeout logic of the test framework is correct. |
411 } | 380 } |
OLD | NEW |