Back to index

unity  6.0.0
Classes | Functions
test_showdesktop_handler.cpp File Reference
#include <list>
#include <algorithm>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <UnityShowdesktopHandler.h>

Go to the source code of this file.

Classes

class  MockWindowInputRemover
class  UnityShowdesktopHandlerTest
class  MockUnityShowdesktopHandlerWindow
class  MockWindowInputRemoverTestFadeOut
class  MockWindowInputRemoverTestFadeOutAlready
class  MockWindowInputRemoverTestFadeOutFadeIn
class  MockWindowInputRemoverTestFadeOutFadeInWithShapeEvent

Functions

 TEST_F (UnityShowdesktopHandlerTest, TestNoORWindowsSD)
 TEST_F (UnityShowdesktopHandlerTest, TestNoUnmanagedWindowsSD)
 TEST_F (UnityShowdesktopHandlerTest, TestNoGrabbedWindowsSD)
 TEST_F (UnityShowdesktopHandlerTest, TestNoDesktopOrDockWindowsSD)
 TEST_F (UnityShowdesktopHandlerTest, TestNoSkipTaskbarOrPagerWindowsSD)
 TEST_F (UnityShowdesktopHandlerTest, TestHiddenNotSDAndShadedWindowsNoSD)
 TEST_F (UnityShowdesktopHandlerTest, TestHiddenSDAndShadedWindowsNoSD)
 TEST_F (UnityShowdesktopHandlerTest, TestHiddenSDAndMinimizedWindowsNoSD)
 TEST_F (UnityShowdesktopHandlerTest, TestHiddenNotSDAndNotShadedWindowsSD)
 TEST_F (UnityShowdesktopHandlerTest, TestFadeOutHidesWindow)
 TEST_F (UnityShowdesktopHandlerTest, TestFadeOutOnHiddenDoesntHideWindow)
 TEST_F (UnityShowdesktopHandlerTest, TestFadeOutAlreadyFadedDoesntHideWindow)
 TEST_F (UnityShowdesktopHandlerTest, TestFadeInNonFadedDoesntShowWindow)
 TEST_F (UnityShowdesktopHandlerTest, TestFadeOutHidesWindowFadeInShowsWindow)
 TEST_F (UnityShowdesktopHandlerTest, TestAnimationPostPaintActions)
 TEST_F (UnityShowdesktopHandlerTest, TestAnimationOpacity)
 TEST_F (UnityShowdesktopHandlerTest, TestAnimationPaintMasks)
 TEST_F (UnityShowdesktopHandlerTest, TestShapeEvent)

Function Documentation

TEST_F ( UnityShowdesktopHandlerTest  ,
TestNoORWindowsSD   
)

Definition at line 99 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsOverrideRedirect ()).WillOnce (Return (true));
  EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestNoUnmanagedWindowsSD   
)

Definition at line 109 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
  EXPECT_CALL (mMockWindow, IsManaged ()).WillOnce (Return (false));
  EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestNoGrabbedWindowsSD   
)

Definition at line 120 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
  EXPECT_CALL (mMockWindow, IsManaged ());
  EXPECT_CALL (mMockWindow, IsGrabbed ()).WillOnce (Return (true));
  EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestNoDesktopOrDockWindowsSD   
)

Definition at line 132 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
  EXPECT_CALL (mMockWindow, IsManaged ());
  EXPECT_CALL (mMockWindow, IsGrabbed ());
  EXPECT_CALL (mMockWindow, IsDesktopOrDock ()).WillOnce (Return (true));
  EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestNoSkipTaskbarOrPagerWindowsSD   
)

Definition at line 145 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
  EXPECT_CALL (mMockWindow, IsManaged ());
  EXPECT_CALL (mMockWindow, IsGrabbed ());
  EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
  EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ()).WillOnce (Return (true));
  EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestHiddenNotSDAndShadedWindowsNoSD   
)

Definition at line 159 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
  EXPECT_CALL (mMockWindow, IsManaged ());
  EXPECT_CALL (mMockWindow, IsGrabbed ());
  EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
  EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ());
  EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));
  EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (false));
  EXPECT_CALL (mMockWindow, IsShaded ()).WillOnce (Return (true));
  EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestHiddenSDAndShadedWindowsNoSD   
)

Definition at line 176 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
  EXPECT_CALL (mMockWindow, IsManaged ());
  EXPECT_CALL (mMockWindow, IsGrabbed ());
  EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
  EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ());
  EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));
  EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (true));
  EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestHiddenSDAndMinimizedWindowsNoSD   
)

Definition at line 192 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
  EXPECT_CALL (mMockWindow, IsManaged ());
  EXPECT_CALL (mMockWindow, IsGrabbed ());
  EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
  EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ());
  EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));
  EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (false));
  EXPECT_CALL (mMockWindow, IsShaded ()).WillOnce (Return (false));
  EXPECT_CALL (mMockWindow, IsMinimized ()).WillOnce (Return (true));
  EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestHiddenNotSDAndNotShadedWindowsSD   
)

Definition at line 210 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
  EXPECT_CALL (mMockWindow, IsManaged ());
  EXPECT_CALL (mMockWindow, IsGrabbed ());
  EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
  EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ());
  EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));
  EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (false));
  EXPECT_CALL (mMockWindow, IsShaded ()).WillOnce (Return (false));
  EXPECT_CALL (mMockWindow, IsMinimized ()).WillOnce (Return (false));
  EXPECT_TRUE (ShowdesktopHandler::ShouldHide (&mMockWindow));
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestFadeOutHidesWindow   
)

