OLD | NEW |
1 importScripts('worker-testharness.js'); | 1 importScripts('worker-testharness.js'); |
2 importScripts('../../resources/testharness-helpers.js'); | 2 importScripts('../../resources/testharness-helpers.js'); |
3 importScripts('test-helpers.js'); | 3 importScripts('test-helpers.js'); |
4 | 4 |
5 promise_test(function() { | 5 promise_test(function() { |
6 var lastModified = ''; | 6 var lastModified = ''; |
7 var eTag = ''; | 7 var eTag = ''; |
8 var url = 'other.html'; | 8 var url = 'other.html'; |
9 var expectedText = '<!DOCTYPE html>\n<title>Other</title>\n' + | 9 var expectedText = '<!DOCTYPE html>\n<title>Other</title>\n' + |
10 'Here\'s an other html file.\n'; | 10 'Here\'s an other html file.\n'; |
11 return fetch(url) | 11 return fetch(url) |
12 .then(function(res) { | 12 .then(function(res) { |
13 lastModified = res.headers.get('last-modified'); | 13 lastModified = res.headers.get('last-modified'); |
14 eTag = res.headers.get('etag'); | 14 eTag = res.headers.get('etag'); |
15 assert_not_equals(lastModified, '', 'last-modified must be set.'); | 15 assert_not_equals(lastModified, '', 'last-modified must be set.'); |
16 assert_not_equals(eTag, '', 'eTag must be set.'); | 16 assert_not_equals(eTag, '', 'eTag must be set.'); |
17 | 17 |
18 return fetch(url); | 18 return fetch(url); |
19 }) | 19 }) |
20 .then(function(res) { | 20 .then(function(res) { |
21 assert_equals(res.status, 200, | 21 assert_equals(res.status, 200, |
22 'Automatically cached response status must be 200.'); | 22 'Automatically cached response status must be 200.'); |
23 return res.text(); | 23 return res.text(); |
24 }) | 24 }) |
25 .then(function(text) { | 25 .then(function(text) { |
26 assert_equals( | 26 assert_equals( |
27 text, expectedText, | 27 text, expectedText, |
28 'Automatically cached response body must be correct.'); | 28 'Automatically cached response body must be correct.'); |
29 | 29 |
30 return fetch(url, | 30 return fetch(url, |
31 { headers: [['If-Modified-Since', lastModified]] }); | 31 { headers: [['If-Modified-Since', lastModified]] }); |
32 }) | 32 }) |
33 .then(function(res) { | 33 .then(function(res) { |
34 assert_equals( | 34 assert_equals( |
35 res.status, 304, | 35 res.status, 304, |
36 'When If-Modified-Since is overridden, the response status must ' + | 36 'When If-Modified-Since is overridden, the response status must ' + |
37 'be 304.'); | 37 'be 304.'); |
38 return res.text(); | 38 return res.text(); |
39 }) | 39 }) |
40 .then(function(text) { | 40 .then(function(text) { |
41 assert_equals( | 41 assert_equals( |
42 text, '', | 42 text, '', |
43 'When If-Modified-Since is overridden, the response body must be' + | 43 'When If-Modified-Since is overridden, the response body must be' + |
44 ' empty.'); | 44 ' empty.'); |
45 | 45 |
46 return fetch(url, | 46 return fetch(url, |
47 { headers: [['If-Modified-Since', | 47 { headers: [['If-Modified-Since', |
48 'Tue, 01 Jan 1980 01:00:00 GMT']] }); | 48 'Tue, 01 Jan 1980 01:00:00 GMT']] }); |
49 }) | 49 }) |
50 .then(function(res) { | 50 .then(function(res) { |
51 assert_equals( | 51 assert_equals( |
52 res.status, 200, | 52 res.status, 200, |
53 'When If-Modified-Since is overridden, the modified response ' + | 53 'When If-Modified-Since is overridden, the modified response ' + |
54 'status must be 200.'); | 54 'status must be 200.'); |
55 return res.text(); | 55 return res.text(); |
56 }) | 56 }) |
57 .then(function(text) { | 57 .then(function(text) { |
58 assert_equals( | 58 assert_equals( |
59 text, expectedText, | 59 text, expectedText, |
60 'When If-Modified-Since is overridden, the modified response body' + | 60 'When If-Modified-Since is overridden, the modified response body' + |
61 ' must be correct.'); | 61 ' must be correct.'); |
62 | 62 |
63 return fetch(url, | 63 return fetch(url, |
64 { headers: [['If-Unmodified-Since', lastModified]] }); | 64 { headers: [['If-Unmodified-Since', lastModified]] }); |
65 }) | 65 }) |
66 .then(function(res) { | 66 .then(function(res) { |
67 assert_equals( | 67 assert_equals( |
68 res.status, 200, | 68 res.status, 200, |
69 'When If-Unmodified-Since is overridden, the modified response ' + | 69 'When If-Unmodified-Since is overridden, the modified response ' + |
70 'status must be 200.'); | 70 'status must be 200.'); |
71 return res.text(); | 71 return res.text(); |
72 }) | 72 }) |
73 .then(function(text) { | 73 .then(function(text) { |
74 assert_equals( | 74 assert_equals( |
75 text, expectedText, | 75 text, expectedText, |
76 'When If-Unmodified-Since is overridden, the modified response ' + | 76 'When If-Unmodified-Since is overridden, the modified response ' + |
77 'body must be correct.'); | 77 'body must be correct.'); |
78 | 78 |
79 return fetch(url, | 79 return fetch(url, |
80 { headers: [['If-Unmodified-Since', | 80 { headers: [['If-Unmodified-Since', |
81 'Tue, 01 Jan 1980 01:00:00 GMT']] }); | 81 'Tue, 01 Jan 1980 01:00:00 GMT']] }); |
82 }) | 82 }) |
83 .then(function(res) { | 83 .then(function(res) { |
84 assert_equals( | 84 assert_equals( |
85 res.status, 412, | 85 res.status, 412, |
86 'When If-Unmodified is overridden, the modified response status ' + | 86 'When If-Unmodified is overridden, the modified response status ' + |
87 'must be 412.'); | 87 'must be 412.'); |
88 return res.text(); | 88 return res.text(); |
89 }) | 89 }) |
90 .then(function(text) { | 90 .then(function(text) { |
91 assert_equals( | 91 assert_equals( |
92 text, '', | 92 text, '', |
93 'When If-Unmodified is overridden, the modified response body ' + | 93 'When If-Unmodified is overridden, the modified response body ' + |
94 'must be empty.'); | 94 'must be empty.'); |
95 | 95 |
96 return fetch(url, | 96 return fetch(url, |
97 { headers: [['If-Match', eTag]] }); | 97 { headers: [['If-Match', eTag]] }); |
98 }) | 98 }) |
99 .then(function(res) { | 99 .then(function(res) { |
100 assert_equals( | 100 assert_equals( |
101 res.status, 200, | 101 res.status, 200, |
102 'When If-Match is overridden, the response status must be 200.'); | 102 'When If-Match is overridden, the response status must be 200.'); |
103 return res.text(); | 103 return res.text(); |
104 }) | 104 }) |
105 .then(function(text) { | 105 .then(function(text) { |
106 assert_equals( | 106 assert_equals( |
107 text, expectedText, | 107 text, expectedText, |
108 'When If-Match is overridden, the response body must be correct.'); | 108 'When If-Match is overridden, the response body must be correct.'); |
109 | 109 |
110 return fetch(url, | 110 return fetch(url, |
111 { headers: [['If-Match', 'xyzzy']] }); | 111 { headers: [['If-Match', 'xyzzy']] }); |
112 }) | 112 }) |
113 .then(function(res) { | 113 .then(function(res) { |
114 assert_equals( | 114 assert_equals( |
115 res.status, 412, | 115 res.status, 412, |
116 'When If-Match is overridden to the invalid tag, the response ' + | 116 'When If-Match is overridden to the invalid tag, the response ' + |
117 'status must be 412.'); | 117 'status must be 412.'); |
118 return res.text(); | 118 return res.text(); |
119 }) | 119 }) |
120 .then(function(text) { | 120 .then(function(text) { |
121 assert_equals( | 121 assert_equals( |
122 text, '', | 122 text, '', |
123 'When If-Match is overridden to the invalid tag, the response ' + | 123 'When If-Match is overridden to the invalid tag, the response ' + |
124 'body must be empty.'); | 124 'body must be empty.'); |
125 | 125 |
126 return fetch(url, | 126 return fetch(url, |
127 { headers: [['If-None-Match', eTag]] }); | 127 { headers: [['If-None-Match', eTag]] }); |
128 }) | 128 }) |
129 .then(function(res) { | 129 .then(function(res) { |
130 assert_equals( | 130 assert_equals( |
131 res.status, 304, | 131 res.status, 304, |
132 'When If-None-Match is overridden, the response status must be ' + | 132 'When If-None-Match is overridden, the response status must be ' + |
133 '304.'); | 133 '304.'); |
134 return res.text(); | 134 return res.text(); |
135 }) | 135 }) |
136 .then(function(text) { | 136 .then(function(text) { |
137 assert_equals( | 137 assert_equals( |
138 text, '', | 138 text, '', |
139 'When If-None-Match is overridden, the response body must be ' + | 139 'When If-None-Match is overridden, the response body must be ' + |
140 'empty.'); | 140 'empty.'); |
141 | 141 |
142 return fetch(url, | 142 return fetch(url, |
143 { headers: [['If-None-Match', 'xyzzy']] }); | 143 { headers: [['If-None-Match', 'xyzzy']] }); |
144 }) | 144 }) |
145 .then(function(res) { | 145 .then(function(res) { |
146 assert_equals( | 146 assert_equals( |
147 res.status, 200, | 147 res.status, 200, |
148 'When If-None-Match is overridden to the invalid tag, the ' + | 148 'When If-None-Match is overridden to the invalid tag, the ' + |
149 'response status must be 200.'); | 149 'response status must be 200.'); |
150 return res.text(); | 150 return res.text(); |
151 }) | 151 }) |
152 .then(function(text) { | 152 .then(function(text) { |
153 assert_equals( | 153 assert_equals( |
154 text, expectedText, | 154 text, expectedText, |
155 'When If-None-Match is overridden to the invalid tag, the ' + | 155 'When If-None-Match is overridden to the invalid tag, the ' + |
156 'response body must be correct.'); | 156 'response body must be correct.'); |
157 | 157 |
158 return fetch(url, | 158 return fetch(url, |
159 { headers: [['If-Range', eTag], | 159 { headers: [['If-Range', eTag], |
160 ['Range', 'bytes=10-30']] }); | 160 ['Range', 'bytes=10-30']] }); |
161 }) | 161 }) |
162 .then(function(res) { | 162 .then(function(res) { |
163 assert_equals( | 163 assert_equals( |
164 res.status, 206, | 164 res.status, 206, |
165 'When If-Range is overridden, the response status must be 206.'); | 165 'When If-Range is overridden, the response status must be 206.'); |
166 return res.text(); | 166 return res.text(); |
167 }) | 167 }) |
168 .then(function(text) { | 168 .then(function(text) { |
169 assert_equals( | 169 assert_equals( |
170 text, expectedText.substring(10, 31), | 170 text, expectedText.substring(10, 31), |
171 'When If-Range is overridden, the response body must be correct.'); | 171 'When If-Range is overridden, the response body must be correct.'); |
172 | 172 |
173 return fetch(url, | 173 return fetch(url, |
174 { headers: [['If-Range', 'xyzzy'], | 174 { headers: [['If-Range', 'xyzzy'], |
175 ['Range', 'bytes=10-30']] }); | 175 ['Range', 'bytes=10-30']] }); |
176 }) | 176 }) |
177 .then(function(res) { | 177 .then(function(res) { |
178 assert_equals( | 178 assert_equals( |
179 res.status, 200, | 179 res.status, 200, |
180 'When If-Range is overridden to the invalid tag, the response ' + | 180 'When If-Range is overridden to the invalid tag, the response ' + |
181 'status must be 200.'); | 181 'status must be 200.'); |
182 return res.text(); | 182 return res.text(); |
183 }) | 183 }) |
184 .then(function(text) { | 184 .then(function(text) { |
185 assert_equals( | 185 assert_equals( |
186 text, expectedText, | 186 text, expectedText, |
187 'When If-Range is overridden to the invalid tag, the response ' + | 187 'When If-Range is overridden to the invalid tag, the response ' + |
188 'body must be correct.'); | 188 'body must be correct.'); |
189 | 189 |
190 return fetch('fetch-status.php?status=304'); | 190 return fetch('fetch-status.php?status=304'); |
191 }) | 191 }) |
192 .then(function(res) { | 192 .then(function(res) { |
193 assert_equals( | 193 assert_equals( |
194 res.status, 304 , | 194 res.status, 304 , |
195 'When the server returns 304 and there\'s a cache miss, the ' + | 195 'When the server returns 304 and there\'s a cache miss, the ' + |
196 'response status must be 304.'); | 196 'response status must be 304.'); |
197 }) | 197 }); |
198 }, '304 handling for fetch().'); | 198 }, '304 handling for fetch().'); |
OLD | NEW |