Index: LayoutTests/http/tests/serviceworker/resources/fetch-cache-override-worker.js |
diff --git a/LayoutTests/http/tests/serviceworker/resources/fetch-cache-override-worker.js b/LayoutTests/http/tests/serviceworker/resources/fetch-cache-override-worker.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c37723047f23046fb6a727f38323ac2327771019 |
--- /dev/null |
+++ b/LayoutTests/http/tests/serviceworker/resources/fetch-cache-override-worker.js |
@@ -0,0 +1,169 @@ |
+importScripts('worker-test-harness.js'); |
+importScripts('test-helpers.js'); |
+ |
+promise_test(function() { |
+ var lastModified = ''; |
+ var eTag = ''; |
+ var url = 'other.html'; |
+ var expectedText = '<!DOCTYPE html>\n<title>Other</title>\n' + |
+ '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.
|
+ return fetch(url) |
+ .then(function(res) { |
+ lastModified = res.headers.get('last-modified'); |
+ eTag = res.headers.get('etag'); |
+ assert_not_equals(lastModified, '', 'last-modified must be set.'); |
+ assert_not_equals(eTag, '', 'eTag must be set.'); |
+ |
+ return fetch(url); |
+ }) |
+ .then(function(res) { |
+ assert_equals(res.status, 200, |
+ 'Automatically cached response status must be 200'); |
+ return res.text(); |
+ }) |
+ .then(function(text) { |
+ assert_equals( |
+ text, expectedText, |
+ 'Automatically cached response body must be correct.'); |
+ |
+ return fetch(url, |
+ { headers: [['If-Modified-Since', lastModified]] }); |
+ }) |
+ .then(function(res) { |
+ assert_equals( |
+ res.status, 304, |
+ '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
|
+ return res.text(); |
+ }) |
+ .then(function(text) { |
+ assert_equals( |
+ text, '', |
+ 'If-Modified-Since override modified body must be empty'); |
+ |
+ return fetch(url, |
+ { headers: [['If-Modified-Since', |
+ 'Tue, 01 Jan 1980 01:00:00 GMT']] }); |
+ }) |
+ .then(function(res) { |
+ assert_equals( |
+ res.status, 200, |
+ 'If-Modified-Since override modified response status must be 200'); |
+ return res.text(); |
+ }) |
+ .then(function(text) { |
+ assert_equals( |
+ text, expectedText, |
+ 'If-Modified-Since override modified body must be correct'); |
+ |
+ return fetch(url, |
+ { headers: [['If-Unmodified-Since', lastModified]] }); |
+ }) |
+ .then(function(res) { |
+ assert_equals( |
+ res.status, 200, |
+ 'If-Unmodified-Since override response status must be 200'); |
+ return res.text(); |
+ }) |
+ .then(function(text) { |
+ assert_equals( |
+ text, expectedText, |
+ 'If-Unmodified-Since override response body must be correct'); |
+ |
+ return fetch(url, |
+ { headers: [['If-Unmodified-Since', |
+ 'Tue, 01 Jan 1980 01:00:00 GMT']] }); |
+ }) |
+ .then(function(res) { |
+ assert_equals( |
+ res.status, 412, |
+ 'If-Unmodified-Since override modified response status must be ' + |
+ '412'); |
nhiroki
2014/09/18 10:39:32
+4-space indent?
horo
2014/09/19 05:06:12
Done.
|
+ return res.text(); |
+ }) |
+ .then(function(text) { |
+ assert_equals( |
+ text, '', |
+ 'If-Unmodified-Since override modified response body must be ' + |
+ 'empty'); |
nhiroki
2014/09/18 10:39:32
ditto.
horo
2014/09/19 05:06:13
Done.
|
+ |
+ return fetch(url, |
+ { headers: [['If-Match', eTag]] }); |
+ }) |
+ .then(function(res) { |
+ assert_equals( |
+ res.status, 200, |
+ 'If-Match override response status must be 200'); |
+ return res.text(); |
+ }) |
+ .then(function(text) { |
+ assert_equals( |
+ text, expectedText, |
+ 'If-Match override response body must be correct'); |
+ |
+ return fetch(url, |
+ { headers: [['If-Match', 'xyzzy']] }); |
+ }) |
+ .then(function(res) { |
+ assert_equals( |
+ res.status, 412, |
+ 'If-Match override none match response status must be 412'); |
+ return res.text(); |
+ }) |
+ .then(function(text) { |
+ assert_equals( |
+ text, '', |
+ 'If-Match override none match response body must be empty'); |
+ |
+ return fetch(url, |
+ { headers: [['If-None-Match', eTag]] }); |
+ }) |
+ .then(function(res) { |
+ assert_equals( |
+ res.status, 304, |
+ 'If-None-Match override response status must be 304'); |
+ return res.text(); |
+ }) |
+ .then(function(text) { |
+ assert_equals( |
+ text, '', 'If-None-Match override response body must be empty'); |
+ |
+ return fetch(url, |
+ { headers: [['If-None-Match', 'xyzzy']] }); |
+ }) |
+ .then(function(res) { |
+ assert_equals( |
+ res.status, 200, |
+ 'If-None-Match override none match response status must be 200'); |
+ |
+ return fetch(url, |
+ { headers: [['If-Range', eTag], |
+ ['Range', 'bytes=10-30']] }); |
+ }) |
+ .then(function(res) { |
+ assert_equals( |
+ res.status, 206, |
+ 'If-Range override response status must be 206'); |
+ return res.text(); |
+ }) |
+ .then(function(text) { |
+ assert_equals( |
+ text, expectedText.substring(10, 31), |
+ 'If-Range override cached response body must be correct.'); |
+ |
+ return fetch(url, |
+ { headers: [['If-Range', 'xyzzy'], |
+ ['Range', 'bytes=10-30']] }); |
+ }) |
+ .then(function(res) { |
+ assert_equals( |
+ res.status, 200, |
+ 'If-Range override none match response status must be 200'); |
+ return res.text(); |
+ }) |
+ .then(function(text) { |
+ assert_equals( |
+ text, expectedText, |
+ 'If-Range override none match response body must be correct.'); |
+ }) |
+ }, '304 handling for fetch().'); |
+ |
nhiroki
2014/09/18 10:39:32
nit: There is an empty line.
horo
2014/09/19 05:06:12
Done.
|