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