2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Checks the workspace "empty" event semantics.
23 skip "AnyEvent::I3 too old (need >= 0.15)", 1 if $AnyEvent::I3::VERSION < 0.15;
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();
35 cmd '[id="' . $w1->id . '"] kill';
37 my $cond = AnyEvent->condvar;
38 my $client = i3(get_socket_path(0));
39 $client->connect()->recv;
51 my $event = $cond->recv;
52 is($event->{change}, 'empty', '"Empty" event received upon workspace switch');
55 ################################################################################
56 # check that no workspace empty event is send upon workspace switch if the
57 # workspace is not empty
58 ################################################################################
59 subtest 'No workspace empty event', sub {
60 my $ws2 = fresh_workspace;
61 my $w2 = open_window();
62 my $ws1 = fresh_workspace;
63 my $w1 = open_window();
66 my $cond = AnyEvent->condvar;
67 my $client = i3(get_socket_path(0));
68 $client->connect()->recv;
76 # Wait for the workspace event on a new connection. Events will be delivered
77 # to older connections earlier, so by the time it arrives here, it should be
79 my $ws_event_block_conn = i3(get_socket_path(0));
80 $ws_event_block_conn->connect()->recv;
81 $ws_event_block_conn->subscribe({ workspace => sub { $cond->send(1) }});
87 my @expected_events = grep { $_->{change} eq 'focus' } @events;
88 my @empty_events = grep { $_->{change} eq 'empty' } @events;
89 is(@expected_events, 1, '"Focus" event received');
90 is(@empty_events, 0, 'No "empty" events received');
93 ################################################################################
94 # check that workspace empty event is send when the last window has been closed
95 # on invisible workspace
96 ################################################################################
97 subtest 'Workspace empty event upon window close', sub {
98 my $ws1 = fresh_workspace;
99 my $w1 = open_window();
100 my $ws2 = fresh_workspace;
101 my $w2 = open_window();
103 my $cond = AnyEvent->condvar;
104 my $client = i3(get_socket_path(0));
105 $client->connect()->recv;
113 cmd '[id="' . $w1->id . '"] kill';
117 my $event = $cond->recv;
118 is($event->{change}, 'empty', '"Empty" event received upon window close');