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

Unified Diff: LayoutTests/http/tests/serviceworker/resources/cache-put-test-worker.js

Issue 425413002: [ServiceWorker] Tests for Cache (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/serviceworker/resources/cache-put-test-worker.js
diff --git a/LayoutTests/http/tests/serviceworker/resources/cache-put-test-worker.js b/LayoutTests/http/tests/serviceworker/resources/cache-put-test-worker.js
new file mode 100644
index 0000000000000000000000000000000000000000..be4a78f905d039528b7e3f337583d58dccd74999
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/resources/cache-put-test-worker.js
@@ -0,0 +1,45 @@
+importScripts('worker-test-harness.js');
+
+promise_test(function(t) {
+ var request = new Request('http://example.com/foo', {method: 'GET'});
+ var response = new Response(
+ 'Hello, world!', {
jsbell 2014/08/01 00:02:25 This line break is weird.
asanka 2014/08/13 03:30:04 Indeed. Fixed.
+ status: 200,
+ statusText: 'OK',
+ headers: [['Content-Type', 'text/plain']]
+ });
+ return new Cache().put(request, response)
+ .then(t.step_func(function(result) {
+ assert_equals(result,
+ response,
+ 'Cache.put should resolve with the response ' +
+ 'parameter.');
+ }));
+ }, 'Cache.put with a valid request');
+
+promise_test(function(t) {
+ var request = new Request('http://example.com/foo', {method: 'HEAD'});
+ var response = new Response('Hello, world!', {
+ status: 200,
+ statusText: 'OK',
+ headers: [['Content-Type', 'text/plain']]
+ });
+ return new Cache().put(request, response)
+ .then(t.unreached_func('Cache.put should not accept non-GET requests.'))
+ .catch(t.step_func(function(e) {
+ assert_true(e instanceof TypeError,
+ 'Cache.put should throw a TypeError for non-GET ' +
+ 'requests');
+ }));
+ }, 'Cache.put with a non-GET request');
+
+promise_test(function(t) {
+ var request = new Request('http://example.com/foo', {method: 'HEAD'});
+ return new Cache().put(request, null)
+ .then(t.unreached_func('Cache.put should not accept empty responses.'))
+ .catch(t.step_func(function(e) {
+ assert_true(e instanceof TypeError,
+ 'Cache.put should throw a TypeError for an empty ' +
+ 'response');
+ }));
+ }, 'Cache.put with an empty response');

Powered by Google App Engine
This is Rietveld 408576698