Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

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. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« 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';
nhiroki 2014/09/18 10:39:32 +4-space indent?
horo 2014/09/19 05:06:12 Done.
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 'If-Modified-Since override response status must be 304');
nhiroki 2014/09/18 10:39:32 (suggestion) 'Status of the request overridden wit
horo 2014/09/19 05:06:12 refined
36 return res.text();
37 })
38 .then(function(text) {
39 assert_equals(
40 text, '',
41 'If-Modified-Since override modified body must be empty');
42
43 return fetch(url,
44 { headers: [['If-Modified-Since',
45 'Tue, 01 Jan 1980 01:00:00 GMT']] });
46 })
47 .then(function(res) {
48 assert_equals(
49 res.status, 200,
50 'If-Modified-Since override modified response status must be 200');
51 return res.text();
52 })
53 .then(function(text) {
54 assert_equals(
55 text, expectedText,
56 'If-Modified-Since override modified body must be correct');
57
58 return fetch(url,
59 { headers: [['If-Unmodified-Since', lastModified]] });
60 })
61 .then(function(res) {
62 assert_equals(
63 res.status, 200,
64 'If-Unmodified-Since override response status must be 200');
65 return res.text();
66 })
67 .then(function(text) {
68 assert_equals(
69 text, expectedText,
70 'If-Unmodified-Since override response body must be correct');
71
72 return fetch(url,
73 { headers: [['If-Unmodified-Since',
74 'Tue, 01 Jan 1980 01:00:00 GMT']] });
75 })
76 .then(function(res) {
77 assert_equals(
78 res.status, 412,
79 'If-Unmodified-Since override modified response status must be ' +
80 '412');
nhiroki 2014/09/18 10:39:32 +4-space indent?
horo 2014/09/19 05:06:12 Done.
81 return res.text();
82 })
83 .then(function(text) {
84 assert_equals(
85 text, '',
86 'If-Unmodified-Since override modified response body must be ' +
87 'empty');
nhiroki 2014/09/18 10:39:32 ditto.
horo 2014/09/19 05:06:13 Done.
88
89 return fetch(url,
90 { headers: [['If-Match', eTag]] });
91 })
92 .then(function(res) {
93 assert_equals(
94 res.status, 200,
95 'If-Match override response status must be 200');
96 return res.text();
97 })
98 .then(function(text) {
99 assert_equals(
100 text, expectedText,
101 'If-Match override response body must be correct');
102
103 return fetch(url,
104 { headers: [['If-Match', 'xyzzy']] });
105 })
106 .then(function(res) {
107 assert_equals(
108 res.status, 412,
109 'If-Match override none match response status must be 412');
110 return res.text();
111 })
112 .then(function(text) {
113 assert_equals(
114 text, '',
115 'If-Match override none match response body must be empty');
116
117 return fetch(url,
118 { headers: [['If-None-Match', eTag]] });
119 })
120 .then(function(res) {
121 assert_equals(
122 res.status, 304,
123 'If-None-Match override response status must be 304');
124 return res.text();
125 })
126 .then(function(text) {
127 assert_equals(
128 text, '', 'If-None-Match override response body must be empty');
129
130 return fetch(url,
131 { headers: [['If-None-Match', 'xyzzy']] });
132 })
133 .then(function(res) {
134 assert_equals(
135 res.status, 200,
136 'If-None-Match override none match response status must be 200');
137
138 return fetch(url,
139 { headers: [['If-Range', eTag],
140 ['Range', 'bytes=10-30']] });
141 })
142 .then(function(res) {
143 assert_equals(
144 res.status, 206,
145 'If-Range override response status must be 206');
146 return res.text();
147 })
148 .then(function(text) {
149 assert_equals(
150 text, expectedText.substring(10, 31),
151 'If-Range override cached response body must be correct.');
152
153 return fetch(url,
154 { headers: [['If-Range', 'xyzzy'],
155 ['Range', 'bytes=10-30']] });
156 })
157 .then(function(res) {
158 assert_equals(
159 res.status, 200,
160 'If-Range override none match response status must be 200');
161 return res.text();
162 })
163 .then(function(text) {
164 assert_equals(
165 text, expectedText,
166 'If-Range override none match response body must be correct.');
167 })
168 }, '304 handling for fetch().');
169
nhiroki 2014/09/18 10:39:32 nit: There is an empty line.
horo 2014/09/19 05:06:12 Done.
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
This is Rietveld 408576698