]> git.sur5r.net Git - i3/i3/blob - testcases/t/227-ipc-workspace-empty.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 227-ipc-workspace-empty.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://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 # Checks the workspace "empty" event semantics.
18 #
19 use i3test;
20
21 SKIP: {
22
23     skip "AnyEvent::I3 too old (need >= 0.15)", 1 if $AnyEvent::I3::VERSION < 0.15;
24
25 ################################################################################
26 # check that the workspace empty event is send upon workspace switch when the
27 # old workspace is empty
28 ################################################################################
29 subtest 'Workspace empty event upon switch', sub {
30     my $ws2 = fresh_workspace;
31     my $w2 = open_window();
32     my $ws1 = fresh_workspace;
33     my $w1 = open_window();
34
35     cmd '[id="' . $w1->id . '"] kill';
36
37     my $cond = AnyEvent->condvar;
38     my $client = i3(get_socket_path(0));
39     $client->connect()->recv;
40     $client->subscribe({
41         workspace => sub {
42             my ($event) = @_;
43             $cond->send($event);
44         }
45     })->recv;
46
47     cmd "workspace $ws2";
48
49     sync_with_i3;
50
51     my $event = $cond->recv;
52     is($event->{change}, 'empty', '"Empty" event received upon workspace switch');
53     is($event->{current}->{name}, $ws1, '"current" property should be set to the workspace con');
54 };
55
56 ################################################################################
57 # check that no workspace empty event is send upon workspace switch if the
58 # workspace is not empty
59 ################################################################################
60 subtest 'No workspace empty event', sub {
61     my $ws2 = fresh_workspace;
62     my $w2 = open_window();
63     my $ws1 = fresh_workspace;
64     my $w1 = open_window();
65
66     my @events;
67     my $cond = AnyEvent->condvar;
68     my $client = i3(get_socket_path(0));
69     $client->connect()->recv;
70     $client->subscribe({
71         workspace => sub {
72             my ($event) = @_;
73             push @events, $event;
74         }
75     })->recv;
76
77     # Wait for the workspace event on a new connection. Events will be delivered
78     # to older connections earlier, so by the time it arrives here, it should be
79     # in @events already.
80     my $ws_event_block_conn = i3(get_socket_path(0));
81     $ws_event_block_conn->connect()->recv;
82     $ws_event_block_conn->subscribe({ workspace => sub { $cond->send(1) }});
83
84     cmd "workspace $ws2";
85
86     sync_with_i3;
87
88     my @expected_events = grep { $_->{change} eq 'focus' } @events;
89     my @empty_events = grep { $_->{change} eq 'empty' } @events;
90     is(@expected_events, 1, '"Focus" event received');
91     is(@empty_events, 0, 'No "empty" events received');
92 };
93
94 ################################################################################
95 # check that workspace empty event is send when the last window has been closed
96 # on invisible workspace
97 ################################################################################
98 subtest 'Workspace empty event upon window close', sub {
99     my $ws1 = fresh_workspace;
100     my $w1 = open_window();
101     my $ws2 = fresh_workspace;
102     my $w2 = open_window();
103
104     my $cond = AnyEvent->condvar;
105     my $client = i3(get_socket_path(0));
106     $client->connect()->recv;
107     $client->subscribe({
108         workspace => sub {
109             my ($event) = @_;
110             $cond->send($event);
111         }
112     })->recv;
113
114     cmd '[id="' . $w1->id . '"] kill';
115
116     sync_with_i3;
117
118     my $event = $cond->recv;
119     is($event->{change}, 'empty', '"Empty" event received upon window close');
120     is($event->{current}->{name}, $ws1, '"current" property should be set to the workspace con');
121 };
122
123 }
124
125 done_testing;