]> git.sur5r.net Git - i3/i3/blobdiff - testcases/t/175-startup-notification.t
Merge branch 'release-4.16.1'
[i3/i3] / testcases / t / 175-startup-notification.t
index 3a4dbc81f3ed5d4a305f725acaab5cc516c3bacd..cd6f3950b3642148699f8b46fd7e1291ab83e9b8 100644 (file)
@@ -1,6 +1,19 @@
 #!perl
 # vim:ts=4:sw=4:expandtab
 #
+# Please read the following documents before working on tests:
+# • https://build.i3wm.org/docs/testsuite.html
+#   (or docs/testsuite)
+#
+# • https://build.i3wm.org/docs/lib-i3test.html
+#   (alternatively: perldoc ./testcases/lib/i3test.pm)
+#
+# • https://build.i3wm.org/docs/ipc.html
+#   (or docs/ipc)
+#
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
+#   (unless you are already familiar with Perl)
+#
 # Test for the startup notification protocol.
 #
 
@@ -8,6 +21,10 @@ use i3test;
 use POSIX qw(mkfifo);
 use File::Temp qw(:POSIX);
 
+SKIP: {
+
+    skip "X11::XCB too old (need >= 0.07)", 24 if $X11::XCB::VERSION < 0.07;
+
 use ExtUtils::PkgConfig;
 
 # setup dependency on libstartup-notification using pkg-config
@@ -29,16 +46,10 @@ static SnDisplay *sndisplay;
 static SnLauncheeContext *ctx;
 static xcb_connection_t *conn;
 
-// TODO: this should use $x
-void init_ctx() {
-    int screen;
-    if ((conn = xcb_connect(NULL, &screen)) == NULL ||
-        xcb_connection_has_error(conn))
-        errx(1, "x11 conn failed");
-
-    printf("screen = %d\n", screen);
+void init_ctx(void *connptr) {
+    conn = (xcb_connection_t*)connptr;
     sndisplay = sn_xcb_display_new(conn, NULL, NULL);
-    ctx = sn_launchee_context_new_from_environment(sndisplay, screen);
+    ctx = sn_launchee_context_new_from_environment(sndisplay, 0);
 }
 
 const char *get_startup_id() {
@@ -58,7 +69,7 @@ END_OF_C_CODE
 
 my $first_ws = fresh_workspace;
 
-is(@{get_ws_content($first_ws)}, 0, 'no containers on this workspace yet');
+is_num_children($first_ws, 0, 'no containers on this workspace yet');
 
 ######################################################################
 # 1) initiate startup, switch workspace, create window
@@ -73,7 +84,7 @@ is(@{get_ws_content($first_ws)}, 0, 'no containers on this workspace yet');
 # echo its $DESKTOP_STARTUP_ID. We (blockingly) read the variable into
 # $startup_id in the testcase.
 my $tmp = tmpnam();
-mkfifo($tmp, 0600) or die "Could not create FIFO in $tmp";
+mkfifo($tmp, 0600) or BAIL_OUT "Could not create FIFO in $tmp: $!";
 
 cmd qq|exec echo \$DESKTOP_STARTUP_ID >$tmp|;
 
@@ -88,14 +99,14 @@ isnt($startup_id, '', 'startup_id not empty');
 $ENV{DESKTOP_STARTUP_ID} = $startup_id;
 
 # Create a new libstartup-notification launchee context
-init_ctx();
+init_ctx($x->get_xcb_conn());
 
 # Make sure the context was set up successfully
 is(get_startup_id(), $startup_id, 'libstartup-notification returns the same id');
 
 my $second_ws = fresh_workspace;
 
-is(@{get_ws_content($second_ws)}, 0, 'no containers on the second workspace yet');
+is_num_children($second_ws, 0, 'no containers on the second workspace yet');
 
 my $win = open_window({ dont_map => 1 });
 mark_window($win->id);
@@ -105,8 +116,8 @@ $win->map;
 # We sync with i3 here to make sure $x->input_focus is updated.
 sync_with_i3;
 
-is(@{get_ws_content($second_ws)}, 0, 'still no containers on the second workspace');
-is(@{get_ws_content($first_ws)}, 1, 'one container on the first workspace');
+is_num_children($second_ws, 0, 'still no containers on the second workspace');
+is_num_children($first_ws, 1, 'one container on the first workspace');
 
 ######################################################################
 # same thing, but with _NET_STARTUP_ID set on the leader
@@ -119,26 +130,69 @@ $win = open_window({ dont_map => 1, client_leader => $leader });
 $win->map;
 sync_with_i3;
 
-is(@{get_ws_content($second_ws)}, 0, 'still no containers on the second workspace');
-is(@{get_ws_content($first_ws)}, 2, 'two containers on the first workspace');
+is_num_children($second_ws, 0, 'still no containers on the second workspace');
+is_num_children($first_ws, 2, 'two containers on the first workspace');
 
 ######################################################################
-# 2) open another window after the startup process is completed
-# (should be placed on the current workspace)
+# verifies that finishing startup doesn't immediately stop windows
+# from being placed on the sequence's workspace, but that moving
+# the leader actually deletes the startup sequence mapping
 ######################################################################
 
 complete_startup();
 sync_with_i3;
 
+# even when renaming the workspace, windows should end up on the correct one
+cmd "rename workspace $first_ws to temp";
+
+# Startup has completed but the 30-second deletion time hasn't elapsed,
+# so this window should still go on the leader's initial workspace.
+$win = open_window({ dont_map => 1, client_leader => $leader });
+$win->map;
+sync_with_i3;
+
+cmd "rename workspace temp to $first_ws";
+
+is_num_children($first_ws, 3, 'three containers on the first workspace');
+
+# empty 'from' workspaces should not crash the renaming of startup sequences
+cmd "workspace $first_ws";
+cmd "rename workspace to temp";
+cmd "rename workspace to $first_ws";
+
+# Switch to the first workspace and move the focused window to the
+# second workspace.
+cmd "workspace $first_ws";
+cmd "move workspace $second_ws";
+
+is_num_children($second_ws, 1, 'one container on the second workspace');
+
+# Create and switch to a new workspace, just to be safe.
+my $third_ws = fresh_workspace;
+
+# Moving the window between workspaces should have immediately
+# removed the startup workspace mapping. New windows with that
+# leader should be created on the current workspace.
+$win = open_window({ dont_map => 1, client_leader => $leader });
+$win->map;
+sync_with_i3;
+
+is_num_children($third_ws, 1, 'one container on the third workspace');
+
+######################################################################
+# 2) open another window after the startup process is completed
+# (should be placed on the current workspace)
+######################################################################
+
 my $otherwin = open_window;
-is(@{get_ws_content($second_ws)}, 1, 'one container on the second workspace');
+is_num_children($third_ws, 2, 'two containers on the third workspace');
 
 ######################################################################
 # 3) test that the --no-startup-id flag for exec leads to no DESKTOP_STARTUP_ID
 # environment variable.
 ######################################################################
 
-mkfifo($tmp, 0600) or die "Could not create FIFO in $tmp";
+mkfifo($tmp, 0600) or BAIL_OUT "Could not create FIFO in $tmp: $!";
 
 cmd qq|exec --no-startup-id echo \$DESKTOP_STARTUP_ID >$tmp|;
 
@@ -154,7 +208,7 @@ is($startup_id, '', 'startup_id empty');
 # 4) same thing, but with double quotes in exec
 ######################################################################
 
-mkfifo($tmp, 0600) or die "Could not create FIFO in $tmp";
+mkfifo($tmp, 0600) or BAIL_OUT "Could not create FIFO in $tmp: $!";
 
 cmd qq|exec --no-startup-id "echo \$DESKTOP_STARTUP_ID >$tmp"|;
 
@@ -165,6 +219,6 @@ close($fh);
 unlink($tmp);
 
 is($startup_id, '', 'startup_id empty');
-
+}
 
 done_testing;