1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.html;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.annotation.Alerts;
19 import org.junit.jupiter.api.Test;
20 import org.openqa.selenium.WebDriver;
21
22
23
24
25
26
27
28 public class BaseFrameElement2Test extends WebDriverTestCase {
29
30
31
32
33 @Test
34 @Alerts("posted called")
35 public void windowEventListenersContainer() throws Exception {
36 final String html = DOCTYPE_HTML
37 + "<html>\n"
38 + "<head>\n"
39 + "<script>\n"
40 + " function test() {\n"
41 + " var iframe = document.createElement('iframe');\n"
42 + " iframe.src = '';\n"
43 + " document.documentElement.appendChild(iframe);\n"
44 + " var win = iframe.contentWindow;\n"
45 + " win.addEventListener('message', handler);\n"
46 + " win.postMessage('hello', '*');\n"
47 + " document.title += ' posted';\n"
48 + " }\n"
49 + " function handler() {\n"
50 + " document.title += ' called';\n"
51 + " }\n"
52 + "</script>\n"
53 + "</head>\n"
54 + "<body onload='test()'>\n"
55 + "</body></html>";
56
57 final WebDriver driver = loadPage2(html);
58 assertTitle(driver, getExpectedAlerts()[0]);
59 }
60
61
62
63
64 @Test
65 public void doNotLoopEndless() throws Exception {
66 final String html = DOCTYPE_HTML
67 + "<html>\n"
68 + "<head>\n"
69 + "</head>\n"
70 + "<body>\n"
71 + " <iframe src='”'></iframe>\n"
72 + "</body></html>";
73
74 getMockWebConnection().setDefaultResponse(html);
75
76 loadPage2(html);
77 }
78 }