| OLD | NEW |
| 1 var ReflectionHarness = {}; | 1 var ReflectionHarness = {}; |
| 2 | 2 |
| 3 // @private | 3 // @private |
| 4 ReflectionHarness.passed = document.getElementById("passed"); | 4 ReflectionHarness.passed = document.getElementById("passed"); |
| 5 ReflectionHarness.failed = document.getElementById("failed"); | 5 ReflectionHarness.failed = document.getElementById("failed"); |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * In conformance testing mode, all tests will be run. Otherwise, we'll skip | 8 * Should we report a failure for unexpected exceptions, or just rethrow them? |
| 9 * tests for attributes that have an entirely incorrect type. | 9 * The original test framework reports an exception, but testharness.js doesn't |
| 10 * want that. |
| 11 * |
| 12 * @public |
| 10 */ | 13 */ |
| 11 ReflectionHarness.conformanceTesting = false; | 14 ReflectionHarness.catchUnexpectedExceptions = true; |
| 12 | 15 |
| 13 /** | 16 /** |
| 14 * Returns a string representing val. Basically just adds quotes for strings, | 17 * Returns a string representing val. Basically just adds quotes for strings, |
| 15 * and passes through other recognized types literally. | 18 * and passes through other recognized types literally. |
| 16 * | 19 * |
| 17 * @public | 20 * @public |
| 18 */ | 21 */ |
| 19 ReflectionHarness.stringRep = function(val) { | 22 ReflectionHarness.stringRep = function(val) { |
| 20 if (val === null) { | 23 if (val === null) { |
| 21 // typeof is object, so the switch isn't useful | 24 // typeof is object, so the switch isn't useful |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 79 } |
| 77 } | 80 } |
| 78 | 81 |
| 79 /** | 82 /** |
| 80 * An object representing info about the current test, used for printing out | 83 * An object representing info about the current test, used for printing out |
| 81 * nice messages and so forth. | 84 * nice messages and so forth. |
| 82 */ | 85 */ |
| 83 ReflectionHarness.currentTestInfo = {}; | 86 ReflectionHarness.currentTestInfo = {}; |
| 84 | 87 |
| 85 /** | 88 /** |
| 86 * .test() sets this, and it's used by .assertEquals()/.assertThrows(). | 89 * This is called when we want to test a single element/attribute combination. |
| 87 * Calling .test() recursively is an error. | 90 * For the original harness, it does nothing special (just calls the function), |
| 91 * but for testharness.js, it can wrap everything in a test() call. |
| 88 */ | 92 */ |
| 89 ReflectionHarness.currentTestDescription = null; | 93 ReflectionHarness.testWrapper = function(fn) { |
| 90 | 94 fn(); |
| 91 /** | |
| 92 * Run a group of one or more assertions. If any exceptions are thrown, catch | |
| 93 * them and report a failure. | |
| 94 */ | |
| 95 ReflectionHarness.test = function(fn, description) { | |
| 96 if (this.currentTestDescription) { | |
| 97 throw "TEST BUG: test() may not be called recursively!"; | |
| 98 } | |
| 99 this.currentTestDescription = description; | |
| 100 try { | |
| 101 fn(); | |
| 102 // Not throwing is a success | |
| 103 this.success(); | |
| 104 } catch(err) { | |
| 105 this.failure("Exception thrown during tests with " + description); | |
| 106 } | |
| 107 this.currentTestDescription = null; | |
| 108 } | 95 } |
| 109 | 96 |
| 110 /** | 97 /** |
| 111 * If question === answer, output a success, else report a failure with the | 98 * If question === answer, output a success, else report a failure with the |
| 112 * given description. Currently success and failure both increment counters, | 99 * given description. Currently success and failure both increment counters, |
| 113 * and failures output a message to a <ul>. Which <ul> is decided by the type | 100 * and failures output a message to a <ul>. Which <ul> is decided by the type |
| 114 * parameter -- different attribute types are separated for readability. | 101 * parameter -- different attribute types are separated for readability. |
| 115 * | 102 * |
| 116 * @public | 103 * @public |
| 117 */ | 104 */ |
| 118 ReflectionHarness.assertEquals = function(expected, actual, description) { | 105 ReflectionHarness.test = function(expected, actual, description) { |
| 119 // Special-case -0 yay! | 106 // Special-case -0 yay! |
| 120 if (expected === 0 && actual === 0 && 1/expected === 1/actual) { | 107 if (expected === 0 && actual === 0 && 1/expected === 1/actual) { |
| 121 this.increment(this.passed); | 108 this.increment(this.passed); |
| 109 return true; |
| 122 } else if (expected === actual) { | 110 } else if (expected === actual) { |
| 123 this.increment(this.passed); | 111 this.increment(this.passed); |
| 112 return true; |
| 124 } else { | 113 } else { |
| 125 this.increment(this.failed); | 114 this.increment(this.failed); |
| 126 this.reportFailure(this.currentTestDescription + | 115 this.reportFailure(description + ' (expected ' + this.stringRep(actual) + ',
got ' + this.stringRep(expected) + ')'); |
| 127 (description ? " followed by " + description : "") + | 116 return false; |
| 128 ' (expected ' + this.stringRep(actual) + ', got ' + | 117 } |
| 129 this.stringRep(expected) + ')'); | 118 } |
| 119 |
| 120 ReflectionHarness.run = function(fun, description) { |
| 121 try { |
| 122 fun(); |
| 123 } catch (err) { |
| 124 ReflectionHarness.failure(description); |
| 130 } | 125 } |
| 131 } | 126 } |
| 132 | 127 |
| 133 /** | 128 /** |
| 134 * If calling fn causes a DOMException of the type given by the string | 129 * If calling fn causes a DOMException of the type given by the string |
| 135 * exceptionName (e.g., "IndexSizeError"), output a success. Otherwise, report | 130 * exceptionName (e.g., "INDEX_SIZE_ERR"), output a success. Otherwise, report |
| 136 * a failure. | 131 * a failure with the given description. |
| 137 * | 132 * |
| 138 * @public | 133 * @public |
| 139 */ | 134 */ |
| 140 ReflectionHarness.assertThrows = function(exceptionName, fn) { | 135 ReflectionHarness.testException = function(exceptionName, fn, description) { |
| 141 try { | 136 try { |
| 142 fn(); | 137 fn(); |
| 143 } catch (e) { | 138 } catch (e) { |
| 144 if (e instanceof DOMException && e.code == DOMException[exceptionName]) { | 139 if (e instanceof DOMException && e.code == DOMException[exceptionName]) { |
| 145 this.increment(this.passed); | 140 this.increment(this.passed); |
| 146 return true; | 141 return true; |
| 147 } | 142 } |
| 148 } | 143 } |
| 149 this.increment(this.failed); | 144 this.increment(this.failed); |
| 150 this.reportFailure(this.currentTestDescription + " must throw " + | 145 this.reportFailure(description); |
| 151 exceptionName); | |
| 152 return false; | 146 return false; |
| 153 } | 147 } |
| 154 | 148 |
| 155 /** | 149 /** |
| 156 * Get a description of the current type, e.g., "a.href". | 150 * Get a description of the current type, e.g., "a.href". |
| 157 */ | 151 */ |
| 158 ReflectionHarness.getTypeDescription = function() { | 152 ReflectionHarness.getTypeDescription = function() { |
| 159 var domNode = this.currentTestInfo.domObj.tagName.toLowerCase(); | 153 var domNode = this.currentTestInfo.domObj.tagName.toLowerCase(); |
| 160 var idlNode = this.currentTestInfo.idlObj.nodeName.toLowerCase(); | 154 var idlNode = this.currentTestInfo.idlObj.nodeName.toLowerCase(); |
| 161 var domName = this.currentTestInfo.domName; | 155 var domName = this.currentTestInfo.domName; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } | 241 } |
| 248 | 242 |
| 249 if (type == "undefined") { | 243 if (type == "undefined") { |
| 250 ul.innerHTML += "<li>" + typeDesc; | 244 ul.innerHTML += "<li>" + typeDesc; |
| 251 } else { | 245 } else { |
| 252 ul.innerHTML += "<li><span class=\"type\">" + typeDesc + "</span>: <span cla
ss=\"desc\">" + description + "</span>"; | 246 ul.innerHTML += "<li><span class=\"type\">" + typeDesc + "</span>: <span cla
ss=\"desc\">" + description + "</span>"; |
| 253 } | 247 } |
| 254 } | 248 } |
| 255 | 249 |
| 256 /** | 250 /** |
| 257 * Shorthand function for when we have a failure outside of | 251 * Shorthand function for when we have a failure outside of test(). Generally |
| 258 * assertEquals()/assertThrows(). Generally used when the failure is an | 252 * used when the failure is an exception thrown unexpectedly or such, something |
| 259 * exception thrown unexpectedly or such, something not equality-based. | 253 * not equality-based. |
| 260 * | 254 * |
| 261 * @public | 255 * @public |
| 262 */ | 256 */ |
| 263 ReflectionHarness.failure = function(message) { | 257 ReflectionHarness.failure = function(message) { |
| 264 this.increment(this.failed); | 258 this.increment(this.failed); |
| 265 this.reportFailure(message); | 259 this.reportFailure(message); |
| 266 } | 260 } |
| 267 | 261 |
| 268 /** | 262 /** |
| 269 * Shorthand function for when we have a success outside of | 263 * Shorthand function for when we have a success outside of test(). Only |
| 270 * assertEquals()/assertThrows(). | 264 * called if catchUnexpectedExceptions is true. |
| 271 * | 265 * |
| 272 * @public | 266 * @public |
| 273 */ | 267 */ |
| 274 ReflectionHarness.success = function() { | 268 ReflectionHarness.success = function() { |
| 275 this.increment(this.passed); | 269 this.increment(this.passed); |
| 276 } | 270 } |
| 277 | 271 |
| 278 /** | 272 /** |
| 279 * Increment the count in either "passed" or "failed". el should always be one | 273 * Increment the count in either "passed" or "failed". el should always be one |
| 280 * of those two variables. The implementation of this function amuses me. | 274 * of those two variables. The implementation of this function amuses me. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 continue; | 323 continue; |
| 330 } | 324 } |
| 331 | 325 |
| 332 if (key in elements) { | 326 if (key in elements) { |
| 333 elements[key] = elements[key].concat(src[key]); | 327 elements[key] = elements[key].concat(src[key]); |
| 334 } else { | 328 } else { |
| 335 elements[key] = src[key]; | 329 elements[key] = src[key]; |
| 336 } | 330 } |
| 337 } | 331 } |
| 338 } | 332 } |
| OLD | NEW |