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

Unified Diff: LayoutTests/http/tests/serviceworker/resources/cache-batch-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-batch-test-worker.js
diff --git a/LayoutTests/http/tests/serviceworker/resources/cache-batch-test-worker.js b/LayoutTests/http/tests/serviceworker/resources/cache-batch-test-worker.js
new file mode 100644
index 0000000000000000000000000000000000000000..351f21dbb9525f657b9dc893d17864b1c228c5df
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/resources/cache-batch-test-worker.js
@@ -0,0 +1,78 @@
+importScripts('worker-test-harness.js');
+
+promise_test(function(t) {
+ var batch_operations = [{
+ type: 'put',
+ request: new Request('http://example.com/foo', {method: 'GET'}),
+ response: new Response('Hello, world!', {
+ status: 200,
+ statusText: 'OK',
+ headers: [['Content-Type', 'text/plain']]
+ })
+ }];
+ return new Cache().batch(batch_operations)
+ .then(t.step_func(function(results) {
+ assert_true(Array.isArray(results),
+ 'Cache.batch should return an Array');
+ assert_array_equals(results,
+ [batch_operations[0].response],
+ 'Cache.batch should resolve with an array ' +
+ 'of responses');
+ }));
+ }, 'Cache.batch put with a single request');
+
+promise_test(function(t) {
+ var batch_operations = [{
+ type: 'put',
+ request: new Request('http://example.com/foo', {method: 'HEAD'}),
+ response: new Response('Hello, world!', {
+ status: 200,
+ statusText: 'OK',
+ headers: [['Content-Type', 'text/plain']]
+ })
+ }];
+ return new Cache().batch(batch_operations)
+ .then(t.unreached_func('Cache.batch should not accept non-GET requests.'))
+ .catch(t.step_func(function(e) {
+ assert_true(e instanceof TypeError,
jsbell 2014/08/01 00:02:25 There's a repeated pattern here: <operation> .the
asanka 2014/08/13 03:30:04 I added a convenience method for the .catch(...<ch
+ 'Cache.batch should throw a TypeError for non-GET ' +
+ 'requests');
+ }));
+ }, 'Cache.batch put with a non-GET request');
+
+promise_test(function(t) {
+ var batch_operations = [{
+ type: 'put',
+ request: new Request('http://example.com/foo', {method: 'GET'})
+ }];
+ return new Cache().batch(batch_operations)
+ .then(t.unreached_func('Cache.batch put should not accept an empty ' +
+ 'response.'))
+ .catch(t.step_func(function(e) {
+ assert_true(e instanceof TypeError,
+ 'Cache.batch put should throw a TypeError for ' +
+ 'an empty response');
+ }));
+ }, 'Cache.batch put with an empty response');
+
+promise_test(function(t) {
+ var batch_operations = [{
+ type: 'put',
+ request: new Request('http://example.com/foo', {method: 'HEAD'}),
+ response: new Response('Hello, world!', {
+ status: 200,
+ statusText: 'OK',
+ headers: [['Content-Type', 'text/plain']]
+ }),
+ matchParams: {}
+ }];
+ return new Cache().batch(batch_operations)
+ .then(t.unreached_func('Cache.batch put should not accept a ' +
+ 'non-null matchParams.'))
+ .catch(t.step_func(function(e) {
+ assert_true(e instanceof TypeError,
+ 'Cache.batch put should throw a TypeError for ' +
+ 'a non-null matchParams');
+ }));
+ }, 'Cache.batch put with a non-null matchParams');
+

Powered by Google App Engine
This is Rietveld 408576698