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;
16  
17  import javax.swing.Popup;
18  
19  import org.htmlunit.WebDriverTestCase;
20  import org.htmlunit.junit.annotation.Alerts;
21  import org.junit.jupiter.api.Test;
22  
23  /**
24   * Tests for {@link Popup}.
25   *
26   * @author Marc Guillemot
27   * @author Ronald Brill
28   */
29  public class Popup2Test extends WebDriverTestCase {
30  
31      /**
32       * Just test that a standard use of popup works without exception.
33       * @throws Exception if the test fails
34       */
35      @Test
36      @Alerts("TypeError")
37      public void popup() throws Exception {
38          final String html = DOCTYPE_HTML
39              + "<html><head></title><body>\n"
40              + "<script>\n"
41              + LOG_TITLE_FUNCTION
42              + "  try {\n"
43              + "    var oPopup = window.createPopup();\n"
44              + "    var oPopupBody = oPopup.document.body;\n"
45              + "    oPopupBody.innerHTML = 'bla bla';\n"
46              + "    oPopup.show(100, 100, 200, 50, document.body);\n"
47              + "    log('done');\n"
48              + "  } catch(e) { logEx(e); }\n"
49              + "</script>\n"
50              + "</body></html>";
51  
52          loadPageVerifyTitle2(html);
53      }
54  
55      /**
56       * Regression test for issue 3029277.
57       * The setup of the window was not complete.
58       * @throws Exception if the test fails
59       */
60      @Test
61      @Alerts("TypeError")
62      public void popupBodyStyle() throws Exception {
63          final String html = DOCTYPE_HTML
64              + "<html><head><body>\n"
65              + "<script language='javascript'>\n"
66              + LOG_TITLE_FUNCTION
67              + "  try {\n"
68              + "    popup = window.createPopup();\n"
69              + "    popupBody = popup.document.body;\n"
70              + "    popupBody.style.backgroundColor = '#7f7fff';\n"
71              + "    log('done');\n"
72              + "  } catch(e) { logEx(e); }\n"
73              + "</script>\n"
74              + "</body></html>";
75  
76          loadPageVerifyTitle2(html);
77      }
78  }