test_bug659596.html (2474B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=659596 5 --> 6 <head> 7 <title>Test for Bug 659596</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=659596">Mozilla Bug 659596</a> 13 <p id="display"></p> 14 <pre id="test"> 15 <script type="application/javascript"> 16 17 /** Test for Bug 659596 */ 18 19 function checkReflection(option, attribute) { 20 /** 21 * Getting. 22 */ 23 24 // When attribute isn't present. 25 var tests = [ "", "foo" ]; 26 for (var test of tests) { 27 option.removeAttribute(attribute); 28 option.textContent = test; 29 is(option.getAttribute(attribute), null, 30 "option " + attribute + "'s value should be null"); 31 is(option[attribute], option.textContent, 32 "option." + attribute + " should reflect the text content when the attribute isn't set"); 33 } 34 35 // When attribute is present. 36 tests = [ 37 [ "", "" ], 38 [ "", "foo" ], 39 [ "foo", "bar" ], 40 [ "foo", "" ], 41 ]; 42 for (var test of tests) { 43 option.setAttribute(attribute, test[0]); 44 option.textContent = test[1]; 45 is(option[attribute], option.getAttribute(attribute), 46 "option." + attribute + " should reflect the content attribute when it is set"); 47 } 48 49 /** 50 * Setting. 51 */ 52 53 // When attribute isn't present. 54 tests = [ 55 [ "", "new" ], 56 [ "foo", "new" ], 57 ]; 58 for (var test of tests) { 59 option.removeAttribute(attribute); 60 option.textContent = test[0]; 61 option[attribute] = test[1] 62 63 is(option.getAttribute(attribute), test[1], 64 "when setting, the content attribute should change"); 65 is(option.textContent, test[0], 66 "when setting, the text content should not change"); 67 } 68 69 // When attribute is present. 70 tests = [ 71 [ "", "", "new" ], 72 [ "", "foo", "new" ], 73 [ "foo", "bar", "new" ], 74 [ "foo", "", "new" ], 75 ]; 76 for (var test of tests) { 77 option.setAttribute(attribute, test[0]); 78 option.textContent = test[1]; 79 option[attribute] = test[2]; 80 81 is(option.getAttribute(attribute), test[2], 82 "when setting, the content attribute should change"); 83 is(option.textContent, test[1], 84 "when setting, the text content should not change"); 85 } 86 } 87 88 var option = document.createElement("option"); 89 90 checkReflection(option, "value"); 91 checkReflection(option, "label"); 92 93 </script> 94 </pre> 95 </body> 96 </html>