blob: 0164e82cec3e466e129b690ecde625b8c1e39933 [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 that HTMLSelectElement.add() works when passing an index or an HTML option element as its second argument.");
var mySelect = createSelectElementWithTestData();
function testAdd()
{
HTMLSelectElement.prototype.add.apply(mySelect, arguments);
var result = deepCopy(mySelect);
mySelect = createSelectElementWithTestData(); // Reset
return result;
}
debug("<br>Call HTMLSelectElement.add() with zero arguments:");
shouldThrow("testAdd()");
debug("<br>Call HTMLSelectElement.add() with one argument:");
shouldBeEqualToString('testAdd(createOption("Y1"))', "0,1,2,Y1");
shouldThrowErrorName('testAdd("foo")', "TypeError");
shouldThrowErrorName("testAdd(undefined)", "TypeError");
shouldThrowErrorName("testAdd(null)", "TypeError");
debug("<br>Call HTMLSelectElement.add() with two arguments:");
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");
shouldThrowErrorName('testAdd("foo", 0)', "TypeError");
shouldThrowErrorName('testAdd(undefined, 0)', "TypeError");
shouldThrowErrorName('testAdd(null, 0)', "TypeError");
debug("<br>Call HTMLSelectElement.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");
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>