summaryrefslogtreecommitdiffstats
path: root/tests/modules/SessionManager/session_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/modules/SessionManager/session_test.cpp')
-rw-r--r--tests/modules/SessionManager/session_test.cpp79
1 files changed, 56 insertions, 23 deletions
diff --git a/tests/modules/SessionManager/session_test.cpp b/tests/modules/SessionManager/session_test.cpp
index a108cfe..3f0e0e8 100644
--- a/tests/modules/SessionManager/session_test.cpp
+++ b/tests/modules/SessionManager/session_test.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014 Canonical, Ltd.
+ * Copyright (C) 2014,2015 Canonical, Ltd.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3, as published by
@@ -15,16 +15,17 @@
*
*/
+#include <qtmir_test.h>
+#include <fake_mirsurfaceitem.h>
+
#include <Unity/Application/application.h>
#include <Unity/Application/mirsurfaceitem.h>
-#include "qtmir_test.h"
#include "stub_scene_surface.h"
using namespace qtmir;
using mir::scene::MockSession;
-
namespace ms = mir::scene;
namespace mtd = mir::test::doubles;
@@ -43,6 +44,30 @@ public:
}
};
+TEST_F(SessionTests, FromStartingToRunningOnceSurfaceDrawsFirstFrame)
+{
+ using namespace testing;
+
+ const QString appId("test-app");
+ quint64 procId = 5551;
+
+ auto mirSession = std::make_shared<MockSession>(appId.toStdString(), procId);
+
+ auto session = std::make_shared<qtmir::Session>(mirSession, mirServer->the_prompt_session_manager());
+
+ // On Starting as it has no surface.
+ EXPECT_EQ(Session::Starting, session->state());
+
+ FakeMirSurfaceItem *surface = new FakeMirSurfaceItem;
+ session->setSurface(surface);
+
+ // Still on Starting as the surface hasn't drawn its first frame yet
+ EXPECT_EQ(Session::Starting, session->state());
+
+ surface->drawFirstFrame();
+ EXPECT_EQ(Session::Running, session->state());
+}
+
TEST_F(SessionTests, AddChildSession)
{
using namespace testing;
@@ -192,17 +217,6 @@ TEST_F(SessionTests, DeleteSessionDeletesChildSessions)
EXPECT_THAT(destroyed, UnorderedElementsAre(session1, session2, session3));
}
-class MockQtMirSession : public qtmir::Session
-{
-public:
- MockQtMirSession(const std::shared_ptr<ms::Session>& session,
- const std::shared_ptr<ms::PromptSessionManager>& promptSessionManager)
- : Session(session, promptSessionManager)
- {}
-
- using SessionInterface::appendPromptSession;
-};
-
TEST_F(SessionTests, SuspendPromptSessionWhenSessionSuspends)
{
using namespace testing;
@@ -211,17 +225,25 @@ TEST_F(SessionTests, SuspendPromptSessionWhenSessionSuspends)
quint64 procId = 5551;
auto mirSession = std::make_shared<MockSession>(appId.toStdString(), procId);
- EXPECT_CALL(*mirSession, set_lifecycle_state(_));
- auto session = std::make_shared<MockQtMirSession>(mirSession, mirServer->the_prompt_session_manager());
- session->setState(Session::State::Running);
+ auto session = std::make_shared<qtmir::Session>(mirSession, mirServer->the_prompt_session_manager());
+ {
+ FakeMirSurfaceItem *surface = new FakeMirSurfaceItem;
+ session->setSurface(surface);
+ surface->drawFirstFrame();
+ }
+ EXPECT_EQ(Session::Running, session->state());
auto mirPromptSession = std::make_shared<ms::MockPromptSession>();
session->appendPromptSession(mirPromptSession);
EXPECT_CALL(*mirServer->the_mock_prompt_session_manager(), suspend_prompt_session(_)).Times(1);
- session->setState(Session::State::Suspended);
+ EXPECT_CALL(*mirSession, set_lifecycle_state(mir_lifecycle_state_will_suspend));
+ session->suspend();
+ EXPECT_EQ(Session::Suspending, session->state());
+ session->doSuspend();
+ EXPECT_EQ(Session::Suspended, session->state());
Mock::VerifyAndClear(mirServer->the_mock_prompt_session_manager().get());
}
@@ -234,18 +256,29 @@ TEST_F(SessionTests, ResumePromptSessionWhenSessionResumes)
quint64 procId = 5551;
auto mirSession = std::make_shared<MockSession>(appId.toStdString(), procId);
- EXPECT_CALL(*mirSession, set_lifecycle_state(_));
- auto session = std::make_shared<MockQtMirSession>(mirSession, mirServer->the_prompt_session_manager());
- session->setState(Session::State::Suspended);
+ auto session = std::make_shared<qtmir::Session>(mirSession, mirServer->the_prompt_session_manager());
+ {
+ FakeMirSurfaceItem *surface = new FakeMirSurfaceItem;
+ session->setSurface(surface);
+ surface->drawFirstFrame();
+ }
+ EXPECT_EQ(Session::Running, session->state());
+
+ EXPECT_CALL(*mirSession, set_lifecycle_state(mir_lifecycle_state_will_suspend));
+ session->suspend();
+ EXPECT_EQ(Session::Suspending, session->state());
+ session->doSuspend();
+ EXPECT_EQ(Session::Suspended, session->state());
auto mirPromptSession = std::make_shared<ms::MockPromptSession>();
session->appendPromptSession(mirPromptSession);
EXPECT_CALL(*mirServer->the_mock_prompt_session_manager(), resume_prompt_session(_)).Times(1);
- session->setState(Session::State::Running);
+ EXPECT_CALL(*mirSession, set_lifecycle_state(mir_lifecycle_state_resumed));
+ session->resume();
+ EXPECT_EQ(Session::Running, session->state());
Mock::VerifyAndClear(mirServer->the_mock_prompt_session_manager().get());
}
-