Bug 1301094 - Part 3: Test for Blob+XHR+FormData+Workers. r=smaug, a=ritu
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 12 Sep 2016 12:19:01 +0200
changeset 348198 0a758b4f6289f29b5bda37c4e52873242e9cf669
parent 348197 a3d30b90a3fb710034d459d8e8b101f77cb1e7b5
child 348199 1fa0170cde4115a43d7f0c1fc7c4110071a54936
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, ritu
bugs1301094
milestone50.0a2
Bug 1301094 - Part 3: Test for Blob+XHR+FormData+Workers. r=smaug, a=ritu
dom/workers/test/mochitest.ini
dom/workers/test/script_bug1301094.js
dom/workers/test/test_bug1301094.html
dom/workers/test/worker_bug1301094.js
--- a/dom/workers/test/mochitest.ini
+++ b/dom/workers/test/mochitest.ini
@@ -100,16 +100,18 @@ support-files =
   sharedWorker_lifetime.js
   worker_referrer.js
   websocket_https.html
   websocket_https_worker.js
   worker_fileReader.js
   fileapi_chromeScript.js
   importScripts_3rdParty_worker.js
   worker_bug1278777.js
+  worker_bug1301094.js
+  script_bug1301094.js
   !/dom/base/test/file_websocket_basic_wsh.py
   !/dom/base/test/file_websocket_hello_wsh.py
   !/dom/base/test/file_websocket_http_resource.txt
   !/dom/base/test/file_websocket_permessage_deflate_disabled_wsh.py
   !/dom/base/test/file_websocket_permessage_deflate_params_wsh.py
   !/dom/base/test/file_websocket_permessage_deflate_rejected_wsh.py
   !/dom/base/test/file_websocket_permessage_deflate_wsh.py
   !/dom/base/test/file_websocket_wsh.py
@@ -225,8 +227,9 @@ skip-if = buildapp == 'b2g' || toolkit =
 [test_referrer.html]
 [test_referrer_header_worker.html]
 [test_importScripts_3rdparty.html]
 [test_sharedWorker_ports.html]
 [test_sharedWorker_lifetime.html]
 [test_fileReader.html]
 [test_navigator_workers_hardwareConcurrency.html]
 [test_bug1278777.html]
+[test_bug1301094.html]
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/script_bug1301094.js
@@ -0,0 +1,15 @@
+var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+Cu.importGlobalProperties(["File", "Directory"]);
+
+addMessageListener("file.open", function (e) {
+  var tmpFile = Cc["@mozilla.org/file/directory_service;1"]
+                  .getService(Ci.nsIDirectoryService)
+                  .QueryInterface(Ci.nsIProperties)
+                  .get('TmpD', Ci.nsIFile)
+  tmpFile.append('file.txt');
+  tmpFile.createUnique(Components.interfaces.nsIFile.FILE_TYPE, 0o600);
+
+  sendAsyncMessage("file.opened", {
+    data: new File(tmpFile)
+  });
+});
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/test_bug1301094.html
@@ -0,0 +1,69 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1301094
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1301094</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1301094">Mozilla Bug 1301094</a>
+  <input id="file" type="file"></input>
+  <script type="application/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+var url = SimpleTest.getTestFileURL("script_bug1301094.js");
+script = SpecialPowers.loadChromeScript(url);
+
+var mainThreadOk, workerOk;
+
+function maybeFinish() {
+  if (mainThreadOk & workerOk) {
+    SimpleTest.finish();
+  }
+}
+
+function onOpened(message) {
+  var input = document.getElementById('file');
+  SpecialPowers.wrap(input).mozSetDndFilesAndDirectories([message.data]);
+
+  var worker = new Worker('worker_bug1301094.js');
+  worker.onerror = function() {
+    ok(false, "We should not see any error.");
+    SimpleTest.finish();
+  }
+
+  worker.onmessage = function(e) {
+    ok(e.data, "Everything seems OK on the worker-side.");
+
+    workerOk = true;
+    maybeFinish();
+  }
+
+  is(input.files.length, 1, "We have something");
+  ok(input.files[0] instanceof Blob, "We have one Blob");
+  worker.postMessage(input.files[0]);
+
+  var xhr = new XMLHttpRequest();
+  xhr.open("POST", 'worker_bug1301094.js', false);
+  xhr.onload = function() {
+    ok(xhr.responseText, "Everything seems OK on the main-thread-side.");
+    mainThreadOk = true;
+    maybeFinish();
+  };
+
+  var fd = new FormData();
+  fd.append('file', input.files[0]);
+  xhr.send(fd);
+}
+
+script.addMessageListener("file.opened", onOpened);
+script.sendAsyncMessage("file.open");
+
+  </script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/worker_bug1301094.js
@@ -0,0 +1,11 @@
+onmessage = function(e) {
+  var xhr = new XMLHttpRequest();
+  xhr.open("POST", 'worker_bug1301094.js', false);
+  xhr.onload = function() {
+    self.postMessage("OK");
+  };
+
+  var fd = new FormData();
+  fd.append('file', e.data);
+  xhr.send(fd);
+}