<!DOCTYPE html>
<html><body>
<script src="../../resources/js-test-pre.js"></script>

<div id="container">
    <input id="input" type="text" value="something">
    <input id="readonlyInput" type="text" readonly value="something">
    <input id="disabledInput" type="text" disabled value="something">

    <textarea id="textarea">something</textarea>
    <textarea id="readonlyTextarea" readonly>something</textarea>
    <textarea id="disabledTextarea" disabled>something</textarea>
</div>
<pre id="console"></pre>

<script>
function doubleClickOn(element)
{
    var x = element.offsetLeft + element.offsetWidth / 2;
    var y = element.offsetTop + element.offsetHeight / 2;

    eventSender.mouseMoveTo(x, y);
    eventSender.mouseDown();
    eventSender.mouseUp();
    eventSender.mouseDown();
    eventSender.mouseUp();
}

var selectEventFiredOnInput = false;
var selectEventFiredOnReadonlyInput = false;
var selectEventFiredOnDisabledInput = false;
var selectEventFiredOnTextarea = false;
var selectEventFiredOnReadonlyTextarea = false;
var selectEventFiredOnDisabledTextarea = false;

input.addEventListener('select', function() {
    selectEventFiredOnInput = true;
});
readonlyInput.addEventListener('select', function() {
    selectEventFiredOnReadonlyInput = true;
});
disabledInput.addEventListener('select', function() {
    selectEventFiredOnDisabledInput = true;
});

textarea.addEventListener('select', function() {
    selectEventFiredOnTextarea = true;
});
readonlyTextarea.addEventListener('select', function() {
    selectEventFiredOnReadonlyTextarea = true;
});
disabledTextarea.addEventListener('select', function() {
    selectEventFiredOnDisabledTextarea = true;
});

debug('double clicking on normal input');
doubleClickOn(input);
shouldBeTrue('selectEventFiredOnInput');
debug('');

debug('double clicking on readonly input');
doubleClickOn(readonlyInput);
shouldBeTrue('selectEventFiredOnReadonlyInput');
debug('');

debug('double clicking on disabled input');
doubleClickOn(disabledInput);
shouldBeTrue('selectEventFiredOnDisabledInput');
debug('');

debug('double clicking on normal textarea');
doubleClickOn(textarea);
shouldBeTrue('selectEventFiredOnTextarea');
debug('');

debug('double clicking on readonly textarea');
doubleClickOn(readonlyTextarea);
shouldBeTrue('selectEventFiredOnReadonlyTextarea');
debug('');

debug('double clicking on disabled textarea');
doubleClickOn(disabledTextarea);
shouldBeTrue('selectEventFiredOnDisabledTextarea');
debug('');

container.innerHTML = "";
</script>

<script src="../../resources/js-test-post.js"></script>
</body></html>
