Bug 1317473 - Make GMPService accept paths with mixed dir separators. r?jesup draft
authorChris Pearce <cpearce@mozilla.com>
Tue, 15 Nov 2016 10:56:43 +1300
changeset 439466 ce471b9cbe5eaf9011318ba0f90297a310c5a19b
parent 439375 79feeed4293336089590320a9f30a813fade8e3c
child 439467 3b176cbfadebf6463384105c261ff208bc58b1c2
push id36008
push usercpearce@mozilla.com
push dateWed, 16 Nov 2016 02:19:14 +0000
reviewersjesup
bugs1317473
milestone53.0a1
Bug 1317473 - Make GMPService accept paths with mixed dir separators. r?jesup The mochitest harness on Windows sets MOZ_GMP_PATH to paths with a mixture of Windows and UNIX dir separators, and the NS_NewLocalFile() call in GMPServiceParent::AddOnGMPThread() fails on this input. We've had this problem before, and if we fixed the test harness to give us input with platform specific line endings somebody would likely just break this again someday and have this issue again, so just make the GMP service normalize the paths it's given to have consistent dir separators. This makes test_peerConnection_basicH264Video.html pass when run locally on my Windows machine. MozReview-Commit-ID: 88hSvTdZuWg
dom/media/gmp/GMPServiceParent.cpp
--- a/dom/media/gmp/GMPServiceParent.cpp
+++ b/dom/media/gmp/GMPServiceParent.cpp
@@ -1095,28 +1095,37 @@ GeckoMediaPluginServiceParent::ClonePlug
   }
 
   return gmp.forget();
 }
 
 RefPtr<GenericPromise>
 GeckoMediaPluginServiceParent::AddOnGMPThread(nsString aDirectory)
 {
+#ifdef XP_WIN
+  // On Windows our various test harnesses often pass paths with UNIX dir
+  // separators, or a mix of dir separators. NS_NewLocalFile() can't handle
+  // that, so fixup to match the platform's expected format. This makes us
+  // more robust in the face of bad input and test harnesses changing...
+  std::replace(aDirectory.BeginWriting(), aDirectory.EndWriting(), '/', '\\');
+#endif
+
   MOZ_ASSERT(NS_GetCurrentThread() == mGMPThread);
   nsCString dir = NS_ConvertUTF16toUTF8(aDirectory);
   RefPtr<AbstractThread> thread(GetAbstractGMPThread());
   if (!thread) {
     LOGD(("%s::%s: %s No GMP Thread", __CLASS__, __FUNCTION__, dir.get()));
     return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
   }
   LOGD(("%s::%s: %s", __CLASS__, __FUNCTION__, dir.get()));
 
   nsCOMPtr<nsIFile> directory;
   nsresult rv = NS_NewLocalFile(aDirectory, false, getter_AddRefs(directory));
   if (NS_WARN_IF(NS_FAILED(rv))) {
+    LOGD(("%s::%s: failed to create nsIFile for dir=%s rv=%x", __CLASS__, __FUNCTION__, dir.get(), rv));
     return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
   }
 
   RefPtr<GMPParent> gmp = CreateGMPParent();
   if (!gmp) {
     NS_WARNING("Can't Create GMPParent");
     return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
   }