Bug 1146612 - Add a test to ensure that Cache.put() with an existing request will reorder it in the DB; r=bkelly
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 23 Mar 2015 17:46:56 -0400
changeset 264196 8370190f31b27a2003d337d6c55ac21457764536
parent 264195 7386c130fb784279ee3e4805caa08a97d7e7058e
child 264197 5c2cd6a6cb35ab0a76af96c49ddf0e0b64486e61
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1146612
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1146612 - Add a test to ensure that Cache.put() with an existing request will reorder it in the DB; r=bkelly
dom/cache/test/mochitest/mochitest.ini
dom/cache/test/mochitest/test_cache_put_reorder.html
dom/cache/test/mochitest/test_cache_put_reorder.js
--- a/dom/cache/test/mochitest/mochitest.ini
+++ b/dom/cache/test/mochitest/mochitest.ini
@@ -14,20 +14,22 @@ support-files =
   mirror.sjs
   test_cache_match_vary.js
   vary.sjs
   test_caches.js
   test_cache_keys.js
   test_cache_put.js
   test_cache_requestCache.js
   test_cache_delete.js
+  test_cache_put_reorder.js
 
 [test_cache.html]
 [test_cache_add.html]
 [test_cache_match_request.html]
 [test_cache_matchAll_request.html]
 [test_cache_overwrite.html]
 [test_cache_match_vary.html]
 [test_caches.html]
 [test_cache_keys.html]
 [test_cache_put.html]
 [test_cache_requestCache.html]
 [test_cache_delete.html]
+[test_cache_put_reorder.html]
new file mode 100644
--- /dev/null
+++ b/dom/cache/test/mochitest/test_cache_put_reorder.html
@@ -0,0 +1,20 @@
+<!-- Any copyright is dedicated to the Public Domain.
+   - http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Ensure that using Cache.put to overwrite an entry will change its insertion order</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_put_reorder.js")
+    .then(function() {
+      SimpleTest.finish();
+    });
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/cache/test/mochitest/test_cache_put_reorder.js
@@ -0,0 +1,31 @@
+var name = "putreorder" + context;
+var c;
+
+var reqs = [
+  "//mochi.test:8888/?foo" + context,
+  "//mochi.test:8888/?bar" + context,
+  "//mochi.test:8888/?baz" + context,
+];
+
+caches.open(name).then(function(cache) {
+  c = cache;
+  return c.addAll(reqs);
+}).then(function() {
+  return c.put(reqs[1], new Response("overwritten"));
+}).then(function() {
+  return c.keys();
+}).then(function(keys) {
+  is(keys.length, 3, "Correct number of entries expected");
+  ok(keys[0].url.indexOf(reqs[0]) >= 0, "The first entry should be untouched");
+  ok(keys[2].url.indexOf(reqs[1]) >= 0, "The second entry should be moved to the end");
+  ok(keys[1].url.indexOf(reqs[2]) >= 0, "The third entry should now be the second one");
+  return c.match(reqs[1]);
+}).then(function(r) {
+  return r.text();
+}).then(function(body) {
+  is(body, "overwritten", "The body should be overwritten");
+  return caches.delete(name);
+}).then(function(deleted) {
+  ok(deleted, "The cache should be deleted successfully");
+  testDone();
+});