Bug 1317473 - Make GMPService accept paths with mixed dir separators. r=jesup
authorChris Pearce <cpearce@mozilla.com>
Tue, 15 Nov 2016 10:56:43 +1300
changeset 439661 4fc83233df681d000842ef2945bc6207d519efd2
parent 439660 b7ccea321333c5b935bc04fe2455d2c522b4da9d
child 439662 1fe99466c9f9baac154feca8acfef89c14af0848
push id36064
push userrthijssen@mozilla.com
push dateWed, 16 Nov 2016 13:38:27 +0000
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
--- a/dom/media/gmp/GMPServiceParent.cpp
+++ b/dom/media/gmp/GMPServiceParent.cpp
@@ -1095,28 +1095,37 @@ GeckoMediaPluginServiceParent::ClonePlug
   return gmp.forget();
 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(), '/', '\\');
   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__);