Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / cache-override.html
blobaf4fa3acc92fb9a213e6f5e5745ef32533a32055
1 <html>
2 <body>
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>
5 <script>
6 if (window.testRunner) {
7 testRunner.dumpAsText();
8 testRunner.waitUntilDone();
11 var console_messages = document.createElement("ul");
12 document.body.appendChild(console_messages);
14 function log(message)
16 var item = document.createElement("li");
17 item.appendChild(document.createTextNode(message));
18 console_messages.appendChild(item);
21 // sync
22 req = new XMLHttpRequest;
23 req.open("GET", "resources/reply.xml", false);
24 log("Fetching the resource once to cache the response...");
25 req.send(null);
26 lastModified = req.getResponseHeader("Last-Modified");
27 eTag = req.getResponseHeader("ETag");
29 req.open("GET", "resources/reply.xml", false);
30 req.send(null);
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);
33 else
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);
38 req.send(null);
39 log("If-Modified-Since override: status = " + req.status);
41 req.open("GET", "resources/reply.xml", false);
42 req.setRequestHeader("If-MODIFIED-Since", lastModified);
43 req.send(null);
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");
48 req.send(null);
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);
53 req.send(null);
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");
58 req.send(null);
59 log("If-Unmodified-Since override (modified): status = " + req.status);
61 req.open("GET", "resources/reply.xml", false);
62 req.setRequestHeader("If-Match", eTag);
63 req.send(null);
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");
69 // req.send(null);
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);
74 req.send(null);
75 log("If-None-Match override: status = " + req.status);
77 req.open("GET", "resources/reply.xml", false);
78 req.setRequestHeader("If-None-Match", "xyzzy");
79 req.send(null);
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");
85 req.send(null);
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");
91 req.send(null);
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");
96 req.send(null);
97 log("If-Modified-Since override (uncached response): status = " + req.status);
99 // async
100 var asyncStep = 1;
102 req.onreadystatechange = processStateChange;
103 req.open("GET", "resources/reply.xml", true);
104 req.send(null);
106 function processStateChange() {
108 if (req.readyState == 4){
109 if (asyncStep == 1) {
110 asyncStep = 2;
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);
113 else
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);
120 req.send(null);
121 } else if (asyncStep == 2) {
122 asyncStep = 3;
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");
129 req.send(null);
130 } else if (asyncStep == 3) {
131 asyncStep = 4;
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);
138 req.send(null);
139 } else if (asyncStep == 4) {
140 asyncStep = 5;
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");
147 req.send(null);
148 } else if (asyncStep == 5) {
149 asyncStep = 6;
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);
156 req.send(null);
157 } else if (asyncStep == 6) {
158 asyncStep = 7;
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");
165 req.send(null);
166 } else if (asyncStep == 7) {
167 asyncStep = 8;
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);
175 req.send(null);
176 } else if (asyncStep == 8) {
177 asyncStep = 9;
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");
184 req.send(null);
185 } else if (asyncStep == 9) {
186 asyncStep = 10;
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");
194 req.send(null);
195 } else if (asyncStep == 10) {
196 asyncStep = 11;
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");
204 req.send(null);
205 } else if (asyncStep == 11) {
206 asyncStep = 12;
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");
213 req.send(null);
214 } else if (asyncStep == 12) {
215 log("async: If-Modified-Since override (uncached response): status = " + req.status);
216 if (window.testRunner)
217 testRunner.notifyDone();
221 </script>
222 </body>
223 </html>