blob: a1ae634185dc37fbac454f5be50194e01cefdfb0 [file] [log] [blame]
<!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>