test_fileReader.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Test for FileReader in workers</title>
  5. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  6. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  7. </head>
  8. <body>
  9. <script type="text/javascript;version=1.7">
  10. const minFileSize = 20000;
  11. SimpleTest.waitForExplicitFinish();
  12. // Create strings containing data we'll test with. We'll want long
  13. // strings to ensure they span multiple buffers while loading
  14. var testTextData = "asd b\tlah\u1234w\u00a0r";
  15. while (testTextData.length < minFileSize) {
  16. testTextData = testTextData + testTextData;
  17. }
  18. var testASCIIData = "abcdef 123456\n";
  19. while (testASCIIData.length < minFileSize) {
  20. testASCIIData = testASCIIData + testASCIIData;
  21. }
  22. var testBinaryData = "";
  23. for (var i = 0; i < 256; i++) {
  24. testBinaryData += String.fromCharCode(i);
  25. }
  26. while (testBinaryData.length < minFileSize) {
  27. testBinaryData = testBinaryData + testBinaryData;
  28. }
  29. var dataurldata0 = testBinaryData.substr(0, testBinaryData.length -
  30. testBinaryData.length % 3);
  31. var dataurldata1 = testBinaryData.substr(0, testBinaryData.length - 2 -
  32. testBinaryData.length % 3);
  33. var dataurldata2 = testBinaryData.substr(0, testBinaryData.length - 1 -
  34. testBinaryData.length % 3);
  35. //Set up files for testing
  36. var openerURL = SimpleTest.getTestFileURL("fileapi_chromeScript.js");
  37. var opener = SpecialPowers.loadChromeScript(openerURL);
  38. opener.addMessageListener("files.opened", onFilesOpened);
  39. opener.sendAsyncMessage("files.open", [
  40. testASCIIData,
  41. testBinaryData,
  42. null,
  43. convertToUTF8(testTextData),
  44. convertToUTF16(testTextData),
  45. "",
  46. dataurldata0,
  47. dataurldata1,
  48. dataurldata2,
  49. ]);
  50. function onFilesOpened(message) {
  51. var worker = new Worker('worker_fileReader.js');
  52. worker.postMessage({ blobs: message,
  53. testTextData: testTextData,
  54. testASCIIData: testASCIIData,
  55. testBinaryData: testBinaryData,
  56. dataurldata0: dataurldata0,
  57. dataurldata1: dataurldata1,
  58. dataurldata2: dataurldata2 });
  59. worker.onmessage = function(e) {
  60. var msg = e.data;
  61. if (msg.type == 'finish') {
  62. SimpleTest.finish();
  63. return;
  64. }
  65. if (msg.type == 'check') {
  66. ok(msg.status, msg.msg);
  67. return;
  68. }
  69. ok(false, "Unknown message.");
  70. }
  71. }
  72. function convertToUTF16(s) {
  73. res = "";
  74. for (var i = 0; i < s.length; ++i) {
  75. c = s.charCodeAt(i);
  76. res += String.fromCharCode(c & 255, c >>> 8);
  77. }
  78. return res;
  79. }
  80. function convertToUTF8(s) {
  81. return unescape(encodeURIComponent(s));
  82. }
  83. </script>
  84. </body>
  85. </html>