Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / suggested-value-after-setvalue.html
blob811d0ddecc1b2d8ddb28dfb78c2115b1a5d3f516
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <p id="description">This test setting a value clears suggested value.</p>
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>
8 <script src="../../resources/dump-as-markup.js"></script>
9 <script>
11 var input = document.getElementById('test');
12 var textarea = document.getElementById('textarea');
13 textarea.value = 'initial value';
14 var select = document.getElementById('select');
15 select.selectedIndex = -1;
16 var result = document.getElementById('result');
17 if (!window.internals)
18 testFailed('This test requires internals object');
19 else {
20 input.focus();
21 input.selectionStart = input.selectionEnd = 0;
23 internals.setSuggestedValue(input, 'suggested value');
24 internals.setSuggestedValue(textarea, 'suggested value');
25 internals.setSuggestedValue(select, 'TX');
27 Markup.description(document.getElementById('description').textContent)
29 function addText(text) {
30 input.parentNode.appendChild(document.createTextNode(text));
33 function log() {
34 while (input.parentNode.firstChild != input.parentNode.lastChild)
35 input.parentNode.removeChild(input.parentNode.lastChild);
36 function addTextResult(value) { addText(value + ': ' + eval(value)); }
37 addTextResult('input.value');
38 addTextResult('internals.suggestedValue(input)');
39 addTextResult('input.selectionStart');
40 addTextResult('input.selectionEnd');
41 addTextResult('textarea.value');
42 addTextResult('internals.suggestedValue(textarea)');
43 addTextResult('select.value');
44 addTextResult('internals.suggestedValue(select)');
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);
54 return selectedValues.join(',');
57 log();
58 Markup.dump(input.parentNode, 'After setting suggestedValue');
60 input.value = 'new value';
61 textarea.value = 'new value';
62 select.value = 'CA';
64 log();
65 var innerTextValue = internals.shadowRoot(input).firstChild.innerText;
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');
71 Markup.dump(input.parentNode, 'After setting value');
74 </script>
75 </body>
76 </html>