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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 // Will call |callback()| on completion. If the extension you send to | 114 // Will call |callback()| on completion. If the extension you send to |
115 // is not loaded, the extension system will still call |callback()| | 115 // is not loaded, the extension system will still call |callback()| |
116 // but will set lastError. | 116 // but will set lastError. |
117 function isExtensionEnabled(callback) { | 117 function isExtensionEnabled(callback) { |
118 sendMessage({'method': 'isExtensionEnabled'}, callback); | 118 sendMessage({'method': 'isExtensionEnabled'}, callback); |
119 } | 119 } |
120 | 120 |
121 // | 121 // |
122 // Manual tests. | |
123 // | |
124 | |
125 function manualTestChooseDesktopMedia() { | |
126 chooseDesktopMedia(function(results) { | |
127 alert('Cancel ID: ' + results.cancelId + | |
128 ', stream ID: ' + results.streamId); | |
129 }); | |
130 } | |
131 | |
132 function manualTestListenForSinksChangedEvent() { | |
133 listenForSinksChangedEvent(function(msg) { | |
134 if (msg['eventName'] && msg['eventName'] == 'onSinksChanged') | |
135 alert('Got onSinksChanged event.'); | |
136 }); | |
137 } | |
138 | |
139 // | |
140 // Automated tests. | 122 // Automated tests. |
141 // | 123 // |
142 | 124 |
143 // Very micro test framework. Add all tests to |TESTS|. Each test must | 125 // Very micro test framework. Add all tests to |TESTS|. Each test must |
144 // call the passed-in callback eventually with a string indicating | 126 // call the passed-in callback eventually with a string indicating |
145 // results. Empty results indicate success. | 127 // results. Empty results indicate success. |
146 var TESTS = [ | 128 var TESTS = [ |
147 testCpuGetInfo, | 129 testCpuGetInfo, |
148 testLogging, | 130 testLogging, |
149 testDisabledLogging, | 131 testDisabledLogging, |
150 testDisabledLoggingButUpload, | 132 testDisabledLoggingButUpload, |
151 testEnabledLoggingButDiscard, | 133 testEnabledLoggingButDiscard, |
152 testGetSinks, | 134 testGetSinks, |
153 testGetActiveSink, | 135 testGetActiveSink, |
154 testSetActiveSink, | 136 testSetActiveSink, |
155 testGetAssociatedSink, | 137 testGetAssociatedSink, |
156 testIsExtensionEnabled, | 138 testIsExtensionEnabled, |
157 testSendingToInvalidExtension, | 139 testSendingToInvalidExtension, |
158 | 140 |
159 // Uncomment to manually test timeout logic. | 141 // Uncomment to manually test timeout logic. |
160 //testTimeout, | 142 //testTimeout, |
161 ]; | 143 ]; |
162 | 144 |
| 145 var TEST_TIMEOUT_MS = 3000; |
| 146 |
163 function runAllTests(callback) { | 147 function runAllTests(callback) { |
164 var results = ''; | 148 var results = ''; |
165 | 149 |
166 // Run one test at a time, running the next only on completion. | 150 // Run one test at a time, running the next only on completion. |
167 // This makes it easier to deal with timing out tests that do not | 151 // This makes it easier to deal with timing out tests that do not |
168 // complete successfully. | 152 // complete successfully. |
169 // | 153 // |
170 // It also seems necessary (instead of starting all the tests in | 154 // It also seems necessary (instead of starting all the tests in |
171 // parallel) as the webrtcLoggingPrivate API does not seem to like | 155 // parallel) as the webrtcLoggingPrivate API does not seem to like |
172 // certain sequences of interleaved requests (it may DCHECK in | 156 // certain sequences of interleaved requests (it may DCHECK in |
(...skipping 10 matching lines...) Expand all Loading... |
183 | 167 |
184 // Start the test function... | 168 // Start the test function... |
185 test(function(currentResults) { | 169 test(function(currentResults) { |
186 nextTest(test.name, currentResults, false); | 170 nextTest(test.name, currentResults, false); |
187 }); | 171 }); |
188 | 172 |
189 // ...and also start a timeout. | 173 // ...and also start a timeout. |
190 function onTimeout() { | 174 function onTimeout() { |
191 nextTest(test.name, '', true); | 175 nextTest(test.name, '', true); |
192 } | 176 } |
193 setTimeout(onTimeout, 3000); | 177 setTimeout(onTimeout, TEST_TIMEOUT_MS); |
194 } | 178 } |
195 | 179 |
196 function nextTest(testName, currentResults, timedOut) { | 180 function nextTest(testName, currentResults, timedOut) { |
197 // The check for testIndex is necessary for timeouts arriving | 181 // The check for testIndex is necessary for timeouts arriving |
198 // after testIndex is already past the end of the TESTS array. | 182 // after testIndex is already past the end of the TESTS array. |
199 if (testIndex >= TESTS.length || | 183 if (testIndex >= TESTS.length || |
200 testName != TESTS[testIndex].name) { | 184 testName != TESTS[testIndex].name) { |
201 // Either a timeout of a function that already completed, or a | 185 // Either a timeout of a function that already completed, or a |
202 // function completing after a timeout. Either way we ignore. | 186 // function completing after a timeout. Either way we ignore. |
203 console.log('Ignoring results for ' + testName + | 187 console.log('Ignoring results for ' + testName + |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } else { | 333 } else { |
350 callback(''); | 334 callback(''); |
351 } | 335 } |
352 }); | 336 }); |
353 } | 337 } |
354 | 338 |
355 function testTimeout(callback) { | 339 function testTimeout(callback) { |
356 // Never call the callback. Used for manually testing that the | 340 // Never call the callback. Used for manually testing that the |
357 // timeout logic of the test framework is correct. | 341 // timeout logic of the test framework is correct. |
358 } | 342 } |
OLD | NEW |