test_option_disabled.html (6092B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=759666 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for HTMLOptionElement disabled attribute and pseudo-class</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=759666">Mozilla Bug 759666</a> 14 <p id="display"></p> 15 <div id="content" style="display: none"> 16 17 </div> 18 <pre id="test"> 19 <script type="application/javascript"> 20 21 /** Test for HTMLOptionElement disabled attribute and pseudo-class */ 22 23 var testCases = [ 24 // Static checks. 25 { html: "<option></option>", 26 result: { attr: null, idl: false, pseudo: false } }, 27 { html: "<option disabled></option>", 28 result: { attr: "", idl: true, pseudo: true } }, 29 { html: "<optgroup><option></option></otpgroup>", 30 result: { attr: null, idl: false, pseudo: false } }, 31 { html: "<optgroup><option disabled></option></optgroup>", 32 result: { attr: "", idl: true, pseudo: true } }, 33 { html: "<optgroup disabled><option disabled></option></optgroup>", 34 result: { attr: "", idl: true, pseudo: true } }, 35 { html: "<optgroup disabled><option></option></optgroup>", 36 result: { attr: null, idl: false, pseudo: true } }, 37 { html: "<optgroup><optgroup disabled><option></option></optgroup></optgroup>", 38 result: { attr: null, idl: false, pseudo: true } }, 39 { html: "<optgroup disabled><optgroup><option></option></optgroup></optgroup>", 40 result: { attr: null, idl: false, pseudo: false } }, 41 { html: "<optgroup disabled><optgroup><option disabled></option></optgroup></optgroup>", 42 result: { attr: "", idl: true, pseudo: true } }, 43 44 // Dynamic checks: changing disable value. 45 { html: "<option></option>", 46 modifier(c) { c.querySelector('option').disabled = true; }, 47 result: { attr: "", idl: true, pseudo: true } }, 48 { html: "<option disabled></option>", 49 modifier(c) { c.querySelector('option').disabled = false; }, 50 result: { attr: null, idl: false, pseudo: false } }, 51 { html: "<optgroup><option></option></otpgroup>", 52 modifier(c) { c.querySelector('optgroup').disabled = true; }, 53 result: { attr: null, idl: false, pseudo: true } }, 54 { html: "<optgroup><option disabled></option></optgroup>", 55 modifier(c) { c.querySelector('option').disabled = false; }, 56 result: { attr: null, idl: false, pseudo: false } }, 57 { html: "<optgroup disabled><option disabled></option></optgroup>", 58 modifier(c) { c.querySelector('optgroup').disabled = false; }, 59 result: { attr: "", idl: true, pseudo: true } }, 60 { html: "<optgroup disabled><option disabled></option></optgroup>", 61 modifier(c) { c.querySelector('option').disabled = false; }, 62 result: { attr: null, idl: false, pseudo: true } }, 63 { html: "<optgroup disabled><option disabled></option></optgroup>", 64 modifier(c) { c.querySelector('optgroup').disabled = c.querySelector('option').disabled = false; }, 65 result: { attr: null, idl: false, pseudo: false } }, 66 { html: "<optgroup disabled><option></option></optgroup>", 67 modifier(c) { c.querySelector('optgroup').disabled = false; }, 68 result: { attr: null, idl: false, pseudo: false } }, 69 { html: "<optgroup><optgroup disabled><option></option></optgroup></optgroup>", 70 modifier(c) { c.querySelector('optgroup[disabled]').disabled = false; }, 71 result: { attr: null, idl: false, pseudo: false } }, 72 { html: "<optgroup disabled><optgroup><option></option></optgroup></optgroup>", 73 modifier(c) { c.querySelector('optgroup[disabled]').disabled = false; }, 74 result: { attr: null, idl: false, pseudo: false } }, 75 { html: "<optgroup disabled><optgroup><option disabled></option></optgroup></optgroup>", 76 modifier(c) { c.querySelector('optgroup').disabled = false; }, 77 result: { attr: "", idl: true, pseudo: true } }, 78 { html: "<optgroup disabled><optgroup><option disabled></option></optgroup></optgroup>", 79 modifier(c) { c.querySelector('option').disabled = false; }, 80 result: { attr: null, idl: false, pseudo: false } }, 81 { html: "<optgroup disabled><optgroup><option disabled></option></optgroup></optgroup>", 82 modifier(c) { c.querySelector('option').disabled = c.querySelector('option').disabled = false; }, 83 result: { attr: null, idl: false, pseudo: false } }, 84 85 // Dynamic checks: moving option element. 86 { html: "<optgroup id='a'><option></option></optgroup><optgroup id='b'></optgroup>", 87 modifier(c) { c.querySelector('#b').appendChild(c.querySelector('option')); }, 88 result: { attr: null, idl: false, pseudo: false } }, 89 { html: "<optgroup id='a'><option disabled></option></optgroup><optgroup id='b'></optgroup>", 90 modifier(c) { c.querySelector('#b').appendChild(c.querySelector('option')); }, 91 result: { attr: "", idl: true, pseudo: true } }, 92 { html: "<optgroup id='a'><option></option></optgroup><optgroup disabled id='b'></optgroup>", 93 modifier(c) { c.querySelector('#b').appendChild(c.querySelector('option')); }, 94 result: { attr: null, idl: false, pseudo: true } }, 95 { html: "<optgroup disabled id='a'><option></option></optgroup><optgroup id='b'></optgroup>", 96 modifier(c) { c.querySelector('#b').appendChild(c.querySelector('option')); }, 97 result: { attr: null, idl: false, pseudo: false } }, 98 ]; 99 100 var content = document.getElementById('content'); 101 102 testCases.forEach(function(testCase) { 103 var result = testCase.result; 104 105 content.innerHTML = testCase.html; 106 107 if (testCase.modifier !== undefined) { 108 testCase.modifier(content); 109 } 110 111 var option = content.querySelector('option'); 112 is(option.getAttribute('disabled'), result.attr, "disabled content attribute value should be " + result.attr); 113 is(option.disabled, result.idl, "disabled idl attribute value should be " + result.idl); 114 is(option.matches(":disabled"), result.pseudo, ":disabled state should be " + result.pseudo); 115 is(option.matches(":enabled"), !result.pseudo, ":enabled state should be " + !result.pseudo); 116 117 content.innerHTML = ""; 118 }); 119 120 </script> 121 </pre> 122 </body> 123 </html>