<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
<!--
  Touch tests that involve the ontouchstart, ontouchmove, ontouchend or ontouchcancel callbacks
  should be written in an asynchronous fashion so they can be run on mobile platforms like Android.
  You will need to invoke isSuccessfullyParsed() in your test script when the test completes.
-->
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
var div = document.createElement("div");
div.style.width = "200%";
var slider = document.createElement("input");
slider.setAttribute("type", "range");
slider.style.width = "200px";
slider.style.height = "30px";

document.body.insertBefore(div, document.getElementById('console'));
div.appendChild(slider);


var checkPosition = (function() {

  var nCheck = 0;

  var expectedPositions = [50, 0];

  return function() {
    shouldBeEqualToString("slider.value", String(expectedPositions[nCheck++]));
  };

})();

function onKeyDown() {
    checkPosition();
    testRunner.notifyDone();
    isSuccessfullyParsed();
}

document.addEventListener('keydown', onKeyDown);

description("Tests to ensure that touch events are delivered to an input element with type=range even when there are no touch event handlers in Javascript. This test is only expected to pass if ENABLE_TOUCH_SLIDER is defined.");

if (window.testRunner) {
    testRunner.waitUntilDone();
}

if (window.eventSender) {
    var x = slider.offsetLeft;
    var y = slider.offsetTop + slider.clientHeight/2;
    var w = slider.clientWidth;

    checkPosition();

    eventSender.clearTouchPoints();
    eventSender.addTouchPoint(x + w/2, y);
    eventSender.touchStart();

    eventSender.updateTouchPoint(0, x, y);
    eventSender.touchMove();

    eventSender.releaseTouchPoint(0);
    eventSender.touchEnd();

    eventSender.keyDown(' ');

} else {
    debug('This test requires DRT.');
}
</script>
</body>
</html>
