Testcases: Bar modes and states
Patch status: rejected
Patch by Tony Crisci
Long description:
Add a new testcase to check that the bar will transition correctly through its various modes and states. Currently, bar modes are (mostly) implemented, and bar states are described in todos.
To apply this patch, use:
curl http://cr.i3wm.org/patch/273/raw.patch | git am
b/testcases/t/213-bar-mode.t
18 |
@@ -0,0 +1,121 @@ |
19 |
+#!perl |
20 |
+# vim:ts=4:sw=4:expandtab |
21 |
+# |
22 |
+# Please read the following documents before working on tests: |
23 |
+# • http://build.i3wm.org/docs/testsuite.html |
24 |
+# (or docs/testsuite) |
25 |
+# |
26 |
+# • http://build.i3wm.org/docs/lib-i3test.html |
27 |
+# (alternatively: perldoc ./testcases/lib/i3test.pm) |
28 |
+# |
29 |
+# • http://build.i3wm.org/docs/ipc.html |
30 |
+# (or docs/ipc) |
31 |
+# |
32 |
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf |
33 |
+# (unless you are already familiar with Perl) |
34 |
+# |
35 |
+# Checks the bar will transition correctly through its various modes and |
36 |
+# states. |
37 |
+# |
38 |
+# Requires AnyEvent::I3 >= 0.15. |
39 |
+# |
40 |
+use i3test i3_autostart => 0; |
41 |
+ |
42 |
+# Takes a list of containers and counts the i3bars among them |
43 |
+sub count_bars { |
44 |
+ my @cons = @_; |
45 |
+ my $result = 0; |
46 |
+ |
47 |
+ foreach my $con (@cons) { |
48 |
+ # TODO: find a better way to find out if something is a bar or not |
49 |
+ $result += 1 if $con->{name} =~ /^i3bar/; |
50 |
+ } |
51 |
+ return $result; |
52 |
+} |
53 |
+ |
54 |
+# Waits until the bar shows up on the screen, but only in dock mode. The bar |
55 |
+# will take longer to be mapped on the screen than i3 itself takes to load. |
56 |
+# When that happens, IPC emits a `window` event with information about the |
57 |
+# container of the bar. |
58 |
+sub wait_for_bar { |
59 |
+ my $cv = AE::cv; |
60 |
+ my $i3 = i3(get_socket_path()); |
61 |
+ $i3->_ensure_connection; |
62 |
+ # TODO: figure out how to unsubscribe from this event |
63 |
+ $i3->subscribe({ |
64 |
+ window => sub { |
65 |
+ if ($cv) { |
66 |
+ my ($reply) = @_; |
67 |
+ $cv->send($reply) if count_bars($reply->{container}); |
68 |
+ } |
69 |
+ } |
70 |
+ })->recv; |
71 |
+ my $t = AE::timer 2, 0, sub { warn "timeout (2 secs)"; $cv->send(0) }; |
72 |
+ my $result = $cv->recv; |
73 |
+ undef $t; |
74 |
+ undef $cv; |
75 |
+} |
76 |
+ |
77 |
+# Test whether the dock contains a client that is a bar |
78 |
+sub dock_has_bar { count_bars(get_dock_clients) } |
79 |
+ |
80 |
+# Convenience function to help readability |
81 |
+sub dock_doesnt_have_bar { !dock_has_bar } |
82 |
+ |
83 |
+##################################################################### |
84 |
+# test that i3bar transitions correctly between modes |
85 |
+##################################################################### |
86 |
+ |
87 |
+my $config = <<EOT; |
88 |
+# i3 config file (v4) |
89 |
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 |
90 |
+ |
91 |
+bar { |
92 |
+ i3bar_command ../i3bar/i3bar |
93 |
+} |
94 |
+EOT |
95 |
+ |
96 |
+my $pid = launch_with_config($config); |
97 |
+my $i3 = i3(get_socket_path()); |
98 |
+ |
99 |
+wait_for_bar if dock_doesnt_have_bar; |
100 |
+ |
101 |
+ok(dock_has_bar, 'i3bar starts in dock mode'); |
102 |
+ |
103 |
+cmd 'bar mode invisible'; |
104 |
+wait_for_unmap if dock_has_bar; |
105 |
+ |
106 |
+ok(dock_has_bar, 'i3bar goes from dock to invisible mode'); |
107 |
+ |
108 |
+cmd 'bar mode dock'; |
109 |
+wait_for_bar if dock_doesnt_have_bar; |
110 |
+ |
111 |
+ok(dock_has_bar, 'i3bar goes from invisible to dock mode'); |
112 |
+ |
113 |
+cmd 'bar mode hide'; |
114 |
+wait_for_unmap if dock_has_bar; |
115 |
+ |
116 |
+ok(dock_doesnt_have_bar, 'i3bar goes from dock to hide mode'); |
117 |
+ |
118 |
+cmd 'bar mode dock'; |
119 |
+wait_for_bar if dock_doesnt_have_bar; |
120 |
+ |
121 |
+ok(dock_has_bar, 'i3bar goes from hide to dock mode'); |
122 |
+ |
123 |
+# TODO: test that `bar hidden_state show` and `bar hidden_state hide` work in |
124 |
+# hide mode (difficult because i3 does not manage the bar window in hide mode, |
125 |
+# so it does not show up in `get_tree`). |
126 |
+ |
127 |
+# TODO: test that the bar will be revealed when a workspace becomes urgent in |
128 |
+# hide mode. |
129 |
+ |
130 |
+# TODO: test that the bar shows up when the modifier key is pressed in hide |
131 |
+# mode (difficult because we have to press a key). |
132 |
+ |
133 |
+# TODO: test that the bar is hidden when the modifier key is released, and will |
134 |
+# not be revealed again until a workspace newly becomes urgent, even if |
135 |
+# existing urgent workspaces are urgent on later redraws. |
136 |
+ |
137 |
+exit_gracefully($pid); |
138 |
+ |
139 |
+done_testing; |