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 HTMLDetailsElement}.
23   *
24   * @author Ronald Brill
25   */
26  public class HTMLDetailsElementTest extends WebDriverTestCase {
27  
28      /**
29       * @throws Exception if an error occurs
30       */
31      @Test
32      @Alerts({"false", "null", "true", "", "false", "null", "true", "",
33               "true", "", "true", "TrUE", "false", "null"})
34      public void open() throws Exception {
35          final String html = DOCTYPE_HTML
36              + "<html>\n"
37              + "  <head>\n"
38              + "    <script>\n"
39              + LOG_TITLE_FUNCTION
40              + "      function test() {\n"
41              + "        var det = document.getElementById('detail');\n"
42              + "        log(det.open);\n"
43              + "        log(det.getAttribute('open'));\n"
44  
45              + "        det.open = true;\n"
46              + "        log(det.open);\n"
47              + "        log(det.getAttribute('open'));\n"
48  
49              + "        det.open = false;\n"
50              + "        log(det.open);\n"
51              + "        log(det.getAttribute('open'));\n"
52  
53              + "        det.open = 'true';\n"
54              + "        log(det.open);\n"
55              + "        log(det.getAttribute('open'));\n"
56  
57              + "        det.open = 'faLSE';\n"
58              + "        log(det.open);\n"
59              + "        log(det.getAttribute('open'));\n"
60  
61              + "        det.setAttribute('open', 'TrUE');\n"
62              + "        log(det.open);\n"
63              + "        log(det.getAttribute('open'));\n"
64  
65              + "        det.removeAttribute('open');\n"
66              + "        log(det.open);\n"
67              + "        log(det.getAttribute('open'));\n"
68              + "      }\n"
69              + "    </script>\n"
70              + "  </head>\n"
71              + "  <body onload='test()'>\n"
72              + "    <details id='detail'>\n"
73              + "      <summary>Automated Status: Operational</summary>\n"
74              + "      <p>Velocity: 12m/s</p>\n"
75              + "      <p>Direction: North</p>\n"
76              + "    </details>\n"
77              + "  </body>\n"
78              + "</html>";
79  
80          loadPageVerifyTitle2(html);
81      }
82  
83      /**
84       * @throws Exception if an error occurs
85       */
86      @Test
87      @Alerts({"false", "null", "false", "null", "true", "", "true", "blah", "false", "null"})
88      public void openString() throws Exception {
89          final String html = DOCTYPE_HTML
90              + "<html>\n"
91              + "  <head>\n"
92              + "    <script>\n"
93              + LOG_TITLE_FUNCTION
94              + "      function test() {\n"
95              + "        var det = document.getElementById('detail');\n"
96              + "        log(det.open);\n"
97              + "        log(det.getAttribute('open'));\n"
98  
99              + "        det.open = '';\n"
100             + "        log(det.open);\n"
101             + "        log(det.getAttribute('open'));\n"
102 
103             + "        det.open = 'abc';\n"
104             + "        log(det.open);\n"
105             + "        log(det.getAttribute('open'));\n"
106 
107             + "        det.setAttribute('open', 'blah');\n"
108             + "        log(det.open);\n"
109             + "        log(det.getAttribute('open'));\n"
110 
111             + "        det.removeAttribute('open');\n"
112             + "        log(det.open);\n"
113             + "        log(det.getAttribute('open'));\n"
114             + "      }\n"
115             + "    </script>\n"
116             + "  </head>\n"
117             + "  <body onload='test()'>\n"
118             + "    <details id='detail'>\n"
119             + "      <summary>Automated Status: Operational</summary>\n"
120             + "      <p>Velocity: 12m/s</p>\n"
121             + "      <p>Direction: North</p>\n"
122             + "    </details>\n"
123             + "  </body>\n"
124             + "</html>";
125 
126         loadPageVerifyTitle2(html);
127     }
128 
129     /**
130      * @throws Exception if an error occurs
131      */
132     @Test
133     @Alerts(DEFAULT = {"", "null", "", "", "abc", "abc", "blah", "blah", "", "null"},
134             FF_ESR = {"undefined", "null", "", "null", "abc", "null", "abc", "blah", "abc", "null"})
135     public void name() throws Exception {
136         final String html = DOCTYPE_HTML
137             + "<html>\n"
138             + "  <head>\n"
139             + "    <script>\n"
140             + LOG_TITLE_FUNCTION
141             + "      function test() {\n"
142             + "        var det = document.getElementById('detail');\n"
143             + "        log(det.name);\n"
144             + "        log(det.getAttribute('name'));\n"
145 
146             + "        det.name = '';\n"
147             + "        log(det.name);\n"
148             + "        log(det.getAttribute('name'));\n"
149 
150             + "        det.name = 'abc';\n"
151             + "        log(det.name);\n"
152             + "        log(det.getAttribute('name'));\n"
153 
154             + "        det.setAttribute('name', 'blah');\n"
155             + "        log(det.name);\n"
156             + "        log(det.getAttribute('name'));\n"
157 
158             + "        det.removeAttribute('name');\n"
159             + "        log(det.name);\n"
160             + "        log(det.getAttribute('name'));\n"
161             + "      }\n"
162             + "    </script>\n"
163             + "  </head>\n"
164             + "  <body onload='test()'>\n"
165             + "    <details id='detail'>\n"
166             + "      <summary>Automated Status: Operational</summary>\n"
167             + "      <p>Velocity: 12m/s</p>\n"
168             + "      <p>Direction: North</p>\n"
169             + "    </details>\n"
170             + "  </body>\n"
171             + "</html>";
172 
173         loadPageVerifyTitle2(html);
174     }
175 }