From 43c73c2bcfacc6e95b3ae74eea75c87bbdfda621 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 11 Mar 2015 19:45:30 -0400 Subject: [PATCH] Bug 1142333 - Add a test for passing Request objects to DOM cache match methods; r=bkelly --- dom/cache/test/mochitest/mochitest.ini | 2 + .../mochitest/test_cache_match_request.html | 20 ++++++ .../mochitest/test_cache_match_request.js | 62 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 dom/cache/test/mochitest/test_cache_match_request.html create mode 100644 dom/cache/test/mochitest/test_cache_match_request.js diff --git a/dom/cache/test/mochitest/mochitest.ini b/dom/cache/test/mochitest/mochitest.ini index 5bb71a8372a5..4e2e9c75e21d 100644 --- a/dom/cache/test/mochitest/mochitest.ini +++ b/dom/cache/test/mochitest/mochitest.ini @@ -8,6 +8,8 @@ support-files = message_receiver.html driver.js serviceworker_driver.js + test_cache_match_request.js [test_cache.html] [test_cache_add.html] +[test_cache_match_request.html] diff --git a/dom/cache/test/mochitest/test_cache_match_request.html b/dom/cache/test/mochitest/test_cache_match_request.html new file mode 100644 index 000000000000..9696c164de68 --- /dev/null +++ b/dom/cache/test/mochitest/test_cache_match_request.html @@ -0,0 +1,20 @@ + + + + + Validate calling match with a Request object + + + + + + + + + diff --git a/dom/cache/test/mochitest/test_cache_match_request.js b/dom/cache/test/mochitest/test_cache_match_request.js new file mode 100644 index 000000000000..d2ff6f648c9a --- /dev/null +++ b/dom/cache/test/mochitest/test_cache_match_request.js @@ -0,0 +1,62 @@ +var request = new Request("//mochi.test:8888/"); +var response; +var c; +var responseText; + +function checkResponse(r) { + ok(r !== response, "The objects should not be the same"); + is(r.url, response.url, "The URLs should be the same"); + is(r.status, response.status, "The status codes should be the same"); + is(r.type, response.type, "The response types should be the same"); + is(r.ok, response.ok, "Both responses should have succeeded"); + is(r.statusText, response.statusText, + "Both responses should have the same status text"); + return r.text().then(function(text) { + is(text, responseText, "The response body should be correct"); + }); +} + +fetch(new Request(request)).then(function(r) { + response = r; + return response.text(); +}).then(function(text) { + responseText = text; + return caches.open("match-request"); +}).then(function(cache) { + c = cache; + return c.add(request); +}).then(function() { + return c.match(request); +}).then(function(r) { + return checkResponse(r); +}).then(function() { + return caches.match(request); +}).then(function(r) { + return checkResponse(r); +}).then(function() { + return caches.match(request, {cacheName: "match-request"}); +}).then(function(r) { + return checkResponse(r); +}).then(function() { + return caches.match(request, {cacheName: "foobar"}); +}).catch(function(err) { + is(err.name, "NotFoundError", "Searching in the wrong cache should not succeed"); +}).then(function() { + return caches.delete("match-request"); +}).then(function(success) { + ok(success, "We should be able to delete the cache successfully"); + // Make sure that the cache is still usable after deletion. + return c.match(request); +}).then(function(r) { + return checkResponse(r); +}).then(function() { + // Now, drop the cache, reopen and verify that we can't find the request any more. + c = null; + return caches.open("match-request"); +}).then(function(cache) { + return cache.match(request); +}).catch(function(err) { + is(err.name, "NotFoundError", "Searching in the cache after deletion should not succeed"); +}).then(function() { + testDone(); +});