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   * Unit tests for {@link HTMLOptGroupElement}.
23   *
24   * @author Ronald Brill
25   */
26  public class HTMLOptGroupElementTest extends WebDriverTestCase {
27  
28      /**
29       * @throws Exception if the test fails
30       */
31      @Test
32      @Alerts({"false", "true", "true", "false", "true"})
33      public void disabledAttribute() throws Exception {
34          final String html = DOCTYPE_HTML
35              + "<html>\n"
36              + "  <head>\n"
37              + "    <script>\n"
38              + LOG_TITLE_FUNCTION
39              + "      function test() {\n"
40              + "        var test1 = document.getElementById('test1');\n"
41              + "        log(test1.disabled);\n"
42              + "        test1.disabled = true;\n"
43              + "        log(test1.disabled);\n"
44              + "        test1.disabled = true;\n"
45              + "        log(test1.disabled);\n"
46              + "        test1.disabled = false;\n"
47              + "        log(test1.disabled);\n"
48  
49              + "        var test2 = document.getElementById('test2');\n"
50              + "        log(test2.disabled);\n"
51              + "      }\n"
52              + "    </script>\n"
53              + "  </head>\n"
54              + "  <body onload='test()'>\n"
55              + "    <form name='form1'>\n"
56              + "      <select>\n"
57              + "        <optgroup id='test1'>\n"
58              + "          <option value='group1'>Group1</option>\n"
59              + "        </optgroup>\n"
60              + "        <optgroup id='test2' disabled>\n"
61              + "          <option value='group2'>Group2</option>\n"
62              + "        </optgroup>\n"
63              + "      </select>\n"
64              + "  </form>\n"
65              + "</body></html>";
66  
67          loadPageVerifyTitle2(html);
68      }
69  
70      /**
71       * @throws Exception if the test fails
72       */
73      @Test
74      @Alerts({"", "newLabel", "", "label"})
75      public void labelAttribute() throws Exception {
76          final String html = DOCTYPE_HTML
77              + "<html>\n"
78              + "  <head>\n"
79              + "    <script>\n"
80              + LOG_TITLE_FUNCTION
81              + "      function test() {\n"
82              + "        var test1 = document.getElementById('test1');\n"
83              + "        log(test1.label);\n"
84              + "        test1.label = 'newLabel';\n"
85              + "        log(test1.label);\n"
86              + "        test1.label = '';\n"
87              + "        log(test1.label);\n"
88  
89              + "        var test2 = document.getElementById('test2');\n"
90              + "        log(test2.label);\n"
91              + "      }\n"
92              + "    </script>\n"
93              + "  </head>\n"
94              + "  <body onload='test()'>\n"
95              + "    <form name='form1'>\n"
96              + "      <select>\n"
97              + "        <optgroup id='test1'>\n"
98              + "          <option value='group1'>Group1</option>\n"
99              + "        </optgroup>\n"
100             + "        <optgroup id='test2' label='label'>\n"
101             + "          <option value='group2'>Group2</option>\n"
102             + "        </optgroup>\n"
103             + "      </select>\n"
104             + "  </form>\n"
105             + "</body></html>";
106 
107         loadPageVerifyTitle2(html);
108     }
109 }