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