1 import ./make-test-python.nix ({ lib, pkgs, firefoxPackage, ... }:
3 name = firefoxPackage.pname;
5 meta = with pkgs.lib.maintainers; {
6 maintainers = [ shlevy ];
12 { imports = [ ./common/x11.nix ];
13 environment.systemPackages = [ pkgs.xdotool ];
17 preferences."media.autoplay.default" = 0;
18 package = firefoxPackage;
21 # Create a virtual sound device, with mixing
22 # and all, for recording audio.
23 boot.kernelModules = [ "snd-aloop" ];
24 environment.etc."asound.conf".text = ''
49 systemd.services.audio-recorder = {
50 description = "Record NixOS test audio to /tmp/record.wav";
51 script = "${pkgs.alsa-utils}/bin/arecord -D recorder -f S16_LE -r48000 /tmp/record.wav";
57 exe = lib.getExe firefoxPackage;
59 from contextlib import contextmanager
63 def record_audio(machine: Machine):
65 Perform actions while recording the
68 machine.systemctl("start audio-recorder")
70 machine.systemctl("stop audio-recorder")
73 def wait_for_sound(machine: Machine):
75 Wait until any sound has been emitted.
77 machine.wait_for_file("/tmp/record.wav")
79 # Get at most 2M of the recording
80 machine.execute("tail -c 2M /tmp/record.wav > /tmp/last")
82 size = int(machine.succeed("stat -c '%s' /tmp/last").strip())
83 # Compare it against /dev/zero using `cmp` (skipping 50B of WAVE header).
84 # If some non-NULL bytes are found it returns 1.
85 status, output = machine.execute(
86 f"cmp -i 50 -n {size - 50} /tmp/last /dev/zero 2>&1"
95 with subtest("Wait until Firefox has finished loading the Valgrind docs page"):
97 "xterm -e '${exe} file://${pkgs.valgrind.doc}/share/doc/valgrind/html/index.html' >&2 &"
99 machine.wait_for_window("Valgrind")
102 with subtest("Check whether Firefox can play sound"):
103 with record_audio(machine):
105 "${exe} file://${pkgs.sound-theme-freedesktop}/share/sounds/freedesktop/stereo/phone-incoming-call.oga >&2 &"
107 wait_for_sound(machine)
108 machine.copy_from_vm("/tmp/record.wav")
110 with subtest("Close sound test tab"):
111 machine.execute("xdotool key ctrl+w")
113 with subtest("Close default browser prompt"):
114 machine.execute("xdotool key space")
116 with subtest("Wait until Firefox draws the developer tool panel"):
118 machine.succeed("xwininfo -root -tree | grep Valgrind")
119 machine.screenshot("screen")