Skip to content

Commit

Permalink
firefox: make tests generic
Browse files Browse the repository at this point in the history
  • Loading branch information
brckd authored and rycee committed Apr 28, 2024
1 parent 2e41ec7 commit ef250ba
Show file tree
Hide file tree
Showing 12 changed files with 316 additions and 254 deletions.
13 changes: 11 additions & 2 deletions modules/programs/firefox/mkFirefoxModule.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -940,7 +948,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" {
Expand Down
2 changes: 1 addition & 1 deletion tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 21 additions & 16 deletions tests/modules/programs/firefox/container-id-out-of-range.nix
Original file line number Diff line number Diff line change
@@ -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";
};
};
};
};
});
}
9 changes: 0 additions & 9 deletions tests/modules/programs/firefox/default.nix

This file was deleted.

27 changes: 16 additions & 11 deletions tests/modules/programs/firefox/deprecated-native-messenger.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
modulePath:
{ config, lib, ... }:

with lib;

{ config, lib, ... }:
let

moduleName = concatStringsSep "." modulePath;

{
imports = [ ./setup-firefox-mock-overlay.nix ];
firefoxMockOverlay = import ./setup-firefox-mock-overlay.nix modulePath;

config = lib.mkIf config.test.enableBig {
programs.firefox = {
enable = true;
enableGnomeExtensions = true;
};
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.
''];
};
});
}
55 changes: 31 additions & 24 deletions tests/modules/programs/firefox/duplicate-container-ids.nix
Original file line number Diff line number Diff line change
@@ -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;

profiles = {
my-profile = {
isDefault = true;
id = 1;

programs.firefox = {
enable = true;

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";
};
};
};
};
};
});
}
35 changes: 21 additions & 14 deletions tests/modules/programs/firefox/duplicate-profile-ids.nix
Original file line number Diff line number Diff line change
@@ -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; };
};
};
});
}
11 changes: 11 additions & 0 deletions tests/modules/programs/firefox/firefox.nix
Original file line number Diff line number Diff line change
@@ -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;
}
31 changes: 19 additions & 12 deletions tests/modules/programs/firefox/policies.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
modulePath:
{ config, lib, pkgs, ... }:

{
imports = [ ./setup-firefox-mock-overlay.nix ];
with lib;

config = lib.mkIf config.test.enableBig {
home.stateVersion = "23.05";
let

programs.firefox = {
enable = true;
policies = { BlockAboutConfig = true; };
package = pkgs.firefox.override {
extraPolicies = { DownloadDirectory = "/foo"; };
};
};
cfg = getAttrFromPath modulePath config;

firefoxMockOverlay = import ./setup-firefox-mock-overlay.nix modulePath;

in {
imports = [ firefoxMockOverlay ];

config = mkIf config.test.enableBig ({
home.stateVersion = "23.05";
} // 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"
Expand Down
Loading

0 comments on commit ef250ba

Please sign in to comment.