Bug 1274596 - Implement the fakepath requirement in HTMLInputElement, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 17 Jan 2017 09:56:56 +0100
changeset 374648 8fd2b8d8d76758c519cbca84b98771a94df17f47
parent 374647 001dbd37971539053cd64d14d04490c872b0aab1
child 374649 293533db8cc7dca1e65ceeb386369795e9f99ec2
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1274596
milestone53.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 1274596 - Implement the fakepath requirement in HTMLInputElement, r=smaug
dom/html/HTMLInputElement.cpp
dom/html/test/mochitest.ini
dom/html/test/script_fakepath.js
dom/html/test/test_fakepath.html
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -1767,24 +1767,33 @@ HTMLInputElement::GetValueInternal(nsASt
 {
   if (mType != NS_FORM_INPUT_FILE) {
     GetNonFileValueInternal(aValue);
     return;
   }
 
   if (aCallerType == CallerType::System) {
     aValue.Assign(mFirstFilePath);
-  } else {
-    // Just return the leaf name
-    if (mFilesOrDirectories.IsEmpty()) {
-      aValue.Truncate();
-    } else {
-      GetDOMFileOrDirectoryName(mFilesOrDirectories[0], aValue);
-    }
-  }
+    return;
+  }
+
+  if (mFilesOrDirectories.IsEmpty()) {
+    aValue.Truncate();
+    return;
+  }
+
+  nsAutoString file;
+  GetDOMFileOrDirectoryName(mFilesOrDirectories[0], file);
+  if (file.IsEmpty()) {
+    aValue.Truncate();
+    return;
+  }
+
+  aValue.AssignLiteral("C:\\fakepath\\");
+  aValue.Append(file);
 }
 
 void
 HTMLInputElement::GetNonFileValueInternal(nsAString& aValue) const
 {
   switch (GetValueMode()) {
     case VALUE_MODE_VALUE:
       if (IsSingleLineTextControl(false)) {
--- a/dom/html/test/mochitest.ini
+++ b/dom/html/test/mochitest.ini
@@ -182,16 +182,17 @@ support-files =
   nnc_lockup.gif
   reflect.js
   file_ignoreuserfocus.html
   simpleFileOpener.js
   file_mozaudiochannel.html
   file_bug1166138_1x.png
   file_bug1166138_2x.png
   file_bug1166138_def.png
+  script_fakepath.js
 
 [test_a_text.html]
 [test_anchor_href_cache_invalidation.html]
 [test_applet_attributes_reflection.html]
 [test_base_attributes_reflection.html]
 [test_bug100533.html]
 [test_bug109445.html]
 [test_bug109445.xhtml]
@@ -605,8 +606,9 @@ skip-if = (os == 'android' || os == 'mac
 [test_bug1260704.html]
 [test_allowMedia.html]
 [test_bug1292522_same_domain_with_different_port_number.html]
 [test_bug1295719_event_sequence_for_arrow_keys.html]
 skip-if = os == "android" # up/down arrow keys not supported on android
 [test_bug1295719_event_sequence_for_number_keys.html]
 [test_bug1310865.html]
 [test_bug1315146.html]
+[test_fakepath.html]
new file mode 100644
--- /dev/null
+++ b/dom/html/test/script_fakepath.js
@@ -0,0 +1,13 @@
+var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+Cu.importGlobalProperties(["File"]);
+
+addMessageListener("file.open", function (e) {
+  var tmpFile = Cc["@mozilla.org/file/directory_service;1"]
+                  .getService(Ci.nsIDirectoryService)
+                  .QueryInterface(Ci.nsIProperties)
+                  .get('ProfD', Ci.nsIFile);
+  tmpFile.append('prefs.js');
+  sendAsyncMessage("file.opened", {
+    data: [ File.createFromNsIFile(tmpFile) ]
+  });
+});
new file mode 100644
--- /dev/null
+++ b/dom/html/test/test_fakepath.html
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for Fakepath in HTMLInputElement</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="file" type="file"></input>
+<input id="file_wd" type="file" webkitdirectory></input>
+<script type="application/javascript;version=1.7">
+
+var url = SimpleTest.getTestFileURL("script_fakepath.js");
+script = SpecialPowers.loadChromeScript(url);
+
+function onOpened(message) {
+  var e = document.getElementById("file");
+  SpecialPowers.wrap(e).mozSetDndFilesAndDirectories(message.data);
+  ok(e.value, "C:\\fakepath\\prefs.js");
+
+  e = document.getElementById("file_wd");
+  SpecialPowers.wrap(e).mozSetDndFilesAndDirectories(message.data);
+  ok(e.value, "C:\\fakepath\\prefs.js");
+
+  SimpleTest.finish();
+}
+
+function run() {
+  script.addMessageListener("file.opened", onOpened);
+  script.sendAsyncMessage("file.open");
+}
+
+SpecialPowers.pushPrefEnv({"set": [["dom.input.dirpicker", true],
+                                   ["dom.webkitBlink.dirPicker.enabled", true]]}, run);
+
+SimpleTest.waitForExplicitFinish();
+
+</script>
+</body>
+</html>