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 /** | 5 /** |
6 * Tests that an observation matches the expected value. | 6 * Tests that an observation matches the expected value. |
7 * @param {Object} expected The expected value. | 7 * @param {Object} expected The expected value. |
8 * @param {Object} observed The actual value. | 8 * @param {Object} observed The actual value. |
9 * @param {string=} opt_message Optional message to include with a test | 9 * @param {string=} opt_message Optional message to include with a test |
10 * failure. | 10 * failure. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 try { | 65 try { |
66 f(); | 66 f(); |
67 } catch(err) { | 67 } catch(err) { |
68 triggeredError = true; | 68 triggeredError = true; |
69 } | 69 } |
70 if (!triggeredError) | 70 if (!triggeredError) |
71 throw new Error('Assertion Failed: throw expected.'); | 71 throw new Error('Assertion Failed: throw expected.'); |
72 } | 72 } |
73 | 73 |
74 /** | 74 /** |
75 * Verifies that the contents of the expected and observed arrays match. | |
76 * @param {Array} expected The expected result. | |
Dan Beam
2013/06/20 21:38:03
!Array
kevers
2013/06/21 13:30:49
Done.
| |
77 * @param {Array} observed The actual result. | |
78 */ | |
79 function assertArrayEquals(expected, observed) { | |
80 var v1 = Array.prototype.slice.call(expected); | |
Dan Beam
2013/06/20 21:38:03
Array.prototype.slice.call(null)
TypeError: Array.
| |
81 var v2 = Array.prototype.slice.call(observed); | |
82 var equal = v1.length == v2.length; | |
83 if (equal) { | |
84 for (var i = 0; i < v1.length; i++) { | |
85 if (v1[i] !== v2[i]) { | |
86 equal = false; | |
87 break; | |
88 } | |
89 } | |
90 } | |
91 if (!equal) { | |
92 var message = 'Assertion Failed\n Observed: ' + v2 + | |
93 '\n Expected: ' + v1; | |
94 throw new Error(message); | |
95 } | |
96 } | |
97 | |
98 /** | |
75 * Runs all functions starting with test and reports success or | 99 * Runs all functions starting with test and reports success or |
76 * failure of the test suite. | 100 * failure of the test suite. |
77 */ | 101 */ |
78 function runTests() { | 102 function runTests() { |
79 var tests = []; | 103 var tests = []; |
80 | 104 |
81 if (window.setUp) | 105 if (window.setUp) |
82 window.setUp(); | 106 window.setUp(); |
83 | 107 |
84 var success = true; | 108 var success = true; |
(...skipping 26 matching lines...) Expand all Loading... | |
111 * @param {boolean} success Indicates if the test completed successfully. | 135 * @param {boolean} success Indicates if the test completed successfully. |
112 */ | 136 */ |
113 function endTests(success) { | 137 function endTests(success) { |
114 domAutomationController.setAutomationId(1); | 138 domAutomationController.setAutomationId(1); |
115 domAutomationController.send(success ? 'SUCCESS' : 'FAILURE'); | 139 domAutomationController.send(success ? 'SUCCESS' : 'FAILURE'); |
116 } | 140 } |
117 | 141 |
118 window.onerror = function() { | 142 window.onerror = function() { |
119 endTests(false); | 143 endTests(false); |
120 }; | 144 }; |
OLD | NEW |