]> git.sur5r.net Git - i3/i3/blob - testcases/t/238-ipc-binding-event.t
tests: replace http:// with https:// where appropriate
[i3/i3] / testcases / t / 238-ipc-binding-event.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Test that the binding event works properly
18 # Ticket: #1210
19 use i3test i3_autostart => 0;
20
21 my $keysym = 't';
22 my $command = 'nop';
23 my @mods = ('Shift', 'Ctrl');
24 my $binding_symbol = join("+", @mods) . "+$keysym";
25
26 my $config = <<EOT;
27 # i3 config file (v4)
28 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
29
30 bindsym $binding_symbol $command
31 EOT
32
33 SKIP: {
34     qx(which xdotool 2> /dev/null);
35
36     skip 'xdotool is required to test the binding event. `[apt-get install|pacman -S] xdotool`', 1 if $?;
37
38     skip "AnyEvent::I3 too old (need >= 0.16)", 1 if $AnyEvent::I3::VERSION < 0.16;
39
40     my $pid = launch_with_config($config);
41
42     my $i3 = i3(get_socket_path());
43     $i3->connect->recv;
44
45     my $cv = AE::cv;
46     my $timer = AE::timer 0.5, 0, sub { $cv->send(0); };
47
48     $i3->subscribe({
49             binding => sub {
50                 $cv->send(shift);
51             }
52         })->recv;
53
54     qx(xdotool key $binding_symbol);
55
56     my $e = $cv->recv;
57
58     does_i3_live;
59
60     diag "Event:\n", Dumper($e);
61
62     ok($e,
63         'the binding event should emit when user input triggers an i3 binding event');
64
65     is($e->{change}, 'run',
66         'the `change` field should indicate this binding has run');
67
68     ok($e->{binding},
69         'the `binding` field should be a hash that contains information about the binding');
70
71     is($e->{binding}->{input_type}, 'keyboard',
72         'the input_type field should be the input type of the binding (keyboard or mouse)');
73
74     note 'the `mods` field should contain the symbols for the modifiers of the binding';
75     foreach (@mods) {
76         ok(grep(/$_/i, @{$e->{binding}->{mods}}), "`mods` contains the modifier $_");
77     }
78
79     is($e->{binding}->{command}, $command,
80         'the `command` field should contain the command the binding ran');
81
82     is($e->{binding}->{input_code}, 0,
83         'the input_code should be the specified code if the key was bound with bindcode, and otherwise zero');
84
85     exit_gracefully($pid);
86
87 }
88 done_testing;