]> git.sur5r.net Git - i3/i3/blob - testcases/t/11-goto.t
Merge branch 'next'
[i3/i3] / testcases / t / 11-goto.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 # Beware that this test uses workspace 9 to perform some tests (it expects
4 # the workspace to be empty).
5 # TODO: skip it by default?
6
7 use Test::More tests => 7;
8 use Test::Deep;
9 use X11::XCB qw(:all);
10 use Data::Dumper;
11 use Time::HiRes qw(sleep);
12 use FindBin;
13 use Digest::SHA1 qw(sha1_base64);
14 use lib "$FindBin::Bin/lib";
15 use i3test;
16 use AnyEvent::I3;
17
18 BEGIN {
19     use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
20 }
21
22 my $x = X11::XCB::Connection->new;
23
24 my $i3 = i3;
25
26 # Switch to the nineth workspace
27 $i3->command('9')->recv;
28
29 #####################################################################
30 # Create two windows and make sure focus switching works
31 #####################################################################
32
33 my $top = i3test::open_standard_window($x);
34 sleep(0.25);
35 my $mid = i3test::open_standard_window($x);
36 sleep(0.25);
37 my $bottom = i3test::open_standard_window($x);
38 sleep(0.25);
39
40 diag("top id = " . $top->id);
41 diag("mid id = " . $mid->id);
42 diag("bottom id = " . $bottom->id);
43
44 #
45 # Returns the input focus after sending the given command to i3 via IPC
46 # end sleeping for half a second to make sure i3 reacted
47 #
48 sub focus_after {
49     my $msg = shift;
50
51     $i3->command($msg)->recv;
52     return $x->input_focus;
53 }
54
55 $focus = $x->input_focus;
56 is($focus, $bottom->id, "Latest window focused");
57
58 $focus = focus_after("ml");
59 is($focus, $bottom->id, "Right window still focused");
60
61 $focus = focus_after("h");
62 is($focus, $mid->id, "Middle window focused");
63
64 #####################################################################
65 # Now goto a mark which does not exist
66 #####################################################################
67
68 my $random_mark = sha1_base64(rand());
69
70 $focus = focus_after("goto $random_mark");
71 is($focus, $mid->id, "focus unchanged");
72
73 $i3->command("mark $random_mark")->recv;
74
75 $focus = focus_after("k");
76 is($focus, $top->id, "Top window focused");
77
78 $focus = focus_after("goto $random_mark");
79 is($focus, $mid->id, "goto worked");
80