firefox: make tests generic

This commit is contained in:
bricked 2024-03-16 18:07:14 +01:00 committed by Robert Helgesson
parent 88cd895cf6
commit 5347da6f16
No known key found for this signature in database
GPG Key ID: 96E745BD17AA17ED
12 changed files with 316 additions and 254 deletions

View File

@ -29,7 +29,8 @@ let
else
unwrappedPackageName;
profilesPath = if isDarwin then "${cfg.configPath}/Profiles" else cfg.configPath;
profilesPath =
if isDarwin then "${cfg.configPath}/Profiles" else cfg.configPath;
nativeMessagingHostsPath = if isDarwin then
"${cfg.vendorPath}/NativeMessagingHosts"
@ -271,6 +272,13 @@ in {
description = "The name of the browser.";
};
wrappedPackageName = mkOption {
internal = true;
type = with types; nullOr str;
default = wrappedPackageName;
description = "Name of the wrapped browser package.";
};
vendorPath = mkOption {
internal = true;
type = with types; nullOr str;
@ -945,7 +953,8 @@ in {
null;
privateSalt = if profile.search.privateDefault != null then
profile.path + profile.search.privateDefault + disclaimer cfg.name
profile.path + profile.search.privateDefault
+ disclaimer cfg.name
else
null;
in pkgs.runCommand "search.json.mozlz4" {

View File

@ -188,7 +188,7 @@ in import nmtSrc {
./modules/programs/bemenu
./modules/programs/borgmatic
./modules/programs/boxxy
./modules/programs/firefox
./modules/programs/firefox/firefox.nix
./modules/programs/foot
./modules/programs/fuzzel
./modules/programs/getmail

View File

@ -1,27 +1,32 @@
modulePath:
{ config, lib, ... }:
{
imports = [ ./setup-firefox-mock-overlay.nix ];
with lib;
config = lib.mkIf config.test.enableBig {
let
firefoxMockOverlay = import ./setup-firefox-mock-overlay.nix modulePath;
in {
imports = [ firefoxMockOverlay ];
config = mkIf config.test.enableBig ({
test.asserts.assertions.expected =
[ "Container id must be smaller than 4294967294 (2^32 - 2)" ];
} // setAttrByPath modulePath {
enable = true;
programs.firefox = {
enable = true;
profiles.my-profile = {
isDefault = true;
id = 1;
profiles.my-profile = {
isDefault = true;
id = 1;
containers = {
"shopping" = {
id = 4294967294;
color = "blue";
icon = "circle";
};
containers = {
"shopping" = {
id = 4294967294;
color = "blue";
icon = "circle";
};
};
};
};
});
}

View File

@ -1,9 +0,0 @@
{
firefox-profile-settings = ./profile-settings.nix;
firefox-state-version-19_09 = ./state-version-19_09.nix;
firefox-deprecated-native-messenger = ./deprecated-native-messenger.nix;
firefox-duplicate-profile-ids = ./duplicate-profile-ids.nix;
firefox-duplicate-container-ids = ./duplicate-container-ids.nix;
firefox-container-id-out-of-range = ./container-id-out-of-range.nix;
firefox-policies = ./policies.nix;
}

View File

@ -1,21 +1,26 @@
modulePath:
{ config, lib, ... }:
{
imports = [ ./setup-firefox-mock-overlay.nix ];
with lib;
config = lib.mkIf config.test.enableBig {
programs.firefox = {
enable = true;
enableGnomeExtensions = true;
};
let
moduleName = concatStringsSep "." modulePath;
firefoxMockOverlay = import ./setup-firefox-mock-overlay.nix modulePath;
in {
imports = [ firefoxMockOverlay ];
config = mkIf config.test.enableBig (setAttrByPath modulePath {
enable = true;
enableGnomeExtensions = true;
} // {
test.asserts.warnings.expected = [''
Using 'programs.firefox.enableGnomeExtensions' has been deprecated and
Using '${moduleName}.enableGnomeExtensions' has been deprecated and
will be removed in the future. Please change to overriding the package
configuration using 'programs.firefox.package' instead. You can refer to
configuration using '${moduleName}.package' instead. You can refer to
its example for how to do this.
''];
};
});
}

View File

@ -1,35 +1,42 @@
modulePath:
{ config, lib, ... }:
{
imports = [ ./setup-firefox-mock-overlay.nix ];
with lib;
config = lib.mkIf config.test.enableBig {
let
cfg = getAttrFromPath modulePath config;
firefoxMockOverlay = import ./setup-firefox-mock-overlay.nix modulePath;
in {
imports = [ firefoxMockOverlay ];
config = mkIf config.test.enableBig ({
test.asserts.assertions.expected = [''
Must not have a Firefox container with an existing ID but
Must not have a ${cfg.name} container with an existing ID but
- ID 9 is used by dangerous, shopping''];
} // setAttrByPath modulePath {
enable = true;
programs.firefox = {
enable = true;
profiles = {
my-profile = {
isDefault = true;
id = 1;
profiles = {
my-profile = {
isDefault = true;
id = 1;
containers = {
"shopping" = {
id = 9;
color = "blue";
icon = "circle";
};
"dangerous" = {
id = 9;
color = "red";
icon = "circle";
};
containers = {
"shopping" = {
id = 9;
color = "blue";
icon = "circle";
};
"dangerous" = {
id = 9;
color = "red";
icon = "circle";
};
};
};
};
};
});
}

View File

@ -1,23 +1,30 @@
modulePath:
{ config, lib, ... }:
{
imports = [ ./setup-firefox-mock-overlay.nix ];
with lib;
config = lib.mkIf config.test.enableBig {
let
cfg = getAttrFromPath modulePath config;
firefoxMockOverlay = import ./setup-firefox-mock-overlay.nix modulePath;
in {
imports = [ firefoxMockOverlay ];
config = mkIf config.test.enableBig ({
test.asserts.assertions.expected = [''
Must not have a Firefox profile with an existing ID but
Must not have a ${cfg.name} profile with an existing ID but
- ID 1 is used by first, second''];
} // setAttrByPath modulePath {
enable = true;
programs.firefox = {
enable = true;
profiles = {
first = {
isDefault = true;
id = 1;
};
second = { id = 1; };
profiles = {
first = {
isDefault = true;
id = 1;
};
second = { id = 1; };
};
};
});
}

View File

@ -0,0 +1,11 @@
let name = "firefox";
in builtins.mapAttrs (test: module: import module [ "programs" name ]) {
"${name}-profile-settings" = ./profile-settings.nix;
"${name}-state-version-19_09" = ./state-version-19_09.nix;
"${name}-deprecated-native-messenger" = ./deprecated-native-messenger.nix;
"${name}-duplicate-profile-ids" = ./duplicate-profile-ids.nix;
"${name}-duplicate-container-ids" = ./duplicate-container-ids.nix;
"${name}-container-id-out-of-range" = ./container-id-out-of-range.nix;
"${name}-policies" = ./policies.nix;
}

View File

@ -1,22 +1,29 @@
modulePath:
{ config, lib, pkgs, ... }:
{
imports = [ ./setup-firefox-mock-overlay.nix ];
with lib;
config = lib.mkIf config.test.enableBig {
let
cfg = getAttrFromPath modulePath config;
firefoxMockOverlay = import ./setup-firefox-mock-overlay.nix modulePath;
in {
imports = [ firefoxMockOverlay ];
config = mkIf config.test.enableBig ({
home.stateVersion = "23.05";
programs.firefox = {
enable = true;
policies = { BlockAboutConfig = true; };
package = pkgs.firefox.override {
extraPolicies = { DownloadDirectory = "/foo"; };
};
} // setAttrByPath modulePath {
enable = true;
policies = { BlockAboutConfig = true; };
package = pkgs.${cfg.wrappedPackageName}.override {
extraPolicies = { DownloadDirectory = "/foo"; };
};
}) // {
nmt.script = ''
jq=${lib.getExe pkgs.jq}
config_file="${config.programs.firefox.finalPackage}/lib/firefox/distribution/policies.json"
config_file="${cfg.finalPackage}/lib/${cfg.wrappedPackageName}/distribution/policies.json"
assertFileExists "$config_file"

View File

@ -1,177 +1,184 @@
modulePath:
{ config, lib, pkgs, ... }:
{
imports = [ ./setup-firefox-mock-overlay.nix ];
with lib;
config = lib.mkIf config.test.enableBig {
programs.firefox = {
enable = true;
profiles.basic.isDefault = true;
let
profiles.test = {
id = 1;
settings = {
"general.smoothScroll" = false;
"browser.newtabpage.pinned" = [{
title = "NixOS";
url = "https://nixos.org";
cfg = getAttrFromPath modulePath config;
firefoxMockOverlay = import ./setup-firefox-mock-overlay.nix modulePath;
in {
imports = [ firefoxMockOverlay ];
config = mkIf config.test.enableBig (setAttrByPath modulePath {
enable = true;
profiles.basic.isDefault = true;
profiles.test = {
id = 1;
settings = {
"general.smoothScroll" = false;
"browser.newtabpage.pinned" = [{
title = "NixOS";
url = "https://nixos.org";
}];
};
};
profiles.bookmarks = {
id = 2;
settings = { "general.smoothScroll" = false; };
bookmarks = [
{
toolbar = true;
bookmarks = [{
name = "Home Manager";
url = "https://wiki.nixos.org/wiki/Home_Manager";
}];
};
};
}
{
name = "wikipedia";
tags = [ "wiki" ];
keyword = "wiki";
url = "https://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go";
}
{
name = "kernel.org";
url = "https://www.kernel.org";
}
{
name = "Nix sites";
bookmarks = [
{
name = "homepage";
url = "https://nixos.org/";
}
{
name = "wiki";
tags = [ "wiki" "nix" ];
url = "https://wiki.nixos.org/";
}
{
name = "Nix sites";
bookmarks = [
{
name = "homepage";
url = "https://nixos.org/";
}
{
name = "wiki";
url = "https://wiki.nixos.org/";
}
];
}
];
}
];
};
profiles.bookmarks = {
id = 2;
settings = { "general.smoothScroll" = false; };
bookmarks = [
{
toolbar = true;
bookmarks = [{
name = "Home Manager";
url = "https://wiki.nixos.org/wiki/Home_Manager";
profiles.search = {
id = 3;
search = {
force = true;
default = "Google";
privateDefault = "DuckDuckGo";
order = [ "Nix Packages" "NixOS Wiki" ];
engines = {
"Nix Packages" = {
urls = [{
template = "https://search.nixos.org/packages";
params = [
{
name = "type";
value = "packages";
}
{
name = "query";
value = "{searchTerms}";
}
];
}];
}
{
name = "wikipedia";
tags = [ "wiki" ];
keyword = "wiki";
url =
"https://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go";
}
{
name = "kernel.org";
url = "https://www.kernel.org";
}
{
name = "Nix sites";
bookmarks = [
{
name = "homepage";
url = "https://nixos.org/";
}
{
name = "wiki";
tags = [ "wiki" "nix" ];
url = "https://wiki.nixos.org/";
}
{
name = "Nix sites";
bookmarks = [
{
name = "homepage";
url = "https://nixos.org/";
}
{
name = "wiki";
url = "https://wiki.nixos.org/";
}
];
}
];
}
];
};
profiles.search = {
id = 3;
search = {
force = true;
default = "Google";
privateDefault = "DuckDuckGo";
order = [ "Nix Packages" "NixOS Wiki" ];
engines = {
"Nix Packages" = {
urls = [{
template = "https://search.nixos.org/packages";
params = [
{
name = "type";
value = "packages";
}
{
name = "query";
value = "{searchTerms}";
}
];
}];
icon =
"/run/current-system/sw/share/icons/hicolor/scalable/apps/nix-snowflake.svg";
icon =
"/run/current-system/sw/share/icons/hicolor/scalable/apps/nix-snowflake.svg";
definedAliases = [ "@np" ];
};
"NixOS Wiki" = {
urls = [{
template =
"https://wiki.nixos.org/index.php?search={searchTerms}";
}];
iconUpdateURL = "https://wiki.nixos.org/favicon.png";
updateInterval = 24 * 60 * 60 * 1000;
definedAliases = [ "@nw" ];
};
"Bing".metaData.hidden = true;
"Google".metaData.alias = "@g";
definedAliases = [ "@np" ];
};
"NixOS Wiki" = {
urls = [{
template =
"https://wiki.nixos.org/index.php?search={searchTerms}";
}];
iconUpdateURL = "https://wiki.nixos.org/favicon.png";
updateInterval = 24 * 60 * 60 * 1000;
definedAliases = [ "@nw" ];
};
"Bing".metaData.hidden = true;
"Google".metaData.alias = "@g";
};
};
};
profiles.searchWithoutDefault = {
id = 4;
search = {
force = true;
order = [ "Google" "Nix Packages" ];
engines = {
"Nix Packages" = {
urls = [{
template = "https://search.nixos.org/packages";
params = [
{
name = "type";
value = "packages";
}
{
name = "query";
value = "{searchTerms}";
}
];
}];
profiles.searchWithoutDefault = {
id = 4;
search = {
force = true;
order = [ "Google" "Nix Packages" ];
engines = {
"Nix Packages" = {
urls = [{
template = "https://search.nixos.org/packages";
params = [
{
name = "type";
value = "packages";
}
{
name = "query";
value = "{searchTerms}";
}
];
}];
definedAliases = [ "@np" ];
};
};
};
};
profiles.containers = {
id = 5;
containers = {
"shopping" = {
id = 6;
icon = "circle";
color = "yellow";
definedAliases = [ "@np" ];
};
};
};
};
profiles.containers = {
id = 5;
containers = {
"shopping" = {
id = 6;
icon = "circle";
color = "yellow";
};
};
};
} // {
nmt.script = ''
assertFileRegex \
home-path/bin/firefox \
home-path/bin/${cfg.wrappedPackageName} \
MOZ_APP_LAUNCHER
assertDirectoryExists home-files/.mozilla/firefox/basic
assertDirectoryExists home-files/${cfg.configPath}/basic
assertFileContent \
home-files/.mozilla/firefox/test/user.js \
home-files/${cfg.configPath}/test/user.js \
${./profile-settings-expected-user.js}
assertFileContent \
home-files/.mozilla/firefox/containers/containers.json \
home-files/${cfg.configPath}/containers/containers.json \
${./profile-settings-expected-containers.json}
bookmarksUserJs=$(normalizeStorePaths \
home-files/.mozilla/firefox/bookmarks/user.js)
home-files/${cfg.configPath}/bookmarks/user.js)
assertFileContent \
$bookmarksUserJs \
@ -179,7 +186,7 @@
bookmarksFile="$(sed -n \
'/browser.bookmarks.file/ {s|^.*\(/nix/store[^"]*\).*|\1|;p}' \
$TESTED/home-files/.mozilla/firefox/bookmarks/user.js)"
$TESTED/home-files/${cfg.configPath}/bookmarks/user.js)"
assertFileContent \
$bookmarksFile \
@ -197,12 +204,12 @@
}
assertFirefoxSearchContent \
home-files/.mozilla/firefox/search/search.json.mozlz4 \
home-files/${cfg.configPath}/search/search.json.mozlz4 \
${./profile-settings-expected-search.json}
assertFirefoxSearchContent \
home-files/.mozilla/firefox/searchWithoutDefault/search.json.mozlz4 \
home-files/${cfg.configPath}/searchWithoutDefault/search.json.mozlz4 \
${./profile-settings-expected-search-without-default.json}
'';
};
});
}

View File

@ -1,16 +1,24 @@
{ pkgs, ... }:
modulePath:
{ config, lib, pkgs, ... }:
{
with lib;
let
cfg = getAttrFromPath modulePath config;
in {
nixpkgs.overlays = [
(self: super: {
firefox-unwrapped = pkgs.runCommandLocal "firefox-0" {
meta.description = "I pretend to be Firefox";
passthru.gtk3 = null;
} ''
mkdir -p "$out"/{bin,lib}
touch "$out/bin/firefox"
chmod 755 "$out/bin/firefox"
'';
"${cfg.wrappedPackageName}-unwrapped" =
pkgs.runCommandLocal "${cfg.wrappedPackageName}-0" {
meta.description = "I pretend to be ${cfg.name}";
passthru.gtk3 = null;
} ''
mkdir -p "$out"/{bin,lib}
touch "$out/bin/${cfg.wrappedPackageName}"
chmod 755 "$out/bin/${cfg.wrappedPackageName}"
'';
chrome-gnome-shell =
pkgs.runCommandLocal "dummy-chrome-gnome-shell" { } ''

View File

@ -1,19 +1,24 @@
modulePath:
{ config, lib, pkgs, ... }:
with lib;
{
imports = [ ./setup-firefox-mock-overlay.nix ];
let
config = lib.mkIf config.test.enableBig {
cfg = getAttrFromPath modulePath config;
firefoxMockOverlay = import ./setup-firefox-mock-overlay.nix modulePath;
in {
imports = [ firefoxMockOverlay ];
config = lib.mkIf config.test.enableBig ({
home.stateVersion = "19.09";
programs.firefox.enable = true;
} // setAttrByPath modulePath { enable = true; } // {
nmt.script = ''
assertFileRegex \
home-path/bin/firefox \
home-path/bin/${cfg.wrappedPackageName} \
MOZ_APP_LAUNCHER
'';
};
});
}