bug1014466_worker.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/
  4. */
  5. function ok(a, msg) {
  6. postMessage({type: "status", status: !!a, msg: msg });
  7. }
  8. onmessage = function(event) {
  9. function getResponse(url) {
  10. var xhr = new XMLHttpRequest();
  11. xhr.open("GET", url, false);
  12. xhr.send();
  13. return xhr.responseText;
  14. }
  15. const testFile1 = "bug1014466_data1.txt";
  16. const testFile2 = "bug1014466_data2.txt";
  17. const testData1 = getResponse(testFile1);
  18. const testData2 = getResponse(testFile2);
  19. var response_count = 0;
  20. var xhr = new XMLHttpRequest();
  21. xhr.onreadystatechange = function() {
  22. if (xhr.readyState == xhr.DONE && xhr.status == 200) {
  23. response_count++;
  24. switch (response_count) {
  25. case 1:
  26. ok(xhr.responseText == testData1, "Check data 1");
  27. test_data2();
  28. break;
  29. case 2:
  30. ok(xhr.responseText == testData2, "Check data 2");
  31. postMessage({type: "finish" });
  32. break;
  33. default:
  34. ok(false, "Unexpected response received");
  35. postMessage({type: "finish" });
  36. break;
  37. }
  38. }
  39. }
  40. xhr.onerror = function(event) {
  41. ok(false, "Got an error event: " + event);
  42. postMessage({type: "finish" });
  43. }
  44. function test_data1() {
  45. xhr.open("GET", testFile1, true);
  46. xhr.responseType = "text";
  47. xhr.send();
  48. }
  49. function test_data2() {
  50. xhr.abort();
  51. xhr.open("GET", testFile2, true);
  52. xhr.responseType = "text";
  53. xhr.send();
  54. }
  55. test_data1();
  56. }