1 description("This test performs a check that :valid/:invalid CSS psudo selectors are lively applied.");
3 // Setup for static elements.
4 var form = document.createElement('form');
5 document.body.appendChild(form);
6 var nonForm = document.createElement('div');
7 document.body.appendChild(nonForm);
9 function makeInvalid() {
10 var i = document.createElement('textarea');
18 function backgroundOf(el) {
19 return document.defaultView.getComputedStyle(el, null).getPropertyValue('background-color');
22 var elBackground = 'backgroundOf(el)';
23 var invalidColor = 'rgb(255, 0, 0)';
24 var normalColor = 'rgb(255, 255, 255)';
25 var disabledColor = 'rgb(0, 0, 0)';
26 var readOnlyColor = 'rgb(0, 255, 0)';
27 var validColor = 'rgb(0, 0, 255)';
29 // --------------------------------
30 // willValidate change
31 // --------------------------------
32 var el = makeInvalid();
33 // Confirm this element is invalid.
34 debug('Chheck the initial state:');
35 shouldBe(elBackground, 'invalidColor');
37 debug('Change name:');
39 shouldBe(elBackground, 'invalidColor');
41 shouldBe(elBackground, 'invalidColor');
43 debug('Change disabled:');
46 shouldBe(elBackground, 'disabledColor');
48 shouldBe(elBackground, 'invalidColor');
50 debug('Change readOnly:');
53 shouldBe(elBackground, 'readOnlyColor');
55 shouldBe(elBackground, 'invalidColor');
57 debug('Inside/outside of a form:');
59 nonForm.appendChild(el);
60 shouldBe(elBackground, 'invalidColor');
62 shouldBe(elBackground, 'invalidColor');
64 // --------------------------------
66 // --------------------------------
67 debug('Change the value by DOM attribute:');
70 shouldBe(elBackground, 'validColor');
72 shouldBe(elBackground, 'invalidColor');
74 debug('Change the value by key input:');
77 eventSender.keyDown('a');
78 shouldBe(elBackground, 'validColor');
79 eventSender.keyDown('backspace', []);
80 shouldBe(elBackground, 'invalidColor');
82 // --------------------------------
84 // --------------------------------
85 debug('Change required:');
88 shouldBe(elBackground, 'validColor');
90 shouldBe(elBackground, 'invalidColor');
92 debug('Change maxlength:');
94 el.value = '1234567890';
95 shouldBe(elBackground, 'validColor');
96 // Make the value dirty by deleting the last character.
98 el.setSelectionRange(10, 10);
99 document.execCommand('delete');
101 shouldBe(elBackground, 'invalidColor');
103 shouldBe(elBackground, 'validColor');