Mir

Merge lp:~nick-dedekind/mir/1355173.trust-prompt-suspend into lp:mir

Proposed by Nick Dedekind
Status: Merged
Approved by: Alberto Aguirre
Approved revision: no longer in the source branch.
Merged at revision: 2167
Proposed branch: lp:~nick-dedekind/mir/1355173.trust-prompt-suspend
Merge into: lp:mir
Diff against target: 860 lines (+445/-45)
26 files modified
client-ABI-sha1sums (+1/-1)
common-ABI-sha1sums (+1/-1)
include/common/mir_toolkit/common.h (+2/-1)
include/server/mir/scene/prompt_session.h (+24/-0)
include/server/mir/scene/prompt_session_listener.h (+2/-0)
include/server/mir/scene/prompt_session_manager.h (+12/-0)
include/server/mir/scene/session.h (+2/-0)
platform-ABI-sha1sums (+1/-1)
server-ABI-sha1sums (+5/-5)
src/include/server/mir/scene/null_prompt_session_listener.h (+2/-0)
src/server/scene/CMakeLists.txt (+1/-0)
src/server/scene/application_session.cpp (+18/-0)
src/server/scene/application_session.h (+2/-0)
src/server/scene/prompt_session_impl.cpp (+81/-0)
src/server/scene/prompt_session_impl.h (+50/-0)
src/server/scene/prompt_session_manager_impl.cpp (+22/-9)
src/server/scene/prompt_session_manager_impl.h (+6/-0)
tests/acceptance-tests/test_prompt_session_client_api.cpp (+53/-24)
tests/include/mir_test_doubles/mock_prompt_session_listener.h (+2/-0)
tests/include/mir_test_doubles/mock_scene_session.h (+2/-0)
tests/include/mir_test_doubles/null_prompt_session.h (+16/-0)
tests/include/mir_test_doubles/null_prompt_session_manager.h (+8/-0)
tests/include/mir_test_doubles/stub_scene_session.h (+8/-0)
tests/unit-tests/scene/CMakeLists.txt (+1/-0)
tests/unit-tests/scene/test_prompt_session_impl.cpp (+110/-0)
tests/unit-tests/scene/test_prompt_session_manager.cpp (+13/-3)
To merge this branch: bzr merge lp:~nick-dedekind/mir/1355173.trust-prompt-suspend
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alberto Aguirre (community) Approve
Alan Griffiths Approve
Cemil Azizoglu (community) Approve
Review via email: mp+241588@code.launchpad.net

Commit message

Add support for suspending and resuming trust prompts

Description of the change

Add support for suspending trust prompts

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

51 virtual void start_prompt_session() = 0;
52 virtual void stop_prompt_session() = 0;
53 + virtual void suspend_prompt_session(bool suspended) = 0;

It would be consistent with the existing interface to have:

    void suspend_prompt_session() = 0;
    void resume_prompt_session() = 0;

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

No acceptance tests

~~~~

No unit tests

~~~~

186 + std::mutex mutable guard;
187 + MirPromptSessionState m_state;

The "m_" wart belongs to another project.

And we don't really need a mutex. Vis:

    std::atomic<MirPromptSessionState> state;

~~~~

143 === added file 'src/server/scene/prompt_session_impl.h'

Really, why not just add a "std::atomic<MirPromptSessionState> state{mir_prompt_session_state_stopped};" member to scene::PromptSession?

If you're probably intending some logic in some implementation of PromptSession somewhere the that would be better supported by telling the prompt sesson the transitions, not setting the states; vis:

    void start();
    void stop();
    void suspend();
    void resume();

~~~~

224 + if (suspended && prompt_session->state() == mir_prompt_session_state_started)
225 + {
226 + prompt_session->set_state(mir_prompt_session_state_suspended);
227 + }
228 + else if (!suspended && prompt_session->state() == mir_prompt_session_state_suspended)
229 + {
230 + prompt_session->set_state(mir_prompt_session_state_started);

1. It would also be be easier to follow the code without the boolean parameter (separate functions for suspend and resume or a MirPromptSessionState parameter).

2. This code looks racy:

nothing prevents the state being changed between "prompt_session->state()" and "prompt_session->set_state(mir_prompt_session_state_suspended)"

If logic depends on current and future state then it belings in a transition method in the object that holds the mutex locked.

~~~~

290 +
...
297 +

Spurious whitespace.

review: Needs Fixing
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

What Alan said :)

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

565 +#include "mir_test_doubles/mock_scene_session.h"
...
573 - std::shared_ptr<ms::Session> const helper{std::make_shared<mtd::StubSceneSession>(helper_pid)};
574 + std::shared_ptr<mtd::MockSceneSession> const helper{std::make_shared<::testing::NiceMock<mtd::MockSceneSession>>()};
...
582 + ON_CALL(*helper, process_id()).WillByDefault(Return(helper_pid));
583 +
...
591 + EXPECT_CALL(*helper, start_prompt_session()).Times(1);
...
596 + EXPECT_CALL(*helper, stop_prompt_session()).Times(1);
...
608 + EXPECT_CALL(*helper, suspend_prompt_session()).Times(1);
...
613 + EXPECT_CALL(*helper, resume_prompt_session()).Times(1);

Do these additional expectations actually add anything?

If they do, then wny do we need:

618 + // Need to verify explicitly as we see unmatched callbacks during teardown of fixture
619 + Mock::VerifyAndClearExpectations(&prompt_session_listener);

and not a similar verification for helper?

review: Needs Information
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

No acceptance tests

This is, after all, a feature we are expected to support.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

Needs fixing:

Missing acceptance tests - I suppose something similar to:
"TEST_F(PromptSessionClientAPI, notifies_start_and_stop)"

===
733 + // Need to verify explicitly as we see unmatched callbacks during teardown of fixture
734 + Mock::VerifyAndClearExpectations(&prompt_session_listener);
===
Not needed.

===
716 // Need to verify explicitly as we see unmatched callbacks during teardown of fixture
717 Mock::VerifyAndClearExpectations(&prompt_session_listener);
===
Pre-existing, but not needed either.

===
198 + std::unique_lock<std::mutex> lk(guard);
210 + std::unique_lock<std::mutex> lk(guard);
222 + std::unique_lock<std::mutex> lk(guard);
234 + std::unique_lock<std::mutex> lk(guard);
===
Prefer std::lock_guard<std::mutex> as no features of unique_lock are used.

