OLD | NEW |
1 /*global self*/ | 1 /*global self*/ |
2 /*jshint latedef: nofunc*/ | 2 /*jshint latedef: nofunc*/ |
3 /* | 3 /* |
4 Distributed under both the W3C Test Suite License [1] and the W3C | 4 Distributed under both the W3C Test Suite License [1] and the W3C |
5 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the | 5 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the |
6 policies and contribution forms [3]. | 6 policies and contribution forms [3]. |
7 | 7 |
8 [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license | 8 [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license |
9 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license | 9 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license |
10 [3] http://www.w3.org/2004/10/27-testcases | 10 [3] http://www.w3.org/2004/10/27-testcases |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 | 690 |
691 /* | 691 /* |
692 * Return true if object is probably a Node object. | 692 * Return true if object is probably a Node object. |
693 */ | 693 */ |
694 function is_node(object) | 694 function is_node(object) |
695 { | 695 { |
696 // I use duck-typing instead of instanceof, because | 696 // I use duck-typing instead of instanceof, because |
697 // instanceof doesn't work if the node is from another window (like an | 697 // instanceof doesn't work if the node is from another window (like an |
698 // iframe's contentWindow): | 698 // iframe's contentWindow): |
699 // http://www.w3.org/Bugs/Public/show_bug.cgi?id=12295 | 699 // http://www.w3.org/Bugs/Public/show_bug.cgi?id=12295 |
700 if ("nodeType" in object && | 700 try { |
701 "nodeName" in object && | 701 var has_node_properties = ("nodeType" in object && |
702 "nodeValue" in object && | 702 "nodeName" in object && |
703 "childNodes" in object) { | 703 "nodeValue" in object && |
| 704 "childNodes" in object); |
| 705 } catch (e) { |
| 706 // We're probably cross-origin, which means we aren't a node |
| 707 return false; |
| 708 } |
| 709 |
| 710 if (has_node_properties) { |
704 try { | 711 try { |
705 object.nodeType; | 712 object.nodeType; |
706 } catch (e) { | 713 } catch (e) { |
707 // The object is probably Node.prototype or another prototype | 714 // The object is probably Node.prototype or another prototype |
708 // object that inherits from it, and not a Node instance. | 715 // object that inherits from it, and not a Node instance. |
709 return false; | 716 return false; |
710 } | 717 } |
711 return true; | 718 return true; |
712 } | 719 } |
713 return false; | 720 return false; |
714 } | 721 } |
715 | 722 |
| 723 var replacements = { |
| 724 "0": "0", |
| 725 "1": "x01", |
| 726 "2": "x02", |
| 727 "3": "x03", |
| 728 "4": "x04", |
| 729 "5": "x05", |
| 730 "6": "x06", |
| 731 "7": "x07", |
| 732 "8": "b", |
| 733 "9": "t", |
| 734 "10": "n", |
| 735 "11": "v", |
| 736 "12": "f", |
| 737 "13": "r", |
| 738 "14": "x0e", |
| 739 "15": "x0f", |
| 740 "16": "x10", |
| 741 "17": "x11", |
| 742 "18": "x12", |
| 743 "19": "x13", |
| 744 "20": "x14", |
| 745 "21": "x15", |
| 746 "22": "x16", |
| 747 "23": "x17", |
| 748 "24": "x18", |
| 749 "25": "x19", |
| 750 "26": "x1a", |
| 751 "27": "x1b", |
| 752 "28": "x1c", |
| 753 "29": "x1d", |
| 754 "30": "x1e", |
| 755 "31": "x1f", |
| 756 "0xfffd": "ufffd", |
| 757 "0xfffe": "ufffe", |
| 758 "0xffff": "uffff", |
| 759 }; |
| 760 |
716 /* | 761 /* |
717 * Convert a value to a nice, human-readable string | 762 * Convert a value to a nice, human-readable string |
718 */ | 763 */ |
719 function format_value(val, seen) | 764 function format_value(val, seen) |
720 { | 765 { |
721 if (!seen) { | 766 if (!seen) { |
722 seen = []; | 767 seen = []; |
723 } | 768 } |
724 if (typeof val === "object" && val !== null) { | 769 if (typeof val === "object" && val !== null) { |
725 if (seen.indexOf(val) >= 0) { | 770 if (seen.indexOf(val) >= 0) { |
726 return "[...]"; | 771 return "[...]"; |
727 } | 772 } |
728 seen.push(val); | 773 seen.push(val); |
729 } | 774 } |
730 if (Array.isArray(val)) { | 775 if (Array.isArray(val)) { |
731 return "[" + val.map(function(x) {return format_value(x, seen);}).jo
in(", ") + "]"; | 776 return "[" + val.map(function(x) {return format_value(x, seen);}).jo
in(", ") + "]"; |
732 } | 777 } |
733 | 778 |
734 switch (typeof val) { | 779 switch (typeof val) { |
735 case "string": | 780 case "string": |
736 val = val.replace("\\", "\\\\"); | 781 val = val.replace("\\", "\\\\"); |
737 for (var i = 0; i < 32; i++) { | 782 for (var p in replacements) { |
738 var replace = "\\"; | 783 var replace = "\\" + replacements[p]; |
739 switch (i) { | 784 val = val.replace(RegExp(String.fromCharCode(p), "g"), replace); |
740 case 0: replace += "0"; break; | |
741 case 1: replace += "x01"; break; | |
742 case 2: replace += "x02"; break; | |
743 case 3: replace += "x03"; break; | |
744 case 4: replace += "x04"; break; | |
745 case 5: replace += "x05"; break; | |
746 case 6: replace += "x06"; break; | |
747 case 7: replace += "x07"; break; | |
748 case 8: replace += "b"; break; | |
749 case 9: replace += "t"; break; | |
750 case 10: replace += "n"; break; | |
751 case 11: replace += "v"; break; | |
752 case 12: replace += "f"; break; | |
753 case 13: replace += "r"; break; | |
754 case 14: replace += "x0e"; break; | |
755 case 15: replace += "x0f"; break; | |
756 case 16: replace += "x10"; break; | |
757 case 17: replace += "x11"; break; | |
758 case 18: replace += "x12"; break; | |
759 case 19: replace += "x13"; break; | |
760 case 20: replace += "x14"; break; | |
761 case 21: replace += "x15"; break; | |
762 case 22: replace += "x16"; break; | |
763 case 23: replace += "x17"; break; | |
764 case 24: replace += "x18"; break; | |
765 case 25: replace += "x19"; break; | |
766 case 26: replace += "x1a"; break; | |
767 case 27: replace += "x1b"; break; | |
768 case 28: replace += "x1c"; break; | |
769 case 29: replace += "x1d"; break; | |
770 case 30: replace += "x1e"; break; | |
771 case 31: replace += "x1f"; break; | |
772 } | |
773 val = val.replace(RegExp(String.fromCharCode(i), "g"), replace); | |
774 } | 785 } |
775 return '"' + val.replace(/"/g, '\\"') + '"'; | 786 return '"' + val.replace(/"/g, '\\"') + '"'; |
776 case "boolean": | 787 case "boolean": |
777 case "undefined": | 788 case "undefined": |
778 return String(val); | 789 return String(val); |
779 case "number": | 790 case "number": |
780 // In JavaScript, -0 === 0 and String(-0) == "0", so we have to | 791 // In JavaScript, -0 === 0 and String(-0) == "0", so we have to |
781 // special-case. | 792 // special-case. |
782 if (val === -0 && 1/val === -Infinity) { | 793 if (val === -0 && 1/val === -Infinity) { |
783 return "-0"; | 794 return "-0"; |
(...skipping 27 matching lines...) Expand all Loading... |
811 return "DocumentType node"; | 822 return "DocumentType node"; |
812 case Node.DOCUMENT_FRAGMENT_NODE: | 823 case Node.DOCUMENT_FRAGMENT_NODE: |
813 return "DocumentFragment node with " + val.childNodes.length
+ (val.childNodes.length == 1 ? " child" : " children"); | 824 return "DocumentFragment node with " + val.childNodes.length
+ (val.childNodes.length == 1 ? " child" : " children"); |
814 default: | 825 default: |
815 return "Node object of unknown type"; | 826 return "Node object of unknown type"; |
816 } | 827 } |
817 } | 828 } |
818 | 829 |
819 /* falls through */ | 830 /* falls through */ |
820 default: | 831 default: |
821 return typeof val + ' "' + truncate(String(val), 60) + '"'; | 832 try { |
| 833 return typeof val + ' "' + truncate(String(val), 60) + '"'; |
| 834 } catch(e) { |
| 835 return ("[stringifying object threw " + String(e) + |
| 836 " with type " + String(typeof e) + "]"); |
| 837 } |
822 } | 838 } |
823 } | 839 } |
824 expose(format_value, "format_value"); | 840 expose(format_value, "format_value"); |
825 | 841 |
826 /* | 842 /* |
827 * Assertions | 843 * Assertions |
828 */ | 844 */ |
829 | 845 |
830 function assert_true(actual, description) | 846 function assert_true(actual, description) |
831 { | 847 { |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 return this.step_func(function() { | 1447 return this.step_func(function() { |
1432 assert_unreached(description); | 1448 assert_unreached(description); |
1433 }); | 1449 }); |
1434 }; | 1450 }; |
1435 | 1451 |
1436 Test.prototype.step_timeout = function(f, timeout) { | 1452 Test.prototype.step_timeout = function(f, timeout) { |
1437 var test_this = this; | 1453 var test_this = this; |
1438 var args = Array.prototype.slice.call(arguments, 2); | 1454 var args = Array.prototype.slice.call(arguments, 2); |
1439 return setTimeout(this.step_func(function() { | 1455 return setTimeout(this.step_func(function() { |
1440 return f.apply(test_this, args); | 1456 return f.apply(test_this, args); |
1441 }, timeout * tests.timeout_multiplier)); | 1457 }), timeout * tests.timeout_multiplier); |
1442 } | 1458 } |
1443 | 1459 |
1444 Test.prototype.add_cleanup = function(callback) { | 1460 Test.prototype.add_cleanup = function(callback) { |
1445 this.cleanup_callbacks.push(callback); | 1461 this.cleanup_callbacks.push(callback); |
1446 }; | 1462 }; |
1447 | 1463 |
1448 Test.prototype.force_timeout = function() { | 1464 Test.prototype.force_timeout = function() { |
1449 this.set_status(this.TIMEOUT); | 1465 this.set_status(this.TIMEOUT); |
1450 this.phase = this.phases.HAS_RESULT; | 1466 this.phase = this.phases.HAS_RESULT; |
1451 }; | 1467 }; |
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2650 tests.status.status = tests.status.ERROR; | 2666 tests.status.status = tests.status.ERROR; |
2651 tests.status.message = e.message; | 2667 tests.status.message = e.message; |
2652 tests.status.stack = e.stack; | 2668 tests.status.stack = e.stack; |
2653 } | 2669 } |
2654 }); | 2670 }); |
2655 | 2671 |
2656 test_environment.on_tests_ready(); | 2672 test_environment.on_tests_ready(); |
2657 | 2673 |
2658 })(); | 2674 })(); |
2659 // vim: set expandtab shiftwidth=4 tabstop=4: | 2675 // vim: set expandtab shiftwidth=4 tabstop=4: |
OLD | NEW |