1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.html;
16
17 import java.io.File;
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 import org.openqa.selenium.By;
25 import org.openqa.selenium.WebDriver;
26 import org.openqa.selenium.htmlunit.HtmlUnitDriver;
27
28
29
30
31
32
33
34 @RunWith(BrowserRunner.class)
35 public class HtmlEmbedTest extends WebDriverTestCase {
36
37
38
39
40 @Test
41 @Alerts({"[object HTMLEmbedElement]", "[object HTMLCollection]", "1", "[object HTMLEmbedElement]"})
42 public void simpleScriptable() throws Exception {
43 final String html = DOCTYPE_HTML
44 + "<html><head>\n"
45 + "<script>\n"
46 + LOG_TITLE_FUNCTION
47 + " function test() {\n"
48 + " log(document.getElementById('myId'));\n"
49 + " log(document.embeds);\n"
50 + " log(document.embeds.length);\n"
51 + " log(document.embeds[0]);\n"
52 + " }\n"
53 + "</script>\n"
54 + "</head><body onload='test()'>\n"
55 + " <embed id='myId'/>\n"
56 + "</body></html>";
57
58 final WebDriver driver = loadPageVerifyTitle2(html);
59 if (driver instanceof HtmlUnitDriver) {
60 final HtmlElement element = toHtmlElement(driver.findElement(By.id("myId")));
61 assertTrue(HtmlEmbed.class.isInstance(element));
62 }
63 }
64
65
66
67
68 @Test
69 @Alerts("[object HTMLEmbedElement]")
70 public void saveAs() throws Exception {
71 final String html = DOCTYPE_HTML
72 + "<html><head>\n"
73 + "<script>\n"
74 + LOG_TITLE_FUNCTION
75 + " function test() {\n"
76 + " log(document.getElementById('myId'));\n"
77 + " }\n"
78 + "</script>\n"
79 + "</head><body onload='test()'>\n"
80 + " <embed id='myId' src='helloworld.bin'/>\n"
81 + "</body></html>";
82
83 getMockWebConnection().setDefaultResponse("something");
84 final WebDriver driver = loadPageVerifyTitle2(html);
85 if (driver instanceof HtmlUnitDriver) {
86 final HtmlEmbed element = (HtmlEmbed) toHtmlElement(driver.findElement(By.id("myId")));
87 final File file = new File(System.getProperty("user.home"), "htmlunit-embed.bin");
88 element.saveAs(file);
89 final long length = file.length();
90 assertTrue(file.delete());
91 assertTrue(length > 0);
92 }
93 }
94 }