<!DOCTYPE html>
<html>
<head>
<script src="../../../../resources/js-test.js"></script>
<script src="../../../../resources/ui-helper.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<input type="time" id="input" value="01:01:01">
<script>
description('Test if change event fires when the user selects the default value after the value was changed by JS.');

var eventsCounter = {};
function recordEvent(event) {
    if (eventsCounter[event.type] === undefined)
        eventsCounter[event.type] = 0;
    eventsCounter[event.type]++;
    debug('==> "' + event.type + '" event was dispatched.');
}

var input = document.getElementById('input');
input.addEventListener('input', recordEvent, false);
input.addEventListener('change', recordEvent, false);

input.value = '02:01:01';

shouldBeEqualToString('input.value', '02:01:01');
shouldBeUndefined('eventsCounter.input');
shouldBeUndefined('eventsCounter.change');

// We assume the date format is h:m a.

input.focus();

debug("Digit keys");                               // [00]/00/00
UIHelper.keyDown('downArrow');

shouldBeEqualToString('input.value', '01:01:01');
shouldBe('eventsCounter.input', '1');
shouldBe('eventsCounter.change', '1');

</script>
</body>
</html>