use POSIX qw(mkfifo);
use File::Temp qw(:POSIX);
-my $x = X11::XCB::Connection->new;
use ExtUtils::PkgConfig;
# setup dependency on libstartup-notification using pkg-config
unlink($tmp);
+isnt($startup_id, '', 'startup_id not empty');
+
$ENV{DESKTOP_STARTUP_ID} = $startup_id;
# Create a new libstartup-notification launchee context
is(@{get_ws_content($second_ws)}, 0, 'no containers on the second workspace yet');
-my $win = open_window($x, { dont_map => 1 });
+my $win = open_window({ dont_map => 1 });
mark_window($win->id);
$win->map;
-wait_for_map($x);
+# We don’t use wait_for_map because the window will not get mapped -- it is on
+# a different workspace.
# We sync with i3 here to make sure $x->input_focus is updated.
-sync_with_i3($x);
+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');
-# TODO: the same thing, but in a CLIENT_LEADER situation
+######################################################################
+# same thing, but with _NET_STARTUP_ID set on the leader
+######################################################################
+
+my $leader = open_window({ dont_map => 1 });
+mark_window($leader->id);
+
+$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');
######################################################################
# 2) open another window after the startup process is completed
######################################################################
complete_startup();
-sync_with_i3($x);
+sync_with_i3;
-my $otherwin = open_window($x);
+my $otherwin = open_window;
is(@{get_ws_content($second_ws)}, 1, 'one container on the second 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";
+
+cmd qq|exec --no-startup-id echo \$DESKTOP_STARTUP_ID >$tmp|;
+
+open($fh, '<', $tmp);
+chomp($startup_id = <$fh>);
+close($fh);
+
+unlink($tmp);
+
+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";
+
+cmd qq|exec --no-startup-id "echo \$DESKTOP_STARTUP_ID >$tmp"|;
+
+open($fh, '<', $tmp);
+chomp($startup_id = <$fh>);
+close($fh);
+
+unlink($tmp);
+
+is($startup_id, '', 'startup_id empty');
+
+
done_testing;