From: Michael Stapelberg Date: Sat, 24 Sep 2011 14:38:31 +0000 (+0100) Subject: tests: refactor t/58-wm_take_focus to use wait_for_event X-Git-Tag: 4.1~139^2~4 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=378611c11c2ab113b2bbd61f6b69a1dd7f610002;p=i3%2Fi3 tests: refactor t/58-wm_take_focus to use wait_for_event --- diff --git a/testcases/t/58-wm_take_focus.t b/testcases/t/58-wm_take_focus.t index 372f41cd..a90ce1c3 100644 --- a/testcases/t/58-wm_take_focus.t +++ b/testcases/t/58-wm_take_focus.t @@ -7,105 +7,35 @@ use X11::XCB qw(:all); use i3test; use v5.10; -BEGIN { - use_ok('EV'); - use_ok('AnyEvent'); - use_ok('X11::XCB::Window'); - use_ok('X11::XCB::Event::Generic'); - use_ok('X11::XCB::Event::MapNotify'); - use_ok('X11::XCB::Event::ClientMessage'); -} - my $x = X11::XCB::Connection->new; subtest 'Window without WM_TAKE_FOCUS', sub { + fresh_workspace; - my $tmp = fresh_workspace; - - my $window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#00ff00', - event_mask => [ 'structure_notify' ], - ); - - $window->name('Window 1'); - $window->map; - - my $cv = AE::cv; - - my $prep = EV::prepare sub { - $x->flush; - }; - - my $check = EV::check sub { - while (defined(my $event = $x->poll_for_event)) { - if ($event->response_type == 161) { - # clientmessage - $cv->send(0); - } - } - }; + my $window = open_window($x); - my $w = EV::io $x->get_file_descriptor, EV::READ, sub { - # do nothing, we only need this watcher so that EV picks up the events - }; - - # Trigger timeout after 1 second - my $t = AE::timer 1, 0, sub { - $cv->send(1); - }; - - my $result = $cv->recv; - ok($result, 'cv result'); + ok(!wait_for_event($x, 1, sub { $_[0]->{response_type} == 161 }), 'did not receive ClientMessage'); done_testing; }; subtest 'Window with WM_TAKE_FOCUS', sub { + fresh_workspace; - my $tmp = fresh_workspace; + my $take_focus = $x->atom(name => 'WM_TAKE_FOCUS'); - my $window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#00ff00', - event_mask => [ 'structure_notify' ], - protocols => [ $x->atom(name => 'WM_TAKE_FOCUS') ], - ); + my $window = open_window($x, { + dont_map => 1, + protocols => [ $take_focus ], + }); - $window->name('Window 1'); $window->map; - my $cv = AE::cv; - - my $prep = EV::prepare sub { - $x->flush; - }; - - my $check = EV::check sub { - while (defined(my $event = $x->poll_for_event)) { - if ($event->response_type == 161) { - $cv->send($event->data); - } - } - }; - - my $w = EV::io $x->get_file_descriptor, EV::READ, sub { - # do nothing, we only need this watcher so that EV picks up the events - }; - - my $t = AE::timer 1, 0, sub { - say "timer!"; - $cv->send(undef); - }; - - my $result = $cv->recv; - ok(defined($result), 'got a ClientMessage'); - if (defined($result)) { - my ($data, $time) = unpack("L2", $result); - is($data, $x->atom(name => 'WM_TAKE_FOCUS')->id, 'first uint32_t contains WM_TAKE_FOCUS atom'); - } + ok(wait_for_event($x, 1, sub { + return 0 unless $_[0]->{response_type} == 161; + my ($data, $time) = unpack("L2", $_[0]->{data}); + return ($data == $take_focus->id); + }), 'got ClientMessage with WM_TAKE_FOCUS atom'); done_testing; };