Bug 1421176 - nsMultiplexInputStream::Available() sanitize - mochitest. r=smaug, a=gchang
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 30 Nov 2017 20:00:23 +0100
changeset 445232 019a43b61a5b2f48824f8e795a4c39659b1ef43b
parent 445231 e76ff14f1538e77ee2a7569e1eab3a16924feab4
child 445233 0509c78748016f4e861affa165e4f510e540c692
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, gchang
bugs1421176
milestone58.0
Bug 1421176 - nsMultiplexInputStream::Available() sanitize - mochitest. r=smaug, a=gchang This is a test to check if nsMultiplexInputStream supports empty inputStreams.
dom/file/ipc/tests/mochitest.ini
dom/file/ipc/tests/script_file.js
dom/file/ipc/tests/test_ipcBlob_emptyMultiplex.html
--- a/dom/file/ipc/tests/mochitest.ini
+++ b/dom/file/ipc/tests/mochitest.ini
@@ -1,6 +1,6 @@
 [DEFAULT]
-support-files =
-  script_file.js
+support-files = script_file.js
 
 [test_ipcBlob_fileReaderSync.html]
 [test_ipcBlob_workers.html]
+[test_ipcBlob_emptyMultiplex.html]
--- a/dom/file/ipc/tests/script_file.js
+++ b/dom/file/ipc/tests/script_file.js
@@ -2,23 +2,41 @@ var { classes: Cc, interfaces: Ci, utils
 Cu.importGlobalProperties(["File"]);
 
 addMessageListener("file.open", function (e) {
   var testFile = Cc["@mozilla.org/file/directory_service;1"]
                    .getService(Ci.nsIDirectoryService)
                    .QueryInterface(Ci.nsIProperties)
                    .get("ProfD", Ci.nsIFile);
   testFile.append("ipc_fileReader_testing");
-  testFile.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0o600);
+  testFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0o600);
 
   var outStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
                       .createInstance(Components.interfaces.nsIFileOutputStream);
   outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
                  0666, 0);
 
   var fileData = "Hello World!";
   outStream.write(fileData, fileData.length);
   outStream.close();
 
   File.createFromNsIFile(testFile).then(function(file) {
     sendAsyncMessage("file.opened", { file });
   });
 });
+
+addMessageListener("emptyfile.open", function (e) {
+  var testFile = Cc["@mozilla.org/file/directory_service;1"]
+                   .getService(Ci.nsIDirectoryService)
+                   .QueryInterface(Ci.nsIProperties)
+                   .get("ProfD", Ci.nsIFile);
+  testFile.append("ipc_fileReader_testing");
+  testFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0o600);
+
+  var outStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
+                      .createInstance(Components.interfaces.nsIFileOutputStream);
+  outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
+                 0666, 0);
+
+  File.createFromNsIFile(testFile).then(function(file) {
+    sendAsyncMessage("emptyfile.opened", { file });
+  });
+});
new file mode 100644
--- /dev/null
+++ b/dom/file/ipc/tests/test_ipcBlob_emptyMultiplex.html
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test an empty IPCBlob together with other parts</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<script type="text/javascript">
+
+function checkContent(msg, content) {
+  return new Promise(resolve => {
+    let fr = new FileReader();
+    fr.readAsText(new Blob(content));
+    fr.onloadend = () => {
+      is(fr.result, "Hello world!", "The content matches: " + msg);
+      resolve();
+    };
+  });
+}
+
+SimpleTest.waitForExplicitFinish();
+
+let url = SimpleTest.getTestFileURL("script_file.js");
+
+let script = SpecialPowers.loadChromeScript(url);
+script.addMessageListener("emptyfile.opened", message => {
+  checkContent("middle", ["Hello ", message.file, "world!"]).
+  then(() => checkContent("begin", [message.file, "Hello world!"])).
+  then(() => checkContent("end", ["Hello world!", message.file])).
+  then(() => checkContent("random", [message.file, message.file, "Hello world!", message.file])).
+  then(SimpleTest.finish);
+});
+
+script.sendAsyncMessage("emptyfile.open");
+
+</script>
+</pre>
+</body>
+</html>