blob: fc50eb120217b37f83f82aa6974c3740d127cc2e [file] [log] [blame]
<!DOCTYPE html>
<script src="../../../resources/js-test.js"></script>
<form name="my_form">
<select name="set_sel">
<option id="opt">========
</select>
<select name="get_sel">
<option id="one">option 1
<option id="two">option 2
</select>
</form>
<script>
description('Tests the indexed setter and getter for HTMLOptionsCollection.');
var i = 0;
var get_options = document.my_form.get_sel.options;
debug((++i) + ') getting options by index or by getElementById');
shouldBe('get_options[0]', 'document.getElementById("one")');
shouldBe('get_options[1]', 'document.getElementById("two")');
var set_options = document.my_form.set_sel.options;
debug((++i) + ') setting a few elements to Option values');
set_options[1] = new Option('A');
set_options[2] = new Option('B');
shouldBe('set_options.length', '3');
debug((++i) + ') trying to set an element to a non-Option value: undefined');
set_options[10] = undefined;
shouldBe('set_options.length', '3');
debug((++i) + ') trying to set an element to a non-Option value: null');
set_options[10] = null;
shouldBe('set_options.length', '3');
debug((++i) + ') trying to set an element to a non-Option value: form (object of incorrect type)');
shouldThrow('set_options[10] = my_form');
shouldBe('set_options.length', '3');
</script>