| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // These must match with how the video and canvas tags are declared in html. | 5 // These must match with how the video and canvas tags are declared in html. |
| 6 const VIDEO_TAG_WIDTH = 320; | 6 const VIDEO_TAG_WIDTH = 320; |
| 7 const VIDEO_TAG_HEIGHT = 240; | 7 const VIDEO_TAG_HEIGHT = 240; |
| 8 | 8 |
| 9 // Fake video capture background green is of value 135. | 9 // Fake video capture background green is of value 135. |
| 10 const COLOR_BACKGROUND_GREEN = 135; | 10 const COLOR_BACKGROUND_GREEN = 135; |
| 11 | 11 |
| 12 // Number of test events to occur before the test pass. When the test pass, | 12 // Number of test events to occur before the test pass. When the test pass, |
| 13 // the function gAllEventsOccured is called. | 13 // the function gAllEventsOccured is called. |
| 14 var gNumberOfExpectedEvents = 0; | 14 var gNumberOfExpectedEvents = 0; |
| 15 | 15 |
| 16 // Number of events that currently have occurred. | 16 // Number of events that currently have occurred. |
| 17 var gNumberOfEvents = 0; | 17 var gNumberOfEvents = 0; |
| 18 | 18 |
| 19 var gAllEventsOccured = function () {}; | 19 var gAllEventsOccured = function () {}; |
| 20 | 20 |
| 21 var gPendingTimeout; |
| 22 |
| 21 // Use this function to set a function that will be called once all expected | 23 // Use this function to set a function that will be called once all expected |
| 22 // events has occurred. | 24 // events has occurred. |
| 23 function setAllEventsOccuredHandler(handler) { | 25 function setAllEventsOccuredHandler(handler) { |
| 24 gAllEventsOccured = handler; | 26 gAllEventsOccured = handler; |
| 25 } | 27 } |
| 26 | 28 |
| 27 // Tells the C++ code we succeeded, which will generally exit the test. | 29 // Tells the C++ code we succeeded, which will generally exit the test. |
| 28 function reportTestSuccess() { | 30 function reportTestSuccess() { |
| 29 console.log('Test Success'); | 31 console.log('Test Success'); |
| 30 window.domAutomationController.send('OK'); | 32 window.domAutomationController.send('OK'); |
| 31 } | 33 } |
| 32 | 34 |
| 33 // Returns a custom return value to the test. | 35 // Returns a custom return value to the test. |
| 34 function sendValueToTest(value) { | 36 function sendValueToTest(value) { |
| 35 window.domAutomationController.send(value); | 37 window.domAutomationController.send(value); |
| 36 } | 38 } |
| 37 | 39 |
| 38 // Immediately fails the test on the C++ side. | 40 // Immediately fails the test on the C++ side. |
| 39 function failTest(reason) { | 41 function failTest(reason) { |
| 40 var error = new Error(reason); | 42 var error = new Error(reason); |
| 41 window.domAutomationController.send(error.stack); | 43 window.domAutomationController.send(error.stack); |
| 42 } | 44 } |
| 43 | 45 |
| 46 // Fail a test on the C++ side after a timeout. Will cancel any pending timeout. |
| 47 function failTestAfterTimeout(reason, timeout_ms) { |
| 48 cancelTestTimeout(); |
| 49 gPendingTimeout = setTimeout(function() { |
| 50 failTest(reason); |
| 51 }, timeout_ms); |
| 52 } |
| 53 |
| 54 // Cancels the current test timeout. |
| 55 function cancelTestTimeout() { |
| 56 clearTimeout(gPendingTimeout); |
| 57 gPendingTimeout = null; |
| 58 } |
| 59 |
| 44 // Called if getUserMedia fails. | 60 // Called if getUserMedia fails. |
| 45 function printGetUserMediaError(error) { | 61 function printGetUserMediaError(error) { |
| 46 var message = 'getUserMedia request unexpectedly failed:'; | 62 var message = 'getUserMedia request unexpectedly failed:'; |
| 47 if (error.constraintName) | 63 if (error.constraintName) |
| 48 message += ' could not satisfy constraint ' + error.constraintName; | 64 message += ' could not satisfy constraint ' + error.constraintName; |
| 49 else | 65 else |
| 50 message += ' devices not working/user denied access.'; | 66 message += ' devices not working/user denied access.'; |
| 51 failTest(message); | 67 failTest(message); |
| 52 } | 68 } |
| 53 | 69 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if (actual === expected) { | 271 if (actual === expected) { |
| 256 failTest("expected '" + expected + "', got '" + actual + "'."); | 272 failTest("expected '" + expected + "', got '" + actual + "'."); |
| 257 } | 273 } |
| 258 } | 274 } |
| 259 | 275 |
| 260 function assertTrue(booleanExpression, description) { | 276 function assertTrue(booleanExpression, description) { |
| 261 if (!booleanExpression) { | 277 if (!booleanExpression) { |
| 262 failTest(description); | 278 failTest(description); |
| 263 } | 279 } |
| 264 } | 280 } |
| 265 | |
| OLD | NEW |