about summary refs log tree commit diff
path: root/nixos/tests/chromium.nix
diff options
context:
space:
mode:
authorMichael Weiss <dev.primeos@gmail.com>2021-07-09 19:04:04 +0200
committerMichael Weiss <dev.primeos@gmail.com>2021-07-10 10:35:27 +0200
commit8c52061b1fce2036b70836e5dcdfcf4b702dd405 (patch)
tree0a087a3f7f65caf266aa4caa9fb047cd9b4396d2 /nixos/tests/chromium.nix
parentfaec8bbbf78f3a1e3439c321c2270b2f9209bff1 (diff)
nixos/tests/chromium: Refactor launching the browser process
It should now be more flexible and less error-prone.
Diffstat (limited to 'nixos/tests/chromium.nix')
-rw-r--r--nixos/tests/chromium.nix26
1 files changed, 13 insertions, 13 deletions
diff --git a/nixos/tests/chromium.nix b/nixos/tests/chromium.nix
index c17d1953894c2..06d92cd0c0371 100644
--- a/nixos/tests/chromium.nix
+++ b/nixos/tests/chromium.nix
@@ -63,8 +63,8 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
         return "su - ${user} -c " + shlex.quote(cmd)
 
 
-    def get_browser_call():
-        """Returns the name of the browser binary as well as CLI options."""
+    def launch_browser():
+        """Launches the web browser with the correct options."""
         # Determine the name of the binary:
         pname = "${getName chromiumPkg.name}"
         if pname.find("chromium") != -1:
@@ -76,12 +76,19 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
         else:  # For google-chrome-beta and as fallback:
             binary = pname
         # Add optional CLI options:
-        options = ""
+        options = []
         major_version = "${versions.major (getVersion chromiumPkg.name)}"
         if major_version > "91":
             # To avoid a GPU crash:
-            options += "--use-gl=angle --use-angle=swiftshader"
-        return f"{binary} {options}"
+            options += ["--use-gl=angle", "--use-angle=swiftshader"]
+        options.append("file://${startupHTML}")
+        # Launch the process:
+        machine.succeed(ru(f'ulimit -c unlimited; {binary} {shlex.join(options)} & disown'))
+        if binary.startswith("google-chrome"):
+            # Need to click away the first window:
+            machine.wait_for_text("Make Google Chrome the default browser")
+            machine.screenshot("google_chrome_default_browser_prompt")
+            machine.send_key("ret")
 
 
     def create_new_win():
@@ -142,14 +149,7 @@ mapAttrs (channel: chromiumPkg: makeTest rec {
 
     machine.wait_for_x()
 
-    url = "file://${startupHTML}"
-    machine.succeed(ru(f'ulimit -c unlimited; {get_browser_call()} "{url}" & disown'))
-
-    if get_browser_call().startswith("google-chrome"):
-        # Need to click away the first window:
-        machine.wait_for_text("Make Google Chrome the default browser")
-        machine.screenshot("google_chrome_default_browser_prompt")
-        machine.send_key("ret")
+    launch_browser()
 
     machine.wait_for_text("startup done")
     machine.wait_until_succeeds(