Mir

Merge lp:~raof/mir/acceptance-test-for-unfocus-on-surface-release into lp:mir

Proposed by Chris Halse Rogers
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: no longer in the source branch.
Merged at revision: 3555
Proposed branch: lp:~raof/mir/acceptance-test-for-unfocus-on-surface-release
Merge into: lp:mir
Prerequisite: lp:~raof/mir/fix-set-event-handler
Diff against target: 140 lines (+122/-1)
1 file modified
tests/acceptance-tests/test_client_surface_events.cpp (+122/-1)
To merge this branch: bzr merge lp:~raof/mir/acceptance-test-for-unfocus-on-surface-release
Reviewer Review Type Date Requested Status
Alexandros Frantzis (community) Approve
Kevin DuBois (community) Approve
Mir CI Bot continuous-integration Approve
Review via email: mp+298098@code.launchpad.net

Commit message

Acceptance tests for unfocus-on-surface-release behaviour.

We guarantee that for every focus event a MirSurface will receive exactly one
unfocus event, but we didn't have an acceptance test for this behaviour when
destroying a focused surface. Add one.

Description of the change

I want this because I want to remove the unit-test for this behaviour as it requires a ridiculous amount of setup and some of my other changes break that setup.

Also, we probably should have an acceptance test for this anyway :)

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3550
https://mir-jenkins.ubuntu.com/job/mir-ci/1171/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/1318
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/1369
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/1360
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/1360
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1332
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/1332/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1332
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/1332/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1332
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/1332/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1332
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/1332/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1332
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/1332/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/1171/rebuild

review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

It seems like we reimplementing parts of googlemock. Can't we implement the test by using existing googlemock functionality instead (e.g. a mock function called in event_callback)?

review: Needs Information
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

> It seems like we reimplementing parts of googlemock.

To be more clear, that we are reimplementing functionality already provided by googlemock.

Revision history for this message
Chris Halse Rogers (raof) wrote :

This appeared to be the sensible extension of what the existing tests did; I'll see how GMocking it looks.

Revision history for this message
Chris Halse Rogers (raof) wrote :

Ok, that looks much better.

Revision history for this message
Kevin DuBois (kdub) wrote :

looks good to me

review: Approve
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/acceptance-tests/test_client_surface_events.cpp'
2--- tests/acceptance-tests/test_client_surface_events.cpp 2016-06-22 23:10:36 +0000
3+++ tests/acceptance-tests/test_client_surface_events.cpp 2016-06-24 00:22:35 +0000
4@@ -304,6 +304,128 @@
5
6 namespace
7 {
8+bool is_focus_event_with_value(MirEvent const* event, MirSurfaceFocusState state)
9+{
10+ if (mir_event_get_type(event) != mir_event_type_surface)
11+ {
12+ return false;
13+ }
14+
15+ auto surface_event = mir_event_get_surface_event(event);
16+ if (mir_surface_event_get_attribute(surface_event) != mir_surface_attrib_focus)
17+ {
18+ return false;
19+ }
20+ return mir_surface_event_get_attribute_value(surface_event) == state;
21+}
22+
23+bool is_focus_event(MirEvent const* event)
24+{
25+ return is_focus_event_with_value(event, mir_surface_focused);
26+}
27+
28+bool is_unfocus_event(MirEvent const* event)
29+{
30+ return is_focus_event_with_value(event, mir_surface_unfocused);
31+}
32+}
33+
34+TEST_F(ClientSurfaceEvents, focused_window_receives_unfocus_event_on_release)
35+{
36+ using namespace testing;
37+ using namespace std::chrono_literals;
38+
39+ auto surface = mtf::make_any_surface(connection);
40+
41+ mt::Signal focus_received;
42+ mir_surface_set_event_handler(
43+ surface,
44+ [](MirSurface*, MirEvent const* event, void* ctx)
45+ {
46+ auto& done = *reinterpret_cast<mt::Signal*>(ctx);
47+ if (is_focus_event(event))
48+ {
49+ done.raise();
50+ }
51+ },
52+ &focus_received);
53+
54+ // Swap buffers to get the surface into the scene so it can be focused.
55+ auto buffer_stream = mir_surface_get_buffer_stream(surface);
56+ mir_buffer_stream_swap_buffers_sync(buffer_stream);
57+
58+ ASSERT_TRUE(focus_received.wait_for(10s));
59+
60+ mt::Signal unfocus_received;
61+ mir_surface_set_event_handler(
62+ surface,
63+ [](MirSurface*, MirEvent const* event, void* ctx)
64+ {
65+ auto& done = *reinterpret_cast<mt::Signal*>(ctx);
66+ if (is_unfocus_event(event))
67+ {
68+ done.raise();
69+ }
70+ },
71+ &unfocus_received);
72+
73+ mir_surface_release_sync(surface);
74+
75+ EXPECT_TRUE(unfocus_received.wait_for(10s));
76+}
77+
78+TEST_F(ClientSurfaceEvents, unfocused_window_does_not_receive_unfocus_event_on_release)
79+{
80+ using namespace testing;
81+ using namespace std::chrono_literals;
82+
83+ auto surface = mtf::make_any_surface(connection);
84+
85+ mt::Signal focus_received;
86+ mir_surface_set_event_handler(
87+ surface,
88+ [](MirSurface*, MirEvent const* event, void* ctx)
89+ {
90+ auto& done = *reinterpret_cast<mt::Signal*>(ctx);
91+ if (is_focus_event(event))
92+ {
93+ done.raise();
94+ }
95+ },
96+ &focus_received);
97+
98+ // Swap buffers to get the surface into the scene so it can be focused.
99+ auto buffer_stream = mir_surface_get_buffer_stream(surface);
100+ mir_buffer_stream_swap_buffers_sync(buffer_stream);
101+
102+ ASSERT_TRUE(focus_received.wait_for(10s));
103+
104+ mt::Signal unfocus_received;
105+ mir_surface_set_event_handler(
106+ surface,
107+ [](MirSurface*, MirEvent const* event, void* ctx)
108+ {
109+ auto& done = *reinterpret_cast<mt::Signal*>(ctx);
110+ if (is_unfocus_event(event))
111+ {
112+ done.raise();
113+ }
114+ },
115+ &unfocus_received);
116+
117+ // Add a new surface that will take focus.
118+ auto focus_grabbing_surface = mtf::make_any_surface(connection);
119+ mir_buffer_stream_swap_buffers_sync(mir_surface_get_buffer_stream(focus_grabbing_surface));
120+
121+ ASSERT_TRUE(unfocus_received.wait_for(10s));
122+
123+ unfocus_received.reset();
124+
125+ mir_surface_release_sync(surface);
126+
127+ EXPECT_FALSE(unfocus_received.wait_for(1s));
128+}
129+
130 class WrapShellGeneratingCloseEvent : public mir::shell::ShellWrapper
131 {
132 using mir::shell::ShellWrapper::ShellWrapper;
133@@ -345,7 +467,6 @@
134 signal->raise();
135 }
136 }
137-}
138
139 TEST_F(ClientSurfaceStartupEvents, receives_event_sent_during_surface_construction)
140 {

Subscribers

People subscribed via source and target branches