blob: aa09c972872c0130a3862b6a34df34a116adb072 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
<script src="resources/html-select-and-options-collection-utilities.js"></script>
</head>
<body>
<script>
description('Test select.options.add() with optgroup and with index parameter');
var mySelect = createSelectElementWithTestData();
function testAdd()
{
HTMLOptionsCollection.prototype.add.apply(mySelect.options, arguments);
var result = deepCopy(mySelect);
mySelect = createSelectElementWithTestData(); // Reset
return result;
}
function testAddWithoutResettingListOptions()
{
HTMLOptionsCollection.prototype.add.apply(mySelect.options, arguments);
return deepCopy(mySelect);
}
debug("<br>Call HTMLOptionsCollection.add() with zero arguments:");
shouldThrow("testAdd()");
debug("<br>Call HTMLOptionsCollection.add() with only one argument:");
shouldBeEqualToString('testAdd(createOption("Y9"))', "0,1,2,Y9");
shouldThrowErrorName('testAdd("foo")', "TypeError");
shouldThrowErrorName("testAdd(undefined)", "TypeError");
shouldThrowErrorName("testAdd(null)", "TypeError");
debug("<br>Call HTMLOptionsCollection.add() with two arguments:");
shouldBeEqualToString('testAdd(createGroup("Y1", "Y2"), null)', "0,1,2,Y1,Y2");
shouldBeEqualToString('testAdd(createGroup("Y3", "Y4"), 0)', "Y3,Y4,0,1,2");
shouldBeEqualToString('testAdd(createGroup("Y5", "Y6"), 2)', "0,1,Y5,Y6,2");
shouldBeEqualToString('testAdd(createGroup("Y7", "Y8"))', "0,1,2,Y7,Y8");
shouldBeEqualToString('testAddWithoutResettingListOptions(createOption("Y10"), mySelect.options[2])', "0,1,Y10,2");
shouldBeEqualToString('testAdd(createOption("Y11"), mySelect.options[1])', "0,Y11,1,Y10,2");
shouldBeEqualToString('testAddWithoutResettingListOptions(createGroup("Y12", "Y13"), mySelect.options[1])', "0,Y12,Y13,1,2");
shouldBeEqualToString('testAdd(createGroup("Y14", "Y15"), mySelect.options[3])', "0,Y12,Y13,Y14,Y15,1,2");
shouldThrow('testAdd(createOption("Y16"), createOption("Y17"))');
shouldBeEqualToString('testAdd(createOption("Y1"))', "0,1,2,Y1");
shouldBeEqualToString('testAdd(createOption("Y2"), null)', "0,1,2,Y2");
shouldBeEqualToString('testAdd(createOption("Y3"), 0)', "Y3,0,1,2");
shouldBeEqualToString('testAdd(createOption("Y4"), 1)', "0,Y4,1,2");
shouldBeEqualToString('testAdd(createOption("Y5"), 2)', "0,1,Y5,2");
shouldBeEqualToString('testAdd(createOption("Y6"), 3)', "0,1,2,Y6");
shouldBeEqualToString('testAdd(createOption("Y7"), 100)', "0,1,2,Y7");
shouldBeEqualToString('testAdd(createOption("Y8"), -100)', "0,1,2,Y8");
shouldBeEqualToString('testAdd(createOption("Y9"), "0")', "Y9,0,1,2");
shouldBeEqualToString('testAdd(createOption("Y10"), "1")', "0,Y10,1,2");
shouldBeEqualToString('testAdd(createOption("Y11"), "2")', "0,1,Y11,2");
shouldBeEqualToString('testAdd(createOption("Y12"), true)', "0,Y12,1,2");
shouldBeEqualToString('testAdd(createOption("Y13"), false)', "Y13,0,1,2");
shouldBeEqualToString('testAdd(createOption("Y14"), 2147483647)', "0,1,2,Y14");
shouldBeEqualToString('testAdd(createOption("Y15"), 2147483648)', "0,1,2,Y15");
shouldBeEqualToString('testAdd(createOption("Y16"), -2147483647)', "0,1,2,Y16");
shouldBeEqualToString('testAdd(createOption("Y17"), -2147483648)', "0,1,2,Y17");
shouldBeEqualToString('testAdd(createOption("Y18"), -2147483649)', "0,1,2,Y18");
shouldBeEqualToString('testAdd(createOption("Y19"), Infinity)', "Y19,0,1,2");
shouldBeEqualToString('testAdd(createOption("Y20"), -Infinity)', "Y20,0,1,2");
shouldBeEqualToString('testAdd(createOption("Y21"), "foo")', "Y21,0,1,2");
shouldBeEqualToString('testAdd(createOption("Y22"), NaN)', "Y22,0,1,2");
shouldBeEqualToString('testAdd(createOption("Y23"), undefined)', "0,1,2,Y23");
shouldBeEqualToString('testAdd(createOption("Y24"), -2)', "0,1,2,Y24");
shouldBeEqualToString('testAdd(createOption("X"), mySelect.options[0])', "X,0,1,2");
shouldBeEqualToString('testAdd(createOption("X"), mySelect.options[1])', "0,X,1,2");
shouldBeEqualToString('testAdd(createOption("X"), mySelect.options[2])', "0,1,X,2");
shouldBeEqualToString('testAdd(createOption("Y25"), 0, 1)', "Y25,0,1,2");
shouldBeEqualToString('testAdd(createOption("Y25"), mySelect.options[0], 1)', "Y25,0,1,2");
shouldThrowErrorName('testAdd("foo", 0)', "TypeError");
shouldThrowErrorName('testAdd(undefined, 0)', "TypeError");
shouldThrowErrorName('testAdd(null, 0)', "TypeError");
debug("<br>Call HTMLOptionsCollection.add() with three arguments (when it only takes two arguments):");
shouldBeEqualToString('testAdd(createOption("X"), 0, "unnecessary extra argument - should be ignored")', "X,0,1,2");
shouldBeEqualToString('testAdd(createOption("X"), mySelect.options[1], "unnecessary extra argument - should be ignored")', "0,X,1,2");
shouldBeEqualToString('testAdd(createGroup("G1", "G2"), 1, "unnecessary extra argument - should be ignored")', "0,G1,G2,1,2");
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>