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
|
/*
* Copyright © 2018 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 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/>.
*
* Authored by: William Wold <william.wold@canonical.com>
*/
#include "helpers.h"
#include "in_process_server.h"
#include "xdg_shell_stable.h"
#include "surface_builder.h"
#include <gmock/gmock.h>
#include <vector>
#include <memory>
using namespace testing;
class TouchTest:
public wlcs::InProcessServer,
public testing::WithParamInterface<std::shared_ptr<wlcs::SurfaceBuilder>>
{
};
TEST_P(TouchTest, touch_on_surface_seen)
{
int const window_width = 300, window_height = 300;
int const window_top_left_x = 64, window_top_left_y = 7;
wlcs::Client client{the_server()};
auto const surface = GetParam()->build(
the_server(), client, {window_top_left_x, window_top_left_y}, {window_width, window_height});
auto const wl_surface = static_cast<struct wl_surface*>(*surface);
auto touch = the_server().create_touch();
int touch_x = window_top_left_x + 27;
int touch_y = window_top_left_y + 8;
touch.down_at(touch_x, touch_y);
client.roundtrip();
ASSERT_THAT(client.touched_window(), Eq(wl_surface)) << "touch did not register on surface";
ASSERT_THAT(client.touch_position(),
Eq(std::make_pair(
wl_fixed_from_int(touch_x - window_top_left_x),
wl_fixed_from_int(touch_y - window_top_left_y)))) << "touch came down in the wrong place";
touch.up();
client.roundtrip();
}
TEST_P(TouchTest, touch_and_drag_on_surface_seen)
{
int const window_width = 300, window_height = 300;
int const window_top_left_x = 64, window_top_left_y = 12;
int const touch_x = window_top_left_x + 27, touch_y = window_top_left_y + 140;
int const dx = 37, dy = -52;
wlcs::Client client{the_server()};
auto const surface = GetParam()->build(
the_server(), client, {window_top_left_x, window_top_left_y}, {window_width, window_height});
auto const wl_surface = static_cast<struct wl_surface*>(*surface);
auto touch = the_server().create_touch();
touch.down_at(touch_x, touch_y);
client.roundtrip();
ASSERT_THAT(client.touched_window(), Eq(wl_surface)) << "touch did not register on surface";
ASSERT_THAT(client.touch_position(),
Eq(std::make_pair(
wl_fixed_from_int(touch_x - window_top_left_x),
wl_fixed_from_int(touch_y - window_top_left_y)))) << "touch came down in the wrong place";
touch.move_to(touch_x + dx, touch_y + dy);
client.roundtrip();
ASSERT_THAT(client.touched_window(), Eq(wl_surface)) << "surface was unfocused when it shouldn't have been";
ASSERT_THAT(client.touch_position(),
Ne(std::make_pair(
wl_fixed_from_int(touch_x - window_top_left_x),
wl_fixed_from_int(touch_y - window_top_left_y)))) << "touch did not move";
ASSERT_THAT(client.touch_position(),
Eq(std::make_pair(
wl_fixed_from_int(touch_x - window_top_left_x + dx),
wl_fixed_from_int(touch_y - window_top_left_y + dy)))) << "touch did not end up in the right place";
touch.up();
client.roundtrip();
}
TEST_P(TouchTest, touch_drag_outside_of_surface_and_back_not_lost)
{
int const window_width = 300, window_height = 300;
int const window_top_left_x = 64, window_top_left_y = 12;
int const touch_a_x = window_top_left_x + 27, touch_a_y = window_top_left_y + 12;
int const touch_b_x = window_top_left_x - 6, touch_b_y = window_top_left_y + window_width + 8;
wlcs::Client client{the_server()};
auto const surface = GetParam()->build(
the_server(), client, {window_top_left_x, window_top_left_y}, {window_width, window_height});
auto const wl_surface = static_cast<struct wl_surface*>(*surface);
auto touch = the_server().create_touch();
touch.down_at(touch_a_x, touch_a_y);
client.roundtrip();
ASSERT_THAT(client.touched_window(), Eq(wl_surface)) << "touch did not register on surface";
ASSERT_THAT(client.touch_position(),
Eq(std::make_pair(
wl_fixed_from_int(touch_a_x - window_top_left_x),
wl_fixed_from_int(touch_a_y - window_top_left_y)))) << "touch came down in the wrong place";
touch.move_to(touch_b_x, touch_b_y);
client.roundtrip();
EXPECT_THAT(client.touched_window(), Eq(wl_surface)) << "touch was lost when it moved out of the surface";
if (client.touched_window() == wl_surface)
{
EXPECT_THAT(client.touch_position(),
Eq(std::make_pair(
wl_fixed_from_int(touch_b_x - window_top_left_x),
wl_fixed_from_int(touch_b_y - window_top_left_y)))) << "touch did not end up in the right place outside of the surface";
}
touch.move_to(touch_a_x, touch_a_y);
client.roundtrip();
EXPECT_THAT(client.touched_window(), Eq(wl_surface)) << "touch did not come back onto surface";
EXPECT_THAT(client.touch_position(),
Eq(std::make_pair(
wl_fixed_from_int(touch_a_x - window_top_left_x),
wl_fixed_from_int(touch_a_y - window_top_left_y)))) << "touch came back in the wrong place";
touch.up();
client.roundtrip();
}
TEST_P(TouchTest, sends_touch_up_on_surface_destroy)
{
int const window_width = 300, window_height = 300;
int const window_top_left_x = 64, window_top_left_y = 7;
wlcs::Client client{the_server()};
auto surface = GetParam()->build(
the_server(), client, {window_top_left_x, window_top_left_y}, {window_width, window_height});
auto touch = the_server().create_touch();
int touch_x = window_top_left_x + 27;
int touch_y = window_top_left_y + 8;
touch.down_at(touch_x, touch_y);
client.roundtrip();
surface.reset();
client.roundtrip();
ASSERT_THAT(client.touched_window(), Eq(nullptr)) << "Touch did not leave surface when surface was destroyed";
}
INSTANTIATE_TEST_SUITE_P(
AllSurfaceTypes,
TouchTest,
ValuesIn(wlcs::SurfaceBuilder::all_surface_types()),
wlcs::SubsurfaceBuilder::surface_builder_to_string);
|