@@ -94,4 +94,160 @@ public void willValidate() throws Exception {
9494
9595 loadPageVerifyTitle2 (html );
9696 }
97+
98+ /**
99+ * @throws Exception if an error occurs
100+ */
101+ @ Test
102+ @ Alerts ({"false" , "true" , "false" , "true" })
103+ public void setCustomValidityOnPlainOutput () throws Exception {
104+ final String html = DOCTYPE_HTML
105+ + "<html><head>\n "
106+ + " <script>\n "
107+ + LOG_TITLE_FUNCTION
108+ + " function test() {\n "
109+ + " var o = document.getElementById('o');\n "
110+ + " log(o.willValidate);\n "
111+ + " o.setCustomValidity('some error');\n "
112+ + " log(o.validity.customError);\n "
113+ + " log(o.validity.valid);\n "
114+ + " log(o.checkValidity());\n "
115+ // + " log(o.validationMessage);\n"
116+ + " }\n "
117+ + " </script>\n "
118+ + "</head>\n "
119+ + "<body onload='test()'>\n "
120+ + " <form>\n "
121+ + " <output id='o'></output>"
122+ + " </form>\n "
123+ + "</body></html>" ;
124+
125+ loadPageVerifyTitle2 (html );
126+ }
127+
128+ /**
129+ * @throws Exception if an error occurs
130+ */
131+ @ Test
132+ @ Alerts ({"true" , "true" , "true" , "true" , "true" })
133+ public void checkValidityMirrorsWillValidateAcrossAllCases () throws Exception {
134+ final String html = DOCTYPE_HTML
135+ + "<html><head>\n "
136+ + " <script>\n "
137+ + LOG_TITLE_FUNCTION
138+ + " function test() {\n "
139+ + " log(document.getElementById('i1').checkValidity());\n "
140+ + " log(document.getElementById('i2').checkValidity());\n "
141+ + " log(document.getElementById('i3').checkValidity());\n "
142+ + " log(document.getElementById('i4').checkValidity());\n "
143+ + " log(document.getElementById('i5').checkValidity());\n "
144+ + " }\n "
145+ + " </script>\n "
146+ + "</head>\n "
147+ + "<body onload='test()'>\n "
148+ + " <form>\n "
149+ + " <output id='i1'>button</output>"
150+ + " <output id='i2' disabled></output>"
151+ + " <output id='i3' hidden></output>"
152+ + " <output id='i4' readonly></output>"
153+ + " <output id='i5' style='display: none'></output>"
154+ + " </form>\n "
155+ + "</body></html>" ;
156+
157+ loadPageVerifyTitle2 (html );
158+ }
159+
160+ /**
161+ * The reportValidity() coverage, entirely absent currently -- confirms it
162+ * returns the same boolean as checkValidity() for a plain output with a
163+ * custom validity message set.
164+ * @throws Exception if an error occurs
165+ */
166+ @ Test
167+ @ Alerts ({"true" , "true" })
168+ public void reportValidityMatchesCheckValidity () throws Exception {
169+ final String html = DOCTYPE_HTML
170+ + "<html><head>\n "
171+ + " <script>\n "
172+ + LOG_TITLE_FUNCTION
173+ + " function test() {\n "
174+ + " var o = document.getElementById('o');\n "
175+ + " o.setCustomValidity('some error');\n "
176+ + " log(o.checkValidity());\n "
177+ + " log(o.reportValidity());\n "
178+ + " }\n "
179+ + " </script>\n "
180+ + "</head>\n "
181+ + "<body onload='test()'>\n "
182+ + " <form>\n "
183+ + " <output id='o'></output>"
184+ + " </form>\n "
185+ + "</body></html>" ;
186+
187+ loadPageVerifyTitle2 (html );
188+ }
189+
190+ /**
191+ * Clearing a previously-set custom validity message (empty string) must be
192+ * reversible -- checked via .validity.customError and .validity.valid
193+ * regardless of which way the plain-output ambiguity above resolves.
194+ * @throws Exception if an error occurs
195+ */
196+ @ Test
197+ @ Alerts ({"true" , "false" , "true" })
198+ public void clearCustomValidity () throws Exception {
199+ final String html = DOCTYPE_HTML
200+ + "<html><head>\n "
201+ + " <script>\n "
202+ + LOG_TITLE_FUNCTION
203+ + " function test() {\n "
204+ + " var o = document.getElementById('o');\n "
205+ + " o.setCustomValidity('some error');\n "
206+ + " log(o.validity.customError);\n "
207+ + " o.setCustomValidity('');\n "
208+ + " log(o.validity.customError);\n "
209+ + " log(o.validity.valid);\n "
210+ + " }\n "
211+ + " </script>\n "
212+ + "</head>\n "
213+ + "<body onload='test()'>\n "
214+ + " <form>\n "
215+ + " <output id='o'></output>"
216+ + " </form>\n "
217+ + "</body></html>" ;
218+
219+ loadPageVerifyTitle2 (html );
220+ }
221+
222+ /**
223+ * An output that IS a descendant of a disabled fieldset. Since
224+ * willValidate() already reports false uniformly for output regardless of
225+ * its OWN attributes, this checks whether fieldset-ancestor disabling is
226+ * even independently observable for output at all, or whether it's just
227+ * redundant with the element's own always-false state.
228+ * @throws Exception if an error occurs
229+ */
230+ @ Test
231+ @ Alerts ({"false" , "true" })
232+ public void outputInsideDisabledFieldset () throws Exception {
233+ final String html = DOCTYPE_HTML
234+ + "<html><head>\n "
235+ + " <script>\n "
236+ + LOG_TITLE_FUNCTION
237+ + " function test() {\n "
238+ + " var o = document.getElementById('o');\n "
239+ + " log(o.willValidate);\n "
240+ + " o.setCustomValidity('some error');\n "
241+ + " log(o.checkValidity());\n "
242+ + " }\n "
243+ + " </script>\n "
244+ + "</head>\n "
245+ + "<body onload='test()'>\n "
246+ + " <form>\n "
247+ + " <fieldset disabled><output id='o'></output></fieldset>"
248+ + " </form>\n "
249+ + "</body></html>" ;
250+
251+ loadPageVerifyTitle2 (html );
252+ }
97253}
0 commit comments