Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / fetch / script-tests / cache-override.js
blobf4fd1ea5745961737f7a4769d52448b1fd938de8
1 if (self.importScripts) {
2 importScripts('../resources/fetch-test-helpers.js');
5 promise_test(function() {
6 var lastModified = '';
7 var eTag = '';
8 var url = '../resources/doctype.html';
9 var expectedText = '<!DOCTYPE html>\n';
10 return fetch(url)
11 .then(function(res) {
12 lastModified = res.headers.get('last-modified');
13 eTag = res.headers.get('etag');
14 assert_not_equals(lastModified, '', 'last-modified must be set.');
15 assert_not_equals(eTag, '', 'eTag must be set.');
17 return fetch(url);
19 .then(function(res) {
20 assert_equals(res.status, 200,
21 'Automatically cached response status must be 200.');
22 return res.text();
24 .then(function(text) {
25 assert_equals(
26 text, expectedText,
27 'Automatically cached response body must be correct.');
29 return fetch(url,
30 { headers: [['If-Modified-Since', lastModified]] });
32 .then(function(res) {
33 assert_equals(
34 res.status, 304,
35 'When If-Modified-Since is overridden, the response status must ' +
36 'be 304.');
37 return res.text();
39 .then(function(text) {
40 assert_equals(
41 text, '',
42 'When If-Modified-Since is overridden, the response body must be' +
43 ' empty.');
45 return fetch(url,
46 { headers: [['If-Modified-Since',
47 'Tue, 01 Jan 1980 01:00:00 GMT']] });
49 .then(function(res) {
50 assert_equals(
51 res.status, 200,
52 'When If-Modified-Since is overridden, the modified response ' +
53 'status must be 200.');
54 return res.text();
56 .then(function(text) {
57 assert_equals(
58 text, expectedText,
59 'When If-Modified-Since is overridden, the modified response body' +
60 ' must be correct.');
62 return fetch(url,
63 { headers: [['If-Unmodified-Since', lastModified]] });
65 .then(function(res) {
66 assert_equals(
67 res.status, 200,
68 'When If-Unmodified-Since is overridden, the modified response ' +
69 'status must be 200.');
70 return res.text();
72 .then(function(text) {
73 assert_equals(
74 text, expectedText,
75 'When If-Unmodified-Since is overridden, the modified response ' +
76 'body must be correct.');
78 return fetch(url,
79 { headers: [['If-Unmodified-Since',
80 'Tue, 01 Jan 1980 01:00:00 GMT']] });
82 .then(function(res) {
83 assert_equals(
84 res.status, 412,
85 'When If-Unmodified is overridden, the modified response status ' +
86 'must be 412.');
87 return res.text();
89 .then(function(text) {
90 assert_equals(
91 text, '',
92 'When If-Unmodified is overridden, the modified response body ' +
93 'must be empty.');
95 return fetch(url,
96 { headers: [['If-Match', eTag]] });
98 .then(function(res) {
99 assert_equals(
100 res.status, 200,
101 'When If-Match is overridden, the response status must be 200.');
102 return res.text();
104 .then(function(text) {
105 assert_equals(
106 text, expectedText,
107 'When If-Match is overridden, the response body must be correct.');
109 // FIXME: We used to have a test of If-Match overridden with an
110 // invalid etag, but removed due to broken If-Match handling of
111 // Apache 2.4. See crbug.com/423070
113 return fetch(url,
114 { headers: [['If-None-Match', eTag]] });
116 .then(function(res) {
117 assert_equals(
118 res.status, 304,
119 'When If-None-Match is overridden, the response status must be ' +
120 '304.');
121 return res.text();
123 .then(function(text) {
124 assert_equals(
125 text, '',
126 'When If-None-Match is overridden, the response body must be ' +
127 'empty.');
129 return fetch(url,
130 { headers: [['If-None-Match', 'xyzzy']] });
132 .then(function(res) {
133 assert_equals(
134 res.status, 200,
135 'When If-None-Match is overridden to the invalid tag, the ' +
136 'response status must be 200.');
137 return res.text();
139 .then(function(text) {
140 assert_equals(
141 text, expectedText,
142 'When If-None-Match is overridden to the invalid tag, the ' +
143 'response body must be correct.');
145 return fetch(url,
146 { headers: [['If-Range', eTag],
147 ['Range', 'bytes=10-30']] });
149 .then(function(res) {
150 assert_equals(
151 res.status, 206,
152 'When If-Range is overridden, the response status must be 206.');
153 return res.text();
155 .then(function(text) {
156 assert_equals(
157 text, expectedText.substring(10, 31),
158 'When If-Range is overridden, the response body must be correct.');
160 return fetch(url,
161 { headers: [['If-Range', 'xyzzy'],
162 ['Range', 'bytes=10-30']] });
164 .then(function(res) {
165 assert_equals(
166 res.status, 200,
167 'When If-Range is overridden to the invalid tag, the response ' +
168 'status must be 200.');
169 return res.text();
171 .then(function(text) {
172 assert_equals(
173 text, expectedText,
174 'When If-Range is overridden to the invalid tag, the response ' +
175 'body must be correct.');
177 return fetch('../resources/fetch-status.php?status=304');
179 .then(function(res) {
180 assert_equals(
181 res.status, 304 ,
182 'When the server returns 304 and there\'s a cache miss, the ' +
183 'response status must be 304.');
185 }, '304 handling for fetch().');
187 done();