summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/resources/multiple-fields-validity-badinput.js
blob: 5796687f34c7979c90fe32dd38bf5a5e531c07ca (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
var invalidStyleColor = 'rgb(255, 0, 0)';
var input;
var quiet = true;

function colorOf(el) {
    return document.defaultView.getComputedStyle(el, null).getPropertyValue('background-color');
}
function testBadInput(type) {
    if (!window.eventSender) {
        debug('Needs to run this on DRT/WTR.');
        return;
    }
    description('A ' + type + ' input fields with a bad user input should make validity.badInput true and have :invalid style.');
    input = document.createElement('input');
    input.type = type;
    document.body.appendChild(input);
    input.focus();

    debug('Initial state. The elment has no value.');
    shouldNotBe('colorOf(input)', 'invalidStyleColor');
    shouldBeFalse('input.validity.badInput');

    debug('Set a value to the first sub-field. The element becomes badInput.');
    eventSender.keyDown('upArrow');
    shouldBe('colorOf(input)', 'invalidStyleColor');
    shouldBeTrue('input.validity.badInput');

    if (type === 'date' || type === 'datetime' || type === 'datetime-local') {
        debug('Set an invalid date, 2012-02-31.');
        if (type == 'date')
            input.value = '2012-02-01';
        else if (type == 'datetime')
            input.value = '2012-02-01T03:04Z';
        else
            input.value = '2012-02-01T03:04';
        shouldNotBe('colorOf(input)', 'invalidStyleColor', quiet);
        shouldBeFalse('input.validity.badInput');
        eventSender.keyDown('rightArrow'); // -> 02/[01]/2012 ...
        eventSender.keyDown('downArrow'); //  -> 02/[31]/2012 ...
        shouldBeEqualToString('input.value', '');
        shouldBeTrue('input.validity.badInput');
        shouldBe('colorOf(input)', 'invalidStyleColor');
    }
}