Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / form-pseudo-valid-style.html
blob764481e0d0230f60e62ef4362d294fa36977bd8d
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 <style>
6 :invalid { background: rgb(255, 0, 0); }
7 :valid { background: rgb(0, 255, 0); }
8 form:invalid input[type=submit] { background-color: rgb(127, 0, 0); }
9 form:valid input[type=submit] { background-color: rgb(0, 127, 0); }
10 </style>
11 </head>
12 <body>
13 <script>
14 description('Check if :valid/:invalid CSS pseudo selectors are lively applied for forms');
16 function $(id) {
17 return document.getElementById(id);
20 function backgroundOf(element) {
21 return document.defaultView.getComputedStyle(element, null).getPropertyValue('background-color');
24 var invalidColor = 'rgb(255, 0, 0)';
25 var validColor = 'rgb(0, 255, 0)';
26 var subInvalidColor = 'rgb(127, 0, 0)';
27 var subValidColor = 'rgb(0, 127, 0)';
29 var parent = document.createElement('div');
30 document.body.appendChild(parent);
32 debug('Removing and adding required text inputs and modifying their value by a DOM tree mutation:');
33 parent.innerHTML = '<form id=form1><input type=text id=input1 required><input type=text id=input2 required value=a><input type=submit id=sub1></form>';
34 var form1 = $('form1');
35 var input1 = $('input1');
36 var input2 = $('input2');
37 var sub1 = $('sub1');
38 shouldBe('backgroundOf(form1)', 'invalidColor');
39 shouldBe('backgroundOf(sub1)', 'subInvalidColor');
40 shouldBe('form1.removeChild(input1); backgroundOf(form1)', 'validColor');
41 shouldBe('backgroundOf(sub1)', 'subValidColor');
42 shouldBe('form1.appendChild(input1); backgroundOf(form1)', 'invalidColor');
43 shouldBe('backgroundOf(sub1)', 'subInvalidColor');
44 shouldBe('input1.setAttribute("value", "a"); backgroundOf(form1)', 'validColor');
45 shouldBe('backgroundOf(sub1)', 'subValidColor');
46 shouldBe('input2.setAttribute("value", ""); backgroundOf(form1)', 'invalidColor');
47 shouldBe('backgroundOf(sub1)', 'subInvalidColor');
48 debug('')
50 debug('Disabling and marking inputs readonly by a DOM tree mutation:');
51 parent.innerHTML = '<form id=form1><input type=text id=input1 required><input type=text id=input2 required value=a><input type=submit id=sub1></form>';
52 var form1 = $('form1');
53 var input1 = $('input1');
54 var sub1 = $('sub1');
55 shouldBe('backgroundOf(form1)', 'invalidColor');
56 shouldBe('backgroundOf(sub1)', 'subInvalidColor');
57 shouldBe('input1.disabled=1; backgroundOf(form1)', 'validColor');
58 shouldBe('backgroundOf(sub1)', 'subValidColor');
59 shouldBe('input1.disabled=0; backgroundOf(form1)', 'invalidColor');
60 shouldBe('backgroundOf(sub1)', 'subInvalidColor');
61 shouldBe('input1.setAttribute("readonly", "1"); backgroundOf(form1)', 'validColor');
62 shouldBe('backgroundOf(sub1)', 'subValidColor');
63 debug('')
65 debug('Move element under datalist by a DOM tree mutation:');
66 parent.innerHTML = '<form id=form1></form><datalist id=dl1></datalist><input type=text id=input1 required form=form1>';
67 var form1 = $('form1');
68 var input1 = $('input1');
69 var dl1 = $('dl1');
70 shouldBe('backgroundOf(form1)', 'invalidColor');
71 shouldBe('parent.removeChild(input1); backgroundOf(form1)', 'validColor');
72 shouldBe('dl1.appendChild(input1); backgroundOf(form1)', 'validColor');
73 shouldBe('parent.appendChild(input1); backgroundOf(form1)', 'invalidColor');
74 debug('')
76 debug('Adding a required text input that is not a direct child of the form:');
77 parent.innerHTML = '<form id=form1></form>';
78 var form1 = $('form1');
79 shouldBe('backgroundOf(form1)', 'validColor');
80 var div1 = document.createElement('div');
81 var input1 = document.createElement('input');
82 input1.setAttribute('type', 'text');
83 input1.setAttribute('required', '');
84 form1.appendChild(div1);
85 shouldBe('div1.appendChild(input1); backgroundOf(form1)', 'invalidColor');
86 debug('');
88 debug('Render multiple forms and reassign an invalid input from one to another:');
89 parent.innerHTML = '<form id=form1><input type=text id=input1 required><input type=text id=input2 required value="a"></form>'
90 + '<form id=form2><input type=text id=input3><input type=text id=input4 required value="a"></form>'
91 + '<form id=form3></form>';
92 shouldBe('backgroundOf($("form1"))', 'invalidColor');
93 shouldBe('backgroundOf($("form2"))', 'validColor');
94 shouldBe('backgroundOf($("form3"))', 'validColor');
95 var input1 = $('input1');
96 input1.setAttribute("form", "form3");
97 shouldBe('backgroundOf($("form1"))', 'validColor');
98 shouldBe('backgroundOf($("form3"))', 'invalidColor');
99 debug('');
101 debug('Ensure that invalid event was not triggered on style evaluation:');
102 var val = '0';
103 parent.innerHTML = '<form id=form1><input type=text id=input1 required oninvalid="val=\'1\';"></form>';
104 var form1 = $('form1');
105 shouldBe('backgroundOf(form1)', 'invalidColor');
106 shouldBeEqualToString('val', '0');
107 shouldBeEqualToString('form1.checkValidity(); val', '1');
108 debug('');
110 parent.innerHTML = '';
111 </script>
112 </body>
113 </html>