<!DOCTYPE html>
<script src="../../../resources/js-test.js"></script>
<form>
<input type="radio" name="test1" id="radio1">A
<input type="radio" name="test1" id="radio2">B
</form>
<script>
function dispatchEvent(target, eventType, offsetX, offsetY)
{
var targetRect = target.getBoundingClientRect();
var ev = document.createEvent('MouseEvent');
ev.initMouseEvent(eventType, true, true, window, 1, 1, 1, targetRect.left + offsetX, targetRect.top + offsetY, false, false, false, false, 0, document);
target.dispatchEvent(ev);
}
function defaultPreventingHandler(e) {
e.preventDefault();
}
var radio1 = document.getElementById('radio1');
var radio2 = document.getElementById('radio2');
radio1.addEventListener('click', defaultPreventingHandler, false);
radio2.addEventListener('click', defaultPreventingHandler, false);
radio1.checked = true;
// Default-prevented click should not change checked and keep default checked radio
dispatchEvent(radio1, 'click', 2, 2);
dispatchEvent(radio2, 'click', 2, 2);
shouldBeTrue('document.getElementById("radio1").checked');
shouldBeFalse('document.getElementById("radio2").checked');
radio1.checked = false;
// Default-prevented click should not change checked
dispatchEvent(radio1, 'click', 2, 2);
dispatchEvent(radio2, 'click', 2, 2);
shouldBeFalse('document.getElementById("radio1").checked');
shouldBeFalse('document.getElementById("radio2").checked');
</script>