Bug 1245789 - Ensure GMP service has added all plugins before running GMP remove tests. r=gerald,a=ritu
authorChris Pearce <cpearce@mozilla.com>
Tue, 12 Apr 2016 16:12:22 +1200
changeset 324047 30dfb60f7aeee0d7e39a94b37a097b47ac040a9d
parent 324046 3f8bf9e392d1a70b4c089deb89df20862f349840
child 324048 3ce93a15f1417868cc76f598fb4aacef4d8bdc90
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, ritu
bugs1245789
milestone47.0a2
Bug 1245789 - Ensure GMP service has added all plugins before running GMP remove tests. r=gerald,a=ritu MozReview-Commit-ID: 488sYVQbS4x
dom/media/gmp/GMPServiceParent.h
dom/media/gtest/TestGMPRemoveAndDelete.cpp
--- a/dom/media/gmp/GMPServiceParent.h
+++ b/dom/media/gmp/GMPServiceParent.h
@@ -51,17 +51,17 @@ public:
 
   void AsyncShutdownNeeded(GMPParent* aParent);
   void AsyncShutdownComplete(GMPParent* aParent);
 
   int32_t AsyncShutdownTimeoutMs();
 #ifdef MOZ_CRASHREPORTER
   void SetAsyncShutdownPluginState(GMPParent* aGMPParent, char aId, const nsCString& aState);
 #endif // MOZ_CRASHREPORTER
-
+  RefPtr<GenericPromise> EnsureInitialized();
 private:
   friend class GMPServiceParent;
 
   virtual ~GeckoMediaPluginServiceParent();
 
   void ClearStorage();
 
   GMPParent* SelectPluginForAPI(const nsACString& aNodeId,
@@ -99,17 +99,16 @@ private:
   void ForgetThisSiteOnGMPThread(const nsACString& aOrigin);
   void ClearRecentHistoryOnGMPThread(PRTime aSince);
 
 protected:
   friend class GMPParent;
   void ReAddOnGMPThread(const RefPtr<GMPParent>& aOld);
   void PluginTerminated(const RefPtr<GMPParent>& aOld);
   void InitializePlugins() override;
-  RefPtr<GenericPromise> EnsureInitialized();
   RefPtr<GenericPromise::AllPromiseType> LoadFromEnvironment();
   RefPtr<GenericPromise> AddOnGMPThread(const nsAString& aDirectory);
   bool GetContentParentFrom(const nsACString& aNodeId,
                             const nsCString& aAPI,
                             const nsTArray<nsCString>& aTags,
                             UniquePtr<GetGMPContentParentCallback>&& aCallback)
     override;
 private:
--- a/dom/media/gtest/TestGMPRemoveAndDelete.cpp
+++ b/dom/media/gtest/TestGMPRemoveAndDelete.cpp
@@ -223,24 +223,35 @@ GMPRemoveTest::~GMPRemoveTest()
 
   EXPECT_OK(GetServiceParent()->AddPluginDirectory(mOriginalPath));
 }
 
 void
 GMPRemoveTest::Setup()
 {
   GeneratePlugin();
+  GetService()->GetThread(getter_AddRefs(mGMPThread));
+
+  // Spin the event loop until the GMP service has had a chance to complete
+  // adding GMPs from MOZ_GMP_PATH. Otherwise, the RemovePluginDirectory()
+  // below may complete before we're finished adding GMPs from MOZ_GMP_PATH,
+  // and we'll end up not removing the GMP, and the test will fail.
+  RefPtr<AbstractThread> thread(GetServiceParent()->GetAbstractGMPThread());
+  GMPTestMonitor* mon = &mTestMonitor;
+  GetServiceParent()->EnsureInitialized()->Then(thread, __func__,
+    [mon]() { mon->SetFinished(); },
+    [mon]() { mon->SetFinished(); }
+  );
+  mTestMonitor.AwaitFinished();
+
+  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
+  obs->AddObserver(this, GMP_DELETED_TOPIC, false /* strong ref */);
   EXPECT_OK(GetServiceParent()->RemovePluginDirectory(mOriginalPath));
 
   GetServiceParent()->AddPluginDirectory(mTmpPath);
-
-  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
-  obs->AddObserver(this, GMP_DELETED_TOPIC, false /* strong ref */);
-
-  GetService()->GetThread(getter_AddRefs(mGMPThread));
 }
 
 bool
 GMPRemoveTest::CreateVideoDecoder(nsCString aNodeId)
 {
   GMPVideoHost* host;
   GMPVideoDecoderProxy* decoder = nullptr;