]> git.sur5r.net Git - i3/i3/blob - testcases/t/238-ipc-binding-event.t
Merge branch 'next' into master
[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     my $pid = launch_with_config($config);
39
40     my $cv = AnyEvent->condvar;
41
42     my @events = events_for(
43         sub {
44             # TODO: this is still flaky: we need to synchronize every X11
45             # connection with i3. Move to XTEST and synchronize that connection.
46             qx(xdotool key $binding_symbol);
47         },
48         'binding');
49
50     is(scalar @events, 1, 'Received 1 event');
51
52     is($events[0]->{change}, 'run',
53         'the `change` field should indicate this binding has run');
54
55     ok($events[0]->{binding},
56         'the `binding` field should be a hash that contains information about the binding');
57
58     is($events[0]->{binding}->{input_type}, 'keyboard',
59         'the input_type field should be the input type of the binding (keyboard or mouse)');
60
61     note 'the `mods` field should contain the symbols for the modifiers of the binding';
62     foreach (@mods) {
63         ok(grep(/$_/i, @{$events[0]->{binding}->{mods}}), "`mods` contains the modifier $_");
64     }
65
66     is($events[0]->{binding}->{command}, $command,
67         'the `command` field should contain the command the binding ran');
68
69     is($events[0]->{binding}->{input_code}, 0,
70         'the input_code should be the specified code if the key was bound with bindcode, and otherwise zero');
71
72     exit_gracefully($pid);
73
74 }
75 done_testing;