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

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: Created 6 years, 3 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..8ac71173eabaf38e66b75e090f88a281817d7c68
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/resources/cache-put-worker.js
@@ -0,0 +1,125 @@
+importScripts('worker-test-harness.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)
+ .then(function(cache) {
+ return cache.put(test_request, test_response);
+ })
+ .then(function(result) {
+ assert_equals(result,
jkarlin 2014/10/03 15:10:52 assert_equals does a === comparison which will fai
asanka 2014/10/15 23:43:49 Should be okay now.
+ test_response,
+ 'Cache.put should resolve with the response ' +
+ 'parameter.');
+ })
+ .then(function() {
+ return cache.get(test_request);
+ })
+ .then(function(result) {
+ assert_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_equals(result,
+ alternate_test_response,
+ 'Cache.put should replace existing response with ' +
+ 'new response.');
+ })
+ .then(function() {
+ return cache.get(test_request);
+ })
+ .then(function(result) {
+ assert_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_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_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_equals(result, test_response,
+ 'Cache.put should accept a relative URL as the ' +
+ 'request.');
+ })
+ .then(function() {
+ return cache.get(new URL('relative-url', location.href).href);
+ })
+ .then(function(result) {
+ assert_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