1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.event;
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
23
24
25
26
27
28 @RunWith(BrowserRunner.class)
29 public class ProgressEventTest extends WebDriverTestCase {
30
31 private static final String DUMP_EVENT_FUNCTION = " function dump(event) {\n"
32 + " if (event) {\n"
33 + " log(event);\n"
34 + " log(event.type);\n"
35 + " log(event.bubbles);\n"
36 + " log(event.cancelable);\n"
37 + " log(event.composed);\n"
38
39 + " log(event.lengthComputable);\n"
40 + " log(event.loaded);\n"
41 + " log(event.total);\n"
42 + " } else {\n"
43 + " log('no event');\n"
44 + " }\n"
45 + " }\n";
46
47
48
49
50 @Test
51 @Alerts({"[object ProgressEvent]", "progress", "false", "false", "false", "false", "0", "0"})
52 public void create_ctor() throws Exception {
53 final String html = DOCTYPE_HTML
54 + "<html><head><script>\n"
55 + LOG_TITLE_FUNCTION
56 + " function test() {\n"
57 + " try {\n"
58 + " var event = new ProgressEvent('progress');\n"
59 + " dump(event);\n"
60 + " } catch(e) { logEx(e) }\n"
61 + " }\n"
62 + DUMP_EVENT_FUNCTION
63 + "</script></head><body onload='test()'>\n"
64 + "</body></html>";
65
66 loadPageVerifyTitle2(html);
67 }
68
69
70
71
72 @Test
73 @Alerts({"[object ProgressEvent]", "test", "true", "false", "false", "true", "234", "666"})
74 public void create_ctorWithDetails() throws Exception {
75 final String html = DOCTYPE_HTML
76 + "<html><head><script>\n"
77 + LOG_TITLE_FUNCTION
78 + " function test() {\n"
79 + " try {\n"
80 + " var event = new ProgressEvent('test', {\n"
81 + " 'bubbles': true,\n"
82 + " 'lengthComputable': true,\n"
83 + " 'loaded': 234,\n"
84 + " 'total': 666\n"
85 + " });\n"
86 + " dump(event);\n"
87 + " } catch(e) { logEx(e) }\n"
88 + " }\n"
89 + DUMP_EVENT_FUNCTION
90 + "</script></head><body onload='test()'>\n"
91 + "</body></html>";
92
93 loadPageVerifyTitle2(html);
94 }
95
96
97
98
99 @Test
100 @Alerts("NotSupportedError/DOMException")
101 public void create_createEvent() throws Exception {
102 final String html = DOCTYPE_HTML
103 + "<html><head><script>\n"
104 + LOG_TITLE_FUNCTION
105 + " function test() {\n"
106 + " try {\n"
107 + " var event = document.createEvent('ProgressEvent');\n"
108 + " dump(event);\n"
109 + " } catch(e) { logEx(e) }\n"
110 + " }\n"
111 + DUMP_EVENT_FUNCTION
112 + "</script></head><body onload='test()'>\n"
113 + "</body></html>";
114
115 loadPageVerifyTitle2(html);
116 }
117 }