From da403b3667b0b48f5e1da2ac1e884f2b1bddd4a3 Mon Sep 17 00:00:00 2001 From: Maik Fischer Date: Mon, 21 Nov 2011 23:44:20 +0100 Subject: [PATCH] testcases: use $x in wait_for_(un)map change to wait_for_(un)map($win) wait_for_unmap currently ignores its $window parameter, since X11::XCB doesn't provide $event->{window} for unmap events yet. --- testcases/lib/i3test.pm | 15 ++++++++++--- testcases/t/005-floating.t | 7 +++--- testcases/t/100-fullscreen.t | 4 ++-- testcases/t/102-dock.t | 12 +++++------ testcases/t/104-focus-stack.t | 2 +- testcases/t/114-client-leader.t | 10 ++++----- testcases/t/117-workspace.t | 2 +- testcases/t/119-match.t | 14 ++++++------ testcases/t/133-size-hints.t | 2 +- testcases/t/135-floating-focus.t | 10 ++++----- testcases/t/150-regress-dock-restart.t | 2 +- testcases/t/163-wm-state.t | 2 +- testcases/t/165-for_window.t | 30 +++++++++++++------------- testcases/t/166-assign.t | 10 ++++----- 14 files changed, 66 insertions(+), 56 deletions(-) diff --git a/testcases/lib/i3test.pm b/testcases/lib/i3test.pm index 98d27e90..c94101e1 100644 --- a/testcases/lib/i3test.pm +++ b/testcases/lib/i3test.pm @@ -12,6 +12,7 @@ use EV; use List::Util qw(first); use Time::HiRes qw(sleep); use Cwd qw(abs_path); +use Scalar::Util qw(blessed); use SocketActivation; use v5.10; @@ -122,14 +123,22 @@ sub wait_for_event { # thin wrapper around wait_for_event which waits for MAP_NOTIFY # make sure to include 'structure_notify' in the window’s event_mask attribute sub wait_for_map { - wait_for_event 2, sub { $_[0]->{response_type} == MAP_NOTIFY }; + my ($win) = @_; + my $id = (blessed($win) && $win->isa('X11::XCB::Window')) ? $win->id : $win; + wait_for_event 2, sub { + $_[0]->{response_type} == MAP_NOTIFY and $_[0]->{window} == $id + }; } # Wrapper around wait_for_event which waits for UNMAP_NOTIFY. Also calls # sync_with_i3 to make sure i3 also picked up and processed the UnmapNotify # event. sub wait_for_unmap { - wait_for_event 2, sub { $_[0]->{response_type} == UNMAP_NOTIFY }; + my ($win) = @_; + # my $id = (blessed($win) && $win->isa('X11::XCB::Window')) ? $win->id : $win; + wait_for_event 2, sub { + $_[0]->{response_type} == UNMAP_NOTIFY # and $_[0]->{window} == $id + }; sync_with_i3($x); } @@ -163,7 +172,7 @@ sub open_window { return $window if $dont_map; $window->map; - wait_for_map($x); + wait_for_map($window); # We sync with i3 here to make sure $x->input_focus is updated. sync_with_i3($x); return $window; diff --git a/testcases/t/005-floating.t b/testcases/t/005-floating.t index 7e6b8922..d62a0366 100644 --- a/testcases/t/005-floating.t +++ b/testcases/t/005-floating.t @@ -18,7 +18,7 @@ isa_ok($window, 'X11::XCB::Window'); $window->map; -wait_for_map $x; +wait_for_map $window; my ($absolute, $top) = $window->rect; @@ -42,7 +42,7 @@ isa_ok($window, 'X11::XCB::Window'); $window->map; -wait_for_map $x; +wait_for_map $window; ($absolute, $top) = $window->rect; @@ -73,10 +73,11 @@ isa_ok($window, 'X11::XCB::Window'); $window->map; -wait_for_map $x; +wait_for_map $window; cmd 'floating enable'; +# XXX potentionally racy ($absolute, $top) = $window->rect; cmp_ok($absolute->{width}, '==', 80, "i3 let the width at 80"); diff --git a/testcases/t/100-fullscreen.t b/testcases/t/100-fullscreen.t index e014da48..f5fb6693 100644 --- a/testcases/t/100-fullscreen.t +++ b/testcases/t/100-fullscreen.t @@ -45,7 +45,7 @@ is_deeply($window->rect, $original_rect, "rect unmodified before mapping"); $window->map; -wait_for_map $x; +wait_for_map $window; # open another container to make the window get only half of the screen cmd 'open'; @@ -95,7 +95,7 @@ is_deeply($window->rect, $original_rect, "rect unmodified before mapping"); $window->fullscreen(1); $window->map; -wait_for_map $x; +wait_for_map $window; $new_rect = $window->rect; ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned after fullscreen"); diff --git a/testcases/t/102-dock.t b/testcases/t/102-dock.t index 213052f5..f97fa21c 100644 --- a/testcases/t/102-dock.t +++ b/testcases/t/102-dock.t @@ -67,7 +67,7 @@ is($docknode->{rect}->{height}, 40, 'dock height changed'); $window->destroy; -wait_for_unmap $x; +wait_for_unmap $window; @docked = get_dock_clients(); is(@docked, 0, 'no more dock clients'); @@ -91,7 +91,7 @@ is(@docked, 1, 'dock client on bottom'); $window->destroy; -wait_for_unmap $x; +wait_for_unmap $window; @docked = get_dock_clients(); is(@docked, 0, 'no more dock clients'); @@ -125,14 +125,14 @@ $x->change_property( $window->map; -wait_for_map $x; +wait_for_map $window; @docked = get_dock_clients('top'); is(@docked, 1, 'dock client on top'); $window->destroy; -wait_for_unmap $x; +wait_for_unmap $window; @docked = get_dock_clients(); is(@docked, 0, 'no more dock clients'); @@ -162,7 +162,7 @@ $x->change_property( $window->map; -wait_for_map $x; +wait_for_map $window; @docked = get_dock_clients('bottom'); is(@docked, 1, 'dock client on bottom'); @@ -183,7 +183,7 @@ my $fwindow = open_window($x, { $fwindow->transient_for($window); $fwindow->map; -wait_for_map $x; +wait_for_map $fwindow; does_i3_live; diff --git a/testcases/t/104-focus-stack.t b/testcases/t/104-focus-stack.t index 8807d015..1128e16a 100644 --- a/testcases/t/104-focus-stack.t +++ b/testcases/t/104-focus-stack.t @@ -21,7 +21,7 @@ is($x->input_focus, $window->id, 'floating window focused'); $window->unmap; -wait_for_unmap($x); +wait_for_unmap $window; is($x->input_focus, $focus, 'Focus correctly restored'); diff --git a/testcases/t/114-client-leader.t b/testcases/t/114-client-leader.t index d2fd16a0..4d6ecc51 100644 --- a/testcases/t/114-client-leader.t +++ b/testcases/t/114-client-leader.t @@ -25,7 +25,7 @@ my $child = open_floating_window($x, { $child->client_leader($right); $child->map; -ok(wait_for_map($x), 'child window mapped'); +ok(wait_for_map($child), 'child window mapped'); my $cgeom; ($abs, $cgeom) = $child->rect; @@ -38,7 +38,7 @@ my $child2 = open_floating_window($x, { $child2->client_leader($left); $child2->map; -ok(wait_for_map($x), 'second child window mapped'); +ok(wait_for_map($child2), 'second child window mapped'); ($abs, $cgeom) = $child2->rect; cmp_ok(($cgeom->x + $cgeom->width), '<', $rgeom->x, 'child above left window'); @@ -48,7 +48,7 @@ my $fwindow = open_window($x, { dont_map => 1 }); $fwindow->transient_for($right); $fwindow->map; -ok(wait_for_map($x), 'transient window mapped'); +ok(wait_for_map($fwindow), 'transient window mapped'); my ($absolute, $top) = $fwindow->rect; ok($absolute->{x} != 0 && $absolute->{y} != 0, 'i3 did not map it to (0x0)'); @@ -63,7 +63,7 @@ SKIP: { my $window = open_window($x, { dont_map => 1, name => 'Parent window' }); $window->map; -ok(wait_for_map($x), 'parent window mapped'); +ok(wait_for_map($window), 'parent window mapped'); ######################################################################### # Switch to a different workspace and open a child window. It should be opened @@ -75,7 +75,7 @@ my $child = open_window($x, { dont_map => 1, name => 'Child window' }); $child->client_leader($window); $child->map; -ok(wait_for_map($x), 'child window mapped'); +ok(wait_for_map($child), 'child window mapped'); isnt($x->input_focus, $child->id, "Child window focused"); diff --git a/testcases/t/117-workspace.t b/testcases/t/117-workspace.t index a88c669c..3c52e31e 100644 --- a/testcases/t/117-workspace.t +++ b/testcases/t/117-workspace.t @@ -113,7 +113,7 @@ ok(defined($ws), "workspace 0: $tmp was created"); is($ws->{num}, 0, 'workspace number is 0'); cmd "workspace aa: $tmp"; -my $ws = get_ws("aa: $tmp"); +$ws = get_ws("aa: $tmp"); ok(defined($ws), "workspace aa: $tmp was created"); is($ws->{num}, -1, 'workspace number is -1'); diff --git a/testcases/t/119-match.t b/testcases/t/119-match.t index 80c94ab1..cad8163f 100644 --- a/testcases/t/119-match.t +++ b/testcases/t/119-match.t @@ -34,7 +34,7 @@ cmd 'nop now killing the window'; my $id = $win->{id}; cmd qq|[con_id="$id"] kill|; -wait_for_unmap $x; +wait_for_unmap $window; cmd 'nop checking if its gone'; $content = get_ws_content($tmp); @@ -80,7 +80,7 @@ $left->_create; set_wm_class($left->id, 'special', 'special'); $left->name('left'); $left->map; -ok(wait_for_map($x), 'left window mapped'); +ok(wait_for_map($left), 'left window mapped'); my $right = $x->root->create_child( class => WINDOW_CLASS_INPUT_OUTPUT, @@ -93,7 +93,7 @@ $right->_create; set_wm_class($right->id, 'special', 'special'); $right->name('right'); $right->map; -ok(wait_for_map($x), 'right window mapped'); +ok(wait_for_map($right), 'right window mapped'); # two windows should be here $content = get_ws_content($tmp); @@ -123,7 +123,7 @@ $left->_create; set_wm_class($left->id, 'special7', 'special7'); $left->name('left'); $left->map; -ok(wait_for_map($x), 'left window mapped'); +ok(wait_for_map($left), 'left window mapped'); # two windows should be here $content = get_ws_content($tmp); @@ -131,7 +131,7 @@ ok(@{$content} == 1, 'window opened'); cmd '[class="^special[0-9]$"] kill'; -wait_for_unmap $x; +wait_for_unmap $left; $content = get_ws_content($tmp); is(@{$content}, 0, 'window killed'); @@ -153,7 +153,7 @@ $left->_create; set_wm_class($left->id, 'special7', 'special7'); $left->name('ä 3'); $left->map; -ok(wait_for_map($x), 'left window mapped'); +ok(wait_for_map($left), 'left window mapped'); # two windows should be here $content = get_ws_content($tmp); @@ -161,7 +161,7 @@ ok(@{$content} == 1, 'window opened'); cmd '[title="^\w [3]$"] kill'; -wait_for_unmap $x; +wait_for_unmap $left; $content = get_ws_content($tmp); is(@{$content}, 0, 'window killed'); diff --git a/testcases/t/133-size-hints.t b/testcases/t/133-size-hints.t index 90ecf62e..cad6bb71 100644 --- a/testcases/t/133-size-hints.t +++ b/testcases/t/133-size-hints.t @@ -19,7 +19,7 @@ $aspect->max_num(600); $aspect->max_den(300); $win->_create; $win->map; -wait_for_map $x; +wait_for_map $win; $win->hints->aspect($aspect); $x->flush; diff --git a/testcases/t/135-floating-focus.t b/testcases/t/135-floating-focus.t index bae983e7..d5b70008 100644 --- a/testcases/t/135-floating-focus.t +++ b/testcases/t/135-floating-focus.t @@ -45,7 +45,7 @@ cmd 'floating enable'; # now kill the third one (it's floating). focus should stay unchanged cmd '[id="' . $third->id . '"] kill'; -wait_for_unmap($x); +wait_for_unmap($third); is($x->input_focus, $second->id, 'second con still focused after killing third'); @@ -76,12 +76,12 @@ cmd 'floating enable'; # now kill the second one. focus should fall back to the third one, which is # also floating cmd 'kill'; -wait_for_unmap($x); +wait_for_unmap($second); is($x->input_focus, $third->id, 'third con focused'); cmd 'kill'; -wait_for_unmap($x); +wait_for_unmap($third); is($x->input_focus, $first->id, 'first con focused after killing all floating cons'); @@ -114,12 +114,12 @@ sync_with_i3($x); # now kill the second one. focus should fall back to the third one, which is # also floating cmd 'kill'; -wait_for_unmap($x); +wait_for_unmap($second); is($x->input_focus, $third->id, 'third con focused'); cmd 'kill'; -wait_for_unmap($x); +wait_for_unmap($third); is($x->input_focus, $first->id, 'first con focused after killing all floating cons'); diff --git a/testcases/t/150-regress-dock-restart.t b/testcases/t/150-regress-dock-restart.t index a28e0730..5317eef3 100644 --- a/testcases/t/150-regress-dock-restart.t +++ b/testcases/t/150-regress-dock-restart.t @@ -55,7 +55,7 @@ is($docknode->{rect}->{height}, 30, 'dock node has unchanged height after restar $window->destroy; -wait_for_unmap $x; +wait_for_unmap $window; @docked = get_dock_clients; is(@docked, 0, 'no dock clients found'); diff --git a/testcases/t/163-wm-state.t b/testcases/t/163-wm-state.t index e5b42df4..f3e7e2d1 100644 --- a/testcases/t/163-wm-state.t +++ b/testcases/t/163-wm-state.t @@ -15,7 +15,7 @@ is($window->state, ICCCM_WM_STATE_NORMAL, 'WM_STATE normal'); $window->unmap; -wait_for_unmap $x; +wait_for_unmap $window; is($window->state, ICCCM_WM_STATE_WITHDRAWN, 'WM_STATE withdrawn'); diff --git a/testcases/t/165-for_window.t b/testcases/t/165-for_window.t index 88c542eb..80649771 100644 --- a/testcases/t/165-for_window.t +++ b/testcases/t/165-for_window.t @@ -34,14 +34,14 @@ my $window = $x->root->create_child( $window->name('Border window'); $window->map; -wait_for_map $x; +wait_for_map $window; my @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); is($content[0]->{border}, 'normal', 'normal border'); $window->unmap; -wait_for_unmap $x; +wait_for_unmap $window; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 0, 'no more nodes'); @@ -78,14 +78,14 @@ sub set_wm_class { set_wm_class($window->id, 'borderless', 'borderless'); $window->name('Borderless window'); $window->map; -wait_for_map $x; +wait_for_map $window; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); is($content[0]->{border}, 'none', 'no border'); $window->unmap; -wait_for_unmap $x; +wait_for_unmap $window; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 0, 'no more nodes'); @@ -117,7 +117,7 @@ $window = $x->root->create_child( $window->name('special title'); $window->map; -wait_for_map $x; +wait_for_map $window; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); @@ -144,7 +144,7 @@ sync_with_i3 $x; is($content[0]->{border}, 'normal', 'still normal border'); $window->unmap; -wait_for_unmap $x; +wait_for_unmap $window; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 0, 'no more nodes'); @@ -177,7 +177,7 @@ $window = $x->root->create_child( $window->name('special mark title'); $window->map; -wait_for_map $x; +wait_for_map $window; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); @@ -224,14 +224,14 @@ $window->_create; set_wm_class($window->id, 'borderless', 'borderless'); $window->name('usethis'); $window->map; -wait_for_map $x; +wait_for_map $window; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); is($content[0]->{border}, 'none', 'no border'); cmd 'kill'; -wait_for_unmap $x; +wait_for_unmap $window; $window->destroy; # give i3 a chance to delete the window from its tree @@ -245,7 +245,7 @@ $window->_create; set_wm_class($window->id, 'borderless', 'borderless'); $window->name('notthis'); $window->map; -wait_for_map $x; +wait_for_map $window; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); @@ -280,7 +280,7 @@ $window->_create; set_wm_class($window->id, 'bar', 'foo'); $window->name('usethis'); $window->map; -wait_for_map $x; +wait_for_map $window; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); @@ -315,7 +315,7 @@ $window->_create; set_wm_class($window->id, 'bar', 'foo'); $window->name('usethis'); $window->map; -wait_for_map $x; +wait_for_map $window; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); @@ -352,7 +352,7 @@ $window->_create; set_wm_class($window->id, 'bar', 'foo'); $window->name('usethis'); $window->map; -wait_for_map $x; +wait_for_map $window; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); @@ -400,7 +400,7 @@ $x->change_property( $window->name('usethis'); $window->map; -wait_for_map $x; +wait_for_map $window; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); @@ -437,7 +437,7 @@ $window->_create; $window->name('usethis'); $window->map; -wait_for_map $x; +wait_for_map $window; @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); diff --git a/testcases/t/166-assign.t b/testcases/t/166-assign.t index d2bb9fa7..f42962f3 100644 --- a/testcases/t/166-assign.t +++ b/testcases/t/166-assign.t @@ -53,7 +53,7 @@ $window->_create; set_wm_class($window->id, 'special', 'special'); $window->name('special window'); $window->map; -wait_for_map $x; +wait_for_map $window; ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace'); @@ -91,7 +91,7 @@ $window->_create; set_wm_class($window->id, 'special', 'special'); $window->name('special window'); $window->map; -wait_for_map $x; +wait_for_map $window; ok(@{get_ws_content($tmp)} == 0, 'still no containers'); ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists'); @@ -172,7 +172,7 @@ $window->_create; set_wm_class($window->id, 'special', 'special'); $window->name('special window'); $window->map; -wait_for_map $x; +wait_for_map $window; my $content = get_ws($tmp); ok(@{$content->{nodes}} == 0, 'no tiling cons'); @@ -213,7 +213,7 @@ $window->_create; set_wm_class($window->id, 'SPEcial', 'SPEcial'); $window->name('special window'); $window->map; -wait_for_map $x; +wait_for_map $window; $content = get_ws($tmp); ok(@{$content->{nodes}} == 0, 'no tiling cons'); @@ -263,7 +263,7 @@ $window->_create; set_wm_class($window->id, 'special', 'special'); $window->name('special window'); $window->map; -wait_for_map $x; +wait_for_map $window; $content = get_ws($tmp); ok(@{$content->{nodes}} == 0, 'no tiling cons'); -- 2.39.5