summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/resources/common-spinbutton-click-in-iframe.js
blob: 2043a82920a45a77d40e1952d84385d8b6636101 (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
window.jsTestIsAsync = true;

var iframe;
var testInput;

function getSpinButton(input)
{
    if (!window.internals)
        return null;
    return getElementByPseudoId(internals.oldestShadowRoot(input), "-webkit-inner-spin-button");
}

function mouseClick()
{
    if (!window.eventSender)
        return;
    eventSender.mouseDown();
    eventSender.mouseUp();
}

function mouseMoveTo(x, y)
{
    if (!window.eventSender)
        return;
    eventSender.mouseMoveTo(x, y);
}

function runIFrameLoaded(config)
{
    testInput = iframe.contentDocument.getElementById('test');
    testInput.focus();
    var spinButton = getSpinButton(testInput);
    if (spinButton) {
        mouseMoveTo(
            iframe.offsetLeft + spinButton.offsetLeft + spinButton.offsetWidth / 2,
            iframe.offsetTop + spinButton.offsetTop + spinButton.offsetHeight / 4);
    }
    mouseClick();
    shouldBeEqualToString('testInput.value', config['expectedValue']);
    iframe.parentNode.removeChild(iframe);
    finishJSTest();
}

function testClickSpinButtonInIFrame(config)
{
    description('Checks mouse click on spin button in iframe.');
    if (!window.eventSender)
        debug('Please run in DumpRenderTree');

    iframe = document.createElement('iframe');
    iframe.addEventListener('load', function () { runIFrameLoaded(config) });
    iframe.srcdoc = '<input id=test type=' + config['inputType'] + ' value="' + config['initialValue'] + '">';
    document.body.appendChild(iframe);
}