test_cache_restart.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <!-- Any copyright is dedicated to the Public Domain.
  2. - http://creativecommons.org/publicdomain/zero/1.0/ -->
  3. <!DOCTYPE HTML>
  4. <html>
  5. <head>
  6. <title>Test Cache with QuotaManager Restart</title>
  7. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  8. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  9. </head>
  10. <body>
  11. <script class="testbody" type="text/javascript">
  12. function setupTestIframe() {
  13. return new Promise(function(resolve) {
  14. var iframe = document.createElement("iframe");
  15. iframe.src = "empty.html";
  16. iframe.onload = function() {
  17. window.caches = iframe.contentWindow.caches;
  18. resolve();
  19. };
  20. document.body.appendChild(iframe);
  21. });
  22. }
  23. function resetStorage() {
  24. return new Promise(function(resolve, reject) {
  25. var qms = SpecialPowers.Services.qms;
  26. var request = qms.reset();
  27. var cb = SpecialPowers.wrapCallback(resolve);
  28. request.callback = cb;
  29. });
  30. }
  31. SimpleTest.waitForExplicitFinish();
  32. SpecialPowers.pushPrefEnv({
  33. "set": [["dom.caches.enabled", true],
  34. ["dom.caches.testing.enabled", true],
  35. ["dom.quotaManager.testing", true]],
  36. }, function() {
  37. var name = 'foo';
  38. var url = './test_cache_add.js';
  39. var cache;
  40. setupTestIframe().then(function() {
  41. return caches.open(name);
  42. }).then(function(c) {
  43. cache = c;
  44. return cache.add(url);
  45. }).then(function() {
  46. return resetStorage();
  47. }).then(function() {
  48. return cache.match(url).then(function(resp) {
  49. ok(false, 'old cache reference should not work after reset');
  50. }).catch(function(err) {
  51. ok(true, 'old cache reference should not work after reset');
  52. });
  53. }).then(function() {
  54. return caches.open(name);
  55. }).then(function(c) {
  56. cache = c;
  57. return cache.match(url);
  58. }).then(function(resp) {
  59. ok(!!resp, 'cache should work after QM reset');
  60. return caches.delete(name);
  61. }).then(function(success) {
  62. ok(success, 'cache should be deleted');
  63. SimpleTest.finish();
  64. });
  65. });
  66. </script>
  67. </body>
  68. </html>