test_fileReaderSyncErrors.xul 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?xml version="1.0"?>
  2. <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
  3. <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
  4. <!--
  5. https://bugzilla.mozilla.org/show_bug.cgi?id=664783
  6. -->
  7. <window title="Mozilla Bug 664783"
  8. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  9. <script type="application/javascript"
  10. src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  11. <script type="application/javascript" src="dom_worker_helper.js"/>
  12. <!-- test results are displayed in the html:body -->
  13. <body xmlns="http://www.w3.org/1999/xhtml">
  14. <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=664783"
  15. target="_blank">Mozilla Bug 664783</a>
  16. <div id="content" style="display: none">
  17. <input id="fileList" type="file"></input>
  18. </div>
  19. </body>
  20. <!-- test code goes here -->
  21. <script type="application/javascript">
  22. <![CDATA[
  23. /** Test for Bug 664783 **/
  24. var fileNum = 0;
  25. /**
  26. * Create a file which contains the given data.
  27. */
  28. function createFileWithData(fileData) {
  29. var testFile = Components.classes["@mozilla.org/file/directory_service;1"]
  30. .getService(Components.interfaces.nsIProperties)
  31. .get("ProfD", Components.interfaces.nsIFile);
  32. testFile.append("workerFileReaderSyncErrors" + fileNum++);
  33. var outStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
  34. .createInstance(Components.interfaces.nsIFileOutputStream);
  35. outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
  36. 0666, 0);
  37. outStream.write(fileData, fileData.length);
  38. outStream.close();
  39. var fileList = document.getElementById('fileList');
  40. fileList.value = testFile.path;
  41. return fileList.files[0];
  42. }
  43. /**
  44. * Creates a worker which runs errors cases.
  45. */
  46. function runWorkerErrors(file) {
  47. var worker = new Worker("fileReaderSyncErrors_worker.js");
  48. worker.onerror = function(event) {
  49. ok(false, "Worker had an error: " + event.message);
  50. finish();
  51. };
  52. worker.onmessage = function(event) {
  53. if(event.data == undefined) {
  54. // Worker returns undefined when tests have finished running.
  55. finish();
  56. } else {
  57. // Otherwise worker will return results of tests to be evaluated.
  58. is(event.data.actual, event.data.expected, event.data.message);
  59. }
  60. };
  61. worker.postMessage(file);
  62. waitForWorkerFinish();
  63. }
  64. // Run worker which creates exceptions.
  65. runWorkerErrors(createFileWithData("text"));
  66. ]]>
  67. </script>
  68. </window>