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.BrowserRunner;
19  import org.htmlunit.junit.annotation.Alerts;
20  import org.junit.Test;
21  import org.junit.runner.RunWith;
22  
23  /**
24   * Tests for {@link HTMLFieldSetElement}.
25   *
26   * @author <a href="mailto:george@murnock.com">George Murnock</a>
27   * @author Ronald Brill
28   * @author Frank Danek
29   */
30  @RunWith(BrowserRunner.class)
31  public class HTMLFieldSetElementTest extends WebDriverTestCase {
32  
33      /**
34       * @throws Exception if an error occurs
35       */
36      @Test
37      @Alerts({"undefined", "undefined", "undefined", "undefined", "undefined", "undefined",
38               "undefined", "undefined", "undefined", "undefined", "undefined"})
39      public void getAlign() throws Exception {
40          final String html = DOCTYPE_HTML
41              + "<html><body>\n"
42              + "  <form>\n"
43              + "    <fieldset id='f1' align='left' ></fieldset>\n"
44              + "    <fieldset id='f2' align='right' ></fieldset>\n"
45              + "    <fieldset id='f3' align='bottom' ></fieldset>\n"
46              + "    <fieldset id='f4' align='middle' ></fieldset>\n"
47              + "    <fieldset id='f5' align='top' ></fieldset>\n"
48              + "    <fieldset id='f6' align='absbottom' ></fieldset>\n"
49              + "    <fieldset id='f7' align='absmiddle' ></fieldset>\n"
50              + "    <fieldset id='f8' align='baseline' ></fieldset>\n"
51              + "    <fieldset id='f9' align='texttop' ></fieldset>\n"
52              + "    <fieldset id='f10' align='wrong' ></fieldset>\n"
53              + "    <fieldset id='f11' ></fieldset>\n"
54              + "  </form>\n"
55  
56              + "<script>\n"
57              + LOG_TITLE_FUNCTION
58              + "  for (var i = 1; i <= 11; i++) {\n"
59              + "    log(document.getElementById('f' + i).align);\n"
60              + "  }\n"
61              + "</script>\n"
62              + "</body></html>";
63  
64          loadPageVerifyTitle2(html);
65      }
66  
67      /**
68       * @throws Exception if an error occurs
69       */
70      @Test
71      @Alerts({"CenTer", "8", "foo", "left", "right",
72               "bottom", "middle", "top", "absbottom", "absmiddle", "baseline", "texttop"})
73      public void setAlign() throws Exception {
74          final String html = DOCTYPE_HTML
75              + "<html><body>\n"
76              + "  <form>\n"
77              + "    <fieldset id='i1' align='left' />\n"
78              + "  <form>\n"
79  
80              + "<script>\n"
81              + LOG_TITLE_FUNCTION
82              + "  function setAlign(elem, value) {\n"
83              + "    try {\n"
84              + "      elem.align = value;\n"
85              + "    } catch(e) { logEx(e); }\n"
86              + "    log(elem.align);\n"
87              + "  }\n"
88  
89              + "  var elem = document.getElementById('i1');\n"
90              + "  setAlign(elem, 'CenTer');\n"
91  
92              + "  setAlign(elem, '8');\n"
93              + "  setAlign(elem, 'foo');\n"
94  
95              + "  setAlign(elem, 'left');\n"
96              + "  setAlign(elem, 'right');\n"
97              + "  setAlign(elem, 'bottom');\n"
98              + "  setAlign(elem, 'middle');\n"
99              + "  setAlign(elem, 'top');\n"
100             + "  setAlign(elem, 'absbottom');\n"
101             + "  setAlign(elem, 'absmiddle');\n"
102             + "  setAlign(elem, 'baseline');\n"
103             + "  setAlign(elem, 'texttop');\n"
104             + "</script>\n"
105             + "</body></html>";
106 
107         loadPageVerifyTitle2(html);
108     }
109 
110     /**
111      * @throws Exception if the test fails
112      */
113     @Test
114     @Alerts("[object HTMLFormElement]")
115     public void form() throws Exception {
116         final String html = DOCTYPE_HTML
117             + "<html>\n"
118             + "<body>\n"
119             + "  <form>\n"
120             + "    <fieldset id='a' />\n"
121             + "  </form>"
122             + "  <script>\n"
123             + LOG_TITLE_FUNCTION
124             + "    log(document.getElementById('a').form);\n"
125             + "  </script>"
126             + "</body>"
127             + "</html>";
128         loadPageVerifyTitle2(html);
129     }
130 
131     /**
132      * @throws Exception if an error occurs
133      */
134     @Test
135     @Alerts({"false", "false", "false", "false", "false"})
136     public void willValidate() throws Exception {
137         final String html = DOCTYPE_HTML
138                 + "<html><head>\n"
139                 + "  <script>\n"
140                 + LOG_TITLE_FUNCTION
141                 + "    function test() {\n"
142                 + "      log(document.getElementById('i1').willValidate);\n"
143                 + "      log(document.getElementById('i2').willValidate);\n"
144                 + "      log(document.getElementById('i3').willValidate);\n"
145                 + "      log(document.getElementById('i4').willValidate);\n"
146                 + "      log(document.getElementById('i5').willValidate);\n"
147                 + "    }\n"
148                 + "  </script>\n"
149                 + "</head>\n"
150                 + "<body onload='test()'>\n"
151                 + "  <form>\n"
152                 + "    <fieldset id='i1'>fs</fieldset>"
153                 + "    <fieldset id='i2' disabled></fieldset>"
154                 + "    <fieldset id='i3' hidden></fieldset>"
155                 + "    <fieldset id='i4' readonly></fieldset>"
156                 + "    <fieldset id='i5' style='display: none'></fieldset>"
157                 + "  </form>\n"
158                 + "</body></html>";
159 
160         loadPageVerifyTitle2(html);
161     }
162 
163     /**
164      * @throws Exception if an error occurs
165      */
166     @Test
167     @Alerts({"true", "false", "true", "true", "true"})
168     public void willValidateChild() throws Exception {
169         final String html = DOCTYPE_HTML
170                 + "<html><head>\n"
171                 + "  <script>\n"
172                 + LOG_TITLE_FUNCTION
173                 + "    function test() {\n"
174                 + "      log(document.getElementById('i1').willValidate);\n"
175                 + "      log(document.getElementById('i2').willValidate);\n"
176                 + "      log(document.getElementById('i3').willValidate);\n"
177                 + "      log(document.getElementById('i4').willValidate);\n"
178                 + "      log(document.getElementById('i5').willValidate);\n"
179                 + "    }\n"
180                 + "  </script>\n"
181                 + "</head>\n"
182                 + "<body onload='test()'>\n"
183                 + "  <form>\n"
184                 + "    <fieldset><input id='i1'></fieldset>"
185                 + "    <fieldset disabled><input id='i2'></fieldset>"
186                 + "    <fieldset hidden><input id='i3'></fieldset>"
187                 + "    <fieldset readonly><input id='i4'></fieldset>"
188                 + "    <fieldset style='display: none'><input id='i5'></fieldset>"
189                 + "  </form>\n"
190                 + "</body></html>";
191 
192         loadPageVerifyTitle2(html);
193     }
194 }