t/35-floating-focus: rewrite testcase to use windows instead of empty cons

This commit is contained in:
Michael Stapelberg 2011-05-13 19:27:18 +02:00
parent 836a3ad615
commit 5eef824495
1 changed files with 57 additions and 36 deletions

View File

@ -2,6 +2,10 @@
# vim:ts=4:sw=4:expandtab # vim:ts=4:sw=4:expandtab
use i3test; use i3test;
use X11::XCB qw(:all);
use X11::XCB::Connection;
my $x = X11::XCB::Connection->new;
my $tmp = fresh_workspace; my $tmp = fresh_workspace;
@ -9,61 +13,78 @@ my $tmp = fresh_workspace;
# 1: see if focus stays the same when toggling tiling/floating mode # 1: see if focus stays the same when toggling tiling/floating mode
############################################################################# #############################################################################
cmd "open"; my $first = open_standard_window($x);
cmd "open"; my $second = open_standard_window($x);
my @content = @{get_ws_content($tmp)}; is($x->input_focus, $second->id, 'second window focused');
cmp_ok(@content, '==', 2, 'two containers opened');
cmp_ok($content[1]->{focused}, '==', 1, 'Second container focused');
cmd "mode floating"; cmd 'mode floating';
cmd "mode tiling"; cmd 'mode tiling';
@content = @{get_ws_content($tmp)}; is($x->input_focus, $second->id, 'second window still focused after mode toggle');
cmp_ok($content[1]->{focused}, '==', 1, 'Second container still focused after mode toggle');
############################################################################# #############################################################################
# 2: see if the focus gets reverted correctly when closing floating clients # 2: see if focus stays on the current floating window if killing another
# floating window
#############################################################################
$tmp = fresh_workspace;
$first = open_standard_window($x); # window 2
$second = open_standard_window($x); # window 3
my $third = open_standard_window($x); # window 4
is($x->input_focus, $third->id, 'last container focused');
cmd 'mode floating';
cmd '[id="' . $second->id . '"] focus';
is($x->input_focus, $second->id, 'second con focused');
cmd 'mode floating';
# now kill the third one (it's floating). focus should stay unchanged
cmd '[id="' . $third->id . '"] kill';
sleep 0.25;
is($x->input_focus, $second->id, 'second con still focused after killing third');
#############################################################################
# 3: see if the focus gets reverted correctly when closing floating clients
# (first to the next floating client, then to the last focused tiling client) # (first to the next floating client, then to the last focused tiling client)
############################################################################# #############################################################################
$tmp = fresh_workspace; $tmp = fresh_workspace;
cmd "open"; $first = open_standard_window($x); # window 2
cmd "open"; $second = open_standard_window($x); # window 3
cmd "open"; my $third = open_standard_window($x); # window 4
@content = @{get_ws_content($tmp)}; is($x->input_focus, $third->id, 'last container focused');
cmp_ok(@content, '==', 3, 'two containers opened');
cmp_ok($content[2]->{focused}, '==', 1, 'Last container focused');
my $last_id = $content[2]->{id}; cmd 'mode floating';
my $second_id = $content[1]->{id};
my $first_id = $content[0]->{id};
diag("last_id = $last_id, second_id = $second_id, first_id = $first_id");
cmd qq|[con_id="$second_id"] focus|; cmd '[id="' . $second->id . '"] focus';
@content = @{get_ws_content($tmp)};
cmp_ok($content[1]->{focused}, '==', 1, 'Second container focused');
cmd "mode floating"; is($x->input_focus, $second->id, 'second con focused');
cmd qq|[con_id="$last_id"] focus|; cmd 'mode floating';
@content = @{get_ws_content($tmp)};
cmp_ok($content[1]->{focused}, '==', 1, 'Last container focused');
cmd "mode floating"; # now kill the second one. focus should fall back to the third one, which is
# also floating
cmd 'kill';
diag("focused = " . get_focused($tmp)); sleep 0.25;
cmd "kill"; is($x->input_focus, $third->id, 'third con focused');
diag("focused = " . get_focused($tmp)); cmd 'kill';
# TODO: this test result is actually not right. the focus reverts to where the mouse pointer is.
cmp_ok(get_focused($tmp), '==', $second_id, 'Focus reverted to second floating container');
cmd "kill"; sleep 0.25;
@content = @{get_ws_content($tmp)};
cmp_ok($content[0]->{focused}, '==', 1, 'Focus reverted to tiling container'); is($x->input_focus, $first->id, 'first con focused after killing all floating cons');
done_testing; done_testing;