test_serviceworker.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <!--
  2. Any copyright is dedicated to the Public Domain.
  3. http://creativecommons.org/publicdomain/zero/1.0/
  4. -->
  5. <!DOCTYPE HTML>
  6. <html>
  7. <head>
  8. <title>Bug 1137245 - Allow IndexedDB usage in ServiceWorkers</title>
  9. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  11. </head>
  12. <body>
  13. <p id="display"></p>
  14. <div id="content" style="display: none"></div>
  15. <pre id="test"></pre>
  16. <script class="testbody" type="text/javascript">
  17. var regisration;
  18. function simpleRegister() {
  19. return navigator.serviceWorker.register("service_worker.js", {
  20. scope: 'service_worker_client.html'
  21. });
  22. }
  23. function unregister() {
  24. return registration.unregister();
  25. }
  26. function testIndexedDBAvailable(sw) {
  27. registration = sw;
  28. var p = new Promise(function(resolve, reject) {
  29. window.onmessage = function(e) {
  30. if (e.data === "READY") {
  31. sw.active.postMessage("GO");
  32. return;
  33. }
  34. if (!("available" in e.data)) {
  35. ok(false, "Something went wrong");
  36. reject();
  37. return;
  38. }
  39. ok(e.data.available, "IndexedDB available in service worker.");
  40. resolve();
  41. }
  42. });
  43. var content = document.getElementById("content");
  44. ok(content, "Parent exists.");
  45. iframe = document.createElement("iframe");
  46. iframe.setAttribute('src', "service_worker_client.html");
  47. content.appendChild(iframe);
  48. return p.then(() => content.removeChild(iframe));
  49. }
  50. function runTest() {
  51. simpleRegister()
  52. .then(testIndexedDBAvailable)
  53. .then(unregister)
  54. .then(SimpleTest.finish)
  55. .catch(function(e) {
  56. ok(false, "Some test failed with error " + e);
  57. SimpleTest.finish();
  58. });
  59. }
  60. SimpleTest.waitForExplicitFinish();
  61. SpecialPowers.pushPrefEnv({"set": [
  62. ["dom.serviceWorkers.enabled", true],
  63. ["dom.serviceWorkers.testing.enabled", true]
  64. ]}, runTest);
  65. </script>
  66. </pre>
  67. </body>
  68. </html>