LEFT | RIGHT |
1 <!-- | 1 <!-- |
2 - Copyright (C) 2011 Google Inc. | 2 - Copyright (C) 2011 Google Inc. |
3 - | 3 - |
4 - Licensed under the Apache License, Version 2.0 (the "License"); | 4 - Licensed under the Apache License, Version 2.0 (the "License"); |
5 - you may not use this file except in compliance with the License. | 5 - you may not use this file except in compliance with the License. |
6 - You may obtain a copy of the License at | 6 - You may obtain a copy of the License at |
7 - | 7 - |
8 - http://www.apache.org/licenses/LICENSE-2.0 | 8 - http://www.apache.org/licenses/LICENSE-2.0 |
9 - | 9 - |
10 - Unless required by applicable law or agreed to in writing, software | 10 - Unless required by applicable law or agreed to in writing, software |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 <p class="aaa bbb">AAA BBB</p> | 780 <p class="aaa bbb">AAA BBB</p> |
781 <div class="aaa">AAA</div> | 781 <div class="aaa">AAA</div> |
782 <p class="bbb ccc">BBB CCC</p> | 782 <p class="bbb ccc">BBB CCC</p> |
783 </div> | 783 </div> |
784 <script type="text/javascript"> | 784 <script type="text/javascript"> |
785 jsunitRegister('testGetElementsByClassName', | 785 jsunitRegister('testGetElementsByClassName', |
786 function testGetElementsByClassName() { | 786 function testGetElementsByClassName() { |
787 function assertNodeListTextContent(classes, textContent) { | 787 function assertNodeListTextContent(classes, textContent) { |
788 var nodeList = document.getElementsByClassName(classes); | 788 var nodeList = document.getElementsByClassName(classes); |
789 var len = nodeList.length; | 789 var len = nodeList.length; |
790 assertEquals(textContent.length, len); | 790 assertEquals('expected length for ' + classes, textContent.length, len); |
791 for (var i = 0; i < len; ++i) { | 791 for (var i = 0; i < len; ++i) { |
792 assertEquals(textContent[i], canonInnerHtml(nodeList[i].innerHTML)); | 792 assertEquals(classes + ' (result ' + i + ')', |
| 793 textContent[i], canonInnerHtml(nodeList[i].innerHTML)); |
793 } | 794 } |
794 } | 795 } |
795 | 796 |
796 assertNodeListTextContent('aaa', ['AAA BBB', 'AAA']); | 797 assertNodeListTextContent('aaa', ['AAA BBB', 'AAA']); |
797 assertNodeListTextContent('ccc bbb', ['BBB CCC']); | 798 assertNodeListTextContent('ccc bbb', ['BBB CCC']); |
798 assertNodeListTextContent('bbb ccc', ['BBB CCC']); | 799 assertNodeListTextContent('bbb ccc', ['BBB CCC']); |
799 assertNodeListTextContent(' bbb \tccc ', ['BBB CCC']); | 800 assertNodeListTextContent(' bbb \tccc ', ['BBB CCC']); |
800 assertNodeListTextContent('aaa,bbb', []); | 801 assertNodeListTextContent('aaa,bbb', []); |
801 | 802 |
802 pass('testGetElementsByClassName'); | 803 pass('testGetElementsByClassName'); |
| 804 }); |
| 805 </script> |
| 806 |
| 807 <div id="testQuerySelector" class="testcontainer"> |
| 808 <p class="testQuerySelector-ac" id="testQuerySelector-ai">a</p> |
| 809 <p class="testQuerySelector-bc" id="testQuerySelector-bi">b</p> |
| 810 </div> |
| 811 <script type="text/javascript"> |
| 812 // TODO(kpreid): Disable this test if host browser does not provide |
| 813 // querySelector. |
| 814 jsunitRegister('testQuerySelector', |
| 815 function testQuerySelector() { |
| 816 var container = document.getElementById('testQuerySelector'); |
| 817 function assertQueryResult(selectors, textContent) { |
| 818 var nodeList = document.querySelectorAll(selectors); |
| 819 var nodeList2 = container.querySelectorAll(selectors); |
| 820 var single = document.querySelector(selectors); |
| 821 var single2 = container.querySelector(selectors); |
| 822 var len = nodeList.length; |
| 823 assertEquals('expected length for ' + selectors, textContent.length, len); |
| 824 assertEquals('expected same length for ' + selectors, len, |
| 825 nodeList2.length); |
| 826 for (var i = 0; i < len; ++i) { |
| 827 assertEquals(selectors + ' (result ' + i + ' on document)', |
| 828 textContent[i], canonInnerHtml(nodeList[i].innerHTML)); |
| 829 assertEquals(selectors + ' (result ' + i + ' on element)', |
| 830 textContent[i], canonInnerHtml(nodeList2[i].innerHTML)); |
| 831 } |
| 832 assertEquals(selectors + ' (querySelector)', |
| 833 len === 0 ? null : nodeList[0], single); |
| 834 } |
| 835 |
| 836 assertQueryResult('.testQuerySelector-ac', ['a']); |
| 837 assertQueryResult('.testQuerySelector-bc', ['b']); |
| 838 assertQueryResult('#testQuerySelector-ai', ['a']); |
| 839 assertQueryResult('#testQuerySelector-ai, #testQuerySelector-bi', |
| 840 ['a', 'b']); |
| 841 assertQueryResult('#testQuerySelector p', ['a', 'b']); |
| 842 assertEquals('scoped query', 2, container.querySelectorAll('p').length); |
| 843 expectFailure(function() { |
| 844 document.querySelector(','); |
| 845 }, 'syntax error'); |
| 846 |
| 847 // test non-liveness |
| 848 var list = container.querySelectorAll('p'); |
| 849 assertEquals('length before change', 2, list.length); |
| 850 container.appendChild(document.createElement('p')).textContent = 'added'; |
| 851 assertEquals('length after change', 2, list.length); |
| 852 |
| 853 pass('testQuerySelector'); |
803 }); | 854 }); |
804 </script> | 855 </script> |
805 | 856 |
806 <p id="testClassSetByEmitter" class="testcontainer"></p> | 857 <p id="testClassSetByEmitter" class="testcontainer"></p> |
807 <script type="text/javascript"> | 858 <script type="text/javascript"> |
808 jsunitRegister('testClassSetByEmitter', | 859 jsunitRegister('testClassSetByEmitter', |
809 function testClassSetByEmitter() { | 860 function testClassSetByEmitter() { |
810 // Make sure that the HTML emitter correctly sets the class. | 861 // Make sure that the HTML emitter correctly sets the class. |
811 // A testcontainer node should be yellow until it has been marked as having | 862 // A testcontainer node should be yellow until it has been marked as having |
812 // passed. | 863 // passed. |
(...skipping 2181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2994 assertEquals('parent is not body', lastest.parentNode, body); | 3045 assertEquals('parent is not body', lastest.parentNode, body); |
2995 pass('testDocumentBodyAppendChild'); | 3046 pass('testDocumentBodyAppendChild'); |
2996 }); | 3047 }); |
2997 </script> | 3048 </script> |
2998 | 3049 |
2999 <script type="text/javascript"> | 3050 <script type="text/javascript"> |
3000 // jsunitRun('testPropertyAttributeInteraction'); | 3051 // jsunitRun('testPropertyAttributeInteraction'); |
3001 </script> | 3052 </script> |
3002 | 3053 |
3003 </body> | 3054 </body> |
LEFT | RIGHT |