1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host;
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
27
28 public class ApplicationCacheTest extends WebDriverTestCase {
29
30
31
32
33 @Test
34 @Alerts("undefined")
35 public void scriptableToString() throws Exception {
36 final String html = DOCTYPE_HTML
37 + "<html><head>\n"
38 + "<script>\n"
39 + LOG_TITLE_FUNCTION
40 + " function test() {\n"
41 + " log(window.applicationCache);\n"
42 + " }\n"
43 + "</script></head>\n"
44 + "<body onload='test()'>\n"
45 + "</body></html>";
46
47 loadPageVerifyTitle2(html);
48 }
49
50
51
52
53 @Test
54 @Alerts("no applicationCache")
55 public void onchecking() throws Exception {
56 eventHandler("onchecking");
57 }
58
59
60
61
62 @Test
63 @Alerts("no applicationCache")
64 public void onerror() throws Exception {
65 eventHandler("onerror");
66 }
67
68
69
70
71 @Test
72 @Alerts("no applicationCache")
73 public void onnoupdate() throws Exception {
74 eventHandler("onnoupdate");
75 }
76
77
78
79
80 @Test
81 @Alerts("no applicationCache")
82 public void ondownloading() throws Exception {
83 eventHandler("ondownloading");
84 }
85
86
87
88
89 @Test
90 @Alerts("no applicationCache")
91 public void onprogress() throws Exception {
92 eventHandler("onprogress");
93 }
94
95
96
97
98 @Test
99 @Alerts("no applicationCache")
100 public void onupdateready() throws Exception {
101 eventHandler("onupdateready");
102 }
103
104
105
106
107 @Test
108 @Alerts("no applicationCache")
109 public void oncached() throws Exception {
110 eventHandler("oncached");
111 }
112
113 private void eventHandler(final String handler) throws Exception {
114 final String html = DOCTYPE_HTML
115 + "<html><head>\n"
116 + "<script>\n"
117 + LOG_TITLE_FUNCTION
118 + " function test() {\n"
119 + " if (window.applicationCache) {\n"
120 + " window.applicationCache." + handler + " = function(e) {};\n"
121 + " var handler = window.applicationCache." + handler + ".toString();\n"
122
123
124 + " log(handler.replace(/(\\r|\\n|\\r\\n| )/gm, ''));\n"
125 + " } else {\n"
126 + " log('no applicationCache');\n"
127 + " }\n"
128 + " }\n"
129 + "</script></head>\n"
130 + "<body onload='test()'>\n"
131 + "</body></html>";
132
133 loadPageVerifyTitle2(html);
134 }
135
136
137
138
139 @Test
140 @Alerts("no applicationCache")
141 public void eventListener() throws Exception {
142 final String html = DOCTYPE_HTML
143 + "<html><head>\n"
144 + "<script>\n"
145 + LOG_TITLE_FUNCTION
146 + " function test() {\n"
147 + " if (window.applicationCache) {\n"
148 + " log(window.applicationCache.addEventListener == null);\n"
149 + " log(window.applicationCache.removeEventListener == null);\n"
150 + " log(window.applicationCache.dispatchEvent == null);\n"
151
152 + " log(window.applicationCache.attachEvent == null);\n"
153 + " log(window.applicationCache.detachEvent == null);\n"
154 + " } else {\n"
155 + " log('no applicationCache');\n"
156 + " }\n"
157 + " }\n"
158 + "</script></head>\n"
159 + "<body onload='test()'>\n"
160 + "</body></html>";
161
162 loadPageVerifyTitle2(html);
163 }
164 }