From a0dffad2f886867982beb8dacac9a6f4920eedb9 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Thu, 4 Feb 2016 07:59:52 -0800 Subject: [PATCH] Bug 1244764 P2 Make dom/cache mochitests pass with new add()/addAll() behavior. r=ehsan --- dom/cache/test/mochitest/app/sw.js | 5 +++-- dom/cache/test/mochitest/test_cache_add.js | 4 ++-- dom/cache/test/mochitest/test_cache_https.js | 12 ++++++++++-- .../test/mochitest/test_cache_orphaned_body.html | 2 +- .../test/mochitest/test_cache_orphaned_cache.html | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/dom/cache/test/mochitest/app/sw.js b/dom/cache/test/mochitest/app/sw.js index d6970fd89528..f5219b068a01 100644 --- a/dom/cache/test/mochitest/app/sw.js +++ b/dom/cache/test/mochitest/app/sw.js @@ -1,13 +1,14 @@ +var url = 'index.html'; self.addEventListener('message', (message) => { caches.open('acache').then((cache) => { if(message.data == 'write') { - cache.add('aurl').then(() => { + cache.add(url).then(() => { message.source.postMessage({ type: 'written' }); }); } else if (message.data == 'read') { - cache.match('aurl').then((result) => { + cache.match(url).then((result) => { message.source.postMessage({ type: 'done', cached: !!result diff --git a/dom/cache/test/mochitest/test_cache_add.js b/dom/cache/test/mochitest/test_cache_add.js index cee4ebd817db..0719f1a10aa7 100644 --- a/dom/cache/test/mochitest/test_cache_add.js +++ b/dom/cache/test/mochitest/test_cache_add.js @@ -1,7 +1,7 @@ var singleUrl = './test_cache_add.js'; var urlList = [ - './helloworld.txt', - './foobar.txt', + './empty.html', + './frame.html', './test_cache.js' ]; var cache; diff --git a/dom/cache/test/mochitest/test_cache_https.js b/dom/cache/test/mochitest/test_cache_https.js index 1c1cfffebd2b..b12b6d4f3a0b 100644 --- a/dom/cache/test/mochitest/test_cache_https.js +++ b/dom/cache/test/mochitest/test_cache_https.js @@ -4,10 +4,18 @@ var urlBase = 'https://example.com/tests/dom/cache/test/mochitest'; var url1 = urlBase + '/test_cache.js'; var url2 = urlBase + '/test_cache_add.js'; +function addOpaque(cache, url) { + return fetch(new Request(url, { mode: 'no-cors' })).then(function(response) { + return cache.put(url, response); + }); +} + caches.open(name).then(function(c) { cache = c; - return cache.addAll([new Request(url1, { mode: 'no-cors' }), - new Request(url2, { mode: 'no-cors' })]); + return Promise.all([ + addOpaque(cache, url1), + addOpaque(cache, url2) + ]); }).then(function() { return cache.delete(url1); }).then(function(result) { diff --git a/dom/cache/test/mochitest/test_cache_orphaned_body.html b/dom/cache/test/mochitest/test_cache_orphaned_body.html index f00357dc6858..1652b74ba8f2 100644 --- a/dom/cache/test/mochitest/test_cache_orphaned_body.html +++ b/dom/cache/test/mochitest/test_cache_orphaned_body.html @@ -71,7 +71,7 @@ SpecialPowers.pushPrefEnv({ var fullUsage = 0; var resetUsage = 0; var endUsage = 0; - var url = 'cache_add.js'; + var url = 'test_cache_add.js'; // start from a fresh origin directory so other tests do not influence our // results diff --git a/dom/cache/test/mochitest/test_cache_orphaned_cache.html b/dom/cache/test/mochitest/test_cache_orphaned_cache.html index 385f3cd923d9..2cad1a94069c 100644 --- a/dom/cache/test/mochitest/test_cache_orphaned_cache.html +++ b/dom/cache/test/mochitest/test_cache_orphaned_cache.html @@ -70,7 +70,7 @@ SpecialPowers.pushPrefEnv({ var fullUsage = 0; var resetUsage = 0; var endUsage = 0; - var url = 'cache_add.js'; + var url = 'test_cache_add.js'; // start from a fresh origin directory so other tests do not influence our // results