at 15.09-beta 4.9 kB view raw
1import ./make-test.nix ( 2{ pkgs 3, channelMap ? { 4 stable = pkgs.chromium; 5 beta = pkgs.chromiumBeta; 6 dev = pkgs.chromiumDev; 7 } 8, ... 9}: rec { 10 name = "chromium"; 11 meta = with pkgs.stdenv.lib.maintainers; { 12 maintainers = [ aszlig ]; 13 }; 14 15 enableOCR = true; 16 17 machine.imports = [ ./common/x11.nix ]; 18 machine.virtualisation.memorySize = 2047; 19 20 startupHTML = pkgs.writeText "chromium-startup.html" '' 21 <!DOCTYPE html> 22 <html> 23 <head> 24 <meta charset="UTF-8"> 25 <title>Chromium startup notifier</title> 26 </head> 27 <body onload="javascript:document.title='startup done'"> 28 <img src="file://${pkgs.fetchurl { 29 url = "http://nixos.org/logo/nixos.svg"; 30 sha256 = "0p2iaqcx2cj24xqycfw1pi4i5461gnn0034lafpi99ph435x6z68"; 31 }}" /> 32 </body> 33 </html> 34 ''; 35 36 testScript = let 37 xdo = name: text: let 38 xdoScript = pkgs.writeText "${name}.xdo" text; 39 in "${pkgs.xdotool}/bin/xdotool '${xdoScript}'"; 40 in '' 41 sub createNewWin { 42 $machine->nest("creating a new Chromium window", sub { 43 $machine->execute("${xdo "new-window" '' 44 search --onlyvisible --name "startup done" 45 windowfocus --sync 46 windowactivate --sync 47 key Ctrl+n 48 ''}"); 49 }); 50 } 51 52 sub closeWin { 53 Machine::retry sub { 54 $machine->execute("${xdo "close-window" '' 55 search --onlyvisible --name "new tab" 56 windowfocus --sync 57 windowactivate --sync 58 key Ctrl+w 59 ''}"); 60 for (1..20) { 61 my ($status, $out) = $machine->execute("${xdo "wait-for-close" '' 62 search --onlyvisible --name "new tab" 63 ''}"); 64 return 1 if $status != 0; 65 $machine->sleep(1); 66 } 67 } 68 } 69 70 sub waitForNewWin { 71 my $ret = 0; 72 $machine->nest("waiting for new Chromium window to appear", sub { 73 for (1..20) { 74 my ($status, $out) = $machine->execute("${xdo "wait-for-window" '' 75 search --onlyvisible --name "new tab" 76 windowfocus --sync 77 windowactivate --sync 78 ''}"); 79 if ($status == 0) { 80 $ret = 1; 81 last; 82 } 83 $machine->sleep(1); 84 } 85 }); 86 return $ret; 87 } 88 89 sub createAndWaitForNewWin { 90 for (1..3) { 91 createNewWin; 92 return 1 if waitForNewWin; 93 } 94 die "new window didn't appear within 60 seconds"; 95 } 96 97 sub testNewWin { 98 my ($desc, $code) = @_; 99 createAndWaitForNewWin; 100 subtest($desc, $code); 101 closeWin; 102 } 103 104 sub chromiumTest { 105 my ($channel, $pkg, $code) = @_; 106 $machine->waitForX; 107 108 my $url = "file://${startupHTML}"; 109 my $args = "--user-data-dir=/tmp/chromium-$channel"; 110 $machine->execute( 111 "ulimit -c unlimited; ". 112 "$pkg/bin/chromium $args \"$url\" & disown" 113 ); 114 $machine->waitForText(qr/Type to search or enter a URL to navigate/); 115 $machine->waitUntilSucceeds("${xdo "check-startup" '' 116 search --sync --onlyvisible --name "startup done" 117 # close first start help popup 118 key -delay 1000 Escape 119 windowfocus --sync 120 windowactivate --sync 121 ''}"); 122 123 createAndWaitForNewWin; 124 $machine->screenshot($channel."_emptywin"); 125 closeWin; 126 127 $machine->screenshot($channel."_startup_done"); 128 129 subtest("Chromium $channel", $code); 130 131 $machine->shutdown; 132 } 133 134 for (${let 135 mkArray = name: pkg: "[\"${name}\", \"${pkg}\"]"; 136 chanArrays = pkgs.lib.mapAttrsToList mkArray channelMap; 137 in pkgs.lib.concatStringsSep ", " chanArrays}) { 138 my ($channel, $pkg) = @$_; 139 chromiumTest $channel, $pkg, sub { 140 testNewWin "check sandbox", sub { 141 $machine->succeed("${xdo "type-url" '' 142 search --sync --onlyvisible --name "new tab" 143 windowfocus --sync 144 type --delay 1000 "chrome://sandbox" 145 ''}"); 146 147 $machine->succeed("${xdo "submit-url" '' 148 search --sync --onlyvisible --name "new tab" 149 windowfocus --sync 150 key --delay 1000 Return 151 ''}"); 152 153 $machine->screenshot($channel."_sandbox"); 154 155 $machine->succeed("${xdo "submit-url" '' 156 search --sync --onlyvisible --name "sandbox status" 157 windowfocus --sync 158 key --delay 1000 Ctrl+a Ctrl+c 159 ''}"); 160 161 my $clipboard = $machine->succeed("${pkgs.xclip}/bin/xclip -o"); 162 die "sandbox not working properly: $clipboard" 163 unless $clipboard =~ /namespace sandbox.*yes/mi 164 && $clipboard =~ /pid namespaces.*yes/mi 165 && $clipboard =~ /network namespaces.*yes/mi 166 && $clipboard =~ /seccomp.*sandbox.*yes/mi 167 && $clipboard =~ /you are adequately sandboxed/mi; 168 }; 169 }; 170 } 171 ''; 172})