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 HTMLFrameSetElement}.
23   *
24   * @author Bruce Chapman
25   * @author Ahmed Ashour
26   * @author Ronald Brill
27   */
28  public class HTMLFrameSetElementTest extends WebDriverTestCase {
29  
30      /**
31       * @throws Exception if an error occurs
32       */
33      @Test
34      @Alerts({"20%,*", "*,*"})
35      public void cols() throws Exception {
36          final String html = DOCTYPE_HTML
37              + "<html><head>\n"
38              + "<script>"
39              + LOG_TITLE_FUNCTION
40              + "function test() {\n"
41              + "  log(document.getElementById('fs').cols);\n"
42              + "  document.getElementById('fs').cols = '*,*';\n"
43              + "  log(document.getElementById('fs').cols);\n"
44              + "}\n"
45              + "</script></head>\n"
46              + "<frameset id='fs' cols='20%,*' onload='test()'>\n"
47              + "  <frame name='left' src='about:blank' />\n"
48              + "  <frame name='right' src='about:blank' />\n"
49              + "</frameset>\n"
50              + "</html>";
51  
52          loadPageVerifyTitle2(html);
53      }
54  
55      /**
56       * @throws Exception if an error occurs
57       */
58      @Test
59      @Alerts({"20%,*", "*,*"})
60      public void rows() throws Exception {
61          final String framesetContent = DOCTYPE_HTML
62              + "<html><head></head>\n"
63              + "<frameset id='fs' rows='20%,*'>\n"
64              + "  <frame name='top' src='" + URL_SECOND + "' />\n"
65              + "  <frame name='bottom' src='about:blank' />\n"
66              + "</frameset>\n"
67              + "</html>";
68  
69          final String frameContent = DOCTYPE_HTML
70              + "<html><head><title>TopFrame</title>\n"
71              + "<script>\n"
72              + LOG_WINDOW_NAME_FUNCTION
73              + "function doTest() {\n"
74              + "  log(parent.document.getElementById('fs').rows);\n"
75              + "  parent.document.getElementById('fs').rows = '*,*';\n"
76              + "  log(parent.document.getElementById('fs').rows);\n"
77              + "}</script>\n"
78              + "</head>\n"
79              + "<body onload='doTest()'></body></html>";
80  
81          getMockWebConnection().setResponse(URL_SECOND, frameContent);
82  
83          loadPage2(framesetContent);
84          verifyWindowName2(getWebDriver(), getExpectedAlerts());
85      }
86  
87      /**
88       * @throws Exception if an error occurs
89       */
90      @Test
91      @Alerts({"<frameset id=\"fs\" onload=\"test()\"> </frameset>", "new"})
92      public void outerHTML() throws Exception {
93          final String html = DOCTYPE_HTML
94              + "<html><head>\n"
95              + "<script>\n"
96              + LOG_TITLE_FUNCTION
97              + "function test() {\n"
98              + "  log(document.getElementById('fs').outerHTML);\n"
99              + "  document.getElementById('fs').outerHTML = '<div id=\"new\">text<div>';\n"
100             + "  log(document.getElementById('new').id);\n"
101             + "}\n"
102             + "</script></head>\n"
103             + "<frameset id='fs' onload='test()'>\n"
104             + "</frameset>\n"
105             + "</html>";
106 
107         loadPageVerifyTitle2(html);
108     }
109 }