2016-03-20 21:20:39 +00:00
|
|
|
{ system ? builtins.currentSystem
|
2016-03-21 02:50:38 +00:00
|
|
|
, pkgs ? import ../.. { inherit system; }
|
2016-03-20 21:20:39 +00:00
|
|
|
, channelMap ? {
|
|
|
|
stable = pkgs.chromium;
|
|
|
|
beta = pkgs.chromiumBeta;
|
|
|
|
dev = pkgs.chromiumDev;
|
|
|
|
}
|
|
|
|
}:
|
2016-02-29 23:20:27 +00:00
|
|
|
|
|
|
|
with import ../lib/testing.nix { inherit system; };
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
mapAttrs (channel: chromiumPkg: makeTest rec {
|
|
|
|
name = "chromium-${channel}";
|
2015-07-12 11:09:40 +01:00
|
|
|
meta = with pkgs.stdenv.lib.maintainers; {
|
|
|
|
maintainers = [ aszlig ];
|
|
|
|
};
|
2014-11-18 17:41:56 +00:00
|
|
|
|
2015-05-22 10:23:09 +01:00
|
|
|
enableOCR = true;
|
|
|
|
|
2017-02-07 06:36:56 +00:00
|
|
|
machine.imports = [ ./common/user-account.nix ./common/x11.nix ];
|
2015-08-25 10:26:32 +01:00
|
|
|
machine.virtualisation.memorySize = 2047;
|
2017-02-07 06:36:56 +00:00
|
|
|
machine.services.xserver.displayManager.auto.user = "alice";
|
2016-02-29 23:20:27 +00:00
|
|
|
machine.environment.systemPackages = [ chromiumPkg ];
|
2014-11-18 17:41:56 +00:00
|
|
|
|
|
|
|
startupHTML = pkgs.writeText "chromium-startup.html" ''
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<title>Chromium startup notifier</title>
|
|
|
|
</head>
|
|
|
|
<body onload="javascript:document.title='startup done'">
|
|
|
|
<img src="file://${pkgs.fetchurl {
|
2015-11-29 21:43:28 +00:00
|
|
|
url = "http://nixos.org/logo/nixos-hex.svg";
|
|
|
|
sha256 = "0wxpp65npdw2cg8m0cxc9qff1sb3b478cxpg1741d8951g948rg8";
|
2014-11-18 17:41:56 +00:00
|
|
|
}}" />
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
'';
|
|
|
|
|
|
|
|
testScript = let
|
|
|
|
xdo = name: text: let
|
|
|
|
xdoScript = pkgs.writeText "${name}.xdo" text;
|
|
|
|
in "${pkgs.xdotool}/bin/xdotool '${xdoScript}'";
|
|
|
|
in ''
|
2017-02-07 06:36:56 +00:00
|
|
|
# Run as user alice
|
|
|
|
sub ru ($) {
|
|
|
|
my $esc = $_[0] =~ s/'/'\\${"'"}'/gr;
|
|
|
|
return "su - alice -c '$esc'";
|
|
|
|
}
|
|
|
|
|
2014-11-18 17:41:56 +00:00
|
|
|
sub createNewWin {
|
|
|
|
$machine->nest("creating a new Chromium window", sub {
|
2017-02-07 06:36:56 +00:00
|
|
|
$machine->execute(ru "${xdo "new-window" ''
|
2014-11-18 17:41:56 +00:00
|
|
|
search --onlyvisible --name "startup done"
|
|
|
|
windowfocus --sync
|
|
|
|
windowactivate --sync
|
2015-09-12 11:12:57 +01:00
|
|
|
''}");
|
2017-02-07 06:36:56 +00:00
|
|
|
$machine->execute(ru "${xdo "new-window" ''
|
2014-11-18 17:41:56 +00:00
|
|
|
key Ctrl+n
|
|
|
|
''}");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
sub closeWin {
|
|
|
|
Machine::retry sub {
|
2017-02-07 06:36:56 +00:00
|
|
|
$machine->execute(ru "${xdo "close-window" ''
|
2014-11-18 17:41:56 +00:00
|
|
|
search --onlyvisible --name "new tab"
|
|
|
|
windowfocus --sync
|
|
|
|
windowactivate --sync
|
2015-09-12 11:12:57 +01:00
|
|
|
''}");
|
2017-02-07 06:36:56 +00:00
|
|
|
$machine->execute(ru "${xdo "close-window" ''
|
2014-11-18 17:41:56 +00:00
|
|
|
key Ctrl+w
|
|
|
|
''}");
|
|
|
|
for (1..20) {
|
2017-02-07 06:36:56 +00:00
|
|
|
my ($status, $out) = $machine->execute(ru "${xdo "wait-for-close" ''
|
2014-11-18 17:41:56 +00:00
|
|
|
search --onlyvisible --name "new tab"
|
|
|
|
''}");
|
|
|
|
return 1 if $status != 0;
|
|
|
|
$machine->sleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub waitForNewWin {
|
|
|
|
my $ret = 0;
|
|
|
|
$machine->nest("waiting for new Chromium window to appear", sub {
|
|
|
|
for (1..20) {
|
2017-02-07 06:36:56 +00:00
|
|
|
my ($status, $out) = $machine->execute(ru "${xdo "wait-for-window" ''
|
2014-11-18 17:41:56 +00:00
|
|
|
search --onlyvisible --name "new tab"
|
|
|
|
windowfocus --sync
|
|
|
|
windowactivate --sync
|
|
|
|
''}");
|
|
|
|
if ($status == 0) {
|
|
|
|
$ret = 1;
|
2018-04-28 16:24:31 +01:00
|
|
|
|
|
|
|
# XXX: Somehow Chromium is not accepting keystrokes for a few
|
|
|
|
# seconds after a new window has appeared, so let's wait a while.
|
|
|
|
$machine->sleep(10);
|
|
|
|
|
2014-11-18 17:41:56 +00:00
|
|
|
last;
|
|
|
|
}
|
|
|
|
$machine->sleep(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub createAndWaitForNewWin {
|
|
|
|
for (1..3) {
|
|
|
|
createNewWin;
|
|
|
|
return 1 if waitForNewWin;
|
|
|
|
}
|
|
|
|
die "new window didn't appear within 60 seconds";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub testNewWin {
|
|
|
|
my ($desc, $code) = @_;
|
|
|
|
createAndWaitForNewWin;
|
|
|
|
subtest($desc, $code);
|
|
|
|
closeWin;
|
|
|
|
}
|
|
|
|
|
2016-02-29 23:20:27 +00:00
|
|
|
$machine->waitForX;
|
|
|
|
|
|
|
|
my $url = "file://${startupHTML}";
|
2017-02-07 06:36:56 +00:00
|
|
|
$machine->execute(ru "ulimit -c unlimited; chromium \"$url\" & disown");
|
2016-11-09 08:41:10 +00:00
|
|
|
$machine->waitForText(qr/startup done/);
|
2017-02-07 06:36:56 +00:00
|
|
|
$machine->waitUntilSucceeds(ru "${xdo "check-startup" ''
|
2016-02-29 23:20:27 +00:00
|
|
|
search --sync --onlyvisible --name "startup done"
|
|
|
|
# close first start help popup
|
|
|
|
key -delay 1000 Escape
|
|
|
|
windowfocus --sync
|
|
|
|
windowactivate --sync
|
|
|
|
''}");
|
|
|
|
|
|
|
|
createAndWaitForNewWin;
|
|
|
|
$machine->screenshot("empty_windows");
|
|
|
|
closeWin;
|
|
|
|
|
|
|
|
$machine->screenshot("startup_done");
|
|
|
|
|
|
|
|
testNewWin "check sandbox", sub {
|
2017-02-07 06:36:56 +00:00
|
|
|
$machine->succeed(ru "${xdo "type-url" ''
|
2016-02-29 23:20:27 +00:00
|
|
|
search --sync --onlyvisible --name "new tab"
|
2014-11-18 17:41:56 +00:00
|
|
|
windowfocus --sync
|
2016-02-29 23:20:27 +00:00
|
|
|
type --delay 1000 "chrome://sandbox"
|
2014-11-18 17:41:56 +00:00
|
|
|
''}");
|
|
|
|
|
2017-02-07 06:36:56 +00:00
|
|
|
$machine->succeed(ru "${xdo "submit-url" ''
|
2016-02-29 23:20:27 +00:00
|
|
|
search --sync --onlyvisible --name "new tab"
|
|
|
|
windowfocus --sync
|
|
|
|
key --delay 1000 Return
|
|
|
|
''}");
|
2014-11-18 17:41:56 +00:00
|
|
|
|
2016-02-29 23:20:27 +00:00
|
|
|
$machine->screenshot("sandbox_info");
|
2014-11-18 17:41:56 +00:00
|
|
|
|
2018-04-04 11:17:19 +01:00
|
|
|
$machine->succeed(ru "${xdo "find-window" ''
|
2016-02-29 23:20:27 +00:00
|
|
|
search --sync --onlyvisible --name "sandbox status"
|
|
|
|
windowfocus --sync
|
|
|
|
''}");
|
2018-04-04 11:17:19 +01:00
|
|
|
$machine->succeed(ru "${xdo "copy-sandbox-info" ''
|
2016-02-29 23:20:27 +00:00
|
|
|
key --delay 1000 Ctrl+a Ctrl+c
|
|
|
|
''}");
|
2014-11-18 17:41:56 +00:00
|
|
|
|
2017-02-07 06:36:56 +00:00
|
|
|
my $clipboard = $machine->succeed(ru "${pkgs.xclip}/bin/xclip -o");
|
2016-02-29 23:20:27 +00:00
|
|
|
die "sandbox not working properly: $clipboard"
|
|
|
|
unless $clipboard =~ /namespace sandbox.*yes/mi
|
|
|
|
&& $clipboard =~ /pid namespaces.*yes/mi
|
|
|
|
&& $clipboard =~ /network namespaces.*yes/mi
|
|
|
|
&& $clipboard =~ /seccomp.*sandbox.*yes/mi
|
|
|
|
&& $clipboard =~ /you are adequately sandboxed/mi;
|
2018-04-04 11:17:19 +01:00
|
|
|
|
|
|
|
$machine->sleep(1);
|
|
|
|
$machine->succeed(ru "${xdo "find-window-after-copy" ''
|
|
|
|
search --onlyvisible --name "sandbox status"
|
|
|
|
''}");
|
|
|
|
|
|
|
|
my $clipboard = $machine->succeed(ru "echo void | ${pkgs.xclip}/bin/xclip -i");
|
|
|
|
$machine->succeed(ru "${xdo "copy-sandbox-info" ''
|
|
|
|
key --delay 1000 Ctrl+a Ctrl+c
|
|
|
|
''}");
|
|
|
|
|
|
|
|
my $clipboard = $machine->succeed(ru "${pkgs.xclip}/bin/xclip -o");
|
|
|
|
die "copying twice in a row does not work properly: $clipboard"
|
|
|
|
unless $clipboard =~ /namespace sandbox.*yes/mi
|
|
|
|
&& $clipboard =~ /pid namespaces.*yes/mi
|
|
|
|
&& $clipboard =~ /network namespaces.*yes/mi
|
|
|
|
&& $clipboard =~ /seccomp.*sandbox.*yes/mi
|
|
|
|
&& $clipboard =~ /you are adequately sandboxed/mi;
|
|
|
|
|
|
|
|
$machine->screenshot("afer_copy_from_chromium");
|
2016-02-29 23:20:27 +00:00
|
|
|
};
|
2014-11-18 17:41:56 +00:00
|
|
|
|
2016-02-29 23:20:27 +00:00
|
|
|
$machine->shutdown;
|
2014-11-18 17:41:56 +00:00
|
|
|
'';
|
2016-03-20 21:20:39 +00:00
|
|
|
}) channelMap
|