38
38
#include "mir/events/event_builders.h"
40
40
#include "mir/frontend/connector.h"
41
#include "mir/input/input_platform.h"
43
42
#include "mir/test/test_protobuf_server.h"
44
43
#include "mir/test/stub_server_tool.h"
219
218
{ mir_window_attrib_preferred_orientation, mir_orientation_mode_any }
222
struct StubClientInputPlatform : public mircv::InputPlatform
224
std::shared_ptr<mir::dispatch::Dispatchable> create_input_receiver(int /* fd */, std::shared_ptr<mircv::XKBMapper> const&, std::function<void(MirEvent*)> const& /* callback */)
226
return std::shared_ptr<mir::dispatch::Dispatchable>();
230
struct MockClientInputPlatform : public mircv::InputPlatform
232
MOCK_METHOD3(create_input_receiver, std::shared_ptr<mir::dispatch::Dispatchable>(int, std::shared_ptr<mircv::XKBMapper> const&, std::function<void(MirEvent*)> const&));
235
221
class TestConnectionConfiguration : public mcl::DefaultConnectionConfiguration
368
348
MirWindowSpec const spec{nullptr, 33, 45, mir_pixel_format_abgr_8888};
369
349
std::shared_ptr<mtd::MockMirBufferStream> stub_buffer_stream{std::make_shared<mtd::MockMirBufferStream>()};
370
std::shared_ptr<StubClientInputPlatform> const input_platform =
371
std::make_shared<StubClientInputPlatform>();
372
350
std::shared_ptr<MockServerPackageGenerator> const mock_server_tool =
373
351
std::make_shared<MockServerPackageGenerator>();
398
TEST_F(MirClientSurfaceTest, creates_input_thread_with_input_dispatcher_when_delegate_specified)
400
using namespace ::testing;
402
auto dispatched = std::make_shared<mt::Signal>();
404
auto mock_input_dispatcher = std::make_shared<mt::TestDispatchable>([dispatched]() { dispatched->raise(); });
405
auto mock_input_platform = std::make_shared<MockClientInputPlatform>();
407
EXPECT_CALL(*mock_input_platform, create_input_receiver(_, _, _)).Times(1)
408
.WillOnce(Return(mock_input_dispatcher));
410
MirWindow surface{connection.get(), *client_comm_channel, nullptr,
411
stub_buffer_stream, mock_input_platform, spec, surface_proto, wh};
412
surface.set_event_handler(null_event_callback, nullptr);
414
mock_input_dispatcher->trigger();
416
EXPECT_TRUE(dispatched->wait_for(std::chrono::seconds{5}));
419
376
TEST_F(MirClientSurfaceTest, adopts_the_default_stream)
421
378
using namespace ::testing;
423
auto mock_input_platform = std::make_shared<MockClientInputPlatform>();
424
380
auto mock_stream = std::make_shared<mtd::MockMirBufferStream>();
426
382
MirWindow* adopted_by = nullptr;
434
390
MirWindow win{connection.get(), *client_comm_channel, nullptr,
435
mock_stream, mock_input_platform, spec, surface_proto, wh};
391
mock_stream, spec, surface_proto, wh};
436
392
EXPECT_EQ(&win, adopted_by);
437
393
EXPECT_EQ(nullptr, unadopted_by);
446
402
using namespace ::testing;
448
404
mir::frontend::BufferStreamId const mock_stream_id(777888);
449
auto mock_input_platform = std::make_shared<MockClientInputPlatform>();
450
405
auto mock_stream = std::make_shared<mtd::MockMirBufferStream>();
452
407
MirWindow* adopted_by = nullptr;
469
424
spec.streams = replacements;
470
425
MirWindow win{connection.get(), *client_comm_channel, nullptr,
471
nullptr, mock_input_platform, spec, surface_proto, wh};
426
nullptr, spec, surface_proto, wh};
472
427
ASSERT_EQ(&win, adopted_by);
473
428
ASSERT_EQ(nullptr, unadopted_by);
482
437
using namespace testing;
484
auto mock_input_platform = std::make_shared<MockClientInputPlatform>();
486
439
mir::frontend::BufferStreamId const mock_old_stream_id(11);
487
440
auto mock_old_stream = std::make_shared<mtd::MockMirBufferStream>();
488
441
MirWindow* old_adopted_by = nullptr;
509
462
surface_map->insert(mock_new_stream_id, mock_new_stream);
511
464
MirWindow win{connection.get(), *client_comm_channel, nullptr,
512
mock_old_stream, mock_input_platform, spec, surface_proto, wh};
465
mock_old_stream, spec, surface_proto, wh};
514
467
EXPECT_EQ(&win, old_adopted_by);
515
468
EXPECT_EQ(nullptr, old_unadopted_by);
533
486
surface_map->erase(mock_new_stream_id);
536
TEST_F(MirClientSurfaceTest, replacing_delegate_with_nullptr_prevents_further_dispatch)
538
using namespace ::testing;
540
auto dispatched = std::make_shared<mt::Signal>();
542
auto mock_input_dispatcher = std::make_shared<mt::TestDispatchable>([dispatched]() { dispatched->raise(); });
543
auto mock_input_platform = std::make_shared<MockClientInputPlatform>();
545
EXPECT_CALL(*mock_input_platform, create_input_receiver(_, _, _)).Times(1)
546
.WillOnce(Return(mock_input_dispatcher));
548
MirWindow surface{connection.get(), *client_comm_channel, nullptr,
549
stub_buffer_stream, mock_input_platform, spec, surface_proto, wh};
550
surface.set_event_handler(null_event_callback, nullptr);
552
// Should now not get dispatched.
553
surface.set_event_handler(nullptr, nullptr);
555
mock_input_dispatcher->trigger();
557
EXPECT_FALSE(dispatched->wait_for(std::chrono::seconds{1}));
561
TEST_F(MirClientSurfaceTest, does_not_create_input_dispatcher_when_no_delegate_specified)
563
using namespace ::testing;
565
auto mock_input_platform = std::make_shared<MockClientInputPlatform>();
567
EXPECT_CALL(*mock_input_platform, create_input_receiver(_, _, _)).Times(0);
569
MirWindow surface{connection.get(), *client_comm_channel, nullptr,
570
stub_buffer_stream, mock_input_platform, spec, surface_proto, wh};
573
489
TEST_F(MirClientSurfaceTest, valid_surface_is_valid)
575
491
auto const surface = create_and_wait_for_surface_with(*client_comm_channel);
598
514
EXPECT_GE(std::chrono::steady_clock::now(), expected_end);
516
#pragma GCC diagnostic push
517
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
600
518
mir_cursor_configuration_destroy(cursor_config);
519
#pragma GCC diagnostic pop
603
522
TEST_F(MirClientSurfaceTest, configure_wait_handle_really_blocks)
622
541
using namespace testing;
623
542
auto mock_stream = std::make_shared<mtd::MockMirBufferStream>();
624
543
mir::frontend::BufferStreamId const mock_stream_id(2);
625
auto mock_input_platform = std::make_shared<NiceMock<MockClientInputPlatform>>();
626
ON_CALL(*mock_input_platform, create_input_receiver(_,_,_))
627
.WillByDefault(Return(std::make_shared<mt::TestDispatchable>([]{})));
628
544
ON_CALL(*mock_stream, rpc_id()).WillByDefault(Return(mock_stream_id));
630
546
geom::Size size(120, 124);
632
548
auto ev = mir::events::make_event(mir::frontend::SurfaceId(2), size);
634
550
MirWindow surface{connection.get(), *client_comm_channel, nullptr,
635
mock_stream, mock_input_platform, spec, surface_proto, wh};
551
mock_stream, spec, surface_proto, wh};
636
552
surface_map->insert(mock_stream_id, mock_stream);
637
553
surface.handle_event(*ev);
638
554
surface_map->erase(mock_stream_id);
643
559
using namespace testing;
644
560
auto mock_stream = std::make_shared<NiceMock<mtd::MockMirBufferStream>>();
645
561
mir::frontend::BufferStreamId const mock_stream_id(2);
646
auto mock_input_platform = std::make_shared<NiceMock<MockClientInputPlatform>>();
647
562
ON_CALL(*mock_stream, rpc_id()).WillByDefault(Return(mock_stream_id));
648
ON_CALL(*mock_input_platform, create_input_receiver(_,_,_))
649
.WillByDefault(Return(std::make_shared<mt::TestDispatchable>([]{})));
651
564
geom::Size size(120, 124);
652
565
EXPECT_CALL(*mock_stream, set_size(size)).Times(0);
653
566
auto ev = mir::events::make_event(mir::frontend::SurfaceId(2), size);
654
567
MirWindow surface{connection.get(), *client_comm_channel, nullptr,
655
mock_stream, mock_input_platform, spec, surface_proto, wh};
568
mock_stream, spec, surface_proto, wh};
657
570
MirWindowSpec spec;
658
571
std::vector<ContentInfo> info =
669
582
using namespace testing;
670
583
auto mock_stream = std::make_shared<mtd::MockMirBufferStream>();
671
auto mock_input_platform = std::make_shared<NiceMock<MockClientInputPlatform>>();
672
ON_CALL(*mock_input_platform, create_input_receiver(_,_,_))
673
.WillByDefault(Return(std::make_shared<mt::TestDispatchable>([]{})));
674
584
ON_CALL(*mock_stream, rpc_id()).WillByDefault(Return(mir::frontend::BufferStreamId(2)));
675
585
geom::Size size(120, 124);
676
586
EXPECT_CALL(*mock_stream, set_size(size));
680
590
surface_proto.set_height(size.height.as_int());
682
592
MirWindow surface{connection.get(), *client_comm_channel, nullptr,
683
mock_stream, mock_input_platform, spec, surface_proto, wh};
593
mock_stream, spec, surface_proto, wh};
685
595
auto params = surface.get_parameters();
686
596
EXPECT_THAT(params.width, Eq(size.width.as_int()));
697
607
using namespace testing;
698
608
auto mock_stream = std::make_shared<mtd::MockMirBufferStream>();
699
auto mock_input_platform = std::make_shared<NiceMock<MockClientInputPlatform>>();
700
ON_CALL(*mock_input_platform, create_input_receiver(_,_,_))
701
.WillByDefault(Return(std::make_shared<mt::TestDispatchable>([]{})));
702
609
ON_CALL(*mock_stream, rpc_id()).WillByDefault(Return(mir::frontend::BufferStreamId(2)));
703
610
geom::Size size(120, 124);
705
612
surface_proto.set_width(size.width.as_int());
706
613
surface_proto.set_height(size.height.as_int());
707
614
MirWindow surface{connection.get(), *client_comm_channel, nullptr,
708
mock_stream, mock_input_platform, spec, surface_proto, wh};
615
mock_stream, spec, surface_proto, wh};
710
617
auto params = surface.get_parameters();
711
618
EXPECT_THAT(params.width, Eq(size.width.as_int()));