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

--HG--
extra : rebase_source : 2cf63ccd1155e59f9745163cf4a28d3bdb7012ba
This commit is contained in:
Chris Pearce 2016-11-15 10:56:43 +13:00
parent 90b5777783
commit eac0e11773

View File

@ -1100,6 +1100,14 @@ GeckoMediaPluginServiceParent::ClonePlugin(const GMPParent* aOriginal)
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());
@ -1112,6 +1120,7 @@ GeckoMediaPluginServiceParent::AddOnGMPThread(nsString aDirectory)
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__);
}