blob: 1316c7c65942dd93e03ca2da3595ee5818963758 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description('valueMissing tests for radio buttons');
var parent = document.createElement('div');
document.body.appendChild(parent);
debug('Without form element');
parent.innerHTML = '<input name=victim type=radio required>'
+ '<input name=victim type=radio>'
+ '<input name=victim type=radio>';
var inputs = document.getElementsByName('victim');
debug('No checked button:');
shouldBeTrue('inputs[0].validity.valueMissing');
shouldBeTrue('inputs[1].validity.valueMissing');
shouldBeTrue('inputs[2].validity.valueMissing');
debug('The second button has been checked:');
inputs[1].checked = true;
shouldBeFalse('inputs[0].validity.valueMissing');
shouldBeFalse('inputs[1].validity.valueMissing');
shouldBeFalse('inputs[2].validity.valueMissing');
debug('The first button has been checked:');
inputs[0].checked = true;
shouldBeFalse('inputs[0].validity.valueMissing');
shouldBeFalse('inputs[1].validity.valueMissing');
shouldBeFalse('inputs[2].validity.valueMissing');
debug('The third button has been checked:');
inputs[2].checked = true;
shouldBeFalse('inputs[0].validity.valueMissing');
shouldBeFalse('inputs[1].validity.valueMissing');
shouldBeFalse('inputs[2].validity.valueMissing');
debug('');
debug('With form element');
parent.innerHTML = '<form>'
+ '<input name=victim type=radio required>'
+ '<input name=victim type=radio>'
+ '<input name=victim type=radio>'
+ '</form>';
inputs = document.getElementsByName('victim');
debug('No checked button:');
shouldBeTrue('inputs[0].validity.valueMissing');
shouldBeTrue('inputs[1].validity.valueMissing');
shouldBeTrue('inputs[2].validity.valueMissing');
debug('The first button has been checked:');
inputs[0].checked = true;
shouldBeFalse('inputs[0].validity.valueMissing');
shouldBeFalse('inputs[1].validity.valueMissing');
shouldBeFalse('inputs[2].validity.valueMissing');
debug('The second button has been checked:');
inputs[1].checked = true;
shouldBeFalse('inputs[0].validity.valueMissing');
shouldBeFalse('inputs[1].validity.valueMissing');
shouldBeFalse('inputs[2].validity.valueMissing');
debug('The third button has been checked:');
inputs[2].checked = true;
shouldBeFalse('inputs[0].validity.valueMissing');
shouldBeFalse('inputs[1].validity.valueMissing');
shouldBeFalse('inputs[2].validity.valueMissing');
debug('');
debug('Not in a radio button group');
var requiredButton = document.createElement('input');
requiredButton.type = 'radio';
requiredButton.name = 'victim';
requiredButton.required = true;
shouldBeTrue('requiredButton.validity.valueMissing');
parent.innerHTML = '<input name=victim type=radio required><input name=victim type=radio>';
requiredButton = document.getElementsByName('victim')[0];
var button = document.getElementsByName('victim')[1];
shouldBeTrue('requiredButton.validity.valueMissing');
shouldBeTrue('button.validity.valueMissing');
parent.removeChild(button);
shouldBeFalse('button.validity.valueMissing');
parent.removeChild(requiredButton);
shouldBeTrue('requiredButton.validity.valueMissing');
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>