]> git.sur5r.net Git - i3/i3/blob - testcases/t/115-ipc-workspaces.t
tests: replace http:// with https:// where appropriate
[i3/i3] / testcases / t / 115-ipc-workspaces.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 use i3test;
18
19 my $i3 = i3(get_socket_path());
20 $i3->connect()->recv;
21
22 ################################
23 # Workspaces requests and events
24 ################################
25
26 my $old_ws = get_ws(focused_ws());
27
28 # Events
29
30 # We are switching to an empty workpspace from an empty workspace, so we expect
31 # to receive "init", "focus", and "empty".
32 my $init = AnyEvent->condvar;
33 my $focus = AnyEvent->condvar;
34 my $empty = AnyEvent->condvar;
35 $i3->subscribe({
36     workspace => sub {
37         my ($event) = @_;
38         if ($event->{change} eq 'init') {
39             $init->send($event);
40         } elsif ($event->{change} eq 'focus') {
41             $focus->send($event);
42         } elsif ($event->{change} eq 'empty') {
43             $empty->send($event);
44         }
45     }
46 })->recv;
47
48 cmd 'workspace 2';
49
50 my $t;
51 $t = AnyEvent->timer(
52     after => 0.5,
53     cb => sub {
54         $init->send(0);
55         $focus->send(0);
56         $empty->send(0);
57     }
58 );
59
60 my $init_event = $init->recv;
61 my $focus_event = $focus->recv;
62 my $empty_event = $empty->recv;
63
64 my $current_ws = get_ws(focused_ws());
65
66 ok($init_event, 'workspace "init" event received');
67 is($init_event->{current}->{id}, $current_ws->{id}, 'the "current" property should contain the initted workspace con');
68
69 ok($focus_event, 'workspace "focus" event received');
70 is($focus_event->{current}->{id}, $current_ws->{id}, 'the "current" property should contain the focused workspace con');
71 is($focus_event->{old}->{id}, $old_ws->{id}, 'the "old" property should contain the workspace con that was focused last');
72
73 ok($empty_event, 'workspace "empty" event received');
74 is($empty_event->{current}->{id}, $old_ws->{id}, 'the "current" property should contain the emptied workspace con');
75
76 done_testing;