test_bug346485.html (2259B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=346485 5 --> 6 <head> 7 <title>Test for Bug 346485</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=346485">Mozilla Bug 346485</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 <input id='a'> 16 <input id='b'> 17 <output id='o' for='a b'></output> 18 </div> 19 <pre id="test"> 20 <script type="application/javascript"> 21 22 /** Test for Bug 346485 */ 23 24 /** 25 * This test is testing DOMTokenList used by the output element. 26 */ 27 28 function checkHtmlFor(htmlFor, list, msg) { 29 var length = htmlFor.length; 30 is(length, list.length, htmlFor + ": incorrect htmlFor length (" + msg + ")"); 31 for (var i = 0; i < length; ++i) { 32 is(htmlFor[i], list[i], htmlFor + ": wrong element at " + i + " (" + msg + ")"); 33 } 34 } 35 36 var o = document.getElementById('o'); 37 38 is(String(o.htmlFor), 'a b', 39 "htmlFor IDL attribute should reflect for content attribute"); 40 41 is(o.htmlFor.value, 'a b', 42 "value should return the underlying string"); 43 44 is(o.htmlFor.length, 2, "Size should be '2'"); 45 46 ok(o.htmlFor.contains('a'), "It should contain 'a' token'"); 47 ok(!o.htmlFor.contains('c'), "It should not contain 'c' token"); 48 49 is(o.htmlFor.item(0), 'a', "First item is 'a' token'"); 50 is(o.htmlFor.item(42), null, "Out-of-range should return null"); 51 52 o.htmlFor.add('c'); 53 checkHtmlFor(o.htmlFor, ['a', 'b', 'c'], "'c' token should have been added"); 54 55 o.htmlFor.add('a'); 56 checkHtmlFor(o.htmlFor, ['a', 'b', 'c'], "Nothing should have changed"); 57 58 o.htmlFor.remove('a'); 59 checkHtmlFor(o.htmlFor, ['b', 'c'], "'a' token should have been removed"); 60 61 o.htmlFor.remove('d'); 62 checkHtmlFor(o.htmlFor, ['b', 'c'], "Nothing should have been removed"); 63 64 o.htmlFor.toggle('a'); 65 checkHtmlFor(o.htmlFor, ['b', 'c', 'a'], "'a' token should have been added"); 66 67 o.htmlFor.toggle('b'); 68 checkHtmlFor(o.htmlFor, ['c', 'a'], "Nothing should have changed"); 69 70 o.htmlFor.value = "foo bar"; 71 checkHtmlFor(o.htmlFor, ['foo', 'bar'], "The underlying string should have changed"); 72 ok(o.htmlFor.contains('foo'), "It should contain 'foo'"); 73 74 </script> 75 </pre> 76 </body> 77 </html>