View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.javascript.host.html;
16  
17  import org.htmlunit.WebDriverTestCase;
18  import org.htmlunit.junit.annotation.Alerts;
19  import org.junit.jupiter.api.Test;
20  
21  /**
22   * Tests for {@link HTMLFieldSetElement}.
23   *
24   * @author <a href="mailto:george@murnock.com">George Murnock</a>
25   * @author Ronald Brill
26   * @author Frank Danek
27   */
28  public class HTMLFieldSetElementTest extends WebDriverTestCase {
29  
30      /**
31       * @throws Exception if an error occurs
32       */
33      @Test
34      @Alerts({"undefined", "undefined", "undefined", "undefined", "undefined", "undefined",
35               "undefined", "undefined", "undefined", "undefined", "undefined"})
36      public void getAlign() throws Exception {
37          final String html = DOCTYPE_HTML
38              + "<html><body>\n"
39              + "  <form>\n"
40              + "    <fieldset id='f1' align='left' ></fieldset>\n"
41              + "    <fieldset id='f2' align='right' ></fieldset>\n"
42              + "    <fieldset id='f3' align='bottom' ></fieldset>\n"
43              + "    <fieldset id='f4' align='middle' ></fieldset>\n"
44              + "    <fieldset id='f5' align='top' ></fieldset>\n"
45              + "    <fieldset id='f6' align='absbottom' ></fieldset>\n"
46              + "    <fieldset id='f7' align='absmiddle' ></fieldset>\n"
47              + "    <fieldset id='f8' align='baseline' ></fieldset>\n"
48              + "    <fieldset id='f9' align='texttop' ></fieldset>\n"
49              + "    <fieldset id='f10' align='wrong' ></fieldset>\n"
50              + "    <fieldset id='f11' ></fieldset>\n"
51              + "  </form>\n"
52  
53              + "<script>\n"
54              + LOG_TITLE_FUNCTION
55              + "  for (var i = 1; i <= 11; i++) {\n"
56              + "    log(document.getElementById('f' + i).align);\n"
57              + "  }\n"
58              + "</script>\n"
59              + "</body></html>";
60  
61          loadPageVerifyTitle2(html);
62      }
63  
64      /**
65       * @throws Exception if an error occurs
66       */
67      @Test
68      @Alerts({"CenTer", "8", "foo", "left", "right",
69               "bottom", "middle", "top", "absbottom", "absmiddle", "baseline", "texttop"})
70      public void setAlign() throws Exception {
71          final String html = DOCTYPE_HTML
72              + "<html><body>\n"
73              + "  <form>\n"
74              + "    <fieldset id='i1' align='left' />\n"
75              + "  <form>\n"
76  
77              + "<script>\n"
78              + LOG_TITLE_FUNCTION
79              + "  function setAlign(elem, value) {\n"
80              + "    try {\n"
81              + "      elem.align = value;\n"
82              + "    } catch(e) { logEx(e); }\n"
83              + "    log(elem.align);\n"
84              + "  }\n"
85  
86              + "  var elem = document.getElementById('i1');\n"
87              + "  setAlign(elem, 'CenTer');\n"
88  
89              + "  setAlign(elem, '8');\n"
90              + "  setAlign(elem, 'foo');\n"
91  
92              + "  setAlign(elem, 'left');\n"
93              + "  setAlign(elem, 'right');\n"
94              + "  setAlign(elem, 'bottom');\n"
95              + "  setAlign(elem, 'middle');\n"
96              + "  setAlign(elem, 'top');\n"
97              + "  setAlign(elem, 'absbottom');\n"
98              + "  setAlign(elem, 'absmiddle');\n"
99              + "  setAlign(elem, 'baseline');\n"
100             + "  setAlign(elem, 'texttop');\n"
101             + "</script>\n"
102             + "</body></html>";
103 
104         loadPageVerifyTitle2(html);
105     }
106 
107     /**
108      * @throws Exception if the test fails
109      */
110     @Test
111     @Alerts("[object HTMLFormElement]")
112     public void form() throws Exception {
113         final String html = DOCTYPE_HTML
114             + "<html>\n"
115             + "<body>\n"
116             + "  <form>\n"
117             + "    <fieldset id='a' />\n"
118             + "  </form>"
119             + "  <script>\n"
120             + LOG_TITLE_FUNCTION
121             + "    log(document.getElementById('a').form);\n"
122             + "  </script>"
123             + "</body>"
124             + "</html>";
125         loadPageVerifyTitle2(html);
126     }
127 
128     /**
129      * @throws Exception if an error occurs
130      */
131     @Test
132     @Alerts({"false", "false", "false", "false", "false"})
133     public void willValidate() 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').willValidate);\n"
140                 + "      log(document.getElementById('i2').willValidate);\n"
141                 + "      log(document.getElementById('i3').willValidate);\n"
142                 + "      log(document.getElementById('i4').willValidate);\n"
143                 + "      log(document.getElementById('i5').willValidate);\n"
144                 + "    }\n"
145                 + "  </script>\n"
146                 + "</head>\n"
147                 + "<body onload='test()'>\n"
148                 + "  <form>\n"
149                 + "    <fieldset id='i1'>fs</fieldset>"
150                 + "    <fieldset id='i2' disabled></fieldset>"
151                 + "    <fieldset id='i3' hidden></fieldset>"
152                 + "    <fieldset id='i4' readonly></fieldset>"
153                 + "    <fieldset id='i5' style='display: none'></fieldset>"
154                 + "  </form>\n"
155                 + "</body></html>";
156 
157         loadPageVerifyTitle2(html);
158     }
159 
160     /**
161      * @throws Exception if an error occurs
162      */
163     @Test
164     @Alerts({"true", "false", "true", "true", "true"})
165     public void willValidateChild() throws Exception {
166         final String html = DOCTYPE_HTML
167                 + "<html><head>\n"
168                 + "  <script>\n"
169                 + LOG_TITLE_FUNCTION
170                 + "    function test() {\n"
171                 + "      log(document.getElementById('i1').willValidate);\n"
172                 + "      log(document.getElementById('i2').willValidate);\n"
173                 + "      log(document.getElementById('i3').willValidate);\n"
174                 + "      log(document.getElementById('i4').willValidate);\n"
175                 + "      log(document.getElementById('i5').willValidate);\n"
176                 + "    }\n"
177                 + "  </script>\n"
178                 + "</head>\n"
179                 + "<body onload='test()'>\n"
180                 + "  <form>\n"
181                 + "    <fieldset><input id='i1'></fieldset>"
182                 + "    <fieldset disabled><input id='i2'></fieldset>"
183                 + "    <fieldset hidden><input id='i3'></fieldset>"
184                 + "    <fieldset readonly><input id='i4'></fieldset>"
185                 + "    <fieldset style='display: none'><input id='i5'></fieldset>"
186                 + "  </form>\n"
187                 + "</body></html>";
188 
189         loadPageVerifyTitle2(html);
190     }
191 }