| OLD | NEW |
| 1 ReflectionTests = {}; | 1 ReflectionTests = {}; |
| 2 | 2 |
| 3 ReflectionTests.start = new Date().getTime(); | 3 ReflectionTests.start = new Date().getTime(); |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Resolve the given URL to an absolute URL, relative to the current document's | 6 * Resolve the given URL to an absolute URL, relative to the current document's |
| 7 * address. There's no API that I know of that exposes this directly, so we | 7 * address. There's no API that I know of that exposes this directly, so we |
| 8 * actually just create an <a> element, set its href, and stitch together the | 8 * actually just create an <a> element, set its href, and stitch together the |
| 9 * various properties. Seems to work. We don't try to reimplement the | 9 * various properties. Seems to work. We don't try to reimplement the |
| 10 * algorithm here, because we're not concerned with its correctness -- we're | 10 * algorithm here, because we're not concerned with its correctness -- we're |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 * "domExpected": What values to expect with IDL get after setAttribute(). | 132 * "domExpected": What values to expect with IDL get after setAttribute(). |
| 133 * Defaults to the same as domTests. | 133 * Defaults to the same as domTests. |
| 134 * "idlTests": What values to test with IDL set. Defaults to domTests. | 134 * "idlTests": What values to test with IDL set. Defaults to domTests. |
| 135 * "idlDomExpected": What to expect from getAttribute() after IDL set. | 135 * "idlDomExpected": What to expect from getAttribute() after IDL set. |
| 136 * Defaults to idlTests. | 136 * Defaults to idlTests. |
| 137 * "idlIdlExpected": What to expect from IDL get after IDL set. Defaults to | 137 * "idlIdlExpected": What to expect from IDL get after IDL set. Defaults to |
| 138 * idlDomExpected. | 138 * idlDomExpected. |
| 139 * | 139 * |
| 140 * Note that all tests/expected values are only baselines, and can be expanded | 140 * Note that all tests/expected values are only baselines, and can be expanded |
| 141 * with additional tests hardcoded into the function for particular types if | 141 * with additional tests hardcoded into the function for particular types if |
| 142 * necessary (e.g., enum). null means "default" as a DOM expected value, and | 142 * necessary. For example, a special codepath is used for enums, and for |
| 143 * "throw an INDEX_SIZE_ERR exception" as an IDL expected value. (This is a | 143 * IDL setters which throw an exception. null means "defaultVal" is the |
| 144 * kind of stupid and fragile convention, but it's simple and works for now.) | 144 * expected value. Expected DOM values are cast to strings by adding "". |
| 145 * Expected DOM values are cast to strings by adding "". | |
| 146 * | 145 * |
| 147 * TODO: Test strings that aren't valid UTF-16. Desired behavior is not clear | 146 * TODO: Test strings that aren't valid UTF-16. Desired behavior is not clear |
| 148 * here at the time of writing, see | 147 * here at the time of writing, see |
| 149 * http://www.w3.org/Bugs/Public/show_bug.cgi?id=12100 | 148 * http://www.w3.org/Bugs/Public/show_bug.cgi?id=12100 |
| 150 * | 149 * |
| 151 * TODO: Test deleting an IDL attribute, and maybe doing other fun stuff to it. | 150 * TODO: Test deleting an IDL attribute, and maybe doing other fun stuff to it. |
| 152 * | 151 * |
| 153 * TODO: Test IDL sets of integer types to out-of-range or other weird values. | 152 * TODO: Test IDL sets of integer types to out-of-range or other weird values. |
| 154 * WebIDL says to wrap, but I'm not sure offhand if that's what we want. | 153 * WebIDL says to wrap, but I'm not sure offhand if that's what we want. |
| 155 * | 154 * |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 -Infinity, "\0", | 371 -Infinity, "\0", |
| 373 {toString:function() {return 2;}, valueOf: null}, | 372 {toString:function() {return 2;}, valueOf: null}, |
| 374 {valueOf:function() {return 3;}}], | 373 {valueOf:function() {return 3;}}], |
| 375 "domExpected": function(val) { | 374 "domExpected": function(val) { |
| 376 var parsed = ReflectionTests.parseNonneg(String(val)); | 375 var parsed = ReflectionTests.parseNonneg(String(val)); |
| 377 if (parsed === false || parsed > maxInt || parsed < minInt) { | 376 if (parsed === false || parsed > maxInt || parsed < minInt) { |
| 378 return null; | 377 return null; |
| 379 } | 378 } |
| 380 return parsed; | 379 return parsed; |
| 381 }, | 380 }, |
| 382 "idlTests": [minInt, -36, -1, 0, 1, maxInt], | 381 "idlTests": [minInt, -36, -1, 0, 1, maxInt], |
| 383 "idlDomExpected": [null, null, null, 0, 1, maxInt] | 382 "idlDomExpected": [null/*exception*/, null/*exception*/, null/*exception
*/, 0, 1, maxInt] |
| 384 }, | 383 }, |
| 385 /** | 384 /** |
| 386 * "If a reflecting IDL attribute is an unsigned integer type (unsigned | 385 * "If a reflecting IDL attribute is an unsigned integer type (unsigned |
| 387 * long) then, on getting, the content attribute must be parsed according | 386 * long) then, on getting, the content attribute must be parsed according |
| 388 * to the rules for parsing non-negative integers, and if that is | 387 * to the rules for parsing non-negative integers, and if that is |
| 389 * successful, and the value is in the range 0 to 2147483647 inclusive, the | 388 * successful, and the value is in the range 0 to 2147483647 inclusive, the |
| 390 * resulting value must be returned. If, on the other hand, it fails or | 389 * resulting value must be returned. If, on the other hand, it fails or |
| 391 * returns an out of range value, or if the attribute is absent, the | 390 * returns an out of range value, or if the attribute is absent, the |
| 392 * default value must be returned instead, or 0 if there is no default | 391 * default value must be returned instead, or 0 if there is no default |
| 393 * value. On setting, the given value must be converted to the shortest | 392 * value. On setting, the given value must be converted to the shortest |
| (...skipping 15 matching lines...) Expand all Loading... |
| 409 {toString:function() {return 2;}, valueOf: null}, | 408 {toString:function() {return 2;}, valueOf: null}, |
| 410 {valueOf:function() {return 3;}}], | 409 {valueOf:function() {return 3;}}], |
| 411 "domExpected": function(val) { | 410 "domExpected": function(val) { |
| 412 var parsed = ReflectionTests.parseNonneg(String(val)); | 411 var parsed = ReflectionTests.parseNonneg(String(val)); |
| 413 // Note maxInt, not maxUnsigned. | 412 // Note maxInt, not maxUnsigned. |
| 414 if (parsed === false || parsed < 0 || parsed > maxInt) { | 413 if (parsed === false || parsed < 0 || parsed > maxInt) { |
| 415 return null; | 414 return null; |
| 416 } | 415 } |
| 417 return parsed; | 416 return parsed; |
| 418 }, | 417 }, |
| 419 "idlTests": [0, 1, 257, 2147483647, "-0"], | 418 "idlTests": [0, 1, 257, maxInt, "-0", maxInt + 1, maxUnsigned], |
| 420 "idlIdlExpected": [0, 1, 257, 2147483647, 0] | 419 "idlIdlExpected": [0, 1, 257, maxInt, 0, null, null], |
| 420 "idlDomExpected": [0, 1, 257, maxInt, 0, null, null], |
| 421 }, | 421 }, |
| 422 /** | 422 /** |
| 423 * "If a reflecting IDL attribute is an unsigned integer type (unsigned | 423 * "If a reflecting IDL attribute is an unsigned integer type (unsigned |
| 424 * long) that is limited to only non-negative numbers greater than zero, | 424 * long) that is limited to only non-negative numbers greater than zero, |
| 425 * then the behavior is similar to the previous case, but zero is not | 425 * then the behavior is similar to the previous case, but zero is not |
| 426 * allowed. On getting, the content attribute must first be parsed | 426 * allowed. On getting, the content attribute must first be parsed |
| 427 * according to the rules for parsing non-negative integers, and if that is | 427 * according to the rules for parsing non-negative integers, and if that is |
| 428 * successful, and the value is in the range 1 to 2147483647 inclusive, the | 428 * successful, and the value is in the range 1 to 2147483647 inclusive, the |
| 429 * resulting value must be returned. If, on the other hand, it fails or | 429 * resulting value must be returned. If, on the other hand, it fails or |
| 430 * returns an out of range value, or if the attribute is absent, the | 430 * returns an out of range value, or if the attribute is absent, the |
| (...skipping 19 matching lines...) Expand all Loading... |
| 450 {toString:function() {return 2;}, valueOf: null}, | 450 {toString:function() {return 2;}, valueOf: null}, |
| 451 {valueOf:function() {return 3;}}], | 451 {valueOf:function() {return 3;}}], |
| 452 "domExpected": function(val) { | 452 "domExpected": function(val) { |
| 453 var parsed = ReflectionTests.parseNonneg(String(val)); | 453 var parsed = ReflectionTests.parseNonneg(String(val)); |
| 454 // Note maxInt, not maxUnsigned. | 454 // Note maxInt, not maxUnsigned. |
| 455 if (parsed === false || parsed < 1 || parsed > maxInt) { | 455 if (parsed === false || parsed < 1 || parsed > maxInt) { |
| 456 return null; | 456 return null; |
| 457 } | 457 } |
| 458 return parsed; | 458 return parsed; |
| 459 }, | 459 }, |
| 460 "idlTests": [0, 1, 2147483647], | 460 "idlTests": [0, 1, maxInt, maxInt + 1, maxUnsigned], |
| 461 "idlDomExpected": [null, 1, 2147483647] | 461 "idlDomExpected": [null/*exception*/, 1, maxInt, null, null] |
| 462 }, | 462 }, |
| 463 /** | 463 /** |
| 464 * "If a reflecting IDL attribute is a floating point number type (double), | 464 * "If a reflecting IDL attribute is a floating point number type (double), |
| 465 * then, on getting, the content attribute must be parsed according to the | 465 * then, on getting, the content attribute must be parsed according to the |
| 466 * rules for parsing floating point number values, and if that is | 466 * rules for parsing floating point number values, and if that is |
| 467 * successful, the resulting value must be returned. If, on the other hand, | 467 * successful, the resulting value must be returned. If, on the other hand, |
| 468 * it fails, or if the attribute is absent, the default value must be | 468 * it fails, or if the attribute is absent, the default value must be |
| 469 * returned instead, or 0.0 if there is no default value. On setting, the | 469 * returned instead, or 0.0 if there is no default value. On setting, the |
| 470 * given value must be converted to the best representation of the number | 470 * given value must be converted to the best representation of the number |
| 471 * as a floating point number and then that string must be used as the new | 471 * as a floating point number and then that string must be used as the new |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 if (defaultVal === undefined) { | 603 if (defaultVal === undefined) { |
| 604 defaultVal = typeInfo.defaultVal; | 604 defaultVal = typeInfo.defaultVal; |
| 605 } | 605 } |
| 606 if (defaultVal !== null) { | 606 if (defaultVal !== null) { |
| 607 ReflectionHarness.test(idlObj[idlName], defaultVal, "IDL get with DOM at
tribute unset"); | 607 ReflectionHarness.test(idlObj[idlName], defaultVal, "IDL get with DOM at
tribute unset"); |
| 608 } | 608 } |
| 609 | 609 |
| 610 var domTests = typeInfo.domTests.slice(0); | 610 var domTests = typeInfo.domTests.slice(0); |
| 611 var domExpected = typeInfo.domExpected.map(function(val) { return val === nu
ll ? defaultVal : val; }); | 611 var domExpected = typeInfo.domExpected.map(function(val) { return val === nu
ll ? defaultVal : val; }); |
| 612 var idlTests = typeInfo.idlTests.slice(0); | 612 var idlTests = typeInfo.idlTests.slice(0); |
| 613 var idlDomExpected = typeInfo.idlDomExpected.slice(0); | 613 var idlDomExpected = typeInfo.idlDomExpected.map(function(val) { return val
=== null ? defaultVal : val; }); |
| 614 var idlIdlExpected = typeInfo.idlIdlExpected.slice(0); | 614 var idlIdlExpected = typeInfo.idlIdlExpected.map(function(val) { return val
=== null ? defaultVal : val; }); |
| 615 switch (data.type) { | 615 switch (data.type) { |
| 616 // Extra tests and other special-casing | 616 // Extra tests and other special-casing |
| 617 case "boolean": | 617 case "boolean": |
| 618 domTests.push(domName); | 618 domTests.push(domName); |
| 619 domExpected.push(true); | 619 domExpected.push(true); |
| 620 break; | 620 break; |
| 621 | 621 |
| 622 case "enum": | 622 case "enum": |
| 623 // Whee, enum is complicated. | 623 // Whee, enum is complicated. |
| 624 if (typeof data.invalidVal == "undefined") { | 624 if (typeof data.invalidVal == "undefined") { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 if (ReflectionHarness.catchUnexpectedExceptions) { | 705 if (ReflectionHarness.catchUnexpectedExceptions) { |
| 706 ReflectionHarness.failure("Exception thrown during tests wit
h setAttribute() to " + ReflectionHarness.stringRep(domTests[i])); | 706 ReflectionHarness.failure("Exception thrown during tests wit
h setAttribute() to " + ReflectionHarness.stringRep(domTests[i])); |
| 707 } else { | 707 } else { |
| 708 throw err; | 708 throw err; |
| 709 } | 709 } |
| 710 } | 710 } |
| 711 } | 711 } |
| 712 } | 712 } |
| 713 | 713 |
| 714 for (var i = 0; i < idlTests.length; i++) { | 714 for (var i = 0; i < idlTests.length; i++) { |
| 715 if (idlDomExpected[i] === null && data.type != "enum") { | 715 if ((data.type == "limited long" && idlTests[i] < 0) || |
| 716 (data.type == "limited unsigned long" && idlTests[i] == 0)) { |
| 716 ReflectionHarness.testException("INDEX_SIZE_ERR", function() { | 717 ReflectionHarness.testException("INDEX_SIZE_ERR", function() { |
| 717 idlObj[idlName] = idlTests[i]; | 718 idlObj[idlName] = idlTests[i]; |
| 718 }, "IDL set to " + ReflectionHarness.stringRep(idlTests[i]) + " must
throw INDEX_SIZE_ERR"); | 719 }, "IDL set to " + ReflectionHarness.stringRep(idlTests[i]) + " must
throw INDEX_SIZE_ERR"); |
| 719 } else { | 720 } else { |
| 720 ReflectionHarness.run(function() { | 721 ReflectionHarness.run(function() { |
| 721 idlObj[idlName] = idlTests[i]; | 722 idlObj[idlName] = idlTests[i]; |
| 722 if (data.type == "boolean") { | 723 if (data.type == "boolean") { |
| 723 // Special case yay | 724 // Special case yay |
| 724 ReflectionHarness.test(domObj.hasAttribute(domName), Boolean
(idlTests[i]), "IDL set to " + ReflectionHarness.stringRep(idlTests[i]) + " foll
owed by hasAttribute()"); | 725 ReflectionHarness.test(domObj.hasAttribute(domName), Boolean
(idlTests[i]), "IDL set to " + ReflectionHarness.stringRep(idlTests[i]) + " foll
owed by hasAttribute()"); |
| 725 } else if (idlDomExpected[i] !== null) { | 726 } else if (idlDomExpected[i] !== null) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 var time = document.getElementById("time"); | 801 var time = document.getElementById("time"); |
| 801 if (time) { | 802 if (time) { |
| 802 time.innerHTML = (new Date().getTime() - ReflectionTests.start)/1000; | 803 time.innerHTML = (new Date().getTime() - ReflectionTests.start)/1000; |
| 803 } | 804 } |
| 804 | 805 |
| 805 if (unimplemented.length) { | 806 if (unimplemented.length) { |
| 806 var p = document.createElement("p"); | 807 var p = document.createElement("p"); |
| 807 p.textContent = "(Note: missing tests for types " + unimplemented.join(", ")
+ ".)"; | 808 p.textContent = "(Note: missing tests for types " + unimplemented.join(", ")
+ ".)"; |
| 808 document.body.appendChild(p); | 809 document.body.appendChild(p); |
| 809 } | 810 } |
| OLD | NEW |