aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/227-ipc-workspace-empty.t
blob: b1f517ef5e4eb67aed9cf44044b02c04a31686db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Checks the workspace "empty" event semantics.
#
use i3test;

################################################################################
# check that the workspace empty event is sent upon workspace switch when the
# old workspace is empty
################################################################################
subtest 'Workspace empty event upon switch', sub {
    my $ws2 = fresh_workspace;
    my $w2 = open_window();
    my $ws1 = fresh_workspace;
    my $w1 = open_window();

    cmd '[id="' . $w1->id . '"] kill';

    my $cond = AnyEvent->condvar;
    my @events = events_for(
	sub { cmd "workspace $ws2" },
	'workspace');

    is(scalar @events, 2, 'Received 2 event');
    is($events[1]->{change}, 'empty', '"Empty" event received upon workspace switch');
    is($events[1]->{current}->{name}, $ws1, '"current" property should be set to the workspace con');
};

################################################################################
# check that no workspace empty event is sent upon workspace switch if the
# workspace is not empty
################################################################################
subtest 'No workspace empty event', sub {
    my $ws2 = fresh_workspace;
    my $w2 = open_window();
    my $ws1 = fresh_workspace;
    my $w1 = open_window();

    my @events = events_for(
	sub { cmd "workspace $ws2" },
	'workspace');

    is(scalar @events, 1, 'Received 1 event');
    is($events[0]->{change}, 'focus', 'Event change is "focus"');
};

################################################################################
# check that workspace empty event is sent when the last window has been closed
# on invisible workspace
################################################################################
subtest 'Workspace empty event upon window close', sub {
    my $ws1 = fresh_workspace;
    my $w1 = open_window();
    my $ws2 = fresh_workspace;
    my $w2 = open_window();

    my @events = events_for(
	sub {
	    $w1->unmap;
	    sync_with_i3;
	},
	'workspace');

    is(scalar @events, 1, 'Received 1 event');
    is($events[0]->{change}, 'empty', '"Empty" event received upon window close');
    is($events[0]->{current}->{name}, $ws1, '"current" property should be set to the workspace con');
};

done_testing;