summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/select/selected-index-preserved-when-option-text-changes.html
blob: a1ae634185dc37fbac454f5be50194e01cefdfb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!doctype html>
<html>
<body>

<select id="theSelect">
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
</select>
<select id="theSelect2" multiple>
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
<option>Item 4</option>
<option>Item 5</option>
</select>

<div id="console"></div>
<script src="../../../resources/js-test.js"></script>
<script>
description("Fix for bug 70547-- changing the text of an option in a select element with no selected option (-1) should preserve that option");

function runTest() {
    debug("Setting selected index to -1");
    mySelect.selectedIndex = -1;
    mySelect.options[0].text = "Changed text for item 1";
    debug("Changed text attribute of first item");
    shouldBe("mySelect.selectedIndex", "-1");

    mySelect.selectedIndex = -1;
    mySelect.options[0].value = "Changed value for item 1";
    debug("Changed value attribute of first item");
    shouldBe("mySelect.selectedIndex", "-1");

    mySelect.selectedIndex = -1;
    mySelect.options[0].label = "Changed label for item 1";
    debug("Changed label attribute of first item");
    shouldBe("mySelect.selectedIndex", "-1");

    debug("Setting selected index to 1");
    mySelect.selectedIndex = 1;
    mySelect.options[0].text = "Changed text for item 1";
    debug("Changed text attribute of first item");
    shouldBe("mySelect.selectedIndex", "1");

    mySelect.selectedIndex = 1;
    mySelect.options[0].value = "Changed value for item 1";
    debug("Changed value attribute of first item");
    shouldBe("mySelect.selectedIndex", "1");

    mySelect.selectedIndex = 1;
    mySelect.options[0].label = "Changed label for item 1";
    debug("Changed label attribute of first item");
    shouldBe("mySelect.selectedIndex", "1");
}

var mySelect = document.getElementById("theSelect");
debug("Running tests on menu list");
runTest();

mySelect = document.getElementById("theSelect2");
debug("Running tests on list box");
runTest();

</script>

</body>
</html>