<!DOCTYPE html>
<body>
<script src="../../../resources/js-test.js"></script>
<script>
function selectionMap(select) {
    var result = '';
    var options = select.options;
    for (var i = 0; i < options.length; ++i)
        result += options[i].selected ? '1' : '0';
    return result;
}

description('Tests for HTMLOptionElement::defaultSelected');

var option1 = document.createElement('option');
shouldBeFalse('option1.defaultSelected');
shouldBeTrue('option1.defaultSelected = true; option1.hasAttribute("selected")');
shouldBeTrue('option1.selected');
shouldBeTrue('option1.selected = false; option1.defaultSelected');
shouldBeFalse('option1.defaultSelected = false; option1.hasAttribute("selected")');
shouldBeTrue('option1.setAttribute("selected", "no"); option1.defaultSelected');
shouldBeFalse('option1.removeAttribute("selected"); option1.defaultSelected');

var select1 = document.createElement('select');
select1.innerHTML = '<option>1<option>2<option>3';
shouldBeEqualToString('selectionMap(select1)', '100');

shouldBeEqualToString('select1[2].defaultSelected = true; selectionMap(select1)', '001');
shouldBeEqualToString('select1[1].defaultSelected = true; selectionMap(select1)', '010');
shouldBeEqualToString('select1[1].defaultSelected = false; selectionMap(select1)', '100');
shouldBeEqualToString('select1[2].selected = true; selectionMap(select1)', '001');
</script>
</body>
