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