===
605 +TEST_F(PromptSession, start_prompt_session_when_stopped)
616 +TEST_F(PromptSession, stop_prompt_session_when_started)
628 +TEST_F(PromptSession, suspend_prompt_session_when_started)
640 +TEST_F(PromptSession, suspend_prompt_session_fails_to_stop_helper_when_not_started)
650 +TEST_F(PromptSession, resume_prompt_session_when_suspended)
663 +TEST_F(PromptSession, resume_prompt_session_fails_to_stop_helper_when_not_started)
===
Redundant prompt_session in test case name
Perhaps something like:

TEST_F(PromptSession, can_start)
TEST_F(PromptSession, can_stop)
TEST_F(PromptSession, can_suspend)
TEST_F(PromptSession, fails_to_suspend_if_not_in_started_state)
TEST_F(PromptSession, can_resume)
TEST_F(PromptSession, fails_to_resume_if_in_stopped_state)

===
204 + helper_session->start_prompt_session();
===
e. al. Do you need to keep the mutex locked while making these calls? Preferably, unlock the mutex before making them (in which case disregard the suggestion for std::lock_guard above).

review: Needs Fixing
Revision history for this message
Robert Carr (robertcarr) wrote :

No action in a while...whats up?

Revision history for this message
Gerry Boland (gerboland) wrote :

He's on hols this week

Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> Needs fixing:
>
> Missing acceptance tests - I suppose something similar to:
> "TEST_F(PromptSessionClientAPI, notifies_start_and_stop)"
>
>
> ===
> 733 + // Need to verify explicitly as we see unmatched callbacks during
> teardown of fixture
> 734 + Mock::VerifyAndClearExpectations(&prompt_session_listener);
> ===
> Not needed.
>
> ===
> 716 // Need to verify explicitly as we see unmatched callbacks during
> teardown of fixture
> 717 Mock::VerifyAndClearExpectations(&prompt_session_listener);
> ===
> Pre-existing, but not needed either.
>
> ===
> 198 + std::unique_lock<std::mutex> lk(guard);
> 210 + std::unique_lock<std::mutex> lk(guard);
> 222 + std::unique_lock<std::mutex> lk(guard);
> 234 + std::unique_lock<std::mutex> lk(guard);
> ===
> Prefer std::lock_guard<std::mutex> as no features of unique_lock are used.
>
> ===
> 605 +TEST_F(PromptSession, start_prompt_session_when_stopped)
> 616 +TEST_F(PromptSession, stop_prompt_session_when_started)
> 628 +TEST_F(PromptSession, suspend_prompt_session_when_started)
> 640 +TEST_F(PromptSession,
> suspend_prompt_session_fails_to_stop_helper_when_not_started)
> 650 +TEST_F(PromptSession, resume_prompt_session_when_suspended)
> 663 +TEST_F(PromptSession,
> resume_prompt_session_fails_to_stop_helper_when_not_started)
> ===
> Redundant prompt_session in test case name
> Perhaps something like:
>
> TEST_F(PromptSession, can_start)
> TEST_F(PromptSession, can_stop)
> TEST_F(PromptSession, can_suspend)
> TEST_F(PromptSession, fails_to_suspend_if_not_in_started_state)
> TEST_F(PromptSession, can_resume)
> TEST_F(PromptSession, fails_to_resume_if_in_stopped_state)

Done.

>
> ===
> 204 + helper_session->start_prompt_session();
> ===
> e. al. Do you need to keep the mutex locked while making these calls?
> Preferably, unlock the mutex before making them (in which case disregard the
> suggestion for std::lock_guard above).

If we don't then we can end up interleaving calls to start/stop/suspend.

Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> 565 +#include "mir_test_doubles/mock_scene_session.h"
> ...
> 573 - std::shared_ptr<ms::Session> const
> helper{std::make_shared<mtd::StubSceneSession>(helper_pid)};
> 574 + std::shared_ptr<mtd::MockSceneSession> const
> helper{std::make_shared<::testing::NiceMock<mtd::MockSceneSession>>()};
> ...
> 582 + ON_CALL(*helper, process_id()).WillByDefault(Return(helper_pid));
> 583 +
> ...
> 591 + EXPECT_CALL(*helper, start_prompt_session()).Times(1);
> ...
> 596 + EXPECT_CALL(*helper, stop_prompt_session()).Times(1);
> ...
> 608 + EXPECT_CALL(*helper, suspend_prompt_session()).Times(1);
> ...
> 613 + EXPECT_CALL(*helper, resume_prompt_session()).Times(1);
>
> Do these additional expectations actually add anything?

Only the fact that the helper should be acted on; although this is covered by the acceptance tests, so I've removed it.

>
> If they do, then wny do we need:
>
> 618 + // Need to verify explicitly as we see unmatched callbacks during
> teardown of fixture
> 619 + Mock::VerifyAndClearExpectations(&prompt_session_listener);
>
> and not a similar verification for helper?

I've removed that VerifyAndClearExpectations. I think there used to be some issue with the teardown, but can't remember it now.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

The following tests FAILED:
   3 - server-ABI-unchanged (Failed)
   4 - client-ABI-unchanged (Failed)
   5 - common-ABI-unchanged (Failed)
   6 - platform-ABI-unchanged (Failed)

You need to run tools/update-all-ABI-sha1sums.sh

review: Needs Fixing
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> The following tests FAILED:
> 3 - server-ABI-unchanged (Failed)
> 4 - client-ABI-unchanged (Failed)
> 5 - common-ABI-unchanged (Failed)
> 6 - platform-ABI-unchanged (Failed)
>
> You need to run tools/update-all-ABI-sha1sums.sh

done.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> 880 lines (+461/-41) 26 files modified (has conflicts)
>
> Text conflict in client-ABI-sha1sums
> Text conflict in common-ABI-sha1sums
> Text conflict in platform-ABI-sha1sums
> Text conflict in server-ABI-sha1sums

You need to sync to trunk and run tools/update-all-ABI-sha1sums.sh

(This project is cursed with checksum files that cause more work than they prevent.)

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> > 880 lines (+461/-41) 26 files modified (has conflicts)
> >
> > Text conflict in client-ABI-sha1sums
> > Text conflict in common-ABI-sha1sums
> > Text conflict in platform-ABI-sha1sums
> > Text conflict in server-ABI-sha1sums
>
> You need to sync to trunk and run tools/update-all-ABI-sha1sums.sh
>
> (This project is cursed with checksum files that cause more work than they
> prevent.)

Bit of a struggle. Hopefully fixed now!

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

271 + if (helper_session)
272 + helper_session->start_prompt_session();

I wonder if is it meaningful for helper_session to be null? As the helper "owns" the trust session it really should exist. Hiding the fact that it doesn't will only lead to obscure behavior.

I guess this should be a postcondition check in PromptSessionManagerImpl::helper_for() though.

review: Needs Information
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

255 +#include <mir/scene/session.h>

Wrong include style for current project.

