Mir

Merge lp:~mir-team/mir/cookie-umock-to-fake-input-tests into lp:mir

Proposed by Brandon Schaefer
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: no longer in the source branch.
Merged at revision: 3055
Proposed branch: lp:~mir-team/mir/cookie-umock-to-fake-input-tests
Merge into: lp:mir
Diff against target: 240 lines (+104/-65)
3 files modified
tests/acceptance-tests/CMakeLists.txt (+1/-0)
tests/acceptance-tests/test_client_cookie.cpp (+103/-64)
tests/umock-acceptance-tests/CMakeLists.txt (+0/-1)
To merge this branch: bzr merge lp:~mir-team/mir/cookie-umock-to-fake-input-tests
Reviewer Review Type Date Requested Status
Alexandros Frantzis (community) Approve
Andreas Pokorny (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+275588@code.launchpad.net

Commit message

Move the test_client_cookies to using fake input device vs using umock.

Added touch screen tests as well.

Description of the change

Move the test_client_cookies to using fake input device vs using umock.

Added touch screen tests as well.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

lgtm

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/CMakeLists.txt'
2--- tests/acceptance-tests/CMakeLists.txt 2015-10-07 16:41:50 +0000
3+++ tests/acceptance-tests/CMakeLists.txt 2015-10-23 21:36:51 +0000
4@@ -51,6 +51,7 @@
5 test_surface_specification.cpp
6 test_system_compositor_window_manager.cpp
7 test_session_mediator_report.cpp
8+ test_client_cookie.cpp
9 )
10
11 if (MIR_TEST_PLATFORM STREQUAL "mesa-kms" OR MIR_TEST_PLATFORM STREQUAL "mesa-x11")
12
13=== renamed file 'tests/umock-acceptance-tests/test_client_cookie.cpp' => 'tests/acceptance-tests/test_client_cookie.cpp'
14--- tests/umock-acceptance-tests/test_client_cookie.cpp 2015-10-15 18:40:48 +0000
15+++ tests/acceptance-tests/test_client_cookie.cpp 2015-10-23 21:36:51 +0000
16@@ -14,17 +14,25 @@
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
20+ * Brandon Schaefer <brandon.schaefer@canonical.com>
21 */
22
23-#include "mir_test_framework/udev_environment.h"
24+#include "mir/input/input_device_info.h"
25+#include "mir_test_framework/fake_input_device.h"
26+
27+#include "mir_test_framework/stub_server_platform_factory.h"
28 #include "mir_test_framework/connected_client_with_a_surface.h"
29-#include "mir/test/wait_condition.h"
30+#include "mir/test/spin_wait.h"
31 #include "mir/cookie_factory.h"
32
33 #include "boost/throw_exception.hpp"
34
35+#include <linux/input.h>
36
37 namespace mtf = mir_test_framework;
38+namespace mt = mir::test;
39+namespace mi = mir::input;
40+namespace mis = mir::input::synthesis;
41
42 namespace
43 {
44@@ -37,9 +45,6 @@
45 public:
46 ClientCookies()
47 {
48- // Needed because the headless server sets stub_input.so
49- add_to_environment("MIR_SERVER_PLATFORM_INPUT_LIB", nullptr);
50-
51 server.override_the_cookie_factory([this] ()
52 { return mir::cookie::CookieFactory::create_saving_secret(cookie_secret); });
53 }
54@@ -58,36 +63,19 @@
55 mir_buffer_stream_swap_buffers_sync(mir_surface_get_buffer_stream(surface));
56 }
57
58- void read_evemu_file(std::string const& evemu_file)
59- {
60- mock_devices.load_device_evemu(evemu_file);
61-
62- udev_read_recording.wait_for_at_most_seconds(max_wait);
63- if (!udev_read_recording.woken())
64- BOOST_THROW_EXCEPTION(std::runtime_error("Timeout waiting for udev to read the recording '" + evemu_file + "'"));
65- }
66-
67 std::vector<uint8_t> cookie_secret;
68- mtf::UdevEnvironment mock_devices;
69- MirCookie out_cookie{0, 0};
70- mir::test::WaitCondition udev_read_recording;
71-};
72-
73-// Need to setup the device before the server gets setup
74-struct ClientCookiesKeyboard : ClientCookies
75-{
76- ClientCookiesKeyboard()
77- {
78- mock_devices.add_standard_device("laptop-keyboard");
79- }
80-};
81-
82-struct ClientCookiesMouse : ClientCookies
83-{
84- ClientCookiesMouse()
85- {
86- mock_devices.add_standard_device("laptop-mouse");
87- }
88+ std::vector<MirCookie> out_cookies;
89+
90+ std::unique_ptr<mtf::FakeInputDevice> fake_keyboard{
91+ mtf::add_fake_input_device(mi::InputDeviceInfo{"keyboard", "keyboard-uid" , mi::DeviceCapability::keyboard})
92+ };
93+ std::unique_ptr<mtf::FakeInputDevice> fake_pointer{
94+ mtf::add_fake_input_device(mi::InputDeviceInfo{"mouse", "mouse-uid" , mi::DeviceCapability::pointer})
95+ };
96+ std::unique_ptr<mtf::FakeInputDevice> fake_touch_screen{
97+ mtf::add_fake_input_device(mi::InputDeviceInfo{
98+ "touch screen", "touch-screen-uid", mi::DeviceCapability::touchscreen | mi::DeviceCapability::multitouch})
99+ };
100 };
101
102 namespace
103@@ -103,45 +91,96 @@
104 if (itype == mir_input_event_type_key)
105 {
106 auto kev = mir_input_event_get_keyboard_event(iev);
107- client->out_cookie = mir_keyboard_event_get_cookie(kev);
108- client->udev_read_recording.wake_up_everyone();
109+ client->out_cookies.push_back(mir_keyboard_event_get_cookie(kev));
110 }
111 else if (itype == mir_input_event_type_pointer)
112 {
113 auto pev = mir_input_event_get_pointer_event(iev);
114- client->out_cookie = mir_pointer_event_get_cookie(pev);
115- client->udev_read_recording.wake_up_everyone();
116+ client->out_cookies.push_back(mir_pointer_event_get_cookie(pev));
117 }
118 else if (itype == mir_input_event_type_touch)
119 {
120 auto tev = mir_input_event_get_touch_event(iev);
121- client->out_cookie = mir_touch_event_get_cookie(tev);
122- client->udev_read_recording.wake_up_everyone();
123+ client->out_cookies.push_back(mir_touch_event_get_cookie(tev));
124 }
125 }
126 }
127-}
128-
129-TEST_F(ClientCookiesKeyboard, keyboard_events_have_attestable_cookies)
130-{
131- read_evemu_file("laptop-keyboard-hello");
132- auto factory = mir::cookie::CookieFactory::create_from_secret(cookie_secret);
133-
134- EXPECT_TRUE(factory->attest_timestamp(out_cookie));
135-}
136-
137-TEST_F(ClientCookiesMouse, pointer_motion_events_do_not_have_attestable_cookies)
138-{
139- read_evemu_file("laptop-mouse-motion");
140- auto factory = mir::cookie::CookieFactory::create_from_secret(cookie_secret);
141-
142- EXPECT_FALSE(factory->attest_timestamp(out_cookie));
143-}
144-
145-TEST_F(ClientCookiesMouse, pointer_click_events_have_attestable_cookies)
146-{
147- read_evemu_file("laptop-mouse-click");
148- auto factory = mir::cookie::CookieFactory::create_from_secret(cookie_secret);
149-
150- EXPECT_TRUE(factory->attest_timestamp(out_cookie));
151+
152+bool wait_for_n_events(size_t n, std::vector<MirCookie>& cookies)
153+{
154+ bool all_events = mt::spin_wait_for_condition_or_timeout(
155+ [&n, &cookies]
156+ {
157+ return cookies.size() >= n;
158+ },
159+ std::chrono::seconds{max_wait});
160+
161+ EXPECT_TRUE(all_events);
162+ return all_events;
163+}
164+}
165+
166+TEST_F(ClientCookies, keyboard_events_have_attestable_cookies)
167+{
168+ fake_keyboard->emit_event(mis::a_key_down_event().of_scancode(KEY_M));
169+ if (wait_for_n_events(1, out_cookies))
170+ {
171+ auto factory = mir::cookie::CookieFactory::create_from_secret(cookie_secret);
172+ EXPECT_TRUE(factory->attest_timestamp(out_cookies.back()));
173+ }
174+}
175+
176+TEST_F(ClientCookies, pointer_motion_events_do_not_have_attestable_cookies)
177+{
178+ fake_pointer->emit_event(mis::a_pointer_event().with_movement(1, 1));
179+ if (wait_for_n_events(1, out_cookies))
180+ {
181+ auto factory = mir::cookie::CookieFactory::create_from_secret(cookie_secret);
182+ EXPECT_FALSE(factory->attest_timestamp(out_cookies.back()));
183+ }
184+}
185+
186+TEST_F(ClientCookies, pointer_click_events_have_attestable_cookies)
187+{
188+ fake_pointer->emit_event(mis::a_button_down_event().of_button(BTN_LEFT).with_action(mis::EventAction::Down));
189+ fake_pointer->emit_event(mis::a_button_up_event().of_button(BTN_LEFT));
190+ if (wait_for_n_events(2, out_cookies))
191+ {
192+ auto factory = mir::cookie::CookieFactory::create_from_secret(cookie_secret);
193+ EXPECT_TRUE(factory->attest_timestamp(out_cookies.back()));
194+ }
195+}
196+
197+TEST_F(ClientCookies, touch_motion_events_do_not_have_attestable_cookies)
198+{
199+ fake_touch_screen->emit_event(
200+ mis::a_touch_event()
201+ .at_position({0, 0})
202+ );
203+
204+ fake_touch_screen->emit_event(
205+ mis::a_touch_event()
206+ .with_action(mis::TouchParameters::Action::Move)
207+ .at_position({1, 1})
208+ );
209+
210+ if (wait_for_n_events(2, out_cookies))
211+ {
212+ auto factory = mir::cookie::CookieFactory::create_from_secret(cookie_secret);
213+ EXPECT_FALSE(factory->attest_timestamp(out_cookies.back()));
214+ }
215+}
216+
217+TEST_F(ClientCookies, touch_click_events_have_attestable_cookies)
218+{
219+ fake_touch_screen->emit_event(
220+ mis::a_touch_event()
221+ .at_position({0, 0})
222+ );
223+
224+ if (wait_for_n_events(1, out_cookies))
225+ {
226+ auto factory = mir::cookie::CookieFactory::create_from_secret(cookie_secret);
227+ EXPECT_TRUE(factory->attest_timestamp(out_cookies.back()));
228+ }
229 }
230
231=== modified file 'tests/umock-acceptance-tests/CMakeLists.txt'
232--- tests/umock-acceptance-tests/CMakeLists.txt 2015-10-06 18:15:53 +0000
233+++ tests/umock-acceptance-tests/CMakeLists.txt 2015-10-23 21:36:51 +0000
234@@ -10,7 +10,6 @@
235 mir_add_wrapped_executable(
236 mir_umock_acceptance_tests
237
238- test_client_cookie.cpp
239 test_libinput.cpp
240 )
241

Subscribers

People subscribed via source and target branches