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