Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / forms / resources / multiple-fields-validity-badinput.js
1 var invalidStyleColor = 'rgb(255, 0, 0)';
2 var input;
3 var quiet = true;
4
5 function colorOf(el) {
6     return document.defaultView.getComputedStyle(el, null).getPropertyValue('background-color');
7 }
8 function testBadInput(type) {
9     if (!window.eventSender) {
10         debug('Needs to run this on DRT/WTR.');
11         return;
12     }
13     description('A ' + type + ' input fields with a bad user input should make validity.badInput true and have :invalid style.');
14     input = document.createElement('input');
15     input.type = type;
16     document.body.appendChild(input);
17     input.focus();
18
19     debug('Initial state. The elment has no value.');
20     shouldNotBe('colorOf(input)', 'invalidStyleColor');
21     shouldBeFalse('input.validity.badInput');
22
23     debug('Set a value to the first sub-field. The element becomes badInput.');
24     eventSender.keyDown('upArrow');
25     shouldBe('colorOf(input)', 'invalidStyleColor');
26     shouldBeTrue('input.validity.badInput');
27
28     if (type === 'date' || type === 'datetime' || type === 'datetime-local') {
29         debug('Set an invalid date, 2012-02-31.');
30         if (type == 'date')
31             input.value = '2012-02-01';
32         else if (type == 'datetime')
33             input.value = '2012-02-01T03:04Z';
34         else
35             input.value = '2012-02-01T03:04';
36         shouldNotBe('colorOf(input)', 'invalidStyleColor', quiet);
37         shouldBeFalse('input.validity.badInput');
38         eventSender.keyDown('rightArrow'); // -> 02/[01]/2012 ...
39         eventSender.keyDown('downArrow'); //  -> 02/[31]/2012 ...
40         shouldBeEqualToString('input.value', '');
41         shouldBeTrue('input.validity.badInput');
42         shouldBe('colorOf(input)', 'invalidStyleColor');
43     }
44 }