| 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 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 } | 560 } |
| 561 if (domObj === undefined) { | 561 if (domObj === undefined) { |
| 562 domObj = idlObj; | 562 domObj = idlObj; |
| 563 } | 563 } |
| 564 | 564 |
| 565 // Note: probably a hack? This kind of assumes that the variables here | 565 // Note: probably a hack? This kind of assumes that the variables here |
| 566 // won't change over the course of the tests, which is wrong, but it's | 566 // won't change over the course of the tests, which is wrong, but it's |
| 567 // probably safe enough. Just don't read stuff that will change. | 567 // probably safe enough. Just don't read stuff that will change. |
| 568 ReflectionHarness.currentTestInfo = {data: data, idlName: idlName, idlObj: i
dlObj, domName: domName, domObj: domObj}; | 568 ReflectionHarness.currentTestInfo = {data: data, idlName: idlName, idlObj: i
dlObj, domName: domName, domObj: domObj}; |
| 569 | 569 |
| 570 ReflectionHarness.testWrapper(function() { | |
| 571 ReflectionTests.doReflects(data, idlName, idlObj, domName, domObj); | |
| 572 }); | |
| 573 }; | |
| 574 | |
| 575 /** | |
| 576 * Actual implementation of the above. | |
| 577 */ | |
| 578 ReflectionTests.doReflects = function(data, idlName, idlObj, domName, domObj) { | |
| 579 // If we don't recognize the type, testing is impossible. | 570 // If we don't recognize the type, testing is impossible. |
| 580 if (this.typeMap[data.type] === undefined) { | 571 if (this.typeMap[data.type] === undefined) { |
| 581 if (unimplemented.indexOf(data.type) == -1) { | 572 if (unimplemented.indexOf(data.type) == -1) { |
| 582 unimplemented.push(data.type); | 573 unimplemented.push(data.type); |
| 583 } | 574 } |
| 584 return; | 575 return; |
| 585 } | 576 } |
| 586 | 577 |
| 587 var typeInfo = this.typeMap[data.type]; | 578 var typeInfo = this.typeMap[data.type]; |
| 588 | 579 |
| 589 if (typeof data.isNullable == "undefined") { | 580 if (typeof data.isNullable == "undefined") { |
| 590 data.isNullable = false; | 581 data.isNullable = false; |
| 591 } | 582 } |
| 592 | 583 |
| 593 // Test that typeof idlObj[idlName] is correct. If not, further tests are | 584 // Test that typeof idlObj[idlName] is correct. If not, further tests are |
| 594 // probably pointless, so bail out. | 585 // probably pointless, so bail out if we're not running conformance tests. |
| 595 var isDefaultValueNull = data.isNullable && data.defaultVal === null; | 586 var expectedType = data.isNullable && data.defaultVal === null ? "object" |
| 596 if (!ReflectionHarness.test(typeof idlObj[idlName], isDefaultValueNull ? "ob
ject" : typeInfo.jsType, "typeof IDL attribute")) { | 587 : typeInfo.js
Type; |
| 588 ReflectionHarness.test(function() { |
| 589 ReflectionHarness.assertEquals(typeof idlObj[idlName], expectedType); |
| 590 }, "typeof IDL attribute"); |
| 591 |
| 592 if (!ReflectionHarness.conformanceTesting && |
| 593 typeof idlObj[idlName] !== expectedType) { |
| 597 return; | 594 return; |
| 598 } | 595 } |
| 599 | 596 |
| 600 // Test default | 597 // Test default |
| 601 var defaultVal = data.defaultVal; | 598 var defaultVal = data.defaultVal; |
| 602 if (defaultVal === undefined) { | 599 if (defaultVal === undefined) { |
| 603 defaultVal = typeInfo.defaultVal; | 600 defaultVal = typeInfo.defaultVal; |
| 604 } | 601 } |
| 605 if (defaultVal !== null || data.isNullable) { | 602 if (defaultVal !== null || data.isNullable) { |
| 606 ReflectionHarness.test(idlObj[idlName], defaultVal, "IDL get with DOM at
tribute unset"); | 603 ReflectionHarness.test(function() { |
| 604 ReflectionHarness.assertEquals(idlObj[idlName], defaultVal); |
| 605 }, "IDL get with DOM attribute unset"); |
| 607 } | 606 } |
| 608 | 607 |
| 609 var domTests = typeInfo.domTests.slice(0); | 608 var domTests = typeInfo.domTests.slice(0); |
| 610 var domExpected = typeInfo.domExpected.map(function(val) { return val === nu
ll ? defaultVal : val; }); | 609 var domExpected = typeInfo.domExpected.map(function(val) { return val === nu
ll ? defaultVal : val; }); |
| 611 var idlTests = typeInfo.idlTests.slice(0); | 610 var idlTests = typeInfo.idlTests.slice(0); |
| 612 var idlDomExpected = typeInfo.idlDomExpected.map(function(val) { return val
=== null ? defaultVal : val; }); | 611 var idlDomExpected = typeInfo.idlDomExpected.map(function(val) { return val
=== null ? defaultVal : val; }); |
| 613 var idlIdlExpected = typeInfo.idlIdlExpected.map(function(val) { return val
=== null ? defaultVal : val; }); | 612 var idlIdlExpected = typeInfo.idlIdlExpected.map(function(val) { return val
=== null ? defaultVal : val; }); |
| 614 switch (data.type) { | 613 switch (data.type) { |
| 615 // Extra tests and other special-casing | 614 // Extra tests and other special-casing |
| 616 case "boolean": | 615 case "boolean": |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 | 696 |
| 698 if (!data.customGetter) { | 697 if (!data.customGetter) { |
| 699 for (var i = 0; i < domTests.length; i++) { | 698 for (var i = 0; i < domTests.length; i++) { |
| 700 if (domExpected[i] === null && !data.isNullable) { | 699 if (domExpected[i] === null && !data.isNullable) { |
| 701 // If you follow all the complicated logic here, you'll find tha
t | 700 // If you follow all the complicated logic here, you'll find tha
t |
| 702 // this will only happen if there's no expected value at all (li
ke | 701 // this will only happen if there's no expected value at all (li
ke |
| 703 // for tabIndex, where the default is too complicated). So skip | 702 // for tabIndex, where the default is too complicated). So skip |
| 704 // the test. | 703 // the test. |
| 705 continue; | 704 continue; |
| 706 } | 705 } |
| 707 try { | 706 ReflectionHarness.test(function() { |
| 708 domObj.setAttribute(domName, domTests[i]); | 707 domObj.setAttribute(domName, domTests[i]); |
| 709 ReflectionHarness.test(domObj.getAttribute(domName), String(domT
ests[i]), "setAttribute() to " + ReflectionHarness.stringRep(domTests[i]) + " fo
llowed by getAttribute()"); | 708 ReflectionHarness.assertEquals(domObj.getAttribute(domName), |
| 710 ReflectionHarness.test(idlObj[idlName], domExpected[i], "setAttr
ibute() to " + ReflectionHarness.stringRep(domTests[i]) + " followed by IDL get"
); | 709 String(domTests[i]), "getAttribute()"); |
| 711 if (ReflectionHarness.catchUnexpectedExceptions) { | 710 ReflectionHarness.assertEquals(idlObj[idlName], domExpected[i], |
| 712 ReflectionHarness.success(); | 711 "IDL get"); |
| 713 } | 712 }, "setAttribute() to " + ReflectionHarness.stringRep(domTests[i])); |
| 714 } catch (err) { | |
| 715 if (ReflectionHarness.catchUnexpectedExceptions) { | |
| 716 ReflectionHarness.failure("Exception thrown during tests wit
h setAttribute() to " + ReflectionHarness.stringRep(domTests[i])); | |
| 717 } else { | |
| 718 throw err; | |
| 719 } | |
| 720 } | |
| 721 } | 713 } |
| 722 } | 714 } |
| 723 | 715 |
| 724 for (var i = 0; i < idlTests.length; i++) { | 716 for (var i = 0; i < idlTests.length; i++) { |
| 725 if ((data.type == "limited long" && idlTests[i] < 0) || | 717 ReflectionHarness.test(function() { |
| 726 (data.type == "limited unsigned long" && idlTests[i] == 0)) { | 718 if ((data.type == "limited long" && idlTests[i] < 0) || |
| 727 ReflectionHarness.testException("INDEX_SIZE_ERR", function() { | 719 (data.type == "limited unsigned long" && idlTests[i] == 0)) { |
| 728 idlObj[idlName] = idlTests[i]; | 720 ReflectionHarness.assertThrows("IndexSizeError", function() { |
| 729 }, "IDL set to " + ReflectionHarness.stringRep(idlTests[i]) + " must
throw INDEX_SIZE_ERR"); | 721 idlObj[idlName] = idlTests[i]; |
| 730 } else { | 722 }); |
| 731 ReflectionHarness.run(function() { | 723 } else { |
| 732 idlObj[idlName] = idlTests[i]; | 724 idlObj[idlName] = idlTests[i]; |
| 733 if (data.type == "boolean") { | 725 if (data.type == "boolean") { |
| 734 // Special case yay | 726 // Special case yay |
| 735 ReflectionHarness.test(domObj.hasAttribute(domName), Boolean
(idlTests[i]), "IDL set to " + ReflectionHarness.stringRep(idlTests[i]) + " foll
owed by hasAttribute()"); | 727 ReflectionHarness.assertEquals(domObj.hasAttribute(domName), |
| 728 Boolean(idlTests[i]), "hasAtt
ribute()"); |
| 736 } else if (idlDomExpected[i] !== null || data.isNullable) { | 729 } else if (idlDomExpected[i] !== null || data.isNullable) { |
| 737 var expected = idlDomExpected[i] + ""; | 730 var expected = idlDomExpected[i] + ""; |
| 738 if (data.isNullable && idlDomExpected[i] === null) { | 731 if (data.isNullable && idlDomExpected[i] === null) { |
| 739 expected = null; | 732 expected = null; |
| 740 } | 733 } |
| 741 ReflectionHarness.test(domObj.getAttribute(domName), expecte
d, "IDL set to " + ReflectionHarness.stringRep(idlTests[i]) + " followed by getA
ttribute()"); | 734 ReflectionHarness.assertEquals(domObj.getAttribute(domName),
expected, |
| 735 "getAttribute()"); |
| 742 } | 736 } |
| 743 if (idlIdlExpected[i] !== null || data.isNullable) { | 737 if (idlIdlExpected[i] !== null || data.isNullable) { |
| 744 ReflectionHarness.test(idlObj[idlName], idlIdlExpected[i], "
IDL set to " + ReflectionHarness.stringRep(idlTests[i]) + " followed by IDL get"
); | 738 ReflectionHarness.assertEquals(idlObj[idlName], idlIdlExpect
ed[i], "IDL get"); |
| 745 } | 739 } |
| 746 if (ReflectionHarness.catchUnexpectedExceptions) { | 740 } |
| 747 ReflectionHarness.success(); | 741 }, "IDL set to " + ReflectionHarness.stringRep(idlTests[i])); |
| 748 } | |
| 749 }, "IDL set to " + ReflectionHarness.stringRep(idlTests[i]) + " shou
ld not throw"); | |
| 750 } | |
| 751 } | 742 } |
| 752 }; | 743 }; |
| 753 | 744 |
| 754 /** | 745 /** |
| 755 * If we have an enumerated attribute limited to the array of values in | 746 * If we have an enumerated attribute limited to the array of values in |
| 756 * keywords, with nonCanon being a map of non-canonical values to their | 747 * keywords, with nonCanon being a map of non-canonical values to their |
| 757 * canonical equivalents, and invalidVal being the invalid value default (or "" | 748 * canonical equivalents, and invalidVal being the invalid value default (or "" |
| 758 * for none), then what would we expect from an IDL get if the content | 749 * for none), then what would we expect from an IDL get if the content |
| 759 * attribute is equal to contentVal? | 750 * attribute is equal to contentVal? |
| 760 */ | 751 */ |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 var time = document.getElementById("time"); | 806 var time = document.getElementById("time"); |
| 816 if (time) { | 807 if (time) { |
| 817 time.innerHTML = (new Date().getTime() - ReflectionTests.start)/1000; | 808 time.innerHTML = (new Date().getTime() - ReflectionTests.start)/1000; |
| 818 } | 809 } |
| 819 | 810 |
| 820 if (unimplemented.length) { | 811 if (unimplemented.length) { |
| 821 var p = document.createElement("p"); | 812 var p = document.createElement("p"); |
| 822 p.textContent = "(Note: missing tests for types " + unimplemented.join(", ")
+ ".)"; | 813 p.textContent = "(Note: missing tests for types " + unimplemented.join(", ")
+ ".)"; |
| 823 document.body.appendChild(p); | 814 document.body.appendChild(p); |
| 824 } | 815 } |
| OLD | NEW |