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

aszlig cd10e3c4 87cc20ed

+21 -18
+21 -18
nixos/tests/chromium.nix
··· 18 18 19 19 enableOCR = true; 20 20 21 - machine.imports = [ ./common/x11.nix ]; 21 + machine.imports = [ ./common/user-account.nix ./common/x11.nix ]; 22 22 machine.virtualisation.memorySize = 2047; 23 + machine.services.xserver.displayManager.auto.user = "alice"; 23 24 machine.environment.systemPackages = [ chromiumPkg ]; 24 25 25 26 startupHTML = pkgs.writeText "chromium-startup.html" '' ··· 43 44 xdoScript = pkgs.writeText "${name}.xdo" text; 44 45 in "${pkgs.xdotool}/bin/xdotool '${xdoScript}'"; 45 46 in '' 47 + # Run as user alice 48 + sub ru ($) { 49 + my $esc = $_[0] =~ s/'/'\\${"'"}'/gr; 50 + return "su - alice -c '$esc'"; 51 + } 52 + 46 53 sub createNewWin { 47 54 $machine->nest("creating a new Chromium window", sub { 48 - $machine->execute("${xdo "new-window" '' 55 + $machine->execute(ru "${xdo "new-window" '' 49 56 search --onlyvisible --name "startup done" 50 57 windowfocus --sync 51 58 windowactivate --sync 52 59 ''}"); 53 - $machine->execute("${xdo "new-window" '' 60 + $machine->execute(ru "${xdo "new-window" '' 54 61 key Ctrl+n 55 62 ''}"); 56 63 }); ··· 58 65 59 66 sub closeWin { 60 67 Machine::retry sub { 61 - $machine->execute("${xdo "close-window" '' 68 + $machine->execute(ru "${xdo "close-window" '' 62 69 search --onlyvisible --name "new tab" 63 70 windowfocus --sync 64 71 windowactivate --sync 65 72 ''}"); 66 - $machine->execute("${xdo "close-window" '' 73 + $machine->execute(ru "${xdo "close-window" '' 67 74 key Ctrl+w 68 75 ''}"); 69 76 for (1..20) { 70 - my ($status, $out) = $machine->execute("${xdo "wait-for-close" '' 77 + my ($status, $out) = $machine->execute(ru "${xdo "wait-for-close" '' 71 78 search --onlyvisible --name "new tab" 72 79 ''}"); 73 80 return 1 if $status != 0; ··· 80 87 my $ret = 0; 81 88 $machine->nest("waiting for new Chromium window to appear", sub { 82 89 for (1..20) { 83 - my ($status, $out) = $machine->execute("${xdo "wait-for-window" '' 90 + my ($status, $out) = $machine->execute(ru "${xdo "wait-for-window" '' 84 91 search --onlyvisible --name "new tab" 85 92 windowfocus --sync 86 93 windowactivate --sync ··· 113 120 $machine->waitForX; 114 121 115 122 my $url = "file://${startupHTML}"; 116 - my $args = "--user-data-dir=/tmp/chromium-${channel}"; 117 - $machine->execute( 118 - "ulimit -c unlimited; ". 119 - "chromium $args \"$url\" & disown" 120 - ); 123 + $machine->execute(ru "ulimit -c unlimited; chromium \"$url\" & disown"); 121 124 $machine->waitForText(qr/startup done/); 122 - $machine->waitUntilSucceeds("${xdo "check-startup" '' 125 + $machine->waitUntilSucceeds(ru "${xdo "check-startup" '' 123 126 search --sync --onlyvisible --name "startup done" 124 127 # close first start help popup 125 128 key -delay 1000 Escape ··· 134 137 $machine->screenshot("startup_done"); 135 138 136 139 testNewWin "check sandbox", sub { 137 - $machine->succeed("${xdo "type-url" '' 140 + $machine->succeed(ru "${xdo "type-url" '' 138 141 search --sync --onlyvisible --name "new tab" 139 142 windowfocus --sync 140 143 type --delay 1000 "chrome://sandbox" 141 144 ''}"); 142 145 143 - $machine->succeed("${xdo "submit-url" '' 146 + $machine->succeed(ru "${xdo "submit-url" '' 144 147 search --sync --onlyvisible --name "new tab" 145 148 windowfocus --sync 146 149 key --delay 1000 Return ··· 148 151 149 152 $machine->screenshot("sandbox_info"); 150 153 151 - $machine->succeed("${xdo "submit-url" '' 154 + $machine->succeed(ru "${xdo "submit-url" '' 152 155 search --sync --onlyvisible --name "sandbox status" 153 156 windowfocus --sync 154 157 ''}"); 155 - $machine->succeed("${xdo "submit-url" '' 158 + $machine->succeed(ru "${xdo "submit-url" '' 156 159 key --delay 1000 Ctrl+a Ctrl+c 157 160 ''}"); 158 161 159 - my $clipboard = $machine->succeed("${pkgs.xclip}/bin/xclip -o"); 162 + my $clipboard = $machine->succeed(ru "${pkgs.xclip}/bin/xclip -o"); 160 163 die "sandbox not working properly: $clipboard" 161 164 unless $clipboard =~ /namespace sandbox.*yes/mi 162 165 && $clipboard =~ /pid namespaces.*yes/mi