| 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. | 8 // Returns a promise that fulfills after the provided |promise| is fulfilled. |
| 9 // The |test| succeeds only if |promise| rejects with an exception matching | 9 // The |test| succeeds only if |promise| rejects with an exception matching |
| 10 // |code|. Accepted values for |code| follow those accepted for assert_throws(). | 10 // |code|. Accepted values for |code| follow those accepted for assert_throws(). |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 return promise.then( | 24 return promise.then( |
| 25 function() { | 25 function() { |
| 26 throw 'assert_promise_rejects: ' + description + ' Promise did not reject.
'; | 26 throw 'assert_promise_rejects: ' + description + ' Promise did not reject.
'; |
| 27 }, | 27 }, |
| 28 function(e) { | 28 function(e) { |
| 29 if (code !== undefined) { | 29 if (code !== undefined) { |
| 30 assert_throws(code, function() { throw e; }, description); | 30 assert_throws(code, function() { throw e; }, description); |
| 31 } | 31 } |
| 32 }); | 32 }); |
| 33 } | 33 } |
| 34 | |
| 35 // Stringifies a DOM object. This function stringifies not only own properties | |
| 36 // but also DOM attributes which are on a prototype chain. Note that | |
| 37 // JSON.stringify only stringifies own properties. | |
| 38 function stringifyDOMObject(object) | |
| 39 { | |
| 40 function deepCopy(src) { | |
| 41 if (typeof src != "object") | |
| 42 return src; | |
| 43 var dst = Array.isArray(src) ? [] : {}; | |
| 44 for (var property in src) { | |
| 45 dst[property] = deepCopy(src[property]); | |
| 46 } | |
| 47 return dst; | |
| 48 } | |
| 49 return JSON.stringify(deepCopy(object)); | |
| 50 } | |
| OLD | NEW |