diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/cache/test/mochitest/test_cache_delete.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/cache/test/mochitest/test_cache_delete.js')
-rw-r--r-- | dom/cache/test/mochitest/test_cache_delete.js | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/dom/cache/test/mochitest/test_cache_delete.js b/dom/cache/test/mochitest/test_cache_delete.js new file mode 100644 index 000000000..aa7bc94eb --- /dev/null +++ b/dom/cache/test/mochitest/test_cache_delete.js @@ -0,0 +1,111 @@ +var name = "delete" + context; +var c; + +function setupTest(reqs) { + return new Promise(function(resolve, reject) { + var cache; + caches.open(name).then(function(c) { + cache = c; + return c.addAll(reqs); + }).then(function() { + resolve(cache); + }).catch(function(err) { + reject(err); + }); + }); +} + +function testBasics() { + var tests = [ + "//mochi.test:8888/?foo" + context, + "//mochi.test:8888/?bar" + context, + ]; + var cache; + return setupTest(tests) + .then(function(c) { + cache = c; + return cache.delete("//mochi.test:8888/?baz"); + }).then(function(deleted) { + ok(!deleted, "Deleting a non-existing entry should fail"); + return cache.keys(); + }).then(function(keys) { + is(keys.length, 2, "No entries from the cache should be deleted"); + return cache.delete(tests[0]); + }).then(function(deleted) { + ok(deleted, "Deleting an existing entry should succeed"); + return cache.keys(); + }).then(function(keys) { + is(keys.length, 1, "Only one entry should exist now"); + ok(keys[0].url.indexOf(tests[1]) >= 0, "The correct entry must be deleted"); + }); +} + +function testFragment() { + var tests = [ + "//mochi.test:8888/?foo" + context, + "//mochi.test:8888/?bar" + context, + "//mochi.test:8888/?baz" + context + "#fragment", + ]; + var cache; + return setupTest(tests) + .then(function(c) { + cache = c; + return cache.delete(tests[0] + "#fragment"); + }).then(function(deleted) { + ok(deleted, "Deleting an existing entry should succeed"); + return cache.keys(); + }).then(function(keys) { + is(keys.length, 2, "Only one entry should exist now"); + ok(keys[0].url.indexOf(tests[1]) >= 0, "The correct entry must be deleted"); + ok(keys[1].url.indexOf(tests[2].replace("#fragment", "")) >= 0, "The correct entry must be deleted"); + // Now, delete a request that was added with a fragment + return cache.delete("//mochi.test:8888/?baz" + context); + }).then(function(deleted) { + ok(deleted, "Deleting an existing entry should succeed"); + return cache.keys(); + }).then(function(keys) { + is(keys.length, 1, "Only one entry should exist now"); + ok(keys[0].url.indexOf(tests[1]) >= 0, "3The correct entry must be deleted"); + }); +} + +function testInterleaved() { + var tests = [ + "//mochi.test:8888/?foo" + context, + "//mochi.test:8888/?bar" + context, + ]; + var newURL = "//mochi.test:8888/?baz" + context; + var cache; + return setupTest(tests) + .then(function(c) { + cache = c; + // Simultaneously add and delete a request + return Promise.all([ + cache.delete(newURL), + cache.add(newURL), + ]); + }).then(function(result) { + ok(!result[1], "deletion should fail"); + return cache.keys(); + }).then(function(keys) { + is(keys.length, 3, "Tree entries should still exist"); + ok(keys[0].url.indexOf(tests[0]) >= 0, "The correct entry must be deleted"); + ok(keys[1].url.indexOf(tests[1]) >= 0, "The correct entry must be deleted"); + ok(keys[2].url.indexOf(newURL) >= 0, "The new entry should be correctly inserted"); + }); +} + +// Make sure to clean up after each test step. +function step(testPromise) { + return testPromise.then(function() { + caches.delete(name); + }); +} + +step(testBasics()).then(function() { + return step(testFragment()); +}).then(function() { + return step(testInterleaved()); +}).then(function() { + testDone(); +}); |