OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <body> | 3 <body> |
4 <p id="description">This test setting a value clears suggested value.</p> | 4 <p id="description">This test setting a value clears suggested value.</p> |
5 <pre><input id="test" type="text" value="initial value"></pre> | 5 <pre><input id="test" type="text" value="initial value"><br> |
6 <textarea id="textarea"></textarea><br> | |
7 <select id="select"><option>CA</option><option>TX</option></select></pre> | |
6 <script src="../../resources/dump-as-markup.js"></script> | 8 <script src="../../resources/dump-as-markup.js"></script> |
7 <script> | 9 <script> |
8 | 10 |
9 var input = document.getElementById('test'); | 11 var input = document.getElementById('test'); |
12 var textarea = document.getElementById('textarea'); | |
13 textarea.value = "initial value"; | |
tkent
2014/06/09 01:01:13
nit: Use single-quotes for consistency.
| |
14 var select = document.getElementById('select'); | |
15 select.selectedIndex = -1; | |
10 var result = document.getElementById('result'); | 16 var result = document.getElementById('result'); |
11 if (!window.internals) | 17 if (!window.internals) |
12 testFailed('This test requires internals object'); | 18 testFailed('This test requires internals object'); |
13 else { | 19 else { |
14 input.focus(); | 20 input.focus(); |
15 input.selectionStart = input.selectionEnd = 0; | 21 input.selectionStart = input.selectionEnd = 0; |
16 | 22 |
17 internals.setSuggestedValue(input, 'suggested value'); | 23 internals.setSuggestedValue(input, 'suggested value'); |
24 internals.setSuggestedValue(textarea, 'suggested value'); | |
25 internals.setSuggestedValue(select, 'TX'); | |
18 | 26 |
19 Markup.description(document.getElementById('description').textContent) | 27 Markup.description(document.getElementById('description').textContent) |
20 | 28 |
21 function addText(text) { | 29 function addText(text) { |
22 input.parentNode.appendChild(document.createTextNode(text)); | 30 input.parentNode.appendChild(document.createTextNode(text)); |
23 } | 31 } |
24 | 32 |
25 function log() { | 33 function log() { |
26 while (input.parentNode.firstChild != input.parentNode.lastChild) | 34 while (input.parentNode.firstChild != input.parentNode.lastChild) |
27 input.parentNode.removeChild(input.parentNode.lastChild); | 35 input.parentNode.removeChild(input.parentNode.lastChild); |
28 function addTextResult(value) { addText(value + ': ' + eval(value)); } | 36 function addTextResult(value) { addText(value + ': ' + eval(value)); } |
29 addTextResult('input.value'); | 37 addTextResult('input.value'); |
30 addTextResult('internals.suggestedValue(input)'); | 38 addTextResult('internals.suggestedValue(input)'); |
31 addTextResult('input.selectionStart'); | 39 addTextResult('input.selectionStart'); |
32 addTextResult('input.selectionEnd'); | 40 addTextResult('input.selectionEnd'); |
41 addTextResult('textarea.value'); | |
42 addTextResult('internals.suggestedValue(textarea)'); | |
43 addTextResult('select.value'); | |
44 addTextResult('internals.suggestedValue(select)'); | |
45 } | |
46 | |
47 function getSelectedValues(select) { | |
48 var selectedValues = []; | |
49 for (var i = 0; i < select.options.length; i++) { | |
50 var option = select.options[i]; | |
51 if (option.selected) | |
52 selectedValues.push(option.value); | |
53 } | |
54 return selectedValues.join(','); | |
33 } | 55 } |
34 | 56 |
35 log(); | 57 log(); |
36 Markup.dump(input.parentNode, 'After setting suggestedValue'); | 58 Markup.dump(input.parentNode, 'After setting suggestedValue'); |
37 | 59 |
38 input.value = 'new value'; | 60 input.value = 'new value'; |
61 textarea.value = 'new value'; | |
62 select.value = 'CA'; | |
39 | 63 |
40 log(); | 64 log(); |
41 var innerTextValue = internals.shadowRoot(input).firstChild.innerText; | 65 var innerTextValue = internals.shadowRoot(input).firstChild.innerText; |
42 addText(innerTextValue == 'new value' ? 'PASS' : 'FAIL'); | 66 var innerTextAreaValue = internals.shadowRoot(textarea).firstChild.innerText ; |
67 var selectedValues = getSelectedValues(select); | |
68 addText(innerTextValue == 'new value' && | |
69 innerTextAreaValue == 'new value' && | |
70 selectedValues == 'CA' ? 'PASS' : 'FAIL'); | |
43 Markup.dump(input.parentNode, 'After setting value'); | 71 Markup.dump(input.parentNode, 'After setting value'); |
44 } | 72 } |
45 | 73 |
46 </script> | 74 </script> |
47 </body> | 75 </body> |
48 </html> | 76 </html> |
OLD | NEW |