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