git.iko.soy/typeable/nixpkgs
on master help sign in
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

commitcd10e3c4ffa3d6c729aab8778bf6027415025c44 authoraszlig <aszlig@redmoonstudios.org> dateTue 7 Feb 2017, 07:36 (10 years ago) parent87cc20e
1 file changed+21−18
nixos/tests/chromium.nix+21−18
nixos/tests/chromium.nix+21−18
@@ -18,8 +18,9 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
1818
1919 enableOCR = true;
2020
21− machine.imports = [ ./common/x11.nix ];
21+ machine.imports = [ ./common/user-account.nix ./common/x11.nix ];
2222 machine.virtualisation.memorySize = 2047;
23+ machine.services.xserver.displayManager.auto.user = "alice";
2324 machine.environment.systemPackages = [ chromiumPkg ];
2425
2526 startupHTML = pkgs.writeText "chromium-startup.html" ''
@@ -43,14 +44,20 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
4344 xdoScript = pkgs.writeText "${name}.xdo" text;
4445 in "${pkgs.xdotool}/bin/xdotool '${xdoScript}'";
4546 in ''
47+ # Run as user alice
48+ sub ru ($) {
49+ my $esc = $_[0] =~ s/'/'\\${"'"}'/gr;
50+ return "su - alice -c '$esc'";
51+ }
52+
4653 sub createNewWin {
4754 $machine->nest("creating a new Chromium window", sub {
48− $machine->execute("${xdo "new-window" ''
55+ $machine->execute(ru "${xdo "new-window" ''
4956 search --onlyvisible --name "startup done"
5057 windowfocus --sync
5158 windowactivate --sync
5259 ''}");
53− $machine->execute("${xdo "new-window" ''
60+ $machine->execute(ru "${xdo "new-window" ''
5461 key Ctrl+n
5562 ''}");
5663 });
@@ -58,16 +65,16 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
5865
5966 sub closeWin {
6067 Machine::retry sub {
61− $machine->execute("${xdo "close-window" ''
68+ $machine->execute(ru "${xdo "close-window" ''
6269 search --onlyvisible --name "new tab"
6370 windowfocus --sync
6471 windowactivate --sync
6572 ''}");
66− $machine->execute("${xdo "close-window" ''
73+ $machine->execute(ru "${xdo "close-window" ''
6774 key Ctrl+w
6875 ''}");
6976 for (1..20) {
70− my ($status, $out) = $machine->execute("${xdo "wait-for-close" ''
77+ my ($status, $out) = $machine->execute(ru "${xdo "wait-for-close" ''
7178 search --onlyvisible --name "new tab"
7279 ''}");
7380 return 1 if $status != 0;
@@ -80,7 +87,7 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
8087 my $ret = 0;
8188 $machine->nest("waiting for new Chromium window to appear", sub {
8289 for (1..20) {
83− my ($status, $out) = $machine->execute("${xdo "wait-for-window" ''
90+ my ($status, $out) = $machine->execute(ru "${xdo "wait-for-window" ''
8491 search --onlyvisible --name "new tab"
8592 windowfocus --sync
8693 windowactivate --sync
@@ -113,13 +120,9 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
113120 $machine->waitForX;
114121
115122 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");
121124 $machine->waitForText(qr/startup done/);
122− $machine->waitUntilSucceeds("${xdo "check-startup" ''
125+ $machine->waitUntilSucceeds(ru "${xdo "check-startup" ''
123126 search --sync --onlyvisible --name "startup done"
124127 # close first start help popup
125128 key -delay 1000 Escape
@@ -134,13 +137,13 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
134137 $machine->screenshot("startup_done");
135138
136139 testNewWin "check sandbox", sub {
137− $machine->succeed("${xdo "type-url" ''
140+ $machine->succeed(ru "${xdo "type-url" ''
138141 search --sync --onlyvisible --name "new tab"
139142 windowfocus --sync
140143 type --delay 1000 "chrome://sandbox"
141144 ''}");
142145
143− $machine->succeed("${xdo "submit-url" ''
146+ $machine->succeed(ru "${xdo "submit-url" ''
144147 search --sync --onlyvisible --name "new tab"
145148 windowfocus --sync
146149 key --delay 1000 Return
@@ -148,15 +151,15 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
148151
149152 $machine->screenshot("sandbox_info");
150153
151− $machine->succeed("${xdo "submit-url" ''
154+ $machine->succeed(ru "${xdo "submit-url" ''
152155 search --sync --onlyvisible --name "sandbox status"
153156 windowfocus --sync
154157 ''}");
155− $machine->succeed("${xdo "submit-url" ''
158+ $machine->succeed(ru "${xdo "submit-url" ''
156159 key --delay 1000 Ctrl+a Ctrl+c
157160 ''}");
158161
159− my $clipboard = $machine->succeed("${pkgs.xclip}/bin/xclip -o");
162+ my $clipboard = $machine->succeed(ru "${pkgs.xclip}/bin/xclip -o");
160163 die "sandbox not working properly: $clipboard"
161164 unless $clipboard =~ /namespace sandbox.*yes/mi
162165 && $clipboard =~ /pid namespaces.*yes/mi