test_chrome_constructor.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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>Validate Interfaces Exposed to Workers</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. SimpleTest.waitForExplicitFinish();
  13. SpecialPowers.pushPrefEnv({
  14. "set": [["dom.caches.enabled", true],
  15. ["dom.caches.testing.enabled", true]],
  16. }, function() {
  17. // attach to a different origin's CacheStorage
  18. var url = 'http://example.com/';
  19. var storage = SpecialPowers.createChromeCache('content', url);
  20. // verify we can use the other origin's CacheStorage as normal
  21. var req = new Request('http://example.com/index.html');
  22. var res = new Response('hello world');
  23. var cache;
  24. storage.open('foo').then(function(c) {
  25. cache = c;
  26. ok(cache, 'storage should create cache');
  27. return cache.put(req, res.clone());
  28. }).then(function() {
  29. return cache.match(req);
  30. }).then(function(foundResponse) {
  31. return Promise.all([res.text(), foundResponse.text()]);
  32. }).then(function(results) {
  33. is(results[0], results[1], 'cache should contain response');
  34. return storage.delete('foo');
  35. }).then(function(deleted) {
  36. ok(deleted, 'storage should delete cache');
  37. SimpleTest.finish();
  38. });
  39. });
  40. </script>
  41. </body>
  42. </html>