~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to tests/acceptance-tests/throwback/test_client_input.cpp

  • Committer: Package Import Robot
  • Author(s): CI Train Bot
  • Date: 2015-05-12 13:12:55 UTC
  • mto: This revision was merged to the branch mainline in revision 96.
  • Revision ID: package-import@ubuntu.com-20150512131255-y7z12i8n4pbvo70x
Tags: upstream-0.13.0+15.10.20150512
ImportĀ upstreamĀ versionĀ 0.13.0+15.10.20150512

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *              Alexandros Frantzis <alexandros.frantzis@canonical.com>
19
19
 */
20
20
 
21
 
#define MIR_INCLUDE_DEPRECATED_EVENT_HEADER 
22
 
 
 
21
#include "mir/events/event_private.h"
23
22
#include "mir/shell/shell_wrapper.h"
24
23
#include "mir/scene/surface_creation_parameters.h"
25
24
#include "mir/scene/surface.h"
91
90
        surface = mir_surface_create_sync(spec);
92
91
        mir_surface_spec_release(spec);
93
92
 
94
 
        MirEventDelegate const event_delegate { handle_input, this };
95
 
        mir_surface_set_event_handler(surface, &event_delegate);
96
 
        mir_surface_swap_buffers_sync(surface);
 
93
        mir_surface_set_event_handler(surface, handle_input, this);
 
94
        mir_buffer_stream_swap_buffers_sync(
 
95
            mir_surface_get_buffer_stream(surface));
97
96
 
98
97
        wait_for_surface_to_become_focused_and_exposed();
99
98
 
108
107
    {
109
108
        auto const client = static_cast<InputClient*>(context);
110
109
 
111
 
        if (ev->type == mir_event_type_surface)
 
110
        if (mir_event_get_type(ev) == mir_event_type_surface)
112
111
            return;
113
112
 
114
113
        client->handler.handle_input(ev);
623
622
            session->default_surface()->consume(key_event);
624
623
        });
625
624
}
 
625
 
 
626
TEST_F(TestClientInput, clients_receive_keymap_change_events)
 
627
{
 
628
    using namespace testing;
 
629
 
 
630
    mt::WaitCondition first_event_received;
 
631
    InputClient client{new_connection(), test_client_name_1};
 
632
 
 
633
    xkb_rule_names names;
 
634
    names.rules = "evdev";
 
635
    names.model = "pc105";
 
636
    names.layout = "dvorak";
 
637
    names.variant = "";
 
638
    names.options = "";
 
639
    
 
640
    InSequence seq;
 
641
    EXPECT_CALL(client.handler, handle_input(
 
642
        mt::KeymapEventWithRules(names)))
 
643
        .Times(1).WillOnce(mt::WakeUp(&client.all_events_received));
 
644
 
 
645
    client.start();
 
646
 
 
647
    server_config().the_session_container()->for_each(
 
648
        [names] (std::shared_ptr<ms::Session> const& session) -> void
 
649
        {
 
650
            session->default_surface()->set_keymap(names);
 
651
        });
 
652
}
 
653
 
 
654
 
 
655
TEST_F(TestClientInput, keymap_changes_change_keycode_received)
 
656
{
 
657
    using namespace testing;
 
658
 
 
659
    xkb_rule_names names;
 
660
    names.rules = "evdev";
 
661
    names.model = "pc105";
 
662
    names.layout = "us";
 
663
    names.variant = "dvorak";
 
664
    names.options = "";
 
665
 
 
666
    mt::WaitCondition first_event_received,
 
667
        client_sees_keymap_change;
 
668
    InputClient client{new_connection(), test_client_name_1};
 
669
    
 
670
    InSequence seq;
 
671
    EXPECT_CALL(client.handler, handle_input(AllOf(
 
672
        mt::KeyDownEvent(), mt::KeyOfSymbol(XKB_KEY_n)))).Times(1);
 
673
    EXPECT_CALL(client.handler, handle_input(mt::KeyUpEvent()))
 
674
        .Times(1).WillOnce(mt::WakeUp(&first_event_received));
 
675
    EXPECT_CALL(client.handler, handle_input(
 
676
        mt::KeymapEventWithRules(names)))
 
677
        .Times(1).WillOnce(mt::WakeUp(&client_sees_keymap_change));
 
678
    EXPECT_CALL(client.handler, handle_input(AllOf(
 
679
        mt::KeyDownEvent(), mt::KeyOfSymbol(XKB_KEY_b)))).Times(1);
 
680
    EXPECT_CALL(client.handler, handle_input(mt::KeyUpEvent()))
 
681
        .Times(1).WillOnce(mt::WakeUp(&client.all_events_received));
 
682
 
 
683
    client.start();
 
684
 
 
685
    fake_event_hub()->synthesize_event(
 
686
        mis::a_key_down_event().of_scancode(KEY_N));
 
687
    fake_event_hub()->synthesize_event(
 
688
        mis::a_key_up_event().of_scancode(KEY_N));
 
689
 
 
690
    first_event_received.wait_for_at_most_seconds(60);
 
691
    
 
692
    server_config().the_session_container()->for_each(
 
693
        [&names] (std::shared_ptr<ms::Session> const& session) -> void
 
694
        {
 
695
            session->default_surface()->set_keymap(names);
 
696
        });
 
697
 
 
698
    client_sees_keymap_change.wait_for_at_most_seconds(60);
 
699
 
 
700
    fake_event_hub()->synthesize_event(
 
701
        mis::a_key_down_event().of_scancode(KEY_N));
 
702
    fake_event_hub()->synthesize_event(
 
703
        mis::a_key_up_event().of_scancode(KEY_N));
 
704
}