review: Needs Fixing
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Oh, and the checksums are out of step once more.

Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

LGTM.

review: Approve
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> 255 +#include <mir/scene/session.h>
>
> Wrong include style for current project.

Done and fixed sums.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

OK

review: Approve
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

LGTM.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

^-- Seems like a spurious failure:
8: [ FAILED ] 1 test, listed below:
8: [ FAILED ] TestClientInput.hidden_clients_do_not_receive_pointer_events

Let's try again.

Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client-ABI-sha1sums'
2--- client-ABI-sha1sums 2014-12-15 06:24:03 +0000
3+++ client-ABI-sha1sums 2014-12-17 12:06:59 +0000
4@@ -10,7 +10,7 @@
5 b141c4d79802ad626d969249c0004744e5c2a525 include/client/mir_toolkit/mir_wait.h
6 c367f5c9285936820fbd50961827d6ce58fb7ff4 include/client/mir_toolkit/version.h
7 23a009b06de7bac17d33d988dc8d968be8bc094a include/common/mir_toolkit/client_types.h
8-3e85c6d9dd1dca9767ea8bdf13ea6bbd1cb11c30 include/common/mir_toolkit/common.h
9+c7c708734715a6d1b6fb2652584adb912071a518 include/common/mir_toolkit/common.h
10 fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h
11 d71dddf6c4275ee423d3e0fa204e3b77b4d87401 include/common/mir_toolkit/event.h
12 49403c824f69fa1cc1f58bf5fe635639148765eb include/common/mir_toolkit/input/input_event.h
13
14=== modified file 'common-ABI-sha1sums'
15--- common-ABI-sha1sums 2014-12-15 06:24:03 +0000
16+++ common-ABI-sha1sums 2014-12-17 12:06:59 +0000
17@@ -16,7 +16,7 @@
18 5ab81600183fdaca3fb949beb2307d1f6e4cbb61 include/common/mir/log.h
19 9ae8473df05dd9e048a73797f01a2f34f7447554 include/common/mir/time/types.h
20 23a009b06de7bac17d33d988dc8d968be8bc094a include/common/mir_toolkit/client_types.h
21-3e85c6d9dd1dca9767ea8bdf13ea6bbd1cb11c30 include/common/mir_toolkit/common.h
22+c7c708734715a6d1b6fb2652584adb912071a518 include/common/mir_toolkit/common.h
23 fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h
24 d71dddf6c4275ee423d3e0fa204e3b77b4d87401 include/common/mir_toolkit/event.h
25 49403c824f69fa1cc1f58bf5fe635639148765eb include/common/mir_toolkit/input/input_event.h
26
27=== modified file 'include/common/mir_toolkit/common.h'
28--- include/common/mir_toolkit/common.h 2014-12-09 03:14:55 +0000
29+++ include/common/mir_toolkit/common.h 2014-12-17 12:06:59 +0000
30@@ -109,7 +109,8 @@
31 typedef enum MirPromptSessionState
32 {
33 mir_prompt_session_state_stopped = 0,
34- mir_prompt_session_state_started
35+ mir_prompt_session_state_started,
36+ mir_prompt_session_state_suspended
37 } MirPromptSessionState;
38
39 /**
40
41=== modified file 'include/server/mir/scene/prompt_session.h'
42--- include/server/mir/scene/prompt_session.h 2014-06-12 10:24:08 +0000
43+++ include/server/mir/scene/prompt_session.h 2014-12-17 12:06:59 +0000
44@@ -29,6 +29,30 @@
45
46 class PromptSession : public frontend::PromptSession
47 {
48+public:
49+ /**
50+ * Start a prompt session
51+ * \param [in] helper The prompt session helper session
52+ */
53+ virtual void start(std::shared_ptr<Session> const& helper_session) = 0;
54+
55+ /**
56+ * Stop a prompt session
57+ * \param [in] helper The prompt session helper session
58+ */
59+ virtual void stop(std::shared_ptr<Session> const& helper_session) = 0;
60+
61+ /**
62+ * Suspend a prompt session
63+ * \param [in] helper The prompt session helper session
64+ */
65+ virtual void suspend(std::shared_ptr<Session> const& helper_session) = 0;
66+
67+ /**
68+ * Resume a prompt session
69+ * \param [in] helper The prompt session helper session
70+ */
71+ virtual void resume(std::shared_ptr<Session> const& helper_session) = 0;
72 };
73
74 }
75
76=== modified file 'include/server/mir/scene/prompt_session_listener.h'
77--- include/server/mir/scene/prompt_session_listener.h 2014-06-12 10:06:11 +0000
78+++ include/server/mir/scene/prompt_session_listener.h 2014-12-17 12:06:59 +0000
79@@ -33,6 +33,8 @@
80 public:
81 virtual void starting(std::shared_ptr<PromptSession> const& prompt_session) = 0;
82 virtual void stopping(std::shared_ptr<PromptSession> const& prompt_session) = 0;
83+ virtual void suspending(std::shared_ptr<PromptSession> const& prompt_session) = 0;
84+ virtual void resuming(std::shared_ptr<PromptSession> const& prompt_session) = 0;
85
86 virtual void prompt_provider_added(PromptSession const& prompt_session, std::shared_ptr<Session> const& prompt_provider) = 0;
87 virtual void prompt_provider_removed(PromptSession const& prompt_session, std::shared_ptr<Session> const& prompt_provider) = 0;
88
89=== modified file 'include/server/mir/scene/prompt_session_manager.h'
90--- include/server/mir/scene/prompt_session_manager.h 2014-12-08 04:03:47 +0000
91+++ include/server/mir/scene/prompt_session_manager.h 2014-12-17 12:06:59 +0000
92@@ -51,6 +51,18 @@
93 virtual void stop_prompt_session(std::shared_ptr<PromptSession> const& prompt_session) const = 0;
94
95 /**
96+ * Suspend a prompt session
97+ * \param [in] prompt_session The prompt session
98+ */
99+ virtual void suspend_prompt_session(std::shared_ptr<PromptSession> const& prompt_session) const = 0;
100+
101+ /**
102+ * Resume a suspended prompt session
103+ * \param [in] prompt_session The prompt session
104+ */
105+ virtual void resume_prompt_session(std::shared_ptr<PromptSession> const& prompt_session) const = 0;
106+
107+ /**
108 * Add a prompt provider to an existing prompt session
109 * \param [in] prompt_session The prompt session
110 * \param [in] prompt_provider The prompt provider to add to the prompt session
111
112=== modified file 'include/server/mir/scene/session.h'
113--- include/server/mir/scene/session.h 2014-12-08 04:03:47 +0000
114+++ include/server/mir/scene/session.h 2014-12-17 12:06:59 +0000
115@@ -43,6 +43,8 @@
116
117 virtual void start_prompt_session() = 0;
118 virtual void stop_prompt_session() = 0;
119+ virtual void suspend_prompt_session() = 0;
120+ virtual void resume_prompt_session() = 0;
121 };
122 }
123 }
124
125=== modified file 'platform-ABI-sha1sums'
126--- platform-ABI-sha1sums 2014-12-15 06:24:03 +0000
127+++ platform-ABI-sha1sums 2014-12-17 12:06:59 +0000
128@@ -16,7 +16,7 @@
129 5ab81600183fdaca3fb949beb2307d1f6e4cbb61 include/common/mir/log.h
130 9ae8473df05dd9e048a73797f01a2f34f7447554 include/common/mir/time/types.h
131 23a009b06de7bac17d33d988dc8d968be8bc094a include/common/mir_toolkit/client_types.h
132-3e85c6d9dd1dca9767ea8bdf13ea6bbd1cb11c30 include/common/mir_toolkit/common.h
133+c7c708734715a6d1b6fb2652584adb912071a518 include/common/mir_toolkit/common.h
134 fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h
135 d71dddf6c4275ee423d3e0fa204e3b77b4d87401 include/common/mir_toolkit/event.h
136 49403c824f69fa1cc1f58bf5fe635639148765eb include/common/mir_toolkit/input/input_event.h
137
138=== modified file 'server-ABI-sha1sums'
139--- server-ABI-sha1sums 2014-12-16 09:43:53 +0000
140+++ server-ABI-sha1sums 2014-12-17 12:06:59 +0000
141@@ -16,7 +16,7 @@
142 5ab81600183fdaca3fb949beb2307d1f6e4cbb61 include/common/mir/log.h
143 9ae8473df05dd9e048a73797f01a2f34f7447554 include/common/mir/time/types.h
144 23a009b06de7bac17d33d988dc8d968be8bc094a include/common/mir_toolkit/client_types.h
145-3e85c6d9dd1dca9767ea8bdf13ea6bbd1cb11c30 include/common/mir_toolkit/common.h
146+c7c708734715a6d1b6fb2652584adb912071a518 include/common/mir_toolkit/common.h
147 fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h
148 d71dddf6c4275ee423d3e0fa204e3b77b4d87401 include/common/mir_toolkit/event.h
149 49403c824f69fa1cc1f58bf5fe635639148765eb include/common/mir_toolkit/input/input_event.h
150@@ -79,11 +79,11 @@
151 d5273f3363b0b776427d5e3f1af99f0f2bcf3fa6 include/server/mir/scene/observer.h
152 10db25fbaefcabb3b191177ed70f5972df7f05f0 include/server/mir/scene/placement_strategy.h
153 74f7f66ffc3e15c428082fb961e748cb4f39dafc include/server/mir/scene/prompt_session_creation_parameters.h
154-4e8269c822ad2daddd92115cbe5332caaa9ef4cc include/server/mir/scene/prompt_session.h
155-79adf11e2b1778897ed97d1713ba4c3d34eb1f31 include/server/mir/scene/prompt_session_listener.h
156-27f614f98ad7c249d9b12dcca30a324220cdd25b include/server/mir/scene/prompt_session_manager.h
157+b657cfb8fb31140b83b78fc19135dd0165ede67b include/server/mir/scene/prompt_session.h
158+a745a63d413ced63b82350b8c253b65dffd5bf44 include/server/mir/scene/prompt_session_listener.h
159+a09a3f18ecea53dc45386c1e2baf545c4177c047 include/server/mir/scene/prompt_session_manager.h
160 5edf446380070f567500069e422d293e88468ee5 include/server/mir/scene/session_coordinator.h
161-f148a69caa39756d43cfaf7cc868ad681bda9ef6 include/server/mir/scene/session.h
162+cf13a79b20acf9e53db6e0078df085b9a023d8da include/server/mir/scene/session.h
163 ee94083f10f890e24c0e0bbdb94842e2dd788deb include/server/mir/scene/session_listener.h
164 7f5f26000fd2312373817d05c488a6a950a47c82 include/server/mir/scene/snapshot.h
165 5bab4dc0a6488b8b9d47e958c6bab94f1dcf2c57 include/server/mir/scene/surface_buffer_access.h
166
167=== modified file 'src/include/server/mir/scene/null_prompt_session_listener.h'
168--- src/include/server/mir/scene/null_prompt_session_listener.h 2014-12-08 04:03:47 +0000
169+++ src/include/server/mir/scene/null_prompt_session_listener.h 2014-12-17 12:06:59 +0000
170@@ -30,6 +30,8 @@
171 public:
172 void starting(std::shared_ptr<PromptSession> const&) override {}
173 void stopping(std::shared_ptr<PromptSession> const&) override {}
174+ void suspending(std::shared_ptr<PromptSession> const&) override {}
175+ void resuming(std::shared_ptr<PromptSession> const&) override {}
176
177 void prompt_provider_added(PromptSession const&, std::shared_ptr<Session> const&) override {}
178 void prompt_provider_removed(PromptSession const&, std::shared_ptr<Session> const&) override {}
179
180=== modified file 'src/server/scene/CMakeLists.txt'
181--- src/server/scene/CMakeLists.txt 2014-12-08 04:03:47 +0000
182+++ src/server/scene/CMakeLists.txt 2014-12-17 12:06:59 +0000
183@@ -21,6 +21,7 @@
184 legacy_scene_change_notification.cpp
185 legacy_surface_change_notification.cpp
186 prompt_session_container.cpp
187+ prompt_session_impl.cpp
188 prompt_session_manager_impl.cpp
189 rendering_tracker.cpp
190 default_coordinate_translator.cpp
191
192=== modified file 'src/server/scene/application_session.cpp'
193--- src/server/scene/application_session.cpp 2014-12-08 04:03:47 +0000
194+++ src/server/scene/application_session.cpp 2014-12-17 12:06:59 +0000
195@@ -202,3 +202,21 @@
196 stop_event.prompt_session.new_state = mir_prompt_session_state_stopped;
197 event_sink->handle_event(stop_event);
198 }
199+
200+void ms::ApplicationSession::suspend_prompt_session()
201+{
202+ MirEvent start_event;
203+ memset(&start_event, 0, sizeof start_event);
204+ start_event.type = mir_event_type_prompt_session_state_change;
205+ start_event.prompt_session.new_state = mir_prompt_session_state_suspended;
206+ event_sink->handle_event(start_event);
207+}
208+
209+void ms::ApplicationSession::resume_prompt_session()
210+{
211+ MirEvent start_event;
212+ memset(&start_event, 0, sizeof start_event);
213+ start_event.type = mir_event_type_prompt_session_state_change;
214+ start_event.prompt_session.new_state = mir_prompt_session_state_started;
215+ event_sink->handle_event(start_event);
216+}
217
218=== modified file 'src/server/scene/application_session.h'
219--- src/server/scene/application_session.h 2014-12-08 04:03:47 +0000
220+++ src/server/scene/application_session.h 2014-12-17 12:06:59 +0000
221@@ -73,6 +73,8 @@
222
223 void start_prompt_session() override;
224 void stop_prompt_session() override;
225+ void suspend_prompt_session() override;
226+ void resume_prompt_session() override;
227
228 protected:
229 ApplicationSession(ApplicationSession const&) = delete;
230
231=== added file 'src/server/scene/prompt_session_impl.cpp'
232--- src/server/scene/prompt_session_impl.cpp 1970-01-01 00:00:00 +0000
233+++ src/server/scene/prompt_session_impl.cpp 2014-12-17 12:06:59 +0000
234@@ -0,0 +1,81 @@
235+/*
236+ * Copyright © 2014 Canonical Ltd.
237+ *
238+ * This program is free software: you can redistribute it and/or modify it
239+ * under the terms of the GNU General Public License version 3,
240+ * as published by the Free Software Foundation.
241+ *
242+ * This program is distributed in the hope that it will be useful,
243+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
244+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
245+ * GNU General Public License for more details.
246+ *
247+ * You should have received a copy of the GNU General Public License
248+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
249+ *
250+ * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
251+ */
252+
253+#include "prompt_session_impl.h"
254+
255+#include "mir/scene/session.h"
256+
257+namespace ms = mir::scene;
258+
259+ms::PromptSessionImpl::PromptSessionImpl() :
260+ current_state(mir_prompt_session_state_stopped)
261+{
262+}
263+
264+void ms::PromptSessionImpl::start(std::shared_ptr<Session> const& helper_session)
265+{
266+ std::lock_guard<std::mutex> lk(guard);
267+
268+ if (current_state == mir_prompt_session_state_stopped)
269+ {
270+ current_state = mir_prompt_session_state_started;
271+ if (helper_session)
272+ helper_session->start_prompt_session();
273+ }
274+}
275+
276+void ms::PromptSessionImpl::stop(std::shared_ptr<Session> const& helper_session)
277+{
278+ std::lock_guard<std::mutex> lk(guard);
279+
280+ if (current_state != mir_prompt_session_state_stopped)
281+ {
282+ current_state = mir_prompt_session_state_stopped;
283+ if (helper_session)
284+ helper_session->stop_prompt_session();
285+ }
286+}
287+
288+void ms::PromptSessionImpl::suspend(std::shared_ptr<Session> const& helper_session)
289+{
290+ std::lock_guard<std::mutex> lk(guard);
291+
292+ if (current_state == mir_prompt_session_state_started)
293+ {
294+ current_state = mir_prompt_session_state_suspended;
295+ if (helper_session)
296+ helper_session->suspend_prompt_session();
297+ }
298+}
299+
300+void ms::PromptSessionImpl::resume(std::shared_ptr<Session> const& helper_session)
301+{
302+ std::lock_guard<std::mutex> lk(guard);
303+
304+ if (current_state == mir_prompt_session_state_suspended)
305+ {
306+ current_state = mir_prompt_session_state_started;
307+ if (helper_session)
308+ helper_session->resume_prompt_session();
309+ }
310+}
311+
312+MirPromptSessionState ms::PromptSessionImpl::state() const
313+{
314+ return current_state;
315+}
316
317=== added file 'src/server/scene/prompt_session_impl.h'
318--- src/server/scene/prompt_session_impl.h 1970-01-01 00:00:00 +0000
319+++ src/server/scene/prompt_session_impl.h 2014-12-17 12:06:59 +0000
320@@ -0,0 +1,50 @@
321+/*
322+ * Copyright © 2014 Canonical Ltd.
323+ *
324+ * This program is free software: you can redistribute it and/or modify it
325+ * under the terms of the GNU General Public License version 3,
326+ * as published by the Free Software Foundation.
327+ *
328+ * This program is distributed in the hope that it will be useful,
329+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
330+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
331+ * GNU General Public License for more details.
332+ *
333+ * You should have received a copy of the GNU General Public License
334+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
335+ *
336+ * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
337+ */
338+
339+#ifndef MIR_SCENE_PROMPT_SESSION_IMPL_H_
340+#define MIR_SCENE_PROMPT_SESSION_IMPL_H_
341+
342+#include "mir/scene/prompt_session.h"
343+
344+#include <mutex>
345+
346+namespace mir
347+{
348+namespace scene
349+{
350+
351+class PromptSessionImpl : public scene::PromptSession
352+{
353+public:
354+ explicit PromptSessionImpl();
355+
356+ void start(std::shared_ptr<Session> const& helper_session) override;
357+ void stop(std::shared_ptr<Session> const& helper_session) override;
358+ void suspend(std::shared_ptr<Session> const& helper_session) override;
359+ void resume(std::shared_ptr<Session> const& helper_session) override;
360+
361+ MirPromptSessionState state() const;
362+
363+private:
364+ std::mutex mutable guard;
365+ MirPromptSessionState current_state;
366+};
367+}
368+}
369+
370+#endif // MIR_SCENE_PROMPT_SESSION_IMPL_H_
371
372=== modified file 'src/server/scene/prompt_session_manager_impl.cpp'
373--- src/server/scene/prompt_session_manager_impl.cpp 2014-12-08 04:03:47 +0000
374+++ src/server/scene/prompt_session_manager_impl.cpp 2014-12-17 12:06:59 +0000
375@@ -21,9 +21,9 @@
376 #include "mir/scene/prompt_session_creation_parameters.h"
377 #include "mir/scene/prompt_session_listener.h"
378 #include "mir/scene/session.h"
379-#include "mir/scene/prompt_session.h"
380 #include "session_container.h"
381 #include "prompt_session_container.h"
382+#include "prompt_session_impl.h"
383
384 namespace ms = mir::scene;
385
386@@ -45,12 +45,7 @@
387 prompt_session_container->for_each_participant_in_prompt_session(prompt_session.get(),
388 [&](std::weak_ptr<Session> const& session, PromptSessionContainer::ParticipantType type)
389 {
390- if (type == PromptSessionContainer::ParticipantType::helper)
391- {
392- if (auto locked_session = session.lock())
393- locked_session->stop_prompt_session();
394- }
395- else if (type == PromptSessionContainer::ParticipantType::prompt_provider)
396+ if (type == PromptSessionContainer::ParticipantType::prompt_provider)
397 {
398 if (auto locked_session = session.lock())
399 participants.push_back(locked_session);
400@@ -63,6 +58,8 @@
401 prompt_session_listener->prompt_provider_removed(*prompt_session, participant);
402 }
403
404+ prompt_session->stop(helper_for(prompt_session));
405+
406 prompt_session_container->remove_prompt_session(prompt_session);
407
408 prompt_session_listener->stopping(prompt_session);
409@@ -104,11 +101,27 @@
410 stop_prompt_session_locked(lock, prompt_session);
411 }
412
413+void ms::PromptSessionManagerImpl::suspend_prompt_session(std::shared_ptr<PromptSession> const& prompt_session) const
414+{
415+ std::lock_guard<std::mutex> lock(prompt_sessions_mutex);
416+
417+ prompt_session->suspend(helper_for(prompt_session));
418+ prompt_session_listener->suspending(prompt_session);
419+}
420+
421+void ms::PromptSessionManagerImpl::resume_prompt_session(std::shared_ptr<PromptSession> const& prompt_session) const
422+{
423+ std::lock_guard<std::mutex> lock(prompt_sessions_mutex);
424+
425+ prompt_session->resume(helper_for(prompt_session));
426+ prompt_session_listener->resuming(prompt_session);
427+}
428+
429 std::shared_ptr<ms::PromptSession> ms::PromptSessionManagerImpl::start_prompt_session_for(
430 std::shared_ptr<Session> const& session,
431 PromptSessionCreationParameters const& params) const
432 {
433- auto prompt_session = std::make_shared<PromptSession>();
434+ auto prompt_session = std::make_shared<PromptSessionImpl>();
435 std::shared_ptr<Session> application_session;
436
437 app_container->for_each(
438@@ -129,7 +142,7 @@
439 if (!prompt_session_container->insert_participant(prompt_session.get(), session, PromptSessionContainer::ParticipantType::helper))
440 BOOST_THROW_EXCEPTION(std::runtime_error("Could not set prompt session helper"));
441
442- session->start_prompt_session();
443+ prompt_session->start(session);
444 prompt_session_listener->starting(prompt_session);
445
446 prompt_session_container->insert_participant(prompt_session.get(), application_session, PromptSessionContainer::ParticipantType::application);
447
448=== modified file 'src/server/scene/prompt_session_manager_impl.h'
449--- src/server/scene/prompt_session_manager_impl.h 2014-12-08 04:03:47 +0000
450+++ src/server/scene/prompt_session_manager_impl.h 2014-12-17 12:06:59 +0000
451@@ -50,6 +50,12 @@
452 void stop_prompt_session(
453 std::shared_ptr<PromptSession> const& prompt_session) const override;
454
455+ void suspend_prompt_session(
456+ std::shared_ptr<PromptSession> const& prompt_session) const override;
457+
458+ void resume_prompt_session(
459+ std::shared_ptr<PromptSession> const& prompt_session) const override;
460+
461 void add_prompt_provider(
462 std::shared_ptr<PromptSession> const& prompt_session,
463 std::shared_ptr<Session> const& prompt_provider) const override;
464
465=== modified file 'tests/acceptance-tests/test_prompt_session_client_api.cpp'
466--- tests/acceptance-tests/test_prompt_session_client_api.cpp 2014-12-08 04:03:47 +0000
467+++ tests/acceptance-tests/test_prompt_session_client_api.cpp 2014-12-17 12:06:59 +0000
468@@ -28,6 +28,7 @@
469 #include "mir/fd.h"
470
471 #include "mir_test_doubles/stub_session_authorizer.h"
472+#include "mir_test_doubles/mock_prompt_session_listener.h"
473 #include "mir_test_framework/headless_in_process_server.h"
474 #include "mir_test_framework/using_stub_client_platform.h"
475 #include "mir_test/popen.h"
476@@ -37,6 +38,7 @@
477
478 #include <condition_variable>
479 #include <mutex>
480+#include <atomic>
481
482 namespace mtd = mir::test::doubles;
483 namespace mtf = mir_test_framework;
484@@ -48,22 +50,6 @@
485
486 namespace
487 {
488-struct MockPromptSessionListener : ms::PromptSessionListener
489-{
490- MockPromptSessionListener()
491- {
492- }
493-
494- MOCK_METHOD1(starting, void(std::shared_ptr<ms::PromptSession> const& prompt_session));
495- MOCK_METHOD1(stopping, void(std::shared_ptr<ms::PromptSession> const& prompt_session));
496-
497- MOCK_METHOD2(prompt_provider_added,
498- void(ms::PromptSession const& session, std::shared_ptr<ms::Session> const& provider));
499-
500- MOCK_METHOD2(prompt_provider_removed,
501- void(ms::PromptSession const& session, std::shared_ptr<ms::Session> const& provider));
502-};
503-
504 struct MockSessionAuthorizer : public mtd::StubSessionAuthorizer
505 {
506 MockSessionAuthorizer()
507@@ -115,9 +101,11 @@
508 std::shared_ptr<ms::PromptSession> server_prompt_session;
509 mtf::UsingStubClientPlatform using_stub_client_platform;
510
511- mir::CachedPtr<MockPromptSessionListener> mock_prompt_session_listener;
512+ mir::CachedPtr<mtd::MockPromptSessionListener> mock_prompt_session_listener;
513 mir::CachedPtr<MockSessionAuthorizer> mock_prompt_session_authorizer;
514
515+ std::atomic<bool> prompt_session_state_change_callback_called;
516+
517 std::shared_ptr<MockSessionAuthorizer> the_mock_session_authorizer()
518 {
519 return mock_prompt_session_authorizer([this]
520@@ -126,11 +114,11 @@
521 });
522 }
523
524- std::shared_ptr<MockPromptSessionListener> the_mock_prompt_session_listener()
525+ std::shared_ptr<mtd::MockPromptSessionListener> the_mock_prompt_session_listener()
526 {
527 return mock_prompt_session_listener([]
528 {
529- return std::make_shared<NiceMock<MockPromptSessionListener>>();
530+ return std::make_shared<NiceMock<mtd::MockPromptSessionListener>>();
531 });
532 }
533
534@@ -195,6 +183,17 @@
535 WillOnce(SaveArg<0>(&server_prompt_session));
536 }
537
538+ void wait_for_state_change_callback()
539+ {
540+ for (int i = 0; !prompt_session_state_change_callback_called.load() && i < 5000; ++i)
541+ {
542+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
543+ std::this_thread::yield();
544+ }
545+
546+ prompt_session_state_change_callback_called.store(false);
547+ }
548+
549 void TearDown() override
550 {
551 application_session.reset();
552@@ -266,6 +265,7 @@
553 {
554 PromptSessionClientAPI* self = static_cast<PromptSessionClientAPI*>(context);
555 self->prompt_session_state_change(prompt_provider, state);
556+ self->prompt_session_state_change_callback_called.store(true);
557 }
558
559 void client_fd_callback(MirPromptSession*, size_t count, int const* fds, void* context)
560@@ -421,20 +421,49 @@
561 {
562 connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__);
563
564- EXPECT_CALL(*this, prompt_session_state_change(_, mir_prompt_session_state_started));
565+ {
566+ InSequence seq;
567+ EXPECT_CALL(*this, prompt_session_state_change(_, mir_prompt_session_state_started));
568+ EXPECT_CALL(*this, prompt_session_state_change(_, mir_prompt_session_state_stopped));
569+ }
570
571 capture_server_prompt_session();
572
573 MirPromptSession* prompt_session = mir_connection_create_prompt_session_sync(
574 connection, application_session_pid, prompt_session_state_change_callback, this);
575-
576- EXPECT_CALL(*this, prompt_session_state_change(_, mir_prompt_session_state_stopped));
577+ wait_for_state_change_callback();
578
579 the_prompt_session_manager()->stop_prompt_session(server_prompt_session);
580+ wait_for_state_change_callback();
581
582 // Verify we have got the "stopped" notification before we go on and release the session
583- Mock::VerifyAndClearExpectations(the_mock_prompt_session_listener().get());
584-
585+ Mock::VerifyAndClearExpectations(this);
586+
587+ mir_prompt_session_release_sync(prompt_session);
588+}
589+
590+TEST_F(PromptSessionClientAPI, notifies_when_server_suspends_prompt_session)
591+{
592+ connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__);
593+ {
594+ InSequence seq;
595+ EXPECT_CALL(*this, prompt_session_state_change(_, mir_prompt_session_state_started));
596+ EXPECT_CALL(*this, prompt_session_state_change(_, mir_prompt_session_state_suspended));
597+ }
598+
599+ capture_server_prompt_session();
600+
601+ MirPromptSession* prompt_session = mir_connection_create_prompt_session_sync(
602+ connection, application_session_pid, prompt_session_state_change_callback, this);
603+ wait_for_state_change_callback();
604+
605+ the_prompt_session_manager()->suspend_prompt_session(server_prompt_session);
606+ wait_for_state_change_callback();
607+
608+ // Verify we have got the "suspend" notification before we go on and release the session
609+ Mock::VerifyAndClearExpectations(this);
610+
611+ EXPECT_CALL(*this, prompt_session_state_change(_, mir_prompt_session_state_stopped));
612 mir_prompt_session_release_sync(prompt_session);
613 }
614
615
616=== modified file 'tests/include/mir_test_doubles/mock_prompt_session_listener.h'
617--- tests/include/mir_test_doubles/mock_prompt_session_listener.h 2014-06-12 10:06:11 +0000
618+++ tests/include/mir_test_doubles/mock_prompt_session_listener.h 2014-12-17 12:06:59 +0000
619@@ -36,6 +36,8 @@
620
621 MOCK_METHOD1(starting, void(std::shared_ptr<scene::PromptSession> const&));
622 MOCK_METHOD1(stopping, void(std::shared_ptr<scene::PromptSession> const&));
623+ MOCK_METHOD1(suspending, void(std::shared_ptr<scene::PromptSession> const&));
624+ MOCK_METHOD1(resuming, void(std::shared_ptr<scene::PromptSession> const&));
625
626 MOCK_METHOD2(prompt_provider_added, void(scene::PromptSession const&, std::shared_ptr<scene::Session> const&));
627 MOCK_METHOD2(prompt_provider_removed, void(scene::PromptSession const&, std::shared_ptr<scene::Session> const&));
628
629=== modified file 'tests/include/mir_test_doubles/mock_scene_session.h'
630--- tests/include/mir_test_doubles/mock_scene_session.h 2014-12-08 04:03:47 +0000
631+++ tests/include/mir_test_doubles/mock_scene_session.h 2014-12-17 12:06:59 +0000
632@@ -55,6 +55,8 @@
633
634 MOCK_METHOD0(start_prompt_session, void());
635 MOCK_METHOD0(stop_prompt_session, void());
636+ MOCK_METHOD0(suspend_prompt_session, void());
637+ MOCK_METHOD0(resume_prompt_session, void());
638 };
639
640 }
641
642=== modified file 'tests/include/mir_test_doubles/null_prompt_session.h'
643--- tests/include/mir_test_doubles/null_prompt_session.h 2014-06-12 10:24:08 +0000
644+++ tests/include/mir_test_doubles/null_prompt_session.h 2014-12-17 12:06:59 +0000
645@@ -29,6 +29,22 @@
646 {
647 class NullPromptSession : public scene::PromptSession
648 {
649+public:
650+ void start(std::shared_ptr<scene::Session> const&) override
651+ {
652+ }
653+
654+ void stop(std::shared_ptr<scene::Session> const&) override
655+ {
656+ }
657+
658+ void suspend(std::shared_ptr<scene::Session> const&) override
659+ {
660+ }
661+
662+ void resume(std::shared_ptr<scene::Session> const&) override
663+ {
664+ }
665 };
666 }
667 }
668
669=== modified file 'tests/include/mir_test_doubles/null_prompt_session_manager.h'
670--- tests/include/mir_test_doubles/null_prompt_session_manager.h 2014-12-08 04:03:47 +0000
671+++ tests/include/mir_test_doubles/null_prompt_session_manager.h 2014-12-17 12:06:59 +0000
672@@ -41,6 +41,14 @@
673 {
674 }
675
676+ void suspend_prompt_session(std::shared_ptr<scene::PromptSession> const&) const override
677+ {
678+ }
679+
680+ void resume_prompt_session(std::shared_ptr<scene::PromptSession> const&) const override
681+ {
682+ }
683+
684 void add_prompt_provider(std::shared_ptr<scene::PromptSession> const&,
685 std::shared_ptr<scene::Session> const&) const
686 {
687
688=== modified file 'tests/include/mir_test_doubles/stub_scene_session.h'
689--- tests/include/mir_test_doubles/stub_scene_session.h 2014-12-08 04:03:47 +0000
690+++ tests/include/mir_test_doubles/stub_scene_session.h 2014-12-17 12:06:59 +0000
691@@ -88,6 +88,14 @@
692 {
693 }
694
695+ void suspend_prompt_session() override
696+ {
697+ }
698+
699+ void resume_prompt_session() override
700+ {
701+ }
702+
703 pid_t const pid;
704 };
705
706
707=== modified file 'tests/unit-tests/scene/CMakeLists.txt'
708--- tests/unit-tests/scene/CMakeLists.txt 2014-12-08 04:03:47 +0000
709+++ tests/unit-tests/scene/CMakeLists.txt 2014-12-17 12:06:59 +0000
710@@ -10,6 +10,7 @@
711 ${CMAKE_CURRENT_SOURCE_DIR}/test_mediating_display_changer.cpp
712 ${CMAKE_CURRENT_SOURCE_DIR}/test_prompt_session_container.cpp
713 ${CMAKE_CURRENT_SOURCE_DIR}/test_prompt_session_manager.cpp
714+ ${CMAKE_CURRENT_SOURCE_DIR}/test_prompt_session_impl.cpp
715
716 ${CMAKE_CURRENT_SOURCE_DIR}/test_surface.cpp
717 ${CMAKE_CURRENT_SOURCE_DIR}/test_surface_impl.cpp
718
719=== added file 'tests/unit-tests/scene/test_prompt_session_impl.cpp'
720--- tests/unit-tests/scene/test_prompt_session_impl.cpp 1970-01-01 00:00:00 +0000
721+++ tests/unit-tests/scene/test_prompt_session_impl.cpp 2014-12-17 12:06:59 +0000
722@@ -0,0 +1,110 @@
723+/*
724+ * Copyright © 2014 Canonical Ltd.
725+ *
726+ * This program is free software: you can redistribute it and/or modify it
727+ * under the terms of the GNU General Public License version 3,
728+ * as published by the Free Software Foundation.
729+ *
730+ * This program is distributed in the hope that it will be useful,
731+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
732+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
733+ * GNU General Public License for more details.
734+ *
735+ * You should have received a copy of the GNU General Public License
736+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
737+ *
738+ * Authored By: Nick Dedekind <nick.dedekind@canonical.com>
739+ */
740+
741+
742+#include "src/server/scene/prompt_session_impl.h"
743+
744+#include "mir_test_doubles/mock_scene_session.h"
745+#include "mir_test/fake_shared.h"
746+
747+#include <gmock/gmock.h>
748+#include <gtest/gtest.h>
749+
750+namespace ms = mir::scene;
751+namespace mt = mir::test;
752+namespace mtd = mir::test::doubles;
753+
754+using namespace ::testing;
755+
756+namespace
757+{
758+
759+struct PromptSession : public testing::Test
760+{
761+ std::shared_ptr<mtd::MockSceneSession> const helper{std::make_shared<::testing::NiceMock<mtd::MockSceneSession>>()};
762+};
763+
764+}
765+
766+TEST_F(PromptSession, start_when_stopped)
767+{
768+ ms::PromptSessionImpl prompt_session;
769+ EXPECT_EQ(prompt_session.state(), mir_prompt_session_state_stopped);
770+
771+ EXPECT_CALL(*helper, start_prompt_session()).Times(1);
772+ prompt_session.start(helper);
773+
774+ EXPECT_EQ(prompt_session.state(), mir_prompt_session_state_started);
775+}
776+
777+TEST_F(PromptSession, stop_when_started)
778+{
779+ ms::PromptSessionImpl prompt_session;
780+ prompt_session.start(helper);
781+ EXPECT_EQ(prompt_session.state(), mir_prompt_session_state_started);
782+
783+ EXPECT_CALL(*helper, stop_prompt_session()).Times(1);
784+ prompt_session.stop(helper);
785+
786+ EXPECT_EQ(prompt_session.state(), mir_prompt_session_state_stopped);
787+}
788+
789+TEST_F(PromptSession, suspend_when_started)
790+{
791+ ms::PromptSessionImpl prompt_session;
792+ prompt_session.start(helper);
793+ EXPECT_EQ(prompt_session.state(), mir_prompt_session_state_started);
794+
795+ EXPECT_CALL(*helper, suspend_prompt_session()).Times(1);
796+ prompt_session.suspend(helper);
797+
798+ EXPECT_EQ(prompt_session.state(), mir_prompt_session_state_suspended);
799+}
800+
801+TEST_F(PromptSession, suspend_fails_to_stop_helper_when_not_started)
802+{
803+ ms::PromptSessionImpl prompt_session;
804+
805+ EXPECT_CALL(*helper, suspend_prompt_session()).Times(0);
806+ prompt_session.suspend(helper);
807+
808+ EXPECT_EQ(prompt_session.state(), mir_prompt_session_state_stopped);
809+}
810+
811+TEST_F(PromptSession, resume_when_suspended)
812+{
813+ ms::PromptSessionImpl prompt_session;
814+ prompt_session.start(helper);
815+ prompt_session.suspend(helper);
816+ EXPECT_EQ(prompt_session.state(), mir_prompt_session_state_suspended);
817+
818+ EXPECT_CALL(*helper, resume_prompt_session()).Times(1);
819+ prompt_session.resume(helper);
820+
821+ EXPECT_EQ(prompt_session.state(), mir_prompt_session_state_started);
822+}
823+
824+TEST_F(PromptSession, resume_fails_to_stop_helper_when_not_started)
825+{
826+ ms::PromptSessionImpl prompt_session;
827+
828+ EXPECT_CALL(*helper, resume_prompt_session()).Times(0);
829+ prompt_session.resume(helper);
830+
831+ EXPECT_EQ(prompt_session.state(), mir_prompt_session_state_stopped);
832+}
833
834=== modified file 'tests/unit-tests/scene/test_prompt_session_manager.cpp'
835--- tests/unit-tests/scene/test_prompt_session_manager.cpp 2014-12-08 04:03:47 +0000
836+++ tests/unit-tests/scene/test_prompt_session_manager.cpp 2014-12-17 12:06:59 +0000
837@@ -128,10 +128,20 @@
838 auto const prompt_session = session_manager.start_prompt_session_for(helper, parameters);
839
840 EXPECT_CALL(prompt_session_listener, stopping(Eq(prompt_session))).Times(1);
841+
842 session_manager.stop_prompt_session(prompt_session);
843-
844- // Need to verify explicitly as we see unmatched callbacks during teardown of fixture
845- Mock::VerifyAndClearExpectations(&prompt_session_listener);
846+}
847+
848+TEST_F(PromptSessionManager, notifies_provider_of_suspend_and_resume)
849+{
850+ InSequence seq;
851+ EXPECT_CALL(prompt_session_listener, suspending(_)).Times(1);
852+
853+ session_manager.suspend_prompt_session(prompt_session);
854+
855+ EXPECT_CALL(prompt_session_listener, resuming(Eq(prompt_session))).Times(1);
856+
857+ session_manager.resume_prompt_session(prompt_session);
858 }
859
860 TEST_F(PromptSessionManager, sets_helper_for)

Subscribers

People subscribed via source and target branches