OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title></title> |
| 5 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.j
s"></script> |
| 6 <script src="class_list.js"></script> |
| 7 <script> |
| 8 |
| 9 goog.require('goog.testing.jsunit'); |
| 10 |
| 11 </script> |
| 12 </head> |
| 13 <body> |
| 14 |
| 15 <script> |
| 16 |
| 17 var el = document.body; |
| 18 |
| 19 function testLength() { |
| 20 el.className = 'a b'; |
| 21 assertEquals(2, el.classList.length); |
| 22 el.setAttribute('class', 'a b c'); |
| 23 assertEquals(3, el.classList.length); |
| 24 } |
| 25 |
| 26 function testItem() { |
| 27 el.className = 'a b'; |
| 28 assertEquals('a', el.classList.item(0)); |
| 29 assertEquals('b', el.classList.item(1)); |
| 30 el.setAttribute('class', 'a b c'); |
| 31 assertEquals('a', el.classList.item(0)); |
| 32 assertEquals('b', el.classList.item(1)); |
| 33 assertEquals('c', el.classList.item(2)); |
| 34 } |
| 35 |
| 36 function testContains() { |
| 37 el.className = 'a b'; |
| 38 assertTrue(el.classList.contains('a')); |
| 39 assertTrue(el.classList.contains('b')); |
| 40 assertFalse(el.classList.contains('c')); |
| 41 |
| 42 assertEquals('b', el.classList.item(1)); |
| 43 el.setAttribute('class', 'a b c'); |
| 44 assertTrue(el.classList.contains('a')); |
| 45 assertTrue(el.classList.contains('b')); |
| 46 assertTrue(el.classList.contains('c')); |
| 47 } |
| 48 |
| 49 function testToken() { |
| 50 assertThrows(function() { |
| 51 el.classList.add(''); |
| 52 }); |
| 53 assertThrows(function() { |
| 54 el.classList.add(' '); |
| 55 }); |
| 56 assertThrows(function() { |
| 57 el.classList.add('\t'); |
| 58 }); |
| 59 assertThrows(function() { |
| 60 el.classList.add('\n'); |
| 61 }); |
| 62 } |
| 63 |
| 64 function testAdd() { |
| 65 el.className = 'a b'; |
| 66 el.classList.add('a'); |
| 67 assertEquals('a b', el.className); |
| 68 el.classList.add('c'); |
| 69 assertEquals('a b c', el.className); |
| 70 } |
| 71 |
| 72 function testRemove() { |
| 73 el.className = 'a b'; |
| 74 el.classList.remove('b'); |
| 75 assertEquals('a', el.className); |
| 76 el.classList.remove('a'); |
| 77 assertEquals('', el.className); |
| 78 } |
| 79 |
| 80 function testToggle() { |
| 81 el.className = 'a b'; |
| 82 assertFalse(el.classList.toggle('a')); |
| 83 assertEquals('b', el.className); |
| 84 assertTrue(el.classList.toggle('a')); |
| 85 assertEquals('b a', el.className); |
| 86 } |
| 87 |
| 88 </script> |
| 89 |
| 90 </body> |
| 91 </html> |
OLD | NEW |