1{ system ? builtins.currentSystem
2, pkgs ? import ../.. { inherit system; }
3, channelMap ? {
4 stable = pkgs.chromium;
5 beta = pkgs.chromiumBeta;
6 dev = pkgs.chromiumDev;
7 }
8}:
9
10with import ../lib/testing.nix { inherit system; };
11with pkgs.lib;
12
13mapAttrs (channel: chromiumPkg: makeTest rec {
14 name = "chromium-${channel}";
15 meta = with pkgs.stdenv.lib.maintainers; {
16 maintainers = [ aszlig ];
17 };
18
19 enableOCR = true;
20
21 machine.imports = [ ./common/user-account.nix ./common/x11.nix ];
22 machine.virtualisation.memorySize = 2047;
23 machine.services.xserver.displayManager.auto.user = "alice";
24 machine.environment.systemPackages = [ chromiumPkg ];
25
26 startupHTML = pkgs.writeText "chromium-startup.html" ''
27 <!DOCTYPE html>
28 <html>
29 <head>
30 <meta charset="UTF-8">
31 <title>Chromium startup notifier</title>
32 </head>
33 <body onload="javascript:document.title='startup done'">
34 <img src="file://${pkgs.fetchurl {
35 url = "http://nixos.org/logo/nixos-hex.svg";
36 sha256 = "0wxpp65npdw2cg8m0cxc9qff1sb3b478cxpg1741d8951g948rg8";
37 }}" />
38 </body>
39 </html>
40 '';
41
42 testScript = let
43 xdo = name: text: let
44 xdoScript = pkgs.writeText "${name}.xdo" text;
45 in "${pkgs.xdotool}/bin/xdotool '${xdoScript}'";
46 in ''
47 # Run as user alice
48 sub ru ($) {
49 my $esc = $_[0] =~ s/'/'\\${"'"}'/gr;
50 return "su - alice -c '$esc'";
51 }
52
53 sub createNewWin {
54 $machine->nest("creating a new Chromium window", sub {
55 $machine->execute(ru "${xdo "new-window" ''
56 search --onlyvisible --name "startup done"
57 windowfocus --sync
58 windowactivate --sync
59 ''}");
60 $machine->execute(ru "${xdo "new-window" ''
61 key Ctrl+n
62 ''}");
63 });
64 }
65
66 sub closeWin {
67 Machine::retry sub {
68 $machine->execute(ru "${xdo "close-window" ''
69 search --onlyvisible --name "new tab"
70 windowfocus --sync
71 windowactivate --sync
72 ''}");
73 $machine->execute(ru "${xdo "close-window" ''
74 key Ctrl+w
75 ''}");
76 for (1..20) {
77 my ($status, $out) = $machine->execute(ru "${xdo "wait-for-close" ''
78 search --onlyvisible --name "new tab"
79 ''}");
80 return 1 if $status != 0;
81 $machine->sleep(1);
82 }
83 }
84 }
85
86 sub waitForNewWin {
87 my $ret = 0;
88 $machine->nest("waiting for new Chromium window to appear", sub {
89 for (1..20) {
90 my ($status, $out) = $machine->execute(ru "${xdo "wait-for-window" ''
91 search --onlyvisible --name "new tab"
92 windowfocus --sync
93 windowactivate --sync
94 ''}");
95 if ($status == 0) {
96 $ret = 1;
97
98 # XXX: Somehow Chromium is not accepting keystrokes for a few
99 # seconds after a new window has appeared, so let's wait a while.
100 $machine->sleep(10);
101
102 last;
103 }
104 $machine->sleep(1);
105 }
106 });
107 return $ret;
108 }
109
110 sub createAndWaitForNewWin {
111 for (1..3) {
112 createNewWin;
113 return 1 if waitForNewWin;
114 }
115 die "new window didn't appear within 60 seconds";
116 }
117
118 sub testNewWin {
119 my ($desc, $code) = @_;
120 createAndWaitForNewWin;
121 subtest($desc, $code);
122 closeWin;
123 }
124
125 $machine->waitForX;
126
127 my $url = "file://${startupHTML}";
128 $machine->execute(ru "ulimit -c unlimited; chromium \"$url\" & disown");
129 $machine->waitForText(qr/startup done/);
130 $machine->waitUntilSucceeds(ru "${xdo "check-startup" ''
131 search --sync --onlyvisible --name "startup done"
132 # close first start help popup
133 key -delay 1000 Escape
134 windowfocus --sync
135 windowactivate --sync
136 ''}");
137
138 createAndWaitForNewWin;
139 $machine->screenshot("empty_windows");
140 closeWin;
141
142 $machine->screenshot("startup_done");
143
144 testNewWin "check sandbox", sub {
145 $machine->succeed(ru "${xdo "type-url" ''
146 search --sync --onlyvisible --name "new tab"
147 windowfocus --sync
148 type --delay 1000 "chrome://sandbox"
149 ''}");
150
151 $machine->succeed(ru "${xdo "submit-url" ''
152 search --sync --onlyvisible --name "new tab"
153 windowfocus --sync
154 key --delay 1000 Return
155 ''}");
156
157 $machine->screenshot("sandbox_info");
158
159 $machine->succeed(ru "${xdo "find-window" ''
160 search --sync --onlyvisible --name "sandbox status"
161 windowfocus --sync
162 ''}");
163 $machine->succeed(ru "${xdo "copy-sandbox-info" ''
164 key --delay 1000 Ctrl+a Ctrl+c
165 ''}");
166
167 my $clipboard = $machine->succeed(ru "${pkgs.xclip}/bin/xclip -o");
168 die "sandbox not working properly: $clipboard"
169 unless $clipboard =~ /namespace sandbox.*yes/mi
170 && $clipboard =~ /pid namespaces.*yes/mi
171 && $clipboard =~ /network namespaces.*yes/mi
172 && $clipboard =~ /seccomp.*sandbox.*yes/mi
173 && $clipboard =~ /you are adequately sandboxed/mi;
174
175 $machine->sleep(1);
176 $machine->succeed(ru "${xdo "find-window-after-copy" ''
177 search --onlyvisible --name "sandbox status"
178 ''}");
179
180 my $clipboard = $machine->succeed(ru "echo void | ${pkgs.xclip}/bin/xclip -i");
181 $machine->succeed(ru "${xdo "copy-sandbox-info" ''
182 key --delay 1000 Ctrl+a Ctrl+c
183 ''}");
184
185 my $clipboard = $machine->succeed(ru "${pkgs.xclip}/bin/xclip -o");
186 die "copying twice in a row does not work properly: $clipboard"
187 unless $clipboard =~ /namespace sandbox.*yes/mi
188 && $clipboard =~ /pid namespaces.*yes/mi
189 && $clipboard =~ /network namespaces.*yes/mi
190 && $clipboard =~ /seccomp.*sandbox.*yes/mi
191 && $clipboard =~ /you are adequately sandboxed/mi;
192
193 $machine->screenshot("afer_copy_from_chromium");
194 };
195
196 $machine->shutdown;
197 '';
198}) channelMap