Bug 1301094 - part 3 - Test for Blob+XHR+FormData+Workers, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 12 Sep 2016 12:19:01 +0200
changeset 354806 cdc7be84b21a4092e04f1665e5eba5b31e54b63f
parent 354805 03c0969b435fca2bda1e4c2bdc70ef10625c1fe0
child 354807 e8b53c6a566ec9f6d9abb194498044a6003c2b86
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1301094
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1301094 - part 3 - Test for Blob+XHR+FormData+Workers, r=smaug
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
@@ -98,16 +98,18 @@ support-files =
   worker_referrer.js
   websocket_https.html
   websocket_https_worker.js
   worker_fileReader.js
   fileapi_chromeScript.js
   importScripts_3rdParty_worker.js
   worker_bug1278777.js
   worker_setTimeoutWith0.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
@@ -222,8 +224,9 @@ skip-if = buildapp == 'b2g' || toolkit =
 [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_setTimeoutWith0.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);
+}