Bug 1319088 - FormData should not add extra '/' in the Blob path, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 01 Dec 2016 08:59:36 +0100
changeset 324974 958963bca7689d9c3ba6027fbcc555aee2705a0a
parent 324973 d4b9373141c6a50c3db80891f5b0727c04dc5a46
child 324975 806c3d121dd45fa9af850d287f61d76e33dd08f1
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewerssmaug
bugs1319088
milestone53.0a1
Bug 1319088 - FormData should not add extra '/' in the Blob path, r=smaug
dom/filesystem/tests/mochitest.ini
dom/filesystem/tests/test_bug1319088.html
dom/html/HTMLInputElement.cpp
--- a/dom/filesystem/tests/mochitest.ini
+++ b/dom/filesystem/tests/mochitest.ini
@@ -2,8 +2,9 @@
 support-files =
   filesystem_commons.js
   script_fileList.js
   worker_basic.js
 
 [test_basic.html]
 [test_webkitdirectory.html]
 [test_worker_basic.html]
+[test_bug1319088.html]
new file mode 100644
--- /dev/null
+++ b/dom/filesystem/tests/test_bug1319088.html
@@ -0,0 +1,66 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for bug 1319088</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+
+<body>
+<input id="input" type="file"></input>
+
+<script type="application/javascript;version=1.7">
+
+function testSetup() {
+  SpecialPowers.pushPrefEnv({"set": [["dom.input.dirpicker", true],
+                                     ["dom.webkitBlink.dirPicker.enabled", true]]}, next);
+}
+
+function populateInputFile() {
+  var url = SimpleTest.getTestFileURL("script_fileList.js");
+  var script = SpecialPowers.loadChromeScript(url);
+
+  function onOpened(message) {
+    var input = document.getElementById("input");
+    SpecialPowers.wrap(input).mozSetFileArray([message.file]);
+
+    script.destroy();
+    next();
+  }
+
+  script.addMessageListener("file.opened", onOpened);
+  script.sendAsyncMessage("file.open");
+}
+
+function checkBug() {
+  var input = document.getElementById("input");
+  is(input.files[0].webkitRelativePath, "", "No relative path!");
+
+  let form = document.createElement('form');
+  form.appendChild(input);
+
+  is(input.files[0].webkitRelativePath, "", "No relative path!");
+  SimpleTest.finish();
+}
+
+var tests = [
+  testSetup,
+  populateInputFile,
+  checkBug,
+];
+
+function next() {
+  if (!tests.length) {
+    SimpleTest.finish();
+    return;
+  }
+
+  var test = tests.shift();
+  test();
+}
+
+SimpleTest.waitForExplicitFinish();
+next();
+</script>
+</body>
+</html>
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -355,28 +355,17 @@ class HTMLInputElementState final : publ
 
     void SetFilesOrDirectories(const nsTArray<OwningFileOrDirectory>& aArray)
     {
       mBlobImplsOrDirectoryPaths.Clear();
       for (uint32_t i = 0; i < aArray.Length(); ++i) {
         if (aArray[i].IsFile()) {
           BlobImplOrDirectoryPath* data = mBlobImplsOrDirectoryPaths.AppendElement();
 
-          RefPtr<File> file = aArray[i].GetAsFile();
-
-          nsAutoString name;
-          file->GetName(name);
-
-          nsAutoString path;
-          path.AssignLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
-          path.Append(name);
-
-          file->SetPath(path);
-
-          data->mBlobImpl = file->Impl();
+          data->mBlobImpl = aArray[i].GetAsFile()->Impl();
           data->mType = BlobImplOrDirectoryPath::eBlobImpl;
         } else {
           MOZ_ASSERT(aArray[i].IsDirectory());
           nsAutoString fullPath;
           nsresult rv = aArray[i].GetAsDirectory()->GetFullRealPath(fullPath);
           if (NS_WARN_IF(NS_FAILED(rv))) {
             continue;
           }