1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
|
/*
* Copyright© 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 or 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mir/input/validator.h"
#include "mir/events/event_private.h"
#include "mir/events/event_builders.h"
#include "mir/test/fake_shared.h"
#include "mir/test/event_matchers.h"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
namespace mi = mir::input;
namespace mev = mir::events;
namespace mt = mir::test;
using namespace ::testing;
namespace mir
{
struct MockEventSink
{
MOCK_METHOD1(handle, void(MirEvent const&));
};
}
namespace
{
struct Validator : public ::testing::Test
{
Validator()
: rewriter([this](MirEvent const& ev) {input_sink.handle(ev);})
{
}
mir::MockEventSink input_sink;
mi::Validator rewriter;
};
void add_another_touch(mir::EventUPtr const& ev, MirTouchId id, MirTouchAction action)
{
mev::add_touch(*ev, id, action, mir_touch_tooltype_finger,
0, 0, 0, 0, 0, 0);
}
mir::EventUPtr make_touch(MirTouchId id, MirTouchAction action)
{
auto ev = mev::make_touch_event(
MirInputDeviceId(0), std::chrono::nanoseconds(0),
mir_input_event_modifier_none);
add_another_touch(ev, id, action);
return ev;
}
}
// We make a touch that represents two unseen touch ID's changing
// this way we expect the server to generate two seperate events to first
// report the down actions
TEST_F(Validator, missing_touch_downs_are_inserted)
{
auto touch = make_touch(0, mir_touch_action_change);
add_another_touch(touch, 1, mir_touch_action_change);
auto inserted_down_id0 = make_touch(0, mir_touch_action_down);
auto inserted_down_id1 = make_touch(0, mir_touch_action_change);
add_another_touch(inserted_down_id1, 1, mir_touch_action_down);
InSequence seq;
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id0.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id1.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch.get())));
rewriter.validate_and_dispatch(*touch);
}
// In this case we first put two touches down, then we show an event which
// reports one of them changing without the others, in this case we
// must insert a touch up event for the ID which has gone missing.
TEST_F(Validator, missing_touch_releases_are_inserted)
{
auto touch_1 = make_touch(0, mir_touch_action_down);
auto touch_2 = make_touch(0, mir_touch_action_change);
add_another_touch(touch_2, 1, mir_touch_action_down);
auto touch_3 = make_touch(0, mir_touch_action_change);
auto inserted_release = make_touch(0, mir_touch_action_change);
add_another_touch(inserted_release, 1, mir_touch_action_up);
InSequence seq;
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_release.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get())));
rewriter.validate_and_dispatch(*touch_1);
rewriter.validate_and_dispatch(*touch_2);
rewriter.validate_and_dispatch(*touch_3);
}
// Here we put 3 touches down (0, 1, 2) and then send an event which
// shows a change only for touch (2). This means we have to insert missing
// releases for both touches which have gone missing.
TEST_F(Validator, multiple_missing_releases_are_inserted)
{
auto touch_1 = make_touch(0, mir_touch_action_down);
auto touch_2 = make_touch(0, mir_touch_action_change);
add_another_touch(touch_2, 1, mir_touch_action_down);
auto touch_3 = make_touch(0, mir_touch_action_change);
add_another_touch(touch_3, 1, mir_touch_action_change);
add_another_touch(touch_3, 2, mir_touch_action_down);
auto touch_4 = make_touch(2, mir_touch_action_change);
auto inserted_release_id0 = make_touch(0, mir_touch_action_up);
add_another_touch(inserted_release_id0, 1, mir_touch_action_change);
add_another_touch(inserted_release_id0, 2, mir_touch_action_change);
auto inserted_release_id1 = make_touch(1, mir_touch_action_up);
add_another_touch(inserted_release_id1, 2, mir_touch_action_change);
InSequence seq;
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_1))));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_2))));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_3))));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_release_id0))));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*inserted_release_id1))));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(ByRef(*touch_4))));
rewriter.validate_and_dispatch(*touch_1);
rewriter.validate_and_dispatch(*touch_2);
rewriter.validate_and_dispatch(*touch_3);
rewriter.validate_and_dispatch(*touch_4);
}
// In this case we put two touches down (0, 1) and then we show a touch
// with (0, 2). Here we expect point 1 to be released and then point 2 to be put down
// before reporting the touch with ids (0, 2)
TEST_F(Validator, missing_up_and_down_is_inserted)
{
auto touch_1 = make_touch(0, mir_touch_action_down);
auto touch_2 = make_touch(0, mir_touch_action_change);
add_another_touch(touch_2, 1, mir_touch_action_down);
auto touch_3 = make_touch(0, mir_touch_action_change);
add_another_touch(touch_3, 1, mir_touch_action_change);
auto touch_4 = make_touch(0, mir_touch_action_change);
add_another_touch(touch_4, 2, mir_touch_action_change);
auto inserted_release_id1 = make_touch(0, mir_touch_action_change);
add_another_touch(inserted_release_id1, 1, mir_touch_action_up);
auto inserted_down_id2 = make_touch(0, mir_touch_action_change);
add_another_touch(inserted_down_id2, 2, mir_touch_action_down);
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_release_id1.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id2.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_4.get())));
rewriter.validate_and_dispatch(*touch_1);
rewriter.validate_and_dispatch(*touch_2);
rewriter.validate_and_dispatch(*touch_3);
rewriter.validate_and_dispatch(*touch_4);
}
// This is a variation of the previous test
TEST_F(Validator, missing_up_and_down_and_up_is_inserted_variation)
{
auto touch_1 = make_touch(0, mir_touch_action_down);
auto touch_2 = make_touch(0, mir_touch_action_change);
add_another_touch(touch_2, 1, mir_touch_action_down);
auto touch_3 = make_touch(1, mir_touch_action_change);
add_another_touch(touch_3, 2, mir_touch_action_up);
auto inserted_up_id0 = make_touch(0, mir_touch_action_up);
add_another_touch(inserted_up_id0, 1, mir_touch_action_change);
auto inserted_down_id2 = make_touch(1, mir_touch_action_change);
add_another_touch(inserted_down_id2, 2, mir_touch_action_down);
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_up_id0.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id2.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get())));
rewriter.validate_and_dispatch(*touch_1);
rewriter.validate_and_dispatch(*touch_2);
rewriter.validate_and_dispatch(*touch_3);
}
// In this case we put two touches down (0, 1) and then we release touch 1
// now as the next event we just show (0,1) changing as if point 1 had never
// been released. We ensure that a touch down for 1 is inserted before we
// show the change event.
TEST_F(Validator, down_is_inserted_before_released_touch_reappears)
{
auto touch_1 = make_touch(0, mir_touch_action_down);
auto touch_2 = make_touch(0, mir_touch_action_change);
add_another_touch(touch_2, 1, mir_touch_action_down);
auto touch_3 = make_touch(0, mir_touch_action_change);
add_another_touch(touch_3, 1, mir_touch_action_change);
auto touch_4 = make_touch(0, mir_touch_action_change);
add_another_touch(touch_4, 1, mir_touch_action_up);
auto const& touch_5 = touch_3;
auto inserted_down_id1 = make_touch(0, mir_touch_action_change);
add_another_touch(inserted_down_id1, 1, mir_touch_action_down);
InSequence seq;
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_3.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_4.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id1.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_5.get())));
rewriter.validate_and_dispatch(*touch_1);
rewriter.validate_and_dispatch(*touch_2);
rewriter.validate_and_dispatch(*touch_3);
rewriter.validate_and_dispatch(*touch_4);
rewriter.validate_and_dispatch(*touch_5);
}
// Here we put a single point down and then show it dissapearing while another ID appears...similar
// to the missing up and down is inserted case but with only one touch point. We have to inject a release
// for the first touch point and a down for the new touch point.
TEST_F(Validator, up_and_down_inserted_when_id_changes)
{
auto touch_1 = make_touch(0, mir_touch_action_down);
auto touch_2 = make_touch(1, mir_touch_action_change);
auto inserted_up_id0 = make_touch(0, mir_touch_action_up);
auto inserted_down_id1 = make_touch(1, mir_touch_action_down);
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_1.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_up_id0.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(inserted_down_id1.get())));
EXPECT_CALL(input_sink, handle(mt::MirTouchEventMatches(touch_2.get())));
rewriter.validate_and_dispatch(*touch_1);
rewriter.validate_and_dispatch(*touch_2);
}
|