nixos/tests/chromium: Run tests as normal user
The tests have failed because Chromium has started up displaying the following error message in a dialog window: Chromium can not be run as root. Please start Chromium as a normal user. If you need to run as root for development, rerun with the --no-sandbox flag. So let's run as user "alice" and pass all commands using the small helper function "ru" (to keep it short, it's for "Run as User"). Tested it by running the "stable" test on x86_64-linux. Signed-off-by: aszlig <aszlig@redmoonstudios.org> Reported-by: @globin
This commit is contained in:
parent
87cc20eddb
commit
cd10e3c4ff
@ -18,8 +18,9 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
|
|||||||
|
|
||||||
enableOCR = true;
|
enableOCR = true;
|
||||||
|
|
||||||
machine.imports = [ ./common/x11.nix ];
|
machine.imports = [ ./common/user-account.nix ./common/x11.nix ];
|
||||||
machine.virtualisation.memorySize = 2047;
|
machine.virtualisation.memorySize = 2047;
|
||||||
|
machine.services.xserver.displayManager.auto.user = "alice";
|
||||||
machine.environment.systemPackages = [ chromiumPkg ];
|
machine.environment.systemPackages = [ chromiumPkg ];
|
||||||
|
|
||||||
startupHTML = pkgs.writeText "chromium-startup.html" ''
|
startupHTML = pkgs.writeText "chromium-startup.html" ''
|
||||||
@ -43,14 +44,20 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
|
|||||||
xdoScript = pkgs.writeText "${name}.xdo" text;
|
xdoScript = pkgs.writeText "${name}.xdo" text;
|
||||||
in "${pkgs.xdotool}/bin/xdotool '${xdoScript}'";
|
in "${pkgs.xdotool}/bin/xdotool '${xdoScript}'";
|
||||||
in ''
|
in ''
|
||||||
|
# Run as user alice
|
||||||
|
sub ru ($) {
|
||||||
|
my $esc = $_[0] =~ s/'/'\\${"'"}'/gr;
|
||||||
|
return "su - alice -c '$esc'";
|
||||||
|
}
|
||||||
|
|
||||||
sub createNewWin {
|
sub createNewWin {
|
||||||
$machine->nest("creating a new Chromium window", sub {
|
$machine->nest("creating a new Chromium window", sub {
|
||||||
$machine->execute("${xdo "new-window" ''
|
$machine->execute(ru "${xdo "new-window" ''
|
||||||
search --onlyvisible --name "startup done"
|
search --onlyvisible --name "startup done"
|
||||||
windowfocus --sync
|
windowfocus --sync
|
||||||
windowactivate --sync
|
windowactivate --sync
|
||||||
''}");
|
''}");
|
||||||
$machine->execute("${xdo "new-window" ''
|
$machine->execute(ru "${xdo "new-window" ''
|
||||||
key Ctrl+n
|
key Ctrl+n
|
||||||
''}");
|
''}");
|
||||||
});
|
});
|
||||||
@ -58,16 +65,16 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
|
|||||||
|
|
||||||
sub closeWin {
|
sub closeWin {
|
||||||
Machine::retry sub {
|
Machine::retry sub {
|
||||||
$machine->execute("${xdo "close-window" ''
|
$machine->execute(ru "${xdo "close-window" ''
|
||||||
search --onlyvisible --name "new tab"
|
search --onlyvisible --name "new tab"
|
||||||
windowfocus --sync
|
windowfocus --sync
|
||||||
windowactivate --sync
|
windowactivate --sync
|
||||||
''}");
|
''}");
|
||||||
$machine->execute("${xdo "close-window" ''
|
$machine->execute(ru "${xdo "close-window" ''
|
||||||
key Ctrl+w
|
key Ctrl+w
|
||||||
''}");
|
''}");
|
||||||
for (1..20) {
|
for (1..20) {
|
||||||
my ($status, $out) = $machine->execute("${xdo "wait-for-close" ''
|
my ($status, $out) = $machine->execute(ru "${xdo "wait-for-close" ''
|
||||||
search --onlyvisible --name "new tab"
|
search --onlyvisible --name "new tab"
|
||||||
''}");
|
''}");
|
||||||
return 1 if $status != 0;
|
return 1 if $status != 0;
|
||||||
@ -80,7 +87,7 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
|
|||||||
my $ret = 0;
|
my $ret = 0;
|
||||||
$machine->nest("waiting for new Chromium window to appear", sub {
|
$machine->nest("waiting for new Chromium window to appear", sub {
|
||||||
for (1..20) {
|
for (1..20) {
|
||||||
my ($status, $out) = $machine->execute("${xdo "wait-for-window" ''
|
my ($status, $out) = $machine->execute(ru "${xdo "wait-for-window" ''
|
||||||
search --onlyvisible --name "new tab"
|
search --onlyvisible --name "new tab"
|
||||||
windowfocus --sync
|
windowfocus --sync
|
||||||
windowactivate --sync
|
windowactivate --sync
|
||||||
@ -113,13 +120,9 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
|
|||||||
$machine->waitForX;
|
$machine->waitForX;
|
||||||
|
|
||||||
my $url = "file://${startupHTML}";
|
my $url = "file://${startupHTML}";
|
||||||
my $args = "--user-data-dir=/tmp/chromium-${channel}";
|
$machine->execute(ru "ulimit -c unlimited; chromium \"$url\" & disown");
|
||||||
$machine->execute(
|
|
||||||
"ulimit -c unlimited; ".
|
|
||||||
"chromium $args \"$url\" & disown"
|
|
||||||
);
|
|
||||||
$machine->waitForText(qr/startup done/);
|
$machine->waitForText(qr/startup done/);
|
||||||
$machine->waitUntilSucceeds("${xdo "check-startup" ''
|
$machine->waitUntilSucceeds(ru "${xdo "check-startup" ''
|
||||||
search --sync --onlyvisible --name "startup done"
|
search --sync --onlyvisible --name "startup done"
|
||||||
# close first start help popup
|
# close first start help popup
|
||||||
key -delay 1000 Escape
|
key -delay 1000 Escape
|
||||||
@ -134,13 +137,13 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
|
|||||||
$machine->screenshot("startup_done");
|
$machine->screenshot("startup_done");
|
||||||
|
|
||||||
testNewWin "check sandbox", sub {
|
testNewWin "check sandbox", sub {
|
||||||
$machine->succeed("${xdo "type-url" ''
|
$machine->succeed(ru "${xdo "type-url" ''
|
||||||
search --sync --onlyvisible --name "new tab"
|
search --sync --onlyvisible --name "new tab"
|
||||||
windowfocus --sync
|
windowfocus --sync
|
||||||
type --delay 1000 "chrome://sandbox"
|
type --delay 1000 "chrome://sandbox"
|
||||||
''}");
|
''}");
|
||||||
|
|
||||||
$machine->succeed("${xdo "submit-url" ''
|
$machine->succeed(ru "${xdo "submit-url" ''
|
||||||
search --sync --onlyvisible --name "new tab"
|
search --sync --onlyvisible --name "new tab"
|
||||||
windowfocus --sync
|
windowfocus --sync
|
||||||
key --delay 1000 Return
|
key --delay 1000 Return
|
||||||
@ -148,15 +151,15 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
|
|||||||
|
|
||||||
$machine->screenshot("sandbox_info");
|
$machine->screenshot("sandbox_info");
|
||||||
|
|
||||||
$machine->succeed("${xdo "submit-url" ''
|
$machine->succeed(ru "${xdo "submit-url" ''
|
||||||
search --sync --onlyvisible --name "sandbox status"
|
search --sync --onlyvisible --name "sandbox status"
|
||||||
windowfocus --sync
|
windowfocus --sync
|
||||||
''}");
|
''}");
|
||||||
$machine->succeed("${xdo "submit-url" ''
|
$machine->succeed(ru "${xdo "submit-url" ''
|
||||||
key --delay 1000 Ctrl+a Ctrl+c
|
key --delay 1000 Ctrl+a Ctrl+c
|
||||||
''}");
|
''}");
|
||||||
|
|
||||||
my $clipboard = $machine->succeed("${pkgs.xclip}/bin/xclip -o");
|
my $clipboard = $machine->succeed(ru "${pkgs.xclip}/bin/xclip -o");
|
||||||
die "sandbox not working properly: $clipboard"
|
die "sandbox not working properly: $clipboard"
|
||||||
unless $clipboard =~ /namespace sandbox.*yes/mi
|
unless $clipboard =~ /namespace sandbox.*yes/mi
|
||||||
&& $clipboard =~ /pid namespaces.*yes/mi
|
&& $clipboard =~ /pid namespaces.*yes/mi
|
||||||
|
Loading…
Reference in New Issue
Block a user