summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/resources/common-wheel-event.js
blob: ec9d32c58a7a4fa290ca283527108a01e476b16e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function dispatchWheelEvent(element, deltaX, deltaY)
{
    var eventInit = { deltaX: -deltaX, deltaY: -deltaY };
    var event = new WheelEvent('mousewheel', eventInit);
    element.dispatchEvent(event);
}

var input;
function testWheelEvent(parameters)
{
    var inputType = parameters['inputType'];
    var initialValue = parameters['initialValue'];
    var stepUpValue1 = parameters['stepUpValue1'];
    var stepUpValue2 = parameters['stepUpValue2'];
    description('Test for wheel operations for <input type=' + inputType + '>');
    var parent = document.createElement('div');
    document.body.appendChild(parent);
    parent.innerHTML = '<input type=' + inputType + ' id=test value="' + initialValue + '"> <input id=another>';
    input = document.getElementById('test');
    input.focus();

    debug('Initial value is ' + initialValue + '. We\'ll wheel up by 1:');
    dispatchWheelEvent(input, 0, 1);
    shouldBeEqualToString('input.value', stepUpValue1);

    debug('Wheel up by 100:');
    dispatchWheelEvent(input, 0, 100);
    shouldBeEqualToString('input.value', stepUpValue2);

    debug('Wheel down by 1:');
    dispatchWheelEvent(input, 0, -1);
    shouldBeEqualToString('input.value', stepUpValue1);

    debug('Wheel down by 256:');
    dispatchWheelEvent(input, 0, -256);
    shouldBeEqualToString('input.value', initialValue);

    debug('Disabled input element:');
    input.disabled = true;
    dispatchWheelEvent(input, 0, 1);
    shouldBeEqualToString('input.value', initialValue);
    input.removeAttribute('disabled');


    debug('Read-only input element:');
    input.readOnly = true;
    dispatchWheelEvent(input, 0, 1);
    shouldBeEqualToString('input.value', initialValue);
    input.readOnly = false;

    debug('No focus:');
    document.getElementById('another').focus();
    dispatchWheelEvent(input, 0, 1);
    shouldBeEqualToString('input.value', initialValue);

    parent.parentNode.removeChild(parent);
}