mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 1146585 - Add a test for Cache.delete; r=bkelly
This commit is contained in:
parent
9ae27c5155
commit
c65501f8bc
2
dom/cache/test/mochitest/mochitest.ini
vendored
2
dom/cache/test/mochitest/mochitest.ini
vendored
@ -18,6 +18,7 @@ support-files =
|
||||
test_cache_keys.js
|
||||
test_cache_put.js
|
||||
test_cache_requestCache.js
|
||||
test_cache_delete.js
|
||||
|
||||
[test_cache.html]
|
||||
[test_cache_add.html]
|
||||
@ -29,3 +30,4 @@ support-files =
|
||||
[test_cache_keys.html]
|
||||
[test_cache_put.html]
|
||||
[test_cache_requestCache.html]
|
||||
[test_cache_delete.html]
|
||||
|
20
dom/cache/test/mochitest/test_cache_delete.html
vendored
Normal file
20
dom/cache/test/mochitest/test_cache_delete.html
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Validate the Cache.delete() method</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
<script type="text/javascript" src="driver.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<iframe id="frame"></iframe>
|
||||
<script class="testbody" type="text/javascript">
|
||||
runTests("test_cache_delete.js")
|
||||
.then(function() {
|
||||
SimpleTest.finish();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
111
dom/cache/test/mochitest/test_cache_delete.js
vendored
Normal file
111
dom/cache/test/mochitest/test_cache_delete.js
vendored
Normal file
@ -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();
|
||||
});
|
Loading…
Reference in New Issue
Block a user