|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=475156 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 475156</title> |
|
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
10 </head> |
|
11 <body onload="drive(tests.shift());"> |
|
12 <script class="testbody" type="text/javascript"> |
|
13 |
|
14 SimpleTest.waitForExplicitFinish(); |
|
15 |
|
16 var path = "http://mochi.test:8888/tests/content/base/test/"; |
|
17 |
|
18 function fromCache(xhr) |
|
19 { |
|
20 var ch = SpecialPowers.wrap(xhr).channel.QueryInterface(SpecialPowers.Ci.nsICacheInfoChannel); |
|
21 return ch.isFromCache(); |
|
22 } |
|
23 |
|
24 var tests = [ |
|
25 // First just init the file with an ETag |
|
26 { |
|
27 init: function(xhr) |
|
28 { |
|
29 xhr.open("GET", path + "bug475156.sjs?etag=a1"); |
|
30 }, |
|
31 |
|
32 loading: function(xhr) |
|
33 { |
|
34 }, |
|
35 |
|
36 done: function(xhr) |
|
37 { |
|
38 }, |
|
39 }, |
|
40 |
|
41 // Try to load the file the first time regularly, we have to get 200 OK |
|
42 { |
|
43 init: function(xhr) |
|
44 { |
|
45 xhr.open("GET", path + "bug475156.sjs"); |
|
46 }, |
|
47 |
|
48 loading: function(xhr) |
|
49 { |
|
50 is(fromCache(xhr), false, "Not coming from the cache"); |
|
51 }, |
|
52 |
|
53 done: function(xhr) |
|
54 { |
|
55 is(xhr.status, 200, "We get a fresh version of the file"); |
|
56 is(xhr.getResponseHeader("Etag"), "a1", "We got correct ETag"); |
|
57 is(xhr.responseText, "a1", "We got the expected file body"); |
|
58 }, |
|
59 }, |
|
60 |
|
61 // Try to load the file the second time regularly, we have to get 304 Not Modified |
|
62 { |
|
63 init: function(xhr) |
|
64 { |
|
65 xhr.open("GET", path + "bug475156.sjs"); |
|
66 xhr.setRequestHeader("If-Match", "a1"); |
|
67 }, |
|
68 |
|
69 loading: function(xhr) |
|
70 { |
|
71 is(fromCache(xhr), true, "Coming from the cache"); |
|
72 }, |
|
73 |
|
74 done: function(xhr) |
|
75 { |
|
76 is(xhr.status, 200, "We got cached version"); |
|
77 is(xhr.getResponseHeader("Etag"), "a1", "We got correct ETag"); |
|
78 is(xhr.responseText, "a1", "We got the expected file body"); |
|
79 }, |
|
80 }, |
|
81 |
|
82 // Try to load the file the third time regularly, we have to get 304 Not Modified |
|
83 { |
|
84 init: function(xhr) |
|
85 { |
|
86 xhr.open("GET", path + "bug475156.sjs"); |
|
87 xhr.setRequestHeader("If-Match", "a1"); |
|
88 }, |
|
89 |
|
90 loading: function(xhr) |
|
91 { |
|
92 is(fromCache(xhr), true, "Coming from the cache"); |
|
93 }, |
|
94 |
|
95 done: function(xhr) |
|
96 { |
|
97 is(xhr.status, 200, "We got cached version"); |
|
98 is(xhr.getResponseHeader("Etag"), "a1", "We got correct ETag"); |
|
99 is(xhr.responseText, "a1", "We got the expected file body"); |
|
100 }, |
|
101 }, |
|
102 |
|
103 // Now modify the ETag |
|
104 { |
|
105 init: function(xhr) |
|
106 { |
|
107 xhr.open("GET", path + "bug475156.sjs?etag=a2"); |
|
108 }, |
|
109 |
|
110 loading: function(xhr) |
|
111 { |
|
112 }, |
|
113 |
|
114 done: function(xhr) |
|
115 { |
|
116 }, |
|
117 }, |
|
118 |
|
119 // Try to load the file, we have to get 200 OK with the new content |
|
120 { |
|
121 init: function(xhr) |
|
122 { |
|
123 xhr.open("GET", path + "bug475156.sjs"); |
|
124 xhr.setRequestHeader("If-Match", "a2"); |
|
125 }, |
|
126 |
|
127 loading: function(xhr) |
|
128 { |
|
129 is(fromCache(xhr), false, "Not coming from the cache"); |
|
130 }, |
|
131 |
|
132 done: function(xhr) |
|
133 { |
|
134 is(xhr.status, 200, "We get a fresh version of the file"); |
|
135 is(xhr.getResponseHeader("Etag"), "a2", "We got correct ETag"); |
|
136 is(xhr.responseText, "a2", "We got the expected file body"); |
|
137 }, |
|
138 }, |
|
139 |
|
140 // Try to load the file the second time regularly, we have to get 304 Not Modified |
|
141 { |
|
142 init: function(xhr) |
|
143 { |
|
144 xhr.open("GET", path + "bug475156.sjs"); |
|
145 xhr.setRequestHeader("If-Match", "a2"); |
|
146 }, |
|
147 |
|
148 loading: function(xhr) |
|
149 { |
|
150 is(fromCache(xhr), true, "Coming from the cache"); |
|
151 }, |
|
152 |
|
153 done: function(xhr) |
|
154 { |
|
155 is(xhr.status, 200, "We got cached version"); |
|
156 is(xhr.getResponseHeader("Etag"), "a2", "We got correct ETag"); |
|
157 is(xhr.responseText, "a2", "We got the expected file body"); |
|
158 }, |
|
159 }, |
|
160 |
|
161 // Try to load the file the third time regularly, we have to get 304 Not Modified |
|
162 { |
|
163 init: function(xhr) |
|
164 { |
|
165 xhr.open("GET", path + "bug475156.sjs"); |
|
166 xhr.setRequestHeader("If-Match", "a2"); |
|
167 }, |
|
168 |
|
169 loading: function(xhr) |
|
170 { |
|
171 is(fromCache(xhr), true, "Coming from the cache"); |
|
172 }, |
|
173 |
|
174 done: function(xhr) |
|
175 { |
|
176 is(xhr.status, 200, "We got cached version"); |
|
177 is(xhr.getResponseHeader("Etag"), "a2", "We got correct ETag"); |
|
178 is(xhr.responseText, "a2", "We got the expected file body"); |
|
179 }, |
|
180 }, |
|
181 |
|
182 // Now modify the ETag ones more |
|
183 { |
|
184 init: function(xhr) |
|
185 { |
|
186 xhr.open("GET", path + "bug475156.sjs?etag=a3"); |
|
187 }, |
|
188 |
|
189 loading: function(xhr) |
|
190 { |
|
191 }, |
|
192 |
|
193 done: function(xhr) |
|
194 { |
|
195 }, |
|
196 }, |
|
197 |
|
198 // Try to load the file, we have to get 200 OK with the new content |
|
199 { |
|
200 init: function(xhr) |
|
201 { |
|
202 xhr.open("GET", path + "bug475156.sjs"); |
|
203 xhr.setRequestHeader("If-Match", "a3"); |
|
204 }, |
|
205 |
|
206 loading: function(xhr) |
|
207 { |
|
208 is(fromCache(xhr), false, "Not coming from the cache"); |
|
209 }, |
|
210 |
|
211 done: function(xhr) |
|
212 { |
|
213 is(xhr.status, 200, "We get a fresh version of the file"); |
|
214 is(xhr.getResponseHeader("Etag"), "a3", "We got correct ETag"); |
|
215 is(xhr.responseText, "a3", "We got the expected file body"); |
|
216 }, |
|
217 }, |
|
218 |
|
219 // Try to load the file the second time regularly, we have to get 304 Not Modified |
|
220 { |
|
221 init: function(xhr) |
|
222 { |
|
223 xhr.open("GET", path + "bug475156.sjs"); |
|
224 xhr.setRequestHeader("If-Match", "a3"); |
|
225 }, |
|
226 |
|
227 loading: function(xhr) |
|
228 { |
|
229 is(fromCache(xhr), true, "Coming from the cache"); |
|
230 }, |
|
231 |
|
232 done: function(xhr) |
|
233 { |
|
234 is(xhr.status, 200, "We got cached version"); |
|
235 is(xhr.getResponseHeader("Etag"), "a3", "We got correct ETag"); |
|
236 is(xhr.responseText, "a3", "We got the expected file body"); |
|
237 }, |
|
238 }, |
|
239 |
|
240 // Try to load the file the third time regularly, we have to get 304 Not Modified |
|
241 { |
|
242 init: function(xhr) |
|
243 { |
|
244 xhr.open("GET", path + "bug475156.sjs"); |
|
245 xhr.setRequestHeader("If-Match", "a3"); |
|
246 }, |
|
247 |
|
248 loading: function(xhr) |
|
249 { |
|
250 is(fromCache(xhr), true, "Coming from the cache"); |
|
251 }, |
|
252 |
|
253 done: function(xhr) |
|
254 { |
|
255 is(xhr.status, 200, "We got cached version"); |
|
256 is(xhr.getResponseHeader("Etag"), "a3", "We got correct ETag"); |
|
257 is(xhr.responseText, "a3", "We got the expected file body"); |
|
258 }, |
|
259 }, |
|
260 ] |
|
261 |
|
262 |
|
263 function drive(test) |
|
264 { |
|
265 var xhr = new XMLHttpRequest(); |
|
266 test.init(xhr); |
|
267 xhr.onreadystatechange = function() { |
|
268 if (this.readyState == 3) { |
|
269 test.loading(this); |
|
270 } |
|
271 if (this.readyState == 4) { |
|
272 test.done(this); |
|
273 if (tests.length == 0) |
|
274 SimpleTest.finish(); |
|
275 else |
|
276 drive(tests.shift()); |
|
277 } |
|
278 } |
|
279 xhr.send(); |
|
280 } |
|
281 |
|
282 </script> |
|
283 </pre> |
|
284 </body> |
|
285 </html> |
|
286 |