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