16
16
* Authored by: Robert Carr <robert.carr@canonical.com>
19
#define MIR_INCLUDE_DEPRECATED_EVENT_HEADER
21
19
#include "mir_toolkit/mir_client_library.h"
23
21
#include "mir_test/wait_condition.h"
24
22
#include "mir_test/event_matchers.h"
26
24
#include "mir_test_framework/interprocess_client_server_test.h"
27
#include "mir_test_framework/cross_process_sync.h"
25
#include "mir_test/cross_process_sync.h"
29
27
#include <gtest/gtest.h>
30
28
#include <gmock/gmock.h>
62
60
mir_wait_for(mir_surface_create(spec, surface_created, this));
63
61
mir_surface_spec_release(spec);
62
mir_buffer_stream_swap_buffers_sync(mir_surface_get_buffer_stream(surface));
65
64
all_events_received.wait_for_at_most_seconds(60);
66
65
mir_surface_release_sync(surface);
85
84
// We need to set the event delegate from the surface_created
86
85
// callback so we can block the reading of new events
87
86
// until we are ready
88
MirEventDelegate const event_delegate =
93
mir_surface_set_event_handler(surface_, &event_delegate);
87
mir_surface_set_event_handler(surface_, handle_event, self);
103
EXPECT_CALL(observer, see(Pointee(mt::SurfaceEvent(mir_surface_attrib_focus, mir_surface_focused)))).Times(1)
97
EXPECT_CALL(observer, see(mt::SurfaceEvent(mir_surface_attrib_focus, mir_surface_focused))).Times(1)
104
98
.WillOnce(mt::WakeUp(&all_events_received));
105
99
// We may not see mir_surface_unfocused before connection closes
106
EXPECT_CALL(observer, see(Pointee(mt::SurfaceEvent(mir_surface_attrib_focus, mir_surface_unfocused)))).Times(AtMost(1));
100
EXPECT_CALL(observer, see(mt::SurfaceEvent(mir_surface_attrib_focus, mir_surface_unfocused))).Times(AtMost(1));
108
102
connect_and_create_surface();
124
118
// We use this for synchronization to ensure the two clients
125
119
// are launched in a defined order.
126
mtf::CrossProcessSync ready_for_second_client;
120
mt::CrossProcessSync ready_for_second_client;
128
122
auto const client_one = new_client_process([&]
131
125
// We should receive focus as we are created
132
EXPECT_CALL(observer, see(Pointee(mt::SurfaceEvent(mir_surface_attrib_focus,
133
mir_surface_focused)))).Times(1)
126
EXPECT_CALL(observer, see(mt::SurfaceEvent(mir_surface_attrib_focus,
127
mir_surface_focused))).Times(1)
134
128
.WillOnce(SignalFence(&ready_for_second_client));
136
130
// And lose it as the second surface is created
137
EXPECT_CALL(observer, see(Pointee(mt::SurfaceEvent(mir_surface_attrib_focus,
138
mir_surface_unfocused)))).Times(1);
131
EXPECT_CALL(observer, see(mt::SurfaceEvent(mir_surface_attrib_focus,
132
mir_surface_unfocused))).Times(1);
139
133
// And regain it when the second surface is closed
140
EXPECT_CALL(observer, see(Pointee(mt::SurfaceEvent(mir_surface_attrib_focus,
141
mir_surface_focused)))).Times(1).WillOnce(mt::WakeUp(&all_events_received));
134
EXPECT_CALL(observer, see(mt::SurfaceEvent(mir_surface_attrib_focus,
135
mir_surface_focused))).Times(1).WillOnce(mt::WakeUp(&all_events_received));
142
136
// And then lose it as we are closed (but we may not see confirmation before connection closes)
143
EXPECT_CALL(observer, see(Pointee(mt::SurfaceEvent(mir_surface_attrib_focus,
144
mir_surface_unfocused)))).Times(AtMost(1));
137
EXPECT_CALL(observer, see(mt::SurfaceEvent(mir_surface_attrib_focus,
138
mir_surface_unfocused))).Times(AtMost(1));
146
140
connect_and_create_surface();
151
145
ready_for_second_client.wait_for_signal_ready_for();
153
EXPECT_CALL(observer, see(Pointee(
154
mt::SurfaceEvent(mir_surface_attrib_focus, mir_surface_focused))))
147
EXPECT_CALL(observer, see(
148
mt::SurfaceEvent(mir_surface_attrib_focus, mir_surface_focused)))
155
149
.Times(1).WillOnce(mt::WakeUp(&all_events_received));
156
150
// We may not see mir_surface_unfocused before connection closes
157
EXPECT_CALL(observer, see(Pointee(
158
mt::SurfaceEvent(mir_surface_attrib_focus, mir_surface_unfocused))))
151
EXPECT_CALL(observer, see(
152
mt::SurfaceEvent(mir_surface_attrib_focus, mir_surface_unfocused)))
159
153
.Times(AtMost(1));
161
155
connect_and_create_surface();