| OLD | NEW |
| 1 /* | 1 /* |
| 2 * testharness-helpers contains various useful extensions to testharness.js to | 2 * testharness-helpers contains various useful extensions to testharness.js to |
| 3 * allow them to be used across multiple tests before they have been | 3 * allow them to be used across multiple tests before they have been |
| 4 * upstreamed. This file is intended to be usable from both document and worker | 4 * upstreamed. This file is intended to be usable from both document and worker |
| 5 * environments, so code should for example not rely on the DOM. | 5 * environments, so code should for example not rely on the DOM. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 // A testharness test that simplifies testing with promises. | 8 // A testharness test that simplifies testing with promises. |
| 9 // | 9 // |
| 10 // * The |func| argument should be a reference to a function that optionally | 10 // * The |func| argument should be a reference to a function that optionally |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 _is_equal(actual[property], expected[property], | 96 _is_equal(actual[property], expected[property], |
| 97 prefix + '.' + property); | 97 prefix + '.' + property); |
| 98 }); | 98 }); |
| 99 Object.getOwnPropertyNames(actual).forEach(function(property) { | 99 Object.getOwnPropertyNames(actual).forEach(function(property) { |
| 100 assert_own_property(expected, property, prefix); | 100 assert_own_property(expected, property, prefix); |
| 101 }); | 101 }); |
| 102 | 102 |
| 103 object_stack.pop(); | 103 object_stack.pop(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 function _brand(object) { |
| 107 return Object.prototype.toString.call(object).match(/^\[object (.*)\]$/)[1]; |
| 108 } |
| 109 |
| 106 _is_equal(actual, expected, | 110 _is_equal(actual, expected, |
| 107 (description ? description + ' :' : '') + '[object]'); | 111 (description ? description + ': ' : '') + _brand(actual)); |
| 108 }; | 112 }; |
| 109 | 113 |
| 110 // Equivalent to assert_in_array, but uses a weaker equivalence relation | 114 // Equivalent to assert_in_array, but uses a weaker equivalence relation |
| 111 // (assert_object_equals) than '==='. | 115 // (assert_object_equals) than '==='. |
| 112 function assert_object_in_array(actual, expected_array, description) { | 116 function assert_object_in_array(actual, expected_array, description) { |
| 113 assert_true(expected_array.some(function(element) { | 117 assert_true(expected_array.some(function(element) { |
| 114 try { | 118 try { |
| 115 assert_object_equals(actual, element); | 119 assert_object_equals(actual, element); |
| 116 return true; | 120 return true; |
| 117 } catch (e) { | 121 } catch (e) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 141 // elements as determined by assert_object_equals(). The corresponding elements | 145 // elements as determined by assert_object_equals(). The corresponding elements |
| 142 // must occupy corresponding indices in their respective arrays. | 146 // must occupy corresponding indices in their respective arrays. |
| 143 function assert_array_objects_equals(actual, expected, description) { | 147 function assert_array_objects_equals(actual, expected, description) { |
| 144 assert_true(Array.isArray(actual), description); | 148 assert_true(Array.isArray(actual), description); |
| 145 assert_equals(actual.length, expected.length, description); | 149 assert_equals(actual.length, expected.length, description); |
| 146 actual.forEach(function(value, index) { | 150 actual.forEach(function(value, index) { |
| 147 assert_object_equals(value, expected[index], | 151 assert_object_equals(value, expected[index], |
| 148 description + ' : object[' + index + ']'); | 152 description + ' : object[' + index + ']'); |
| 149 }); | 153 }); |
| 150 } | 154 } |
| OLD | NEW |