Definition at line 249 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOut>));

  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsHidden ());
  EXPECT_CALL (mMockWindow, DoHide ());
  EXPECT_CALL (mMockWindow, DoNotifyHidden ());

  mMockHandler.FadeOut ();

  EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestFadeOutOnHiddenDoesntHideWindow   
)

Definition at line 283 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));

  mMockHandler.FadeOut ();

  EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 0);
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestFadeOutAlreadyFadedDoesntHideWindow   
)

Definition at line 296 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOut>));
  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsHidden ());
  EXPECT_CALL (mMockWindow, DoHide ());
  EXPECT_CALL (mMockWindow, DoNotifyHidden ());

  mMockHandler.FadeOut ();
  mMockHandler.FadeOut ();

  EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestFadeInNonFadedDoesntShowWindow   
)

Definition at line 313 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  mMockHandler.FadeIn ();

  EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 0);
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestFadeOutHidesWindowFadeInShowsWindow   
)

Definition at line 345 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOutFadeIn>));
  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsHidden ());
  EXPECT_CALL (mMockWindow, DoHide ());
  EXPECT_CALL (mMockWindow, DoNotifyHidden ());

  mMockHandler.FadeOut ();

  EXPECT_CALL (mMockWindow, DoShow ());
  EXPECT_CALL (mMockWindow, DoNotifyShown ());

  mMockHandler.FadeIn ();

  EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestAnimationPostPaintActions   
)

Definition at line 366 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOutFadeIn>));
  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsHidden ());
  EXPECT_CALL (mMockWindow, DoHide ());
  EXPECT_CALL (mMockWindow, DoNotifyHidden ());

  mMockHandler.FadeOut ();

  EXPECT_CALL (mMockWindow, DoShow ());
  EXPECT_CALL (mMockWindow, DoNotifyShown ());

  for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++)
  {
    ShowdesktopHandlerWindowInterface::PostPaintAction action = mMockHandler.Animate (1);

    if (i == 300)
      EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Wait);
    else
      EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Damage);
  }

  mMockHandler.FadeIn ();

  for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++)
  {
    ShowdesktopHandlerWindowInterface::PostPaintAction action = mMockHandler.Animate (1);

    if (i == 300)
      EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Remove);
    else
      EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Damage);
  }

  EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestAnimationOpacity   
)

Definition at line 407 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOutFadeIn>));
  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsHidden ());
  EXPECT_CALL (mMockWindow, DoHide ());
  EXPECT_CALL (mMockWindow, DoNotifyHidden ());

  mMockHandler.FadeOut ();

  EXPECT_CALL (mMockWindow, DoShow ());
  EXPECT_CALL (mMockWindow, DoNotifyShown ());

  /* The funny expectations here are to account for rounding errors that would
   * otherwise make testing the code painful */

  for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++)
  {
    unsigned short opacity = std::numeric_limits <unsigned short>::max ();
    mMockHandler.PaintOpacity (opacity);

    mMockHandler.Animate (1);

    if (i == 300)
      EXPECT_EQ (opacity, std::numeric_limits <unsigned short>::max ());
    else
    {
      float rem = opacity - std::numeric_limits <unsigned short>::max () * (1.0f - i / static_cast <float> (ShowdesktopHandler::fade_time));
      EXPECT_TRUE (rem <= 1.0f && rem >= -1.0f);
    }
  }

  mMockHandler.FadeIn ();

  for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++)
  {
    unsigned short opacity = std::numeric_limits <unsigned short>::max ();
    mMockHandler.PaintOpacity (opacity);

    mMockHandler.Animate (1);

    if (i == 300)
      EXPECT_EQ (opacity, std::numeric_limits <unsigned short>::max ());
    else
    {
      float rem = opacity - std::numeric_limits <unsigned short>::max () * (i / static_cast <float> (ShowdesktopHandler::fade_time));
      EXPECT_TRUE (rem <= 1.0f && rem >= -1.0f);
    }
  }

  EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestAnimationPaintMasks   
)

Definition at line 463 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOutFadeIn>));
  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsHidden ());
  EXPECT_CALL (mMockWindow, DoHide ());
  EXPECT_CALL (mMockWindow, DoNotifyHidden ());

  mMockHandler.FadeOut ();

  EXPECT_CALL (mMockWindow, DoShow ());
  EXPECT_CALL (mMockWindow, DoNotifyShown ());
  EXPECT_CALL (mMockWindow, GetNoCoreInstanceMask ());

  mMockHandler.Animate (ShowdesktopHandler::fade_time);

  EXPECT_EQ (mMockHandler.GetPaintMask (), 1);

  mMockHandler.FadeIn ();

  mMockHandler.Animate (ShowdesktopHandler::fade_time);

  EXPECT_EQ (mMockHandler.GetPaintMask (), 0);

  EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
}

Here is the call graph for this function:

TEST_F ( UnityShowdesktopHandlerTest  ,
TestShapeEvent   
)

Definition at line 518 of file test_showdesktop_handler.cpp.

{
  MockUnityShowdesktopHandlerWindow mMockWindow;

  EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::getLock <MockWindowInputRemoverTestFadeOutFadeInWithShapeEvent>));
  ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow), static_cast <compiz::WindowInputRemoverLockAcquireInterface *> (&mMockWindow));

  EXPECT_CALL (mMockWindow, IsHidden ());
  EXPECT_CALL (mMockWindow, DoHide ());
  EXPECT_CALL (mMockWindow, DoNotifyHidden ());

  mMockHandler.FadeOut ();

  EXPECT_CALL (mMockWindow, DoShow ());
  EXPECT_CALL (mMockWindow, DoNotifyShown ());

  mMockHandler.HandleShapeEvent ();

  mMockHandler.FadeIn ();

  EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
}

Here is the call graph for this function: