JS Test Harness: Insert the stylesheet dynamically
[WebKit-https.git] / LayoutTests / fast / forms / ValidityState-customError.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../fast/js/resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
9
10 <fieldset name="set" id="fieldset-set"></fieldset>
11 <button   name="set" id="button-set"></button>
12 <button   name="set" id="button-button-set" type="button"></button>
13 <button   name="set" id="button-reset-set" type="reset"></button>
14 <select   name="set" id="select-set"></select>
15 <textarea name="set" id="textarea-set"></textarea>
16 <input    name="set" id="input-set" />
17 <input    name="set" id="input-submit-set" type="submit" />
18
19 <fieldset name="set-and-empty" id="fieldset-set-and-empty"></fieldset>
20 <button   name="set-and-empty" id="button-set-and-empty"></button>
21 <button   name="set-and-empty" id="button-button-set-and-empty" type="button"></button>
22 <button   name="set-and-empty" id="button-reset-set-and-empty" type="reset"></button>
23 <select   name="set-and-empty" id="select-set-and-empty"></select>
24 <textarea name="set-and-empty" id="textarea-set-and-empty"></textarea>
25 <input    name="set-and-empty" id="input-set-and-empty" />
26 <input    name="set-and-empty" id="input-submit-set-and-empty" type="submit" />
27
28 <fieldset name="no-changes" id="fieldset-no-changes"></fieldset>
29 <button   name="no-changes" id="button-no-changes"></button>
30 <button   name="no-changes" id="button-button-no-changes" type="button"></button>
31 <button   name="no-changes" id="button-reset-no-changes" type="reset"></button>
32 <select   name="no-changes" id="select-no-changes"></select>
33 <textarea name="no-changes" id="textarea-no-changes"></textarea>
34 <input    name="no-changes" id="input-no-changes" />
35 <input    name="no-changes" id="input-submit-no-changes" type="submit" />
36
37 <fieldset name="many-changes" id="fieldset-many-changes"></fieldset>
38 <button   name="many-changes" id="button-many-changes"></button>
39 <button   name="many-changes" id="button-button-many-changes" type="button"></button>
40 <button   name="many-changes" id="button-reset-many-changes" type="reset"></button>
41 <select   name="many-changes" id="select-many-changes"></select>
42 <textarea name="many-changes" id="textarea-many-changes"></textarea>
43 <input    name="many-changes" id="input-many-changes" />
44 <input    name="many-changes" id="input-submit-many-changes" type="submit" />
45
46 <script language="JavaScript" type="text/javascript">
47 function customErrorFor(id) {
48     return document.getElementById(id).validity.customError;
49 }
50
51 description("This test checks validity.customError.");
52
53 debug('Set some value for customError.');
54 v = document.getElementsByName("set");
55 for (i = 0; i < v.length; i++)
56     v[i].setCustomValidity("Custom validation message");
57 shouldBeFalse('customErrorFor("fieldset-set")');
58 shouldBeTrue('customErrorFor("button-set")');
59 shouldBeFalse('customErrorFor("button-button-set")');
60 shouldBeFalse('customErrorFor("button-reset-set")');
61 shouldBeTrue('customErrorFor("select-set")');
62 shouldBeTrue('customErrorFor("textarea-set")');
63 shouldBeTrue('customErrorFor("input-set")');
64 shouldBeTrue('customErrorFor("input-submit-set")');
65
66 debug('');
67 debug('Set some value for customError, and clear it.');
68 v = document.getElementsByName("set-and-empty");
69 for (i = 0; i < v.length; i++)
70     v[i].setCustomValidity("Custom validation message");
71 for (i = 0; i < v.length; i++)
72     v[i].setCustomValidity("");
73 shouldBeFalse('customErrorFor("fieldset-set-and-empty")');
74 shouldBeFalse('customErrorFor("button-set-and-empty")');
75 shouldBeFalse('customErrorFor("button-button-set-and-empty")');
76 shouldBeFalse('customErrorFor("button-reset-set-and-empty")');
77 shouldBeFalse('customErrorFor("select-set-and-empty")');
78 shouldBeFalse('customErrorFor("textarea-set-and-empty")');
79 shouldBeFalse('customErrorFor("input-set-and-empty")');
80 shouldBeFalse('customErrorFor("input-submit-set-and-empty")');
81
82 debug('');
83 debug('Not any changes for customError.');
84 shouldBeFalse('customErrorFor("fieldset-no-changes")');
85 shouldBeFalse('customErrorFor("button-no-changes")');
86 shouldBeFalse('customErrorFor("button-button-no-changes")');
87 shouldBeFalse('customErrorFor("button-reset-no-changes")');
88 shouldBeFalse('customErrorFor("select-no-changes")');
89 shouldBeFalse('customErrorFor("textarea-no-changes")');
90 shouldBeFalse('customErrorFor("input-no-changes")');
91 shouldBeFalse('customErrorFor("input-submit-no-changes")');
92
93 debug('');
94 debug('Many changes for customError:');
95 debug('Set some value, and set with no arguments.');
96 v = document.getElementsByName("many-changes");
97 for (i = 0; i < v.length; i++) {
98     v[i].setCustomValidity("Custom string");
99     try {
100         v[i].setCustomValidity();
101         testFailed("setCustomValidity() did not throw");
102     } catch(err) {
103         testPassed("setCustomValidity() threw " + err.message);
104     }
105     v[i].setCustomValidity(undefined);
106 }
107 shouldBeFalse('customErrorFor("fieldset-many-changes")');
108 shouldBeFalse('customErrorFor("button-many-changes")');
109 shouldBeFalse('customErrorFor("button-button-many-changes")');
110 shouldBeFalse('customErrorFor("button-reset-many-changes")');
111 shouldBeFalse('customErrorFor("select-many-changes")');
112 shouldBeFalse('customErrorFor("textarea-many-changes")');
113 shouldBeFalse('customErrorFor("input-many-changes")');
114 shouldBeFalse('customErrorFor("input-submit-many-changes")');
115
116 debug('Set with three arguments.');
117 for (i = 0; i < v.length; i++)
118     v[i].setCustomValidity("one", "two", "three");
119 shouldBeFalse('customErrorFor("fieldset-many-changes")');
120 shouldBeTrue('customErrorFor("button-many-changes")');
121 shouldBeFalse('customErrorFor("button-button-many-changes")');
122 shouldBeFalse('customErrorFor("button-reset-many-changes")');
123 shouldBeTrue('customErrorFor("select-many-changes")');
124 shouldBeTrue('customErrorFor("textarea-many-changes")');
125 shouldBeTrue('customErrorFor("input-many-changes")');
126 shouldBeTrue('customErrorFor("input-submit-many-changes")');
127
128 debug('Set null.');
129 for (i = 0; i < v.length; i++)
130     v[i].setCustomValidity(null);
131 shouldBeFalse('customErrorFor("fieldset-many-changes")');
132 shouldBeFalse('customErrorFor("button-many-changes")');
133 shouldBeFalse('customErrorFor("button-button-many-changes")');
134 shouldBeFalse('customErrorFor("button-reset-many-changes")');
135 shouldBeFalse('customErrorFor("select-many-changes")');
136 shouldBeFalse('customErrorFor("textarea-many-changes")');
137 shouldBeFalse('customErrorFor("input-many-changes")');
138 shouldBeFalse('customErrorFor("input-submit-many-changes")');
139
140 debug('Set some value, and set undefined.');
141 for (i = 0; i < v.length; i++) {
142     v[i].setCustomValidity("Custom string");
143     v[i].setCustomValidity(undefined);
144 }
145 shouldBeFalse('customErrorFor("fieldset-many-changes")');
146 shouldBeFalse('customErrorFor("button-many-changes")');
147 shouldBeFalse('customErrorFor("button-button-many-changes")');
148 shouldBeFalse('customErrorFor("button-reset-many-changes")');
149 shouldBeFalse('customErrorFor("select-many-changes")');
150 shouldBeFalse('customErrorFor("textarea-many-changes")');
151 shouldBeFalse('customErrorFor("input-many-changes")');
152 shouldBeFalse('customErrorFor("input-submit-many-changes")');
153
154 debug('');
155
156 var successfullyParsed = true;
157 </script>
158 <script src="../../fast/js/resources/js-test-post.js"></script>
159 </body>
160 </html>