Chromium Code Reviews

Side by Side Diff: LayoutTests/http/tests/serviceworker/resources/fetch-cache-override-worker.js

Issue 580023002: [Fetch API] Add tests of 304 handling for fetch() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « LayoutTests/http/tests/serviceworker/fetch-cache-override.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 importScripts('worker-test-harness.js');
2 importScripts('test-helpers.js');
3
4 promise_test(function() {
5 var lastModified = '';
6 var eTag = '';
7 var url = 'other.html';
8 var expectedText = '<!DOCTYPE html>\n<title>Other</title>\n' +
9 'Here\'s an other html file.\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.');
16
17 return fetch(url);
18 })
19 .then(function(res) {
20 assert_equals(res.status, 200,
21 'Automatically cached response status must be 200.');
22 return res.text();
23 })
24 .then(function(text) {
25 assert_equals(
26 text, expectedText,
27 'Automatically cached response body must be correct.');
28
29 return fetch(url,
30 { headers: [['If-Modified-Since', lastModified]] });
31 })
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();
38 })
39 .then(function(text) {
40 assert_equals(
41 text, '',
42 'When If-Modified-Since is overridden, the response body must be' +
43 ' empty.');
44
45 return fetch(url,
46 { headers: [['If-Modified-Since',
47 'Tue, 01 Jan 1980 01:00:00 GMT']] });
48 })
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();
55 })
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.');
61
62 return fetch(url,
63 { headers: [['If-Unmodified-Since', lastModified]] });
64 })
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();
71 })
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.');
77
78 return fetch(url,
79 { headers: [['If-Unmodified-Since',
80 'Tue, 01 Jan 1980 01:00:00 GMT']] });
81 })
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();
88 })
89 .then(function(text) {
90 assert_equals(
91 text, '',
92 'When If-Unmodified is overridden, the modified response body ' +
93 'must be empty.');
94
95 return fetch(url,
96 { headers: [['If-Match', eTag]] });
97 })
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();
103 })
104 .then(function(text) {
105 assert_equals(
106 text, expectedText,
107 'When If-Match is overridden, the response body must be correct.');
108
109 return fetch(url,
110 { headers: [['If-Match', 'xyzzy']] });
111 })
112 .then(function(res) {
113 assert_equals(
114 res.status, 412,
115 'When If-Match is overridden to the invalid tag, the response ' +
116 'status must be 412.');
117 return res.text();
118 })
119 .then(function(text) {
120 assert_equals(
121 text, '',
122 'When If-Match is overridden to the invalid tag, the response ' +
123 'body must be empty.');
124
125 return fetch(url,
126 { headers: [['If-None-Match', eTag]] });
127 })
128 .then(function(res) {
129 assert_equals(
130 res.status, 304,
131 'When If-None-Match is overridden, the response status must be ' +
132 '304.');
133 return res.text();
134 })
135 .then(function(text) {
136 assert_equals(
137 text, '',
138 'When If-None-Match is overridden, the response body must be ' +
139 'empty.');
140
141 return fetch(url,
142 { headers: [['If-None-Match', 'xyzzy']] });
143 })
144 .then(function(res) {
145 assert_equals(
146 res.status, 200,
147 'When If-None-Match is overridden to the invalid tag, the ' +
148 'response status must be 200.');
149 return res.text();
150 })
151 .then(function(text) {
152 assert_equals(
153 text, expectedText,
154 'When If-None-Match is overridden to the invalid tag, the ' +
155 'response body must be correct.');
156
157 return fetch(url,
158 { headers: [['If-Range', eTag],
159 ['Range', 'bytes=10-30']] });
160 })
161 .then(function(res) {
162 assert_equals(
163 res.status, 206,
164 'When If-Range is overridden, the response status must be 206.');
165 return res.text();
166 })
167 .then(function(text) {
168 assert_equals(
169 text, expectedText.substring(10, 31),
170 'When If-Range is overridden, the response body must be correct.');
171
172 return fetch(url,
173 { headers: [['If-Range', 'xyzzy'],
174 ['Range', 'bytes=10-30']] });
175 })
176 .then(function(res) {
177 assert_equals(
178 res.status, 200,
179 'When If-Range is overridden to the invalid tag, the response ' +
180 'status must be 200.');
181 return res.text();
182 })
183 .then(function(text) {
184 assert_equals(
185 text, expectedText,
186 'When If-Range is overridden to the invalid tag, the response ' +
187 'body must be correct.');
188
189 return fetch('fetch-status.php?status=304');
190 })
191 .then(function(res) {
192 assert_equals(
193 res.status, 304 ,
194 'When the server returns 304 and there\'s a cache miss, the ' +
195 'response status must be 304.');
196 })
197 }, '304 handling for fetch().');
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/serviceworker/fetch-cache-override.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine