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

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

Issue 425413002: [ServiceWorker] Tests for Cache (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: CacheStorage.{create => open} Created 6 years, 2 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-worker.js
diff --git a/LayoutTests/http/tests/serviceworker/resources/cache-put-worker.js b/LayoutTests/http/tests/serviceworker/resources/cache-put-worker.js
new file mode 100644
index 0000000000000000000000000000000000000000..73639f126615859cff6798c07f8cd84e4d4d55bf
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/resources/cache-put-worker.js
@@ -0,0 +1,126 @@
+importScripts('worker-testharness.js');
+importScripts('/resources/testharness-helpers.js');
+
+var test_request = new Request('http://example.com/foo', {method: 'GET'});
+
+var test_response = new Response('Hello, world!', {
+ status: 200,
+ statusText: 'OK',
+ headers: [['Content-Type', 'text/plain']]
+ });
+
+var alternate_test_response = new Response('Goodbye, world!', {
+ status: 200,
+ statusText: 'OK',
+ headers: [['Content-Type', 'text/plain']]
+ });
+
+promise_test(function(t) {
+ return create_temporary_cache(t)
jsbell 2014/10/20 18:20:41 Consider adding a helper: cache_test(function(t, c
asanka 2014/10/22 22:35:32 Good suggestion. Done.
+ .then(function(cache) {
+ return cache.put(test_request, test_response)
+ .then(function(result) {
+ assert_object_equals(result,
+ test_response,
+ 'Cache.put should resolve with the ' +
+ 'Response object.');
+ })
+ .then(function() {
+ return cache.match(test_request);
+ })
+ .then(function(result) {
+ assert_object_equals(result, test_response,
+ 'Cache.put should update the cache with ' +
+ 'specified request.');
+ });
+ });
+ }, 'Cache.put with a valid request');
+
+promise_test(function(t) {
+ return create_temporary_cache(t)
+ .then(function(cache) {
+ return cache.put(test_request, test_response)
+ .then(function() {
+ return cache.put(test_request, alternate_test_response);
+ })
+ .then(function(result) {
+ assert_object_equals(result,
+ alternate_test_response,
+ 'Cache.put should replace existing ' +
+ 'response with new response.');
+ })
+ .then(function() {
+ return cache.match(test_request);
+ })
+ .then(function(result) {
+ assert_object_equals(result, alternate_test_response,
+ 'Cache.put should replace existing ' +
+ 'response with new response.');
+ });
+ });
+ }, 'Cache.put with an existing request');
+
+promise_test(function(t) {
+ return create_temporary_cache(t)
+ .then(function(cache) {
+ return cache.put('http://example.com/cow-goes-moo', test_response);
+ })
+ .then(function(result) {
+ assert_object_equals(result, test_response,
+ 'Cache.put should accept a ScalarValueString ' +
+ 'as the request.');
+ });
+ }, 'Cache.put with a request string');
+
+promise_test(function(t) {
+ return create_temporary_cache(t)
+ .then(function(cache) {
+ return cache.put('invalid-scheme://should-accept', test_response);
+ })
+ .then(function(result) {
+ assert_object_equals(result, test_response,
+ 'Cache.put should accept a ScalarValueString ' +
+ 'as the request.');
+ });
+ }, 'Cache.put with a request string');
+
+promise_test(function(t) {
+ return create_temporary_cache(t)
+ .then(function(cache) {
+ return cache.put('relative-url', test_response)
+ .then(function(result) {
+ assert_object_equals(result, test_response,
+ 'Cache.put should accept a relative URL ' +
+ 'as the request.');
+ })
+ .then(function() {
+ return cache.match(new URL('relative-url', location.href).href);
+ })
+ .then(function(result) {
+ assert_object_equals(result, test_response,
+ 'Cache.put should accept a relative URL ' +
+ 'as the request.');
+ });
+ });
+ }, 'Cache.put with a relative URL');
+
+promise_test(function(t) {
+ var request = new Request('http://example.com/foo', {method: 'HEAD'});
+ return create_temporary_cache(t)
+ .then(function(cache) {
+ return assert_promise_rejects(
+ cache.put(request, test_response),
+ new TypeError(),
+ 'Cache.put should throw a TypeError for non-GET requests.');
+ });
+ }, 'Cache.put with a non-GET request');
+
+promise_test(function(t) {
+ return create_temporary_cache(t)
+ .then(function(cache) {
+ return assert_promise_rejects(
+ cache.put(test_request, null),
+ new 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