Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / select / select-state-restore.html
blobc0142279d2fe917800c8f448702582bf1580294b
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 <script src="../resources/common.js"></script>
6 </head>
7 <body>
8 <p>Test if selected options are correctly restored even if their positions were changed.</p>
9 <div id="console"></div>
11 <input id="emptyOnFirstVisit">
12 <div id="parent">
13 <form action="data:text/html,&lt;script>history.back()&lt;/script>" id=form1>
14 <select id="select1" multiple>
15 <option id="opt-ca-1" value="CA">California 1</option>
16 <option id="opt-ca-2" value="CA" selected>California 2</option>
17 <option id="opt-la">LA</option>
18 <optgroup>
19 <option id="opt-tk" selected>Tokyo</option>
20 <option id="opt-os">Osaka</option>
21 </optgroup>
22 <option id="opt-ak" value="AK">Alaska</option>
23 <option id="opt-wy" selected>WY</option>
24 </select>
25 </form>
26 </div>
28 <script>
30 jsTestIsAsync = true;
32 function runTest()
34 var state = document.getElementById('emptyOnFirstVisit');
35 if (!state.value) {
36 // First visit.
37 setTimeout(function() {
38 state.value = 'visited';
39 $('opt-tk').selected = false;
40 $('opt-os').selected = true;
41 $('select1').insertBefore($('opt-ak'), $('opt-ca-1'));
42 $('select1').removeChild($('opt-wy'));
43 var newOption = document.createElement('option');
44 newOption.textContent = 'NY';
45 $('select1').appendChild(newOption);
46 newOption.selected = true;
47 $('form1').submit();
48 }, 0);
49 } else {
50 // Went back to this page again, and form state should be restored.
51 shouldBeFalse('$("opt-la").selected');
52 shouldBeFalse('$("opt-tk").selected');
53 shouldBeTrue('$("opt-os").selected');
54 shouldBeFalse('$("opt-ak").selected');
55 shouldBeFalse('$("opt-wy").selected');
56 debug('We don\'t care which one is selected because their values are identical:');
57 shouldBeTrue('!!($("opt-ca-1").selected ^ $("opt-ca-2").selected)');
59 $('parent').innerHTML = '';
60 setTimeout(function() {
61 finishJSTest();
62 }, 0);
66 window.onload = runTest;
67 </script>
68 </body>