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.javascript.host.animations.AnimationEvent;
19 import org.htmlunit.junit.annotation.Alerts;
20 import org.htmlunit.junit.annotation.HtmlUnitNYI;
21 import org.junit.jupiter.api.Test;
22 import org.openqa.selenium.WebDriver;
23
24
25
26
27
28
29 public class AnimationEventTest extends WebDriverTestCase {
30
31 private static final String DUMP_EVENT_FUNCTION = " function dump(event) {\n"
32 + " log(event);\n"
33 + " log(event.type);\n"
34 + " log(event.bubbles);\n"
35 + " log(event.cancelable);\n"
36 + " log(event.composed);\n"
37 + " }\n";
38
39
40
41
42 @Test
43 @Alerts({"[object AnimationEvent]", "animationstart", "false", "false", "false"})
44 public void create_ctor() throws Exception {
45 final String html = DOCTYPE_HTML
46 + "<html><head><script>\n"
47 + LOG_TITLE_FUNCTION
48 + " function test() {\n"
49 + " try {\n"
50 + " var event = new AnimationEvent('animationstart');\n"
51 + " dump(event);\n"
52 + " } catch(e) { logEx(e) }\n"
53 + " }\n"
54 + DUMP_EVENT_FUNCTION
55 + "</script></head><body onload='test()'>\n"
56 + "</body></html>";
57
58 loadPageVerifyTitle2(html);
59 }
60
61
62
63
64 @Test
65 @Alerts(DEFAULT = {"[object AnimationEvent]", "", "false", "false", "false"},
66 FF = "NotSupportedError/DOMException",
67 FF_ESR = "NotSupportedError/DOMException")
68 public void create_createEvent() throws Exception {
69 final String html = DOCTYPE_HTML
70 + "<html><head><script>\n"
71 + LOG_TITLE_FUNCTION
72 + " function test() {\n"
73 + " try {\n"
74 + " var event = document.createEvent('AnimationEvent');\n"
75 + " dump(event);\n"
76 + " } catch(e) { logEx(e); }\n"
77 + " }\n"
78 + DUMP_EVENT_FUNCTION
79 + "</script></head><body onload='test()'>\n"
80 + "</body></html>";
81
82 loadPageVerifyTitle2(html);
83 }
84
85
86
87
88 @Test
89 @Alerts("true")
90 public void inWindow() throws Exception {
91 final String html = DOCTYPE_HTML
92 + "<html>\n"
93 + "<head>\n"
94 + " <script>\n"
95 + LOG_TITLE_FUNCTION
96 + " function test() {\n"
97 + " log('AnimationEvent' in window);\n"
98 + " }\n"
99 + " </script>\n"
100 + "</head>\n"
101 + "<body onload='test()'>\n"
102 + "</body>\n"
103 + "</html>";
104
105 loadPageVerifyTitle2(html);
106 }
107
108
109
110
111
112
113 @Test
114 @Alerts({"animationstart", "animationend"})
115 @HtmlUnitNYI(CHROME = {},
116 EDGE = {},
117 FF = {},
118 FF_ESR = {})
119 public void animate() throws Exception {
120 final String html = DOCTYPE_HTML
121 + "<html><head>\n"
122 + "<style>\n"
123 + " .animate { animation: identifier .1s ; }\n"
124 + " @keyframes identifier {\n"
125 + " 0% { width: 0px; }\n"
126 + " 100% { width: 30px; }\n"
127 + " }\n"
128 + "</style>\n"
129 + "<script>\n"
130 + LOG_TITLE_FUNCTION
131 + "function test() {\n"
132 + " var el = document.getElementById('div1');\n"
133 + " el.addEventListener('animationstart', function(e) {\n"
134 + " log(e.type);\n"
135 + " });\n"
136 + " el.addEventListener('animationend', function(e) {\n"
137 + " log(e.type);\n"
138 + " });\n"
139 + " el.className = 'animate';\n"
140 + "}\n"
141 + "</script>\n"
142 + "</head><body onload='test()'>\n"
143 + "<div id='div1'>TXT</div>\n"
144 + "</body></html>";
145
146 final WebDriver driver = loadPage2(html);
147 Thread.sleep(DEFAULT_WAIT_TIME.toMillis() / 2);
148 verifyTitle2(driver, getExpectedAlerts());
149 }
150 }