summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/resources/multiple-fields-blur-and-focus-events.js
blob: b9c3582cb7ca155772c241e01a33e8535091354c (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
58
59
60
61
62
63
var testInput;
var blurCounter = 0;
var focusCounter = 0;

function keyDown(key, modifiers)
{
    eventSender.keyDown(key, modifiers);
}

function state()
{
    return 'blur=' + blurCounter + ' focus=' + focusCounter;
}

function beginTestCase(testCaseName)
{
    debug(testCaseName);
    blurCounter = 0;
    focusCounter = 0;
}

function startTestFor(typeName)
{
    description('Check blur and focus events for multiple fields ' + typeName + ' input UI');
    document.getElementById('container').innerHTML = '<input id="before">'
        + '<input id="test" type="' + typeName + '">'
        + '<input id="after">';

    testInput = document.getElementById('test');
    testInput.addEventListener('blur', function () { ++blurCounter; });
    testInput.addEventListener('focus', function () { ++focusCounter; });

    beginTestCase('focus() and blur()');
    shouldBeEqualToString('testInput.focus(); state()', 'blur=0 focus=1');
    shouldBeEqualToString('testInput.blur(); state()', 'blur=1 focus=1');

    if (window.eventSender) {
        var numberOfFields;
        switch (typeName) {
        case 'week':
        case 'month':
            numberOfFields = 2;
            break;
        case 'datetime':
        case 'datetime-local':
            numberOfFields = 6;
            break;
        default:
            numberOfFields = 3;
            break;
        }

        beginTestCase('focus and Tab key to blur');
        document.getElementById("before").focus();
        for (var i = 0; i < numberOfFields; i++)
            shouldBeEqualToString('keyDown("\t"); state()', 'blur=0 focus=1');
        shouldBeEqualToString('keyDown("\t"); state()', 'blur=1 focus=1');
    } else {
        debug('Please run in DumpRenderTree for focus and Tab-key test case');
    }
    debug('');
    document.body.removeChild(document.getElementById("container"));
}