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