Bug 1184283 - test... removals draft
authorVladimir Vukicevic <vladimir@pobox.com>
Mon, 25 Jan 2016 17:11:34 -0500
changeset 356576 37b218d46553c59c0f96f131cc3a2e150703c666
parent 356575 771fcb2d5baa92821f97715055680b3558bca660
child 519433 066919062b7d14e24d92e7df87459c6b29121018
push id16548
push userbmo:vladimir@pobox.com
push dateTue, 26 Apr 2016 17:19:15 +0000
bugs1184283
milestone49.0a1
Bug 1184283 - test... removals From 15269f09e7fada5ef2335989989e833fba63d160 Mon Sep 17 00:00:00 2001 testing needs some love
gfx/tests/gtest/TestVsync.cpp
--- a/gfx/tests/gtest/TestVsync.cpp
+++ b/gfx/tests/gtest/TestVsync.cpp
@@ -5,44 +5,42 @@
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include "gfxPlatform.h"
 #include "gfxPrefs.h"
 #include "MainThreadUtils.h"
 #include "nsIThread.h"
 #include "mozilla/RefPtr.h"
-#include "SoftwareVsyncSource.h"
-#include "VsyncSource.h"
+#include "gfxVsync.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/TimeStamp.h"
-#include "mozilla/VsyncDispatcher.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 using namespace mozilla::layers;
 using ::testing::_;
 
 // Timeout for vsync events to occur in milliseconds
 // Windows 8.1 has intermittents at 50 ms. Raise limit to 5 vsync intervals.
 const int kVsyncTimeoutMS = 80;
 
 class TestVsyncObserver : public VsyncObserver {
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TestVsyncObserver, override)
 public:
   TestVsyncObserver()
     : mDidGetVsyncNotification(false)
     , mVsyncMonitor("VsyncMonitor")
   {
   }
 
-  virtual bool NotifyVsync(TimeStamp aVsyncTimeStamp) override {
+  virtual void NotifyVsync(TimeStamp aVsyncTimeStamp) override {
     MonitorAutoLock lock(mVsyncMonitor);
     mDidGetVsyncNotification = true;
     mVsyncMonitor.Notify();
-    return true;
   }
 
   void WaitForVsyncNotification()
   {
     MOZ_ASSERT(NS_IsMainThread());
     if (DidGetVsyncNotification()) {
       return;
     }
@@ -61,147 +59,109 @@ public:
   }
 
   void ResetVsyncNotification()
   {
     MonitorAutoLock lock(mVsyncMonitor);
     mDidGetVsyncNotification = false;
   }
 
-private:
+protected:
+  ~TestVsyncObserver() {}
+
   bool mDidGetVsyncNotification;
-
-private:
   Monitor mVsyncMonitor;
 };
 
 class VsyncTester : public ::testing::Test {
 protected:
   explicit VsyncTester()
   {
     gfxPlatform::GetPlatform();
     gfxPrefs::GetSingleton();
-    mVsyncSource = gfxPlatform::GetPlatform()->GetHardwareVsync();
-    MOZ_RELEASE_ASSERT(mVsyncSource);
+    mVsyncManager = gfxPlatform::GetPlatform()->GetHardwareVsync();
+    MOZ_RELEASE_ASSERT(mVsyncManager);
   }
 
   virtual ~VsyncTester()
   {
-    mVsyncSource = nullptr;
+    mVsyncManager = nullptr;
   }
 
-  RefPtr<VsyncSource> mVsyncSource;
+  RefPtr<VsyncManager> mVsyncManager;
 };
 
-static void
-FlushMainThreadLoop()
-{
-  // Some tasks are pushed onto the main thread when adding vsync observers
-  // This function will ensure all tasks are executed on the main thread
-  // before returning.
-  nsCOMPtr<nsIThread> mainThread;
-  nsresult rv = NS_GetMainThread(getter_AddRefs(mainThread));
-  ASSERT_TRUE(NS_SUCCEEDED(rv));
-
-  rv = NS_OK;
-  bool processed = true;
-  while (processed && NS_SUCCEEDED(rv)) {
-    rv = mainThread->ProcessNextEvent(false, &processed);
-  }
-}
-
 // Tests that we can enable/disable vsync notifications
 TEST_F(VsyncTester, EnableVsync)
 {
-  VsyncSource::Display& globalDisplay = mVsyncSource->GetGlobalDisplay();
-  globalDisplay.DisableVsync();
-  ASSERT_FALSE(globalDisplay.IsVsyncEnabled());
+  RefPtr<VsyncSource> globalDisplay = mVsyncManager->GetGlobalDisplaySource();
+  globalDisplay->DisableVsync();
+  ASSERT_FALSE(globalDisplay->IsVsyncEnabled());
 
-  globalDisplay.EnableVsync();
-  ASSERT_TRUE(globalDisplay.IsVsyncEnabled());
+  globalDisplay->EnableVsync();
+  ASSERT_TRUE(globalDisplay->IsVsyncEnabled());
 
-  globalDisplay.DisableVsync();
-  ASSERT_FALSE(globalDisplay.IsVsyncEnabled());
+  globalDisplay->DisableVsync();
+  ASSERT_FALSE(globalDisplay->IsVsyncEnabled());
 }
 
-// Test that if we have vsync enabled, the display should get vsync notifications
-TEST_F(VsyncTester, CompositorGetVsyncNotifications)
-{
-  CompositorVsyncDispatcher::SetThreadAssertionsEnabled(false);
-
-  VsyncSource::Display& globalDisplay = mVsyncSource->GetGlobalDisplay();
-  globalDisplay.DisableVsync();
-  ASSERT_FALSE(globalDisplay.IsVsyncEnabled());
-
-  RefPtr<CompositorVsyncDispatcher> vsyncDispatcher = new CompositorVsyncDispatcher();
-  RefPtr<TestVsyncObserver> testVsyncObserver = new TestVsyncObserver();
-
-  vsyncDispatcher->SetCompositorVsyncObserver(testVsyncObserver);
-  FlushMainThreadLoop();
-  ASSERT_TRUE(globalDisplay.IsVsyncEnabled());
-
-  testVsyncObserver->WaitForVsyncNotification();
-  ASSERT_TRUE(testVsyncObserver->DidGetVsyncNotification());
-
-  vsyncDispatcher = nullptr;
-  testVsyncObserver = nullptr;
-}
-
+#if 0
 // Test that if we have vsync enabled, the parent refresh driver should get notifications
 TEST_F(VsyncTester, ParentRefreshDriverGetVsyncNotifications)
 {
-  VsyncSource::Display& globalDisplay = mVsyncSource->GetGlobalDisplay();
-  globalDisplay.DisableVsync();
-  ASSERT_FALSE(globalDisplay.IsVsyncEnabled());
+  RefPtr<VsyncSource> globalDisplay = mVsyncManager->GetGlobalDisplaySource();
+  globalDisplay->DisableVsync();
+  ASSERT_FALSE(globalDisplay->IsVsyncEnabled());
 
-  RefPtr<RefreshTimerVsyncDispatcher> vsyncDispatcher = globalDisplay.GetRefreshTimerVsyncDispatcher();
+  RefPtr<RefreshTimerVsyncDispatcher> vsyncDispatcher = globalDisplay->GetRefreshTimerVsyncDispatcher();
   ASSERT_TRUE(vsyncDispatcher != nullptr);
 
   RefPtr<TestVsyncObserver> testVsyncObserver = new TestVsyncObserver();
   vsyncDispatcher->SetParentRefreshTimer(testVsyncObserver);
-  ASSERT_TRUE(globalDisplay.IsVsyncEnabled());
+  ASSERT_TRUE(globalDisplay->IsVsyncEnabled());
 
   testVsyncObserver->WaitForVsyncNotification();
   ASSERT_TRUE(testVsyncObserver->DidGetVsyncNotification());
   vsyncDispatcher->SetParentRefreshTimer(nullptr);
 
   testVsyncObserver->ResetVsyncNotification();
   testVsyncObserver->WaitForVsyncNotification();
   ASSERT_FALSE(testVsyncObserver->DidGetVsyncNotification());
 
   vsyncDispatcher = nullptr;
   testVsyncObserver = nullptr;
 }
 
 // Test that child refresh vsync observers get vsync notifications
 TEST_F(VsyncTester, ChildRefreshDriverGetVsyncNotifications)
 {
-  VsyncSource::Display& globalDisplay = mVsyncSource->GetGlobalDisplay();
-  globalDisplay.DisableVsync();
-  ASSERT_FALSE(globalDisplay.IsVsyncEnabled());
+  RefPtr<VsyncSource> globalDisplay = mVsyncManager->GetGlobalDisplaySource();
+  globalDisplay->DisableVsync();
+  ASSERT_FALSE(globalDisplay->IsVsyncEnabled());
 
-  RefPtr<RefreshTimerVsyncDispatcher> vsyncDispatcher = globalDisplay.GetRefreshTimerVsyncDispatcher();
+  RefPtr<RefreshTimerVsyncDispatcher> vsyncDispatcher = globalDisplay->GetRefreshTimerVsyncDispatcher();
   ASSERT_TRUE(vsyncDispatcher != nullptr);
 
   RefPtr<TestVsyncObserver> testVsyncObserver = new TestVsyncObserver();
   vsyncDispatcher->AddChildRefreshTimer(testVsyncObserver);
-  ASSERT_TRUE(globalDisplay.IsVsyncEnabled());
+  ASSERT_TRUE(globalDisplay->IsVsyncEnabled());
 
   testVsyncObserver->WaitForVsyncNotification();
   ASSERT_TRUE(testVsyncObserver->DidGetVsyncNotification());
 
   vsyncDispatcher->RemoveChildRefreshTimer(testVsyncObserver);
   testVsyncObserver->ResetVsyncNotification();
   testVsyncObserver->WaitForVsyncNotification();
   ASSERT_FALSE(testVsyncObserver->DidGetVsyncNotification());
 
   vsyncDispatcher = nullptr;
   testVsyncObserver = nullptr;
 }
+#endif
 
 // Test that we can read the vsync rate
-TEST_F(VsyncTester, VsyncSourceHasVsyncRate)
+TEST_F(VsyncTester, VsyncSourceHasVsyncInterval)
 {
-  VsyncSource::Display& globalDisplay = mVsyncSource->GetGlobalDisplay();
-  TimeDuration vsyncRate = globalDisplay.GetVsyncRate();
-  ASSERT_NE(vsyncRate, TimeDuration::Forever());
-  ASSERT_GT(vsyncRate.ToMilliseconds(), 0);
+  RefPtr<VsyncSource> globalDisplay = mVsyncManager->GetGlobalDisplaySource();
+  TimeDuration vsyncInterval = globalDisplay->GetVsyncInterval();
+  ASSERT_NE(vsyncInterval, TimeDuration::Forever());
+  ASSERT_GT(vsyncInterval.ToMilliseconds(), 0);
 }