at v206 5.1 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 ''}"); 48 $machine->execute("${xdo "new-window" '' 49 key Ctrl+n 50 ''}"); 51 }); 52 } 53 54 sub closeWin { 55 Machine::retry sub { 56 $machine->execute("${xdo "close-window" '' 57 search --onlyvisible --name "new tab" 58 windowfocus --sync 59 windowactivate --sync 60 ''}"); 61 $machine->execute("${xdo "close-window" '' 62 key Ctrl+w 63 ''}"); 64 for (1..20) { 65 my ($status, $out) = $machine->execute("${xdo "wait-for-close" '' 66 search --onlyvisible --name "new tab" 67 ''}"); 68 return 1 if $status != 0; 69 $machine->sleep(1); 70 } 71 } 72 } 73 74 sub waitForNewWin { 75 my $ret = 0; 76 $machine->nest("waiting for new Chromium window to appear", sub { 77 for (1..20) { 78 my ($status, $out) = $machine->execute("${xdo "wait-for-window" '' 79 search --onlyvisible --name "new tab" 80 windowfocus --sync 81 windowactivate --sync 82 ''}"); 83 if ($status == 0) { 84 $ret = 1; 85 last; 86 } 87 $machine->sleep(1); 88 } 89 }); 90 return $ret; 91 } 92 93 sub createAndWaitForNewWin { 94 for (1..3) { 95 createNewWin; 96 return 1 if waitForNewWin; 97 } 98 die "new window didn't appear within 60 seconds"; 99 } 100 101 sub testNewWin { 102 my ($desc, $code) = @_; 103 createAndWaitForNewWin; 104 subtest($desc, $code); 105 closeWin; 106 } 107 108 sub chromiumTest { 109 my ($channel, $pkg, $code) = @_; 110 $machine->waitForX; 111 112 my $url = "file://${startupHTML}"; 113 my $args = "--user-data-dir=/tmp/chromium-$channel"; 114 $machine->execute( 115 "ulimit -c unlimited; ". 116 "$pkg/bin/chromium $args \"$url\" & disown" 117 ); 118 $machine->waitForText(qr/Type to search or enter a URL to navigate/); 119 $machine->waitUntilSucceeds("${xdo "check-startup" '' 120 search --sync --onlyvisible --name "startup done" 121 # close first start help popup 122 key -delay 1000 Escape 123 windowfocus --sync 124 windowactivate --sync 125 ''}"); 126 127 createAndWaitForNewWin; 128 $machine->screenshot($channel."_emptywin"); 129 closeWin; 130 131 $machine->screenshot($channel."_startup_done"); 132 133 subtest("Chromium $channel", $code); 134 135 $machine->shutdown; 136 } 137 138 for (${let 139 mkArray = name: pkg: "[\"${name}\", \"${pkg}\"]"; 140 chanArrays = pkgs.lib.mapAttrsToList mkArray channelMap; 141 in pkgs.lib.concatStringsSep ", " chanArrays}) { 142 my ($channel, $pkg) = @$_; 143 chromiumTest $channel, $pkg, sub { 144 testNewWin "check sandbox", sub { 145 $machine->succeed("${xdo "type-url" '' 146 search --sync --onlyvisible --name "new tab" 147 windowfocus --sync 148 type --delay 1000 "chrome://sandbox" 149 ''}"); 150 151 $machine->succeed("${xdo "submit-url" '' 152 search --sync --onlyvisible --name "new tab" 153 windowfocus --sync 154 key --delay 1000 Return 155 ''}"); 156 157 $machine->screenshot($channel."_sandbox"); 158 159 $machine->succeed("${xdo "submit-url" '' 160 search --sync --onlyvisible --name "sandbox status" 161 windowfocus --sync 162 ''}"); 163 $machine->succeed("${xdo "submit-url" '' 164 key --delay 1000 Ctrl+a Ctrl+c 165 ''}"); 166 167 my $clipboard = $machine->succeed("${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 }; 176 } 177 ''; 178})