Chromium Code Reviews| 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 // Returns a promise that fulfills after the provided |promise| is fulfilled. | |
| 9 // The |test| succeeds only if |promise| rejects with an exception matching | |
| 10 // |code|. Accepted values for |code| follow those accepted for assert_throws(). | |
| 11 // The optional |description| describes the test being performed. | |
| 12 // | |
| 13 // E.g.: | |
| 14 // assert_promise_rejects( | |
| 15 // new Promise(...), // something that should throw an exception. | |
| 16 // 'NotFoundError', | |
| 17 // 'Should throw NotFoundError.'); | |
| 18 // | |
| 19 // assert_promise_rejects( | |
| 20 // new Promise(...), | |
| 21 // new TypeError(), | |
| 22 // 'Should throw TypeError'); | |
| 23 function assert_promise_rejects(promise, code, description) { | |
| 24 return promise.then( | |
| 25 function() { | |
| 26 throw 'assert_promise_rejects: ' + description + ' Promise did not reject. '; | |
| 27 }, | |
| 28 function(e) { | |
| 29 if (code !== undefined) { | |
| 30 assert_throws(code, function() { throw e; }, description); | |
| 31 } | |
| 32 }); | |
| 33 } | |
| 34 | |
| 35 // Asserts that |object| that is an instance of some interface has the attribute | 8 // Asserts that |object| that is an instance of some interface has the attribute |
| 36 // |attribute_name| following the conditions specified by WebIDL, but it's | 9 // |attribute_name| following the conditions specified by WebIDL, but it's |
| 37 // acceptable that the attribute |attribute_name| is an own property of the | 10 // acceptable that the attribute |attribute_name| is an own property of the |
| 38 // object because we're in the middle of moving the attribute to a prototype | 11 // object because we're in the middle of moving the attribute to a prototype |
| 39 // chain. Once we complete the transition to prototype chains, | 12 // chain. Once we complete the transition to prototype chains, |
| 40 // assert_will_be_idl_attribute must be replaced with assert_idl_attribute | 13 // assert_will_be_idl_attribute must be replaced with assert_idl_attribute |
| 41 // defined in testharness.js. | 14 // defined in testharness.js. |
| 42 // | 15 // |
| 43 // FIXME: Remove assert_will_be_idl_attribute once we complete the transition | 16 // FIXME: Remove assert_will_be_idl_attribute once we complete the transition |
| 44 // of moving the DOM attributes to prototype chains. (http://crbug.com/43394) | 17 // of moving the DOM attributes to prototype chains. (http://crbug.com/43394) |
| 45 function assert_will_be_idl_attribute(object, attribute_name, description) { | 18 function assert_will_be_idl_attribute(object, attribute_name, description) { |
|
jsbell
2016/04/29 17:39:07
aside: we can probably remove this now (separate C
jsbell
2016/04/29 19:09:41
https://codereview.chromium.org/1936533003/
| |
| 46 assert_true(typeof object === "object", description); | 19 assert_true(typeof object === "object", description); |
| 47 | 20 |
| 48 assert_true("hasOwnProperty" in object, description); | 21 assert_true("hasOwnProperty" in object, description); |
| 49 | 22 |
| 50 // Do not test if |attribute_name| is not an own property because | 23 // Do not test if |attribute_name| is not an own property because |
| 51 // |attribute_name| is in the middle of the transition to a prototype | 24 // |attribute_name| is in the middle of the transition to a prototype |
| 52 // chain. (http://crbug.com/43394) | 25 // chain. (http://crbug.com/43394) |
| 53 | 26 |
| 54 assert_true(attribute_name in object, description); | 27 assert_true(attribute_name in object, description); |
| 55 } | 28 } |
| 56 | 29 |
| 57 // Stringifies a DOM object. This function stringifies not only own properties | 30 // Stringifies a DOM object. This function stringifies not only own properties |
| 58 // but also DOM attributes which are on a prototype chain. Note that | 31 // but also DOM attributes which are on a prototype chain. Note that |
| 59 // JSON.stringify only stringifies own properties. | 32 // JSON.stringify only stringifies own properties. |
| 60 function stringifyDOMObject(object) | 33 function stringifyDOMObject(object) |
|
jsbell
2016/04/29 17:39:07
aside: code search tells me there is now just one
jsbell
2016/04/29 21:16:42
https://codereview.chromium.org/1935703003
| |
| 61 { | 34 { |
| 62 function deepCopy(src) { | 35 function deepCopy(src) { |
| 63 if (typeof src != "object") | 36 if (typeof src != "object") |
| 64 return src; | 37 return src; |
| 65 var dst = Array.isArray(src) ? [] : {}; | 38 var dst = Array.isArray(src) ? [] : {}; |
| 66 for (var property in src) { | 39 for (var property in src) { |
| 67 dst[property] = deepCopy(src[property]); | 40 dst[property] = deepCopy(src[property]); |
| 68 } | 41 } |
| 69 return dst; | 42 return dst; |
| 70 } | 43 } |
| 71 return JSON.stringify(deepCopy(object)); | 44 return JSON.stringify(deepCopy(object)); |
| 72 } | 45 } |
| OLD | NEW |