test_output_element.html (5223B)
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 <script type="application/javascript" src="../reflect.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 <script type="application/javascript"> 12 frameLoaded = function() { 13 is(frames.submit_frame.location.href, "about:blank", 14 "Blank frame loaded"); 15 } 16 </script> 17 </head> 18 <body> 19 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=346485">Mozilla Bug 346485</a> 20 <p id="display"></p> 21 <iframe name="submit_frame" onload="frameLoaded()" style="visibility: hidden;"></iframe> 22 <div id="content" style="display: none"> 23 <form id='f' method='get' target='submit_frame' action='foo'> 24 <input name='a' id='a'> 25 <input name='b' id='b'> 26 <output id='o' for='a b' name='output-name'>tulip</output> 27 </form> 28 </div> 29 <pre id="test"> 30 <script type="application/javascript"> 31 32 /** Test for Bug 346485 */ 33 34 function checkNameAttribute(element) 35 { 36 is(element.name, "output-name", "Output name IDL attribute is not correct"); 37 is(element.getAttribute('name'), "output-name", 38 "Output name content attribute is not correct"); 39 } 40 41 function checkValueAndDefaultValueIDLAttribute(element) 42 { 43 is(element.value, element.textContent, 44 "The value IDL attribute should act like the textContent IDL attribute"); 45 46 element.value = "foo"; 47 is(element.value, "foo", "Value should be 'foo'"); 48 49 is(element.defaultValue, "tulip", "Default defaultValue is 'tulip'"); 50 51 element.defaultValue = "bar"; 52 is(element.defaultValue, "bar", "defaultValue should be 'bar'"); 53 54 // More complex situation. 55 element.textContent = 'foo'; 56 var b = document.createElement('b'); 57 b.textContent = 'bar' 58 element.appendChild(b); 59 is(element.value, element.textContent, 60 "The value IDL attribute should act like the textContent IDL attribute"); 61 } 62 63 function checkValueModeFlag(element) 64 { 65 /** 66 * The value mode flag is the flag used to know if value should represent the 67 * textContent or the default value. 68 */ 69 // value mode flag should be 'value' 70 isnot(element.defaultValue, element.value, 71 "When value is set, defaultValue keeps its value"); 72 73 var f = document.getElementById('f'); 74 f.reset(); 75 // value mode flag should be 'default' 76 is(element.defaultValue, element.value, "When reset, defaultValue=value"); 77 is(element.textContent, element.defaultValue, 78 "textContent should contain the defaultValue"); 79 } 80 81 function checkDescendantChanged(element) 82 { 83 /** 84 * Whenever a descendant is changed if the value mode flag is value, 85 * the default value should be the textContent value. 86 */ 87 element.defaultValue = 'tulip'; 88 element.value = 'foo'; 89 90 // set value mode flag to 'default' 91 var f = document.getElementById('f'); 92 f.reset(); 93 94 is(element.textContent, element.defaultValue, 95 "textContent should contain the defaultValue"); 96 element.textContent = "bar"; 97 is(element.textContent, element.defaultValue, 98 "textContent should contain the defaultValue"); 99 } 100 101 function checkFormIDLAttribute(element) 102 { 103 is(element.form, document.getElementById('f'), 104 "form IDL attribute is invalid"); 105 } 106 107 function checkHtmlForIDLAttribute(element) 108 { 109 is(String(element.htmlFor), 'a b', 110 "htmlFor IDL attribute should reflect the for content attribute"); 111 112 // DOMTokenList is tested in another bug so we just test assignation 113 element.htmlFor.value = 'a b c'; 114 is(String(element.htmlFor), 'a b c', "htmlFor should have changed"); 115 } 116 117 function submitForm() 118 { 119 // Setting the values for the submit. 120 document.getElementById('o').value = 'foo'; 121 document.getElementById('a').value = 'afield'; 122 document.getElementById('b').value = 'bfield'; 123 124 frameLoaded = checkFormSubmission; 125 126 // This will call checkFormSubmission() which is going to call ST.finish(). 127 document.getElementById('f').submit(); 128 } 129 130 function checkFormSubmission() 131 { 132 /** 133 * All elements values have been set just before the submission. 134 * The input elements values should be in the submit url but the ouput 135 * element value should not appear. 136 */ 137 138 is(frames.submit_frame.location.href, 139 `${location.origin}/tests/dom/html/test/forms/foo?a=afield&b=bfield`, 140 "The output element value should not be submitted"); 141 SimpleTest.finish(); 142 } 143 144 SimpleTest.waitForExplicitFinish(); 145 addLoadEvent(function() { 146 reflectString({ 147 element: document.createElement("output"), 148 attribute: "name", 149 }); 150 151 var o = document.getElementsByTagName('output'); 152 is(o.length, 1, "There should be one output element"); 153 154 o = o[0]; 155 ok(o instanceof HTMLOutputElement, 156 "The output should be instance of HTMLOutputElement"); 157 158 o = document.getElementById('o'); 159 ok(o instanceof HTMLOutputElement, 160 "The output should be instance of HTMLOutputElement"); 161 162 is(o.type, "output", "Output type IDL attribute should be 'output'"); 163 164 checkNameAttribute(o); 165 166 checkValueAndDefaultValueIDLAttribute(o); 167 168 checkValueModeFlag(o); 169 170 checkDescendantChanged(o); 171 172 checkFormIDLAttribute(o); 173 174 checkHtmlForIDLAttribute(o); 175 176 submitForm(); 177 }); 178 179 </script> 180 </pre> 181 </body> 182 </html>