3 <p>Tests for
<a href=
"https://bugs.webkit.org/show_bug.cgi?id=8210"> bug
8210</a> -
4 Conditional XMLHttpRequest gets should pass
304 responses unchanged.
</p>
6 if (window
.testRunner
) {
7 testRunner
.dumpAsText();
8 testRunner
.waitUntilDone();
11 var console_messages
= document
.createElement("ul");
12 document
.body
.appendChild(console_messages
);
16 var item
= document
.createElement("li");
17 item
.appendChild(document
.createTextNode(message
));
18 console_messages
.appendChild(item
);
22 req
= new XMLHttpRequest
;
23 req
.open("GET", "resources/reply.xml", false);
24 log("Fetching the resource once to cache the response...");
26 lastModified
= req
.getResponseHeader("Last-Modified");
27 eTag
= req
.getResponseHeader("ETag");
29 req
.open("GET", "resources/reply.xml", false);
31 if (req
.responseText
== '<?xml version="1.0" encoding="windows-1251"?>\n<node>Проверка</node>\n')
32 log("Automatically cached response body is correct; status = " + req
.status
);
34 log("Automatically cached response body is different from the expected one; status = " + req
.status
);
36 req
.open("GET", "resources/reply.xml", false);
37 req
.setRequestHeader("If-Modified-Since", lastModified
);
39 log("If-Modified-Since override: status = " + req
.status
);
41 req
.open("GET", "resources/reply.xml", false);
42 req
.setRequestHeader("If-MODIFIED-Since", lastModified
);
44 log("If-MODIFIED-Since override: status = " + req
.status
);
46 req
.open("GET", "resources/reply.xml", false);
47 req
.setRequestHeader("If-Modified-Since", "Tue, 01 Jan 1980 01:00:00 GMT");
49 log("If-Modified-Since override (modified): status = " + req
.status
);
51 req
.open("GET", "resources/reply.xml", false);
52 req
.setRequestHeader("If-Unmodified-Since", lastModified
);
54 log("If-Unmodified-Since override: status = " + req
.status
);
56 req
.open("GET", "resources/reply.xml", false);
57 req
.setRequestHeader("If-Unmodified-Since", "Tue, 01 Jan 1980 01:00:00 GMT");
59 log("If-Unmodified-Since override (modified): status = " + req
.status
);
61 req
.open("GET", "resources/reply.xml", false);
62 req
.setRequestHeader("If-Match", eTag
);
64 log("If-Match override: status = " + req
.status
);
66 // FIXME: Disabled due to a bug of Apache 2.4. See crbug.com/423070
67 // req.open("GET", "resources/reply.xml", false);
68 // req.setRequestHeader("If-Match", "xyzzy");
70 // log("If-Match override (none match): status = " + req.status);
72 req
.open("GET", "resources/reply.xml", false);
73 req
.setRequestHeader("If-None-Match", eTag
);
75 log("If-None-Match override: status = " + req
.status
);
77 req
.open("GET", "resources/reply.xml", false);
78 req
.setRequestHeader("If-None-Match", "xyzzy");
80 log("If-None-Match override (none match): status = " + req
.status
);
82 req
.open("GET", "resources/reply.xml", false);
83 req
.setRequestHeader("If-Range", eTag
);
84 req
.setRequestHeader("Range", "bytes=52-60");
86 log("If-Range override: status = " + req
.status
);
88 req
.open("GET", "resources/reply.xml", false);
89 req
.setRequestHeader("If-Range", "xyzzy");
90 req
.setRequestHeader("Range", "bytes=52-60");
92 log("If-Range override (none match): status = " + req
.status
);
94 req
.open("GET", "resources/304.pl", false);
95 req
.setRequestHeader("If-Modified-Since", "Tue, 01 Jan 1980 01:00:00 GMT");
97 log("If-Modified-Since override (uncached response): status = " + req
.status
);
102 req
.onreadystatechange
= processStateChange
;
103 req
.open("GET", "resources/reply.xml", true);
106 function processStateChange() {
108 if (req
.readyState
== 4){
109 if (asyncStep
== 1) {
111 if (req
.responseText
== '<?xml version="1.0" encoding="windows-1251"?>\n<node>Проверка</node>\n')
112 log("async: Automatically cached response body is correct; status = " + req
.status
);
114 log("async: Automatically cached response body is different from the expected one; status = " + req
.status
+ "; req.responseText='" + req
.responseText
+ "' (expected '<?xml version=\"1.0\" encoding=\"windows-1251\"?>\n<node>Проверка</node>\n')");
116 req
= new XMLHttpRequest();
117 req
.onreadystatechange
= processStateChange
;
118 req
.open("GET", "resources/reply.xml", true);
119 req
.setRequestHeader("If-Modified-Since", lastModified
);
121 } else if (asyncStep
== 2) {
123 log("async: If-Modified-Since override: status = " + req
.status
);
125 req
= new XMLHttpRequest();
126 req
.onreadystatechange
= processStateChange
;
127 req
.open("GET", "resources/reply.xml", true);
128 req
.setRequestHeader("If-Modified-Since", "Tue, 01 Jan 1980 01:00:00 GMT");
130 } else if (asyncStep
== 3) {
132 log("async: If-Modified-Since override (modified): status = " + req
.status
);
134 req
= new XMLHttpRequest();
135 req
.onreadystatechange
= processStateChange
;
136 req
.open("GET", "resources/reply.xml", true);
137 req
.setRequestHeader("If-Unmodified-Since", lastModified
);
139 } else if (asyncStep
== 4) {
141 log("async: If-Unmodified-Since override: status = " + req
.status
);
143 req
= new XMLHttpRequest();
144 req
.onreadystatechange
= processStateChange
;
145 req
.open("GET", "resources/reply.xml", true);
146 req
.setRequestHeader("If-Unmodified-Since", "Tue, 01 Jan 1980 01:00:00 GMT");
148 } else if (asyncStep
== 5) {
150 log("async: If-Unmodified-Since override (modified): status = " + req
.status
);
152 req
= new XMLHttpRequest();
153 req
.onreadystatechange
= processStateChange
;
154 req
.open("GET", "resources/reply.xml", true);
155 req
.setRequestHeader("If-Match", eTag
);
157 } else if (asyncStep
== 6) {
159 log("async: If-Match override: status = " + req
.status
);
161 req
= new XMLHttpRequest();
162 req
.onreadystatechange
= processStateChange
;
163 req
.open("GET", "resources/reply.xml", true);
164 req
.setRequestHeader("If-Match", "xyzzy");
166 } else if (asyncStep
== 7) {
168 // FIXME: Disabled due to a bug of Apache 2.4. See crbug.com/423070
169 // log("async: If-Match override (none match): status = " + req.status);
171 req
= new XMLHttpRequest();
172 req
.onreadystatechange
= processStateChange
;
173 req
.open("GET", "resources/reply.xml", true);
174 req
.setRequestHeader("If-None-Match", eTag
);
176 } else if (asyncStep
== 8) {
178 log("async: If-None-Match override: status = " + req
.status
);
180 req
= new XMLHttpRequest();
181 req
.onreadystatechange
= processStateChange
;
182 req
.open("GET", "resources/reply.xml", true);
183 req
.setRequestHeader("If-None-Match", "xyzzy");
185 } else if (asyncStep
== 9) {
187 log("async: If-None-Match override (none match): status = " + req
.status
);
189 req
= new XMLHttpRequest();
190 req
.onreadystatechange
= processStateChange
;
191 req
.open("GET", "resources/reply.xml", true);
192 req
.setRequestHeader("If-Range", eTag
);
193 req
.setRequestHeader("Range", "bytes=52-59");
195 } else if (asyncStep
== 10) {
197 log("async: If-Range override: status = " + req
.status
);
199 req
= new XMLHttpRequest();
200 req
.onreadystatechange
= processStateChange
;
201 req
.open("GET", "resources/reply.xml", true);
202 req
.setRequestHeader("If-Range", "xyzzy");
203 req
.setRequestHeader("Range", "bytes=52-59");
205 } else if (asyncStep
== 11) {
207 log("async: If-Range override (none match): status = " + req
.status
);
209 req
= new XMLHttpRequest();
210 req
.onreadystatechange
= processStateChange
;
211 req
.open("GET", "resources/304.pl", true);
212 req
.setRequestHeader("If-Modified-Since", "Tue, 01 Jan 1980 01:00:00 GMT");
214 } else if (asyncStep
== 12) {
215 log("async: If-Modified-Since override (uncached response): status = " + req
.status
);
216 if (window
.testRunner
)
217 testRunner
.notifyDone();