test_input_defaultValue.html (2914B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=977029 5 --> 6 <head> 7 <title>Test for Bug 977029</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 </head> 10 <body> 11 <div id="content"> 12 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=977029">Bug 977029</a> 13 <p> 14 Goal of this test is to check that modifying defaultValue and value attribute 15 of input types is working as expected. 16 </p> 17 <form> 18 <input id='a' type="color" value="#00ff00"> 19 <input id='b' type="text" value="foo"> 20 <input id='c' type="email" value="foo"> 21 <input id='d' type="date" value="2010-09-20"> 22 <input id='e' type="search" value="foo"> 23 <input id='f' type="tel" value="foo"> 24 <input id='g' type="url" value="foo"> 25 <input id='h' type="number" value="42"> 26 <input id='i' type="range" value="42" min="0" max="100"> 27 <input id='j' type="time" value="17:00:25.54"> 28 </form> 29 </div> 30 <script type="application/javascript"> 31 32 // [ element id | original defaultValue | another value | another default value] 33 // Preferably use only valid values: the goal of this test isn't to test the 34 // value sanitization algorithm (for input types which have one) as this is 35 // already part of another test) 36 var testData = [["a", "#00ff00", "#00aaaa", "#00ccaa"], 37 ["b", "foo", "bar", "tulip"], 38 ["c", "foo", "foo@bar.org", "tulip"], 39 ["d", "2010-09-20", "2012-09-21", ""], 40 ["e", "foo", "bar", "tulip"], 41 ["f", "foo", "bar", "tulip"], 42 ["g", "foo", "bar", "tulip"], 43 ["h", "42", "1337", "3"], 44 ["i", "42", "17", "3"], 45 ["j", "17:00:25.54", "07:00:25", "03:00:03"], 46 ]; 47 48 for (var data of testData) { 49 id = data[0]; 50 input = document.getElementById(id); 51 originalDefaultValue = data[1]; 52 is(originalDefaultValue, input.defaultValue, 53 "Default value isn't the expected one"); 54 is(originalDefaultValue, input.value, 55 "input.value original value is different from defaultValue"); 56 input.defaultValue = data[2] 57 is(input.defaultValue, input.value, 58 "Changing default value before value was changed should change value too"); 59 input.value = data[3]; 60 input.defaultValue = originalDefaultValue; 61 is(input.value, data[3], 62 "Changing default value after value was changed should not change value"); 63 input.value = data[2]; 64 is(originalDefaultValue, input.defaultValue, 65 "defaultValue shouldn't change when changing value"); 66 input.defaultValue = data[3]; 67 is(input.defaultValue, data[3], 68 "defaultValue should have changed"); 69 // Change the value... 70 input.value = data[2]; 71 is(input.value, data[2], 72 "value should have changed"); 73 // ...then reset the form 74 input.form.reset(); 75 is(input.defaultValue, input.value, 76 "reset form should bring back the default value"); 77 } 78 </script> 79 </body> 80 </html>