Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
michael@0 | 3 | <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?> |
michael@0 | 4 | <!-- |
michael@0 | 5 | https://bugzilla.mozilla.org/show_bug.cgi?id=123456 |
michael@0 | 6 | --> |
michael@0 | 7 | <window title="Mozilla Bug 123456" |
michael@0 | 8 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 9 | <script type="application/javascript" |
michael@0 | 10 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
michael@0 | 11 | <script type="application/javascript" src="dom_worker_helper.js"/> |
michael@0 | 12 | |
michael@0 | 13 | <!-- test results are displayed in the html:body --> |
michael@0 | 14 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 15 | <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=123456" |
michael@0 | 16 | target="_blank">Mozilla Bug 123456</a> |
michael@0 | 17 | |
michael@0 | 18 | <div id="content" style="display: none"> |
michael@0 | 19 | <input id="fileList" type="file"></input> |
michael@0 | 20 | </div> |
michael@0 | 21 | |
michael@0 | 22 | </body> |
michael@0 | 23 | |
michael@0 | 24 | <!-- test code goes here --> |
michael@0 | 25 | <script type="application/javascript"> |
michael@0 | 26 | <![CDATA[ |
michael@0 | 27 | |
michael@0 | 28 | /** Test for Bug 123456 **/ |
michael@0 | 29 | |
michael@0 | 30 | var fileNum = 0; |
michael@0 | 31 | |
michael@0 | 32 | /** |
michael@0 | 33 | * Create a file which contains the given data and optionally adds the specified file extension. |
michael@0 | 34 | */ |
michael@0 | 35 | function createFileWithData(fileData, /** optional */ extension) { |
michael@0 | 36 | var testFile = Components.classes["@mozilla.org/file/directory_service;1"] |
michael@0 | 37 | .getService(Components.interfaces.nsIProperties) |
michael@0 | 38 | .get("ProfD", Components.interfaces.nsIFile); |
michael@0 | 39 | var fileExtension = (extension == undefined) ? "" : "." + extension; |
michael@0 | 40 | testFile.append("workerFile" + fileNum++ + fileExtension); |
michael@0 | 41 | |
michael@0 | 42 | var outStream = Components.classes["@mozilla.org/network/file-output-stream;1"] |
michael@0 | 43 | .createInstance(Components.interfaces.nsIFileOutputStream); |
michael@0 | 44 | outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate |
michael@0 | 45 | 0666, 0); |
michael@0 | 46 | outStream.write(fileData, fileData.length); |
michael@0 | 47 | outStream.close(); |
michael@0 | 48 | |
michael@0 | 49 | var fileList = document.getElementById('fileList'); |
michael@0 | 50 | fileList.value = testFile.path; |
michael@0 | 51 | |
michael@0 | 52 | return fileList.files[0]; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | /** |
michael@0 | 56 | * Create a worker to access file properties. |
michael@0 | 57 | */ |
michael@0 | 58 | function accessFileProperties(file, expectedSize, expectedType) { |
michael@0 | 59 | waitForWorkerFinish(); |
michael@0 | 60 | |
michael@0 | 61 | var worker = new Worker("file_worker.js"); |
michael@0 | 62 | |
michael@0 | 63 | worker.onerror = function(event) { |
michael@0 | 64 | ok(false, "Worker had an error: " + event.data); |
michael@0 | 65 | finish(); |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | worker.onmessage = function(event) { |
michael@0 | 69 | is(event.data.size, expectedSize, "size proproperty accessed from worker is not the same as on main thread."); |
michael@0 | 70 | is(event.data.type, expectedType, "type proproperty accessed from worker is incorrect."); |
michael@0 | 71 | is(event.data.name, file.name, "name proproperty accessed from worker is incorrect."); |
michael@0 | 72 | is(event.data.path, file.path, "path proproperty accessed from worker is incorrect."); |
michael@0 | 73 | is(event.data.lastModifiedDate.toString(), file.lastModifiedDate.toString(), "lastModifiedDate proproperty accessed from worker is incorrect."); |
michael@0 | 74 | is(event.data.mozFullPath, file.mozFullPath, "mozFullPath proproperty accessed from worker is not the same as on main thread."); |
michael@0 | 75 | finish(); |
michael@0 | 76 | }; |
michael@0 | 77 | |
michael@0 | 78 | worker.postMessage(file); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | // Empty file. |
michael@0 | 82 | accessFileProperties(createFileWithData(""), 0, ""); |
michael@0 | 83 | |
michael@0 | 84 | // Typical use case. |
michael@0 | 85 | accessFileProperties(createFileWithData("Hello"), 5, ""); |
michael@0 | 86 | |
michael@0 | 87 | // Longish file. |
michael@0 | 88 | var text = ""; |
michael@0 | 89 | for (var i = 0; i < 10000; ++i) { |
michael@0 | 90 | text += "long"; |
michael@0 | 91 | } |
michael@0 | 92 | accessFileProperties(createFileWithData(text), 40000, ""); |
michael@0 | 93 | |
michael@0 | 94 | // Type detection based on extension. |
michael@0 | 95 | accessFileProperties(createFileWithData("text", "txt"), 4, "text/plain"); |
michael@0 | 96 | |
michael@0 | 97 | ]]> |
michael@0 | 98 | </script> |
michael@0 | 99 | </window> |