test_worker_xhr_parameters.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Test for XMLHttpRequest with system privileges</title>
  6. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  7. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  8. </head>
  9. <body>
  10. <p id="display">
  11. </p>
  12. <div id="content" style="display: none">
  13. </div>
  14. <pre id="test">
  15. <script class="testbody" type="application/javascript;version=1.8">
  16. function message(event) {
  17. if (event.data.test == 'ok')
  18. ok(event.data.a, event.data.event);
  19. else if(event.data.test == 'is')
  20. is(event.data.a, event.data.b, event.data.event);
  21. else if(event.data.test == 'finish') {
  22. run();
  23. }
  24. };
  25. function test1() {
  26. var worker = new Worker("test_worker_xhr_parameters.js");
  27. worker.onmessage = message;
  28. // Run the tests once without API privileges...
  29. worker.postMessage(false);
  30. }
  31. function test2() {
  32. // ...and once with privileges.
  33. SpecialPowers.pushPermissions([{type: "systemXHR", allow: true, context: document}],
  34. function () {
  35. var worker = new Worker("test_worker_xhr_parameters.js");
  36. worker.onmessage = message;
  37. worker.postMessage(true);
  38. }
  39. );
  40. }
  41. var tests = [ test1, test2 ];
  42. function run() {
  43. if (!tests.length) {
  44. SimpleTest.finish();
  45. return;
  46. }
  47. var func = tests.shift();
  48. func();
  49. }
  50. SimpleTest.waitForExplicitFinish();
  51. run();
  52. </script>
  53. </pre>
  54. </body>
  55. </html>