test_location.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. <!--
  8. Tests of DOM Worker Location
  9. -->
  10. <head>
  11. <title>Test for DOM Worker Location</title>
  12. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  13. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  14. </head>
  15. <body>
  16. <p id="display"></p>
  17. <div id="content" style="display: none">
  18. </div>
  19. <pre id="test">
  20. <script class="testbody" language="javascript">
  21. var thisFilename = "test_location.html";
  22. var workerFilename = "location_worker.js";
  23. var href = window.location.href
  24. var queryPos = href.lastIndexOf(window.location.search);
  25. var baseHref = href.substr(0, href.substr(0, queryPos).lastIndexOf("/") + 1);
  26. var path = window.location.pathname;
  27. var basePath = path.substr(0, path.lastIndexOf("/") + 1);
  28. var strings = {
  29. "toString": baseHref + workerFilename,
  30. "href": baseHref + workerFilename,
  31. "protocol": window.location.protocol,
  32. "host": window.location.host,
  33. "hostname": window.location.hostname,
  34. "port": window.location.port,
  35. "pathname": basePath + workerFilename,
  36. "search": "",
  37. "hash": "",
  38. "origin": "http://mochi.test:8888"
  39. };
  40. var lastSlash = href.substr(0, queryPos).lastIndexOf("/") + 1;
  41. is(thisFilename,
  42. href.substr(lastSlash, queryPos - lastSlash),
  43. "Correct filename ");
  44. var worker = new Worker(workerFilename);
  45. worker.onmessage = function(event) {
  46. if (event.data.string == "testfinished") {
  47. SimpleTest.finish();
  48. return;
  49. }
  50. ok(event.data.string in strings, event.data.string);
  51. is(event.data.value, strings[event.data.string], event.data.string);
  52. };
  53. worker.onerror = function(event) {
  54. ok(false, "Worker had an error: " + event.message);
  55. SimpleTest.finish();
  56. }
  57. SimpleTest.waitForExplicitFinish();
  58. </script>
  59. </pre>
  60. </body>
  61. </html>