Back to index

unity  6.0.0
test_showdesktop_handler.cpp
Go to the documentation of this file.
00001 #include <list>
00002 #include <algorithm>
00003 #include <gtest/gtest.h>
00004 #include <gmock/gmock.h>
00005 #include <UnityShowdesktopHandler.h>
00006 
00007 using namespace unity;
00008 using ::testing::_;
00009 using ::testing::Return;
00010 using ::testing::Invoke;
00011 using ::testing::InSequence;
00012 
00013 compiz::WindowInputRemoverInterface::~WindowInputRemoverInterface () {}
00014 
00015 class MockWindowInputRemover :
00016   public compiz::WindowInputRemoverInterface
00017 {
00018   public:
00019 
00020     MockWindowInputRemover ()
00021     {
00022       ON_CALL (*this, saveInput ()).WillByDefault (Return (true));
00023       ON_CALL (*this, removeInput ()).WillByDefault (Return (true));
00024       ON_CALL (*this, restoreInput ()).WillByDefault (Return (true));
00025     }
00026 
00027     MOCK_METHOD0 (saveInput, bool ());
00028     MOCK_METHOD0 (removeInput, bool ());
00029     MOCK_METHOD0 (restoreInput, bool ());
00030 };
00031 
00032 class UnityShowdesktopHandlerTest :
00033   public ::testing::Test
00034 {
00035 public:
00036 
00037   ~UnityShowdesktopHandlerTest ()
00038   {
00039     ShowdesktopHandler::animating_windows.clear ();
00040   }
00041 
00042   template <class T, class A1> static typename T::Ptr makeShared1 (A1 *a) { T * t = new T (a); return (typename T::Ptr) (t); }
00043 
00044   template <class T> static compiz::WindowInputRemoverLock::Ptr getLock ()
00045   {
00046     T *r = new T ();
00047     return makeShared1<compiz::WindowInputRemoverLock, compiz::WindowInputRemoverInterface> (r);
00048   }
00049 };
00050 
00051 
00052 class MockUnityShowdesktopHandlerWindow :
00053   public ShowdesktopHandlerWindowInterface,
00054   public compiz::WindowInputRemoverLockAcquireInterface
00055 {
00056   public:
00057 
00058     MockUnityShowdesktopHandlerWindow ()
00059     {
00060       ON_CALL (*this, IsOverrideRedirect ()).WillByDefault (Return (false));
00061       ON_CALL (*this, IsManaged ()).WillByDefault (Return (true));
00062       ON_CALL (*this, IsGrabbed ()).WillByDefault (Return (false));
00063       ON_CALL (*this, IsDesktopOrDock ()).WillByDefault (Return (false));
00064       ON_CALL (*this, IsSkipTaskbarOrPager ()).WillByDefault (Return (false));
00065       ON_CALL (*this, IsHidden ()).WillByDefault (Return (false));
00066       ON_CALL (*this, IsInShowdesktopMode ()).WillByDefault (Return (false));
00067       ON_CALL (*this, IsShaded ()).WillByDefault (Return (false));
00068       ON_CALL (*this, IsMinimized ()).WillByDefault (Return (false));
00069 
00070       ON_CALL (*this, DoHandleAnimations (_)).WillByDefault (Return (ShowdesktopHandlerWindowInterface::PostPaintAction::Damage));
00071       ON_CALL (*this, GetNoCoreInstanceMask ()).WillByDefault (Return (1));
00072       ON_CALL (*this, GetInputRemover ()).WillByDefault (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemover>));
00073     }
00074 
00075     MOCK_METHOD0 (DoEnableFocus, void ());
00076     MOCK_METHOD0 (DoDisableFocus, void ());
00077     MOCK_METHOD0 (IsOverrideRedirect, bool ());
00078     MOCK_METHOD0 (IsManaged, bool ());
00079     MOCK_METHOD0 (IsGrabbed, bool ());
00080     MOCK_METHOD0 (IsDesktopOrDock, bool ());
00081     MOCK_METHOD0 (IsSkipTaskbarOrPager, bool ());
00082     MOCK_METHOD0 (IsHidden, bool ());
00083     MOCK_METHOD0 (IsInShowdesktopMode, bool ());
00084     MOCK_METHOD0 (IsShaded, bool ());
00085     MOCK_METHOD0 (IsMinimized, bool ());
00086     MOCK_METHOD1 (DoOverrideFrameRegion, void (CompRegion &));
00087     MOCK_METHOD0 (DoHide, void ());
00088     MOCK_METHOD0 (DoNotifyHidden, void ());
00089     MOCK_METHOD0 (DoShow, void ());
00090     MOCK_METHOD0 (DoNotifyShown, void ());
00091     MOCK_METHOD0 (DoMoveFocusAway, void ());
00092     MOCK_METHOD1 (DoHandleAnimations, ShowdesktopHandlerWindowInterface::PostPaintAction (unsigned int));
00093     MOCK_METHOD0 (DoAddDamage, void ());
00094     MOCK_METHOD0 (GetNoCoreInstanceMask, unsigned int ());
00095     MOCK_METHOD0 (GetInputRemover, compiz::WindowInputRemoverLock::Ptr ());
00096     MOCK_METHOD0 (DoDeleteHandler, void ());
00097 };
00098 
00099 TEST_F(UnityShowdesktopHandlerTest, TestNoORWindowsSD)
00100 {
00101   MockUnityShowdesktopHandlerWindow mMockWindow;
00102 
00103   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00104 
00105   EXPECT_CALL (mMockWindow, IsOverrideRedirect ()).WillOnce (Return (true));
00106   EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
00107 }
00108 
00109 TEST_F(UnityShowdesktopHandlerTest, TestNoUnmanagedWindowsSD)
00110 {
00111   MockUnityShowdesktopHandlerWindow mMockWindow;
00112 
00113   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00114 
00115   EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
00116   EXPECT_CALL (mMockWindow, IsManaged ()).WillOnce (Return (false));
00117   EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
00118 }
00119 
00120 TEST_F(UnityShowdesktopHandlerTest, TestNoGrabbedWindowsSD)
00121 {
00122   MockUnityShowdesktopHandlerWindow mMockWindow;
00123 
00124   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00125 
00126   EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
00127   EXPECT_CALL (mMockWindow, IsManaged ());
00128   EXPECT_CALL (mMockWindow, IsGrabbed ()).WillOnce (Return (true));
00129   EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
00130 }
00131 
00132 TEST_F(UnityShowdesktopHandlerTest, TestNoDesktopOrDockWindowsSD)
00133 {
00134   MockUnityShowdesktopHandlerWindow mMockWindow;
00135 
00136   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00137 
00138   EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
00139   EXPECT_CALL (mMockWindow, IsManaged ());
00140   EXPECT_CALL (mMockWindow, IsGrabbed ());
00141   EXPECT_CALL (mMockWindow, IsDesktopOrDock ()).WillOnce (Return (true));
00142   EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
00143 }
00144 
00145 TEST_F(UnityShowdesktopHandlerTest, TestNoSkipTaskbarOrPagerWindowsSD)
00146 {
00147   MockUnityShowdesktopHandlerWindow mMockWindow;
00148 
00149   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00150 
00151   EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
00152   EXPECT_CALL (mMockWindow, IsManaged ());
00153   EXPECT_CALL (mMockWindow, IsGrabbed ());
00154   EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
00155   EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ()).WillOnce (Return (true));
00156   EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
00157 }
00158 
00159 TEST_F(UnityShowdesktopHandlerTest, TestHiddenNotSDAndShadedWindowsNoSD)
00160 {
00161   MockUnityShowdesktopHandlerWindow mMockWindow;
00162 
00163   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00164 
00165   EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
00166   EXPECT_CALL (mMockWindow, IsManaged ());
00167   EXPECT_CALL (mMockWindow, IsGrabbed ());
00168   EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
00169   EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ());
00170   EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));
00171   EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (false));
00172   EXPECT_CALL (mMockWindow, IsShaded ()).WillOnce (Return (true));
00173   EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
00174 }
00175 
00176 TEST_F(UnityShowdesktopHandlerTest, TestHiddenSDAndShadedWindowsNoSD)
00177 {
00178   MockUnityShowdesktopHandlerWindow mMockWindow;
00179 
00180   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00181 
00182   EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
00183   EXPECT_CALL (mMockWindow, IsManaged ());
00184   EXPECT_CALL (mMockWindow, IsGrabbed ());
00185   EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
00186   EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ());
00187   EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));
00188   EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (true));
00189   EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
00190 }
00191 
00192 TEST_F(UnityShowdesktopHandlerTest, TestHiddenSDAndMinimizedWindowsNoSD)
00193 {
00194   MockUnityShowdesktopHandlerWindow mMockWindow;
00195 
00196   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00197 
00198   EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
00199   EXPECT_CALL (mMockWindow, IsManaged ());
00200   EXPECT_CALL (mMockWindow, IsGrabbed ());
00201   EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
00202   EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ());
00203   EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));
00204   EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (false));
00205   EXPECT_CALL (mMockWindow, IsShaded ()).WillOnce (Return (false));
00206   EXPECT_CALL (mMockWindow, IsMinimized ()).WillOnce (Return (true));
00207   EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
00208 }
00209 
00210 TEST_F(UnityShowdesktopHandlerTest, TestHiddenNotSDAndNotShadedWindowsSD)
00211 {
00212   MockUnityShowdesktopHandlerWindow mMockWindow;
00213 
00214   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00215 
00216   EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
00217   EXPECT_CALL (mMockWindow, IsManaged ());
00218   EXPECT_CALL (mMockWindow, IsGrabbed ());
00219   EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
00220   EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ());
00221   EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));
00222   EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (false));
00223   EXPECT_CALL (mMockWindow, IsShaded ()).WillOnce (Return (false));
00224   EXPECT_CALL (mMockWindow, IsMinimized ()).WillOnce (Return (false));
00225   EXPECT_TRUE (ShowdesktopHandler::ShouldHide (&mMockWindow));
00226 }
00227 
00228 class MockWindowInputRemoverTestFadeOut :
00229   public compiz::WindowInputRemoverInterface
00230 {
00231   public:
00232 
00233     MockWindowInputRemoverTestFadeOut ()
00234     {
00235       ON_CALL (*this, saveInput ()).WillByDefault (Return (true));
00236       ON_CALL (*this, removeInput ()).WillByDefault (Return (true));
00237       ON_CALL (*this, restoreInput ()).WillByDefault (Return (true));
00238 
00239       EXPECT_CALL (*this, saveInput ()).WillOnce (Return (true));
00240       EXPECT_CALL (*this, removeInput ()).WillOnce (Return (true));
00241       EXPECT_CALL (*this, restoreInput ()).WillOnce (Return (true));
00242     }
00243 
00244     MOCK_METHOD0 (saveInput, bool ());
00245     MOCK_METHOD0 (removeInput, bool ());
00246     MOCK_METHOD0 (restoreInput, bool ());
00247 };
00248 
00249 TEST_F(UnityShowdesktopHandlerTest, TestFadeOutHidesWindow)
00250 {
00251   MockUnityShowdesktopHandlerWindow mMockWindow;
00252 
00253   EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOut>));
00254 
00255   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00256 
00257   EXPECT_CALL (mMockWindow, IsHidden ());
00258   EXPECT_CALL (mMockWindow, DoHide ());
00259   EXPECT_CALL (mMockWindow, DoNotifyHidden ());
00260 
00261   mMockHandler.FadeOut ();
00262 
00263   EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
00264 }
00265 
00266 class MockWindowInputRemoverTestFadeOutAlready :
00267   public compiz::WindowInputRemoverInterface
00268 {
00269   public:
00270 
00271     MockWindowInputRemoverTestFadeOutAlready ()
00272     {
00273       ON_CALL (*this, saveInput ()).WillByDefault (Return (true));
00274       ON_CALL (*this, removeInput ()).WillByDefault (Return (true));
00275       ON_CALL (*this, restoreInput ()).WillByDefault (Return (true));
00276     }
00277 
00278     MOCK_METHOD0 (saveInput, bool ());
00279     MOCK_METHOD0 (removeInput, bool ());
00280     MOCK_METHOD0 (restoreInput, bool ());
00281 };
00282 
00283 TEST_F(UnityShowdesktopHandlerTest, TestFadeOutOnHiddenDoesntHideWindow)
00284 {
00285   MockUnityShowdesktopHandlerWindow mMockWindow;
00286 
00287   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00288 
00289   EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));
00290 
00291   mMockHandler.FadeOut ();
00292 
00293   EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 0);
00294 }
00295 
00296 TEST_F(UnityShowdesktopHandlerTest, TestFadeOutAlreadyFadedDoesntHideWindow)
00297 {
00298   MockUnityShowdesktopHandlerWindow mMockWindow;
00299 
00300   EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOut>));
00301   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00302 
00303   EXPECT_CALL (mMockWindow, IsHidden ());
00304   EXPECT_CALL (mMockWindow, DoHide ());
00305   EXPECT_CALL (mMockWindow, DoNotifyHidden ());
00306 
00307   mMockHandler.FadeOut ();
00308   mMockHandler.FadeOut ();
00309 
00310   EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
00311 }
00312 
00313 TEST_F(UnityShowdesktopHandlerTest, TestFadeInNonFadedDoesntShowWindow)
00314 {
00315   MockUnityShowdesktopHandlerWindow mMockWindow;
00316 
00317   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00318 
00319   mMockHandler.FadeIn ();
00320 
00321   EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 0);
00322 }
00323 
00324 class MockWindowInputRemoverTestFadeOutFadeIn :
00325   public compiz::WindowInputRemoverInterface
00326 {
00327   public:
00328 
00329     MockWindowInputRemoverTestFadeOutFadeIn ()
00330     {
00331       ON_CALL (*this, saveInput ()).WillByDefault (Return (true));
00332       ON_CALL (*this, removeInput ()).WillByDefault (Return (true));
00333       ON_CALL (*this, restoreInput ()).WillByDefault (Return (true));
00334 
00335       EXPECT_CALL (*this, saveInput ()).WillOnce (Return (true));
00336       EXPECT_CALL (*this, removeInput ()).WillOnce (Return (true));
00337       EXPECT_CALL (*this, restoreInput ()).WillOnce (Return (true));
00338     }
00339 
00340     MOCK_METHOD0 (saveInput, bool ());
00341     MOCK_METHOD0 (removeInput, bool ());
00342     MOCK_METHOD0 (restoreInput, bool ());
00343 };
00344 
00345 TEST_F(UnityShowdesktopHandlerTest, TestFadeOutHidesWindowFadeInShowsWindow)
00346 {
00347   MockUnityShowdesktopHandlerWindow mMockWindow;
00348 
00349   EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOutFadeIn>));
00350   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00351 
00352   EXPECT_CALL (mMockWindow, IsHidden ());
00353   EXPECT_CALL (mMockWindow, DoHide ());
00354   EXPECT_CALL (mMockWindow, DoNotifyHidden ());
00355 
00356   mMockHandler.FadeOut ();
00357 
00358   EXPECT_CALL (mMockWindow, DoShow ());
00359   EXPECT_CALL (mMockWindow, DoNotifyShown ());
00360 
00361   mMockHandler.FadeIn ();
00362 
00363   EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
00364 }
00365 
00366 TEST_F(UnityShowdesktopHandlerTest, TestAnimationPostPaintActions)
00367 {
00368   MockUnityShowdesktopHandlerWindow mMockWindow;
00369 
00370   EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOutFadeIn>));
00371   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00372 
00373   EXPECT_CALL (mMockWindow, IsHidden ());
00374   EXPECT_CALL (mMockWindow, DoHide ());
00375   EXPECT_CALL (mMockWindow, DoNotifyHidden ());
00376 
00377   mMockHandler.FadeOut ();
00378 
00379   EXPECT_CALL (mMockWindow, DoShow ());
00380   EXPECT_CALL (mMockWindow, DoNotifyShown ());
00381 
00382   for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++)
00383   {
00384     ShowdesktopHandlerWindowInterface::PostPaintAction action = mMockHandler.Animate (1);
00385 
00386     if (i == 300)
00387       EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Wait);
00388     else
00389       EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Damage);
00390   }
00391 
00392   mMockHandler.FadeIn ();
00393 
00394   for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++)
00395   {
00396     ShowdesktopHandlerWindowInterface::PostPaintAction action = mMockHandler.Animate (1);
00397 
00398     if (i == 300)
00399       EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Remove);
00400     else
00401       EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Damage);
00402   }
00403 
00404   EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
00405 }
00406 
00407 TEST_F(UnityShowdesktopHandlerTest, TestAnimationOpacity)
00408 {
00409   MockUnityShowdesktopHandlerWindow mMockWindow;
00410 
00411   EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOutFadeIn>));
00412   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00413 
00414   EXPECT_CALL (mMockWindow, IsHidden ());
00415   EXPECT_CALL (mMockWindow, DoHide ());
00416   EXPECT_CALL (mMockWindow, DoNotifyHidden ());
00417 
00418   mMockHandler.FadeOut ();
00419 
00420   EXPECT_CALL (mMockWindow, DoShow ());
00421   EXPECT_CALL (mMockWindow, DoNotifyShown ());
00422 
00423   /* The funny expectations here are to account for rounding errors that would
00424    * otherwise make testing the code painful */
00425 
00426   for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++)
00427   {
00428     unsigned short opacity = std::numeric_limits <unsigned short>::max ();
00429     mMockHandler.PaintOpacity (opacity);
00430 
00431     mMockHandler.Animate (1);
00432 
00433     if (i == 300)
00434       EXPECT_EQ (opacity, std::numeric_limits <unsigned short>::max ());
00435     else
00436     {
00437       float rem = opacity - std::numeric_limits <unsigned short>::max () * (1.0f - i / static_cast <float> (ShowdesktopHandler::fade_time));
00438       EXPECT_TRUE (rem <= 1.0f && rem >= -1.0f);
00439     }
00440   }
00441 
00442   mMockHandler.FadeIn ();
00443 
00444   for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++)
00445   {
00446     unsigned short opacity = std::numeric_limits <unsigned short>::max ();
00447     mMockHandler.PaintOpacity (opacity);
00448 
00449     mMockHandler.Animate (1);
00450 
00451     if (i == 300)
00452       EXPECT_EQ (opacity, std::numeric_limits <unsigned short>::max ());
00453     else
00454     {
00455       float rem = opacity - std::numeric_limits <unsigned short>::max () * (i / static_cast <float> (ShowdesktopHandler::fade_time));
00456       EXPECT_TRUE (rem <= 1.0f && rem >= -1.0f);
00457     }
00458   }
00459 
00460   EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
00461 }
00462 
00463 TEST_F(UnityShowdesktopHandlerTest, TestAnimationPaintMasks)
00464 {
00465   MockUnityShowdesktopHandlerWindow mMockWindow;
00466 
00467   EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOutFadeIn>));
00468   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00469 
00470   EXPECT_CALL (mMockWindow, IsHidden ());
00471   EXPECT_CALL (mMockWindow, DoHide ());
00472   EXPECT_CALL (mMockWindow, DoNotifyHidden ());
00473 
00474   mMockHandler.FadeOut ();
00475 
00476   EXPECT_CALL (mMockWindow, DoShow ());
00477   EXPECT_CALL (mMockWindow, DoNotifyShown ());
00478   EXPECT_CALL (mMockWindow, GetNoCoreInstanceMask ());
00479 
00480   mMockHandler.Animate (ShowdesktopHandler::fade_time);
00481 
00482   EXPECT_EQ (mMockHandler.GetPaintMask (), 1);
00483 
00484   mMockHandler.FadeIn ();
00485 
00486   mMockHandler.Animate (ShowdesktopHandler::fade_time);
00487 
00488   EXPECT_EQ (mMockHandler.GetPaintMask (), 0);
00489 
00490   EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
00491 }
00492 
00493 class MockWindowInputRemoverTestFadeOutFadeInWithShapeEvent :
00494   public compiz::WindowInputRemoverInterface
00495 {
00496   public:
00497 
00498     MockWindowInputRemoverTestFadeOutFadeInWithShapeEvent ()
00499     {
00500       ON_CALL (*this, saveInput ()).WillByDefault (Return (true));
00501       ON_CALL (*this, removeInput ()).WillByDefault (Return (true));
00502       ON_CALL (*this, restoreInput ()).WillByDefault (Return (true));
00503 
00504       InSequence s;
00505 
00506       EXPECT_CALL (*this, saveInput ()).WillOnce (Return (true));
00507       EXPECT_CALL (*this, removeInput ()).WillOnce (Return (true));
00508       EXPECT_CALL (*this, saveInput ()).WillOnce (Return (true));
00509       EXPECT_CALL (*this, removeInput ()).WillOnce (Return (true));
00510       EXPECT_CALL (*this, restoreInput ()).WillOnce (Return (true));
00511     }
00512 
00513     MOCK_METHOD0 (saveInput, bool ());
00514     MOCK_METHOD0 (removeInput, bool ());
00515     MOCK_METHOD0 (restoreInput, bool ());
00516 };
00517 
00518 TEST_F(UnityShowdesktopHandlerTest, TestShapeEvent)
00519 {
00520   MockUnityShowdesktopHandlerWindow mMockWindow;
00521 
00522   EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOutFadeInWithShapeEvent>));
00523   ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));
00524 
00525   EXPECT_CALL (mMockWindow, IsHidden ());
00526   EXPECT_CALL (mMockWindow, DoHide ());
00527   EXPECT_CALL (mMockWindow, DoNotifyHidden ());
00528 
00529   mMockHandler.FadeOut ();
00530 
00531   EXPECT_CALL (mMockWindow, DoShow ());
00532   EXPECT_CALL (mMockWindow, DoNotifyShown ());
00533 
00534   mMockHandler.HandleShapeEvent ();
00535 
00536   mMockHandler.FadeIn ();
00537 
00538   EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
00539 }