diff --git a/components/search/src/configuration_types.rs b/components/search/src/configuration_types.rs index b22ddb39f5..fadaf4f6d8 100644 --- a/components/search/src/configuration_types.rs +++ b/components/search/src/configuration_types.rs @@ -96,7 +96,7 @@ pub(crate) struct JSONEngineBase { /// Specifies details of possible user environments that the engine or variant /// applies to. -#[derive(Debug, Deserialize, Clone)] +#[derive(Debug, Deserialize, Clone, Default)] #[serde(rename_all = "camelCase")] pub(crate) struct JSONVariantEnvironment { /// Indicates that this section applies to all regions and locales. May be diff --git a/components/search/src/environment_matching.rs b/components/search/src/environment_matching.rs index a004275534..5322c5122d 100644 --- a/components/search/src/environment_matching.rs +++ b/components/search/src/environment_matching.rs @@ -151,24 +151,12 @@ mod tests { excluded_regions: vec![], locales: vec![], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "FR".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when all_regions_and_locales is true" @@ -182,24 +170,12 @@ mod tests { excluded_regions: vec![], locales: vec![], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when all_regions_and_locales is false (default) and no regions/locales are specified" @@ -213,24 +189,12 @@ mod tests { excluded_regions: vec![], locales: vec![], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return false when all_regions_and_locales is true and the locale is excluded" @@ -244,24 +208,12 @@ mod tests { excluded_regions: vec![], locales: vec![], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return false when all_regions_and_locales is true and the excluded locale is a different case" @@ -275,24 +227,12 @@ mod tests { excluded_regions: vec![], locales: vec![], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when all_regions_and_locales is true and the locale is not excluded" @@ -302,28 +242,15 @@ mod tests { !matches_user_environment( &crate::JSONVariantEnvironment { all_regions_and_locales: true, - excluded_locales: vec![], excluded_regions: vec!["us".to_string(), "fr".to_string()], locales: vec![], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return false when all_regions_and_locales is true and the region is excluded" @@ -337,24 +264,12 @@ mod tests { excluded_regions: vec!["US".to_string(), "FR".to_string()], locales: vec![], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return false when all_regions_and_locales is true and the excluded region is a different case" @@ -368,24 +283,12 @@ mod tests { excluded_regions: vec!["us".to_string()], locales: vec![], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when all_regions_and_locales is true and the region is not excluded" @@ -402,24 +305,12 @@ mod tests { excluded_regions: vec![], locales: vec!["en-gb".to_string(), "fi".to_string()], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the user locale matches one from the config" @@ -433,24 +324,12 @@ mod tests { excluded_regions: vec![], locales: vec!["en-GB".to_string(), "FI".to_string()], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the user locale matches one from the config and is a different case" @@ -464,24 +343,12 @@ mod tests { excluded_regions: vec![], locales: vec!["en-gb".to_string(), "en-ca".to_string()], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return false when the user locale does not match one from the config" @@ -498,24 +365,12 @@ mod tests { excluded_regions: vec![], locales: vec![], regions: vec!["gb".to_string(), "fr".to_string()], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the user region matches one from the config" @@ -529,24 +384,12 @@ mod tests { excluded_regions: vec![], locales: vec![], regions: vec!["GB".to_string(), "FR".to_string()], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the user region matches one from the config and is a different case" @@ -560,24 +403,12 @@ mod tests { excluded_regions: vec![], locales: vec!["gb".to_string(), "ca".to_string()], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return false when the user region does not match one from the config" @@ -594,24 +425,12 @@ mod tests { excluded_regions: vec!["gb".to_string(), "ca".to_string()], locales: vec!["en-gb".to_string(), "fi".to_string()], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the locale matches and the region is not excluded" @@ -625,24 +444,12 @@ mod tests { excluded_regions: vec!["gb".to_string(), "fr".to_string()], locales: vec!["en-gb".to_string(), "fi".to_string()], regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return false when the locale matches and the region is excluded" @@ -659,24 +466,12 @@ mod tests { excluded_regions: vec![], locales: vec![], regions: vec!["gb".to_string(), "fr".to_string()], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the region matches and the locale is not excluded" @@ -690,24 +485,12 @@ mod tests { excluded_regions: vec![], locales: vec![], regions: vec!["gb".to_string(), "fr".to_string()], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return false when the region matches and the locale is excluded" @@ -719,29 +502,12 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], distributions: vec!["distro-1".to_string()], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Default, distribution_id: "distro-1".into(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the distribution matches one in the environment" @@ -750,29 +516,12 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], distributions: vec!["distro-2".to_string(), "distro-3".to_string()], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Default, distribution_id: "distro-3".into(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the distribution matches one in the environment when there are multiple" @@ -781,29 +530,12 @@ mod tests { assert!( !matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], distributions: vec!["distro-2".to_string(), "distro-3".to_string()], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Default, distribution_id: "distro-4".into(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return false when the distribution does not match any in the environment" @@ -812,29 +544,15 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], regions: vec!["fr".to_string()], distributions: vec!["distro-1".to_string(), "distro-2".to_string()], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, distribution_id: "distro-2".into(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the distribution and region matches the environment" @@ -846,31 +564,15 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec!["fr".to_string()], distributions: vec!["distro-1".to_string(), "distro-2".to_string()], excluded_distributions: vec![" distro-3".to_string(), "distro-4".to_string() ], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Default, distribution_id: "distro-2".into(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the distribution matches the distribution list but not the excluded distributions" @@ -879,29 +581,13 @@ mod tests { assert!( !matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec!["fr".to_string()], distributions: vec!["distro-1".to_string(), "distro-2".to_string()], excluded_distributions: vec!["distro-3".to_string(), "distro-4".to_string()], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Default, distribution_id: "distro-3".into(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return false when the distribution matches the the excluded distributions" @@ -913,29 +599,12 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], - distributions: vec![], - excluded_distributions: vec![], applications: vec![SearchApplicationName::Firefox], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the application name matches the one in the environment" @@ -944,32 +613,15 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], - distributions: vec![], - excluded_distributions: vec![], applications: vec![ SearchApplicationName::FirefoxAndroid, SearchApplicationName::Firefox ], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: "distro-3".into(), - experiment: String::new(), app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the application name matches one in the environment when there are multiple" @@ -978,32 +630,15 @@ mod tests { assert!( !matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], - distributions: vec![], - excluded_distributions: vec![], applications: vec![ SearchApplicationName::FirefoxAndroid, SearchApplicationName::Firefox ], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: "distro-4".into(), - experiment: String::new(), app_name: SearchApplicationName::FirefoxIos, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return false when the applications do not match the one in the environment" @@ -1012,32 +647,18 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], regions: vec!["fr".to_string()], - distributions: vec![], - excluded_distributions: vec![], applications: vec![ SearchApplicationName::FirefoxAndroid, SearchApplicationName::Firefox ], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the application name matches the one in the environment" @@ -1049,29 +670,12 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), channels: vec![SearchUpdateChannel::Nightly], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), update_channel: SearchUpdateChannel::Nightly, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the channel matches one in the environment" @@ -1080,29 +684,12 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), channels: vec![SearchUpdateChannel::Nightly, SearchUpdateChannel::Release], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), update_channel: SearchUpdateChannel::Release, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the channel matches one in the environment when there are multiple" @@ -1111,19 +698,8 @@ mod tests { assert!( !matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), channels: vec![SearchUpdateChannel::Nightly], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), @@ -1142,29 +718,15 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], regions: vec!["fr".to_string()], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), channels: vec![SearchUpdateChannel::Default], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the channel and region matches the environment" @@ -1176,29 +738,12 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], experiment: "warp-drive".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Nightly, - distribution_id: String::new(), experiment: "warp-drive".to_string(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the experiment matches the one in the environment" @@ -1207,29 +752,12 @@ mod tests { assert!( !matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], experiment: "warp-drive".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![SearchDeviceType::Smartphone], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), experiment: "cloak".to_string(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return false when the experiment does not match the one in the environment" @@ -1238,29 +766,15 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], regions: vec!["fr".to_string()], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], experiment: "warp-drive".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), - device_type: vec![SearchDeviceType::Tablet], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), experiment: "warp-drive".to_string(), - app_name: SearchApplicationName::Firefox, - version: String::new(), - device_type: SearchDeviceType::Tablet, + ..Default::default() } ), "Should return true when the experiment and region matches the environment" @@ -1269,84 +783,160 @@ mod tests { #[test] fn test_matches_user_environment_versions() { - fn match_version( - variant_min_version: &str, - variant_max_version: &str, - user_version: &str, - ) -> bool { - matches_user_environment( + assert!( + !matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: String::new(), - channels: vec![], - min_version: variant_min_version.to_string(), - max_version: variant_max_version.to_string(), - device_type: vec![], + min_version: "43.0.0".to_string(), + max_version: "".to_string(), + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Nightly, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: user_version.to_string(), - device_type: SearchDeviceType::None, + version: "42.0.0".to_string(), + ..Default::default() }, - ) - } - - assert!( - !match_version("43.0.0", "", "42.0.0"), + ), "Should return false when the version is below the minimum" ); assert!( - match_version("42.0.0", "", "42.0.0"), + matches_user_environment( + &crate::JSONVariantEnvironment { + min_version: "42.0.0".to_string(), + max_version: "".to_string(), + ..Default::default() + }, + &SearchUserEnvironment { + version: "42.0.0".to_string(), + ..Default::default() + }, + ), "Should return true when the version is equal to the minimum" ); assert!( - match_version("41.0.0", "", "42.0.0"), + matches_user_environment( + &crate::JSONVariantEnvironment { + min_version: "41.0.0".to_string(), + max_version: "".to_string(), + ..Default::default() + }, + &SearchUserEnvironment { + version: "42.0.0".to_string(), + ..Default::default() + }, + ), "Should return true when the version is above the minimum" ); assert!( - match_version("", "43.0.0", "42.0.0"), + matches_user_environment( + &crate::JSONVariantEnvironment { + min_version: "".to_string(), + max_version: "43.0.0".to_string(), + ..Default::default() + }, + &SearchUserEnvironment { + version: "42.0.0".to_string(), + ..Default::default() + }, + ), "Should return true when the version is below the maximum" ); assert!( - match_version("", "42.0.0", "42.0.0"), + matches_user_environment( + &crate::JSONVariantEnvironment { + min_version: "".to_string(), + max_version: "42.0.0".to_string(), + ..Default::default() + }, + &SearchUserEnvironment { + version: "42.0.0".to_string(), + ..Default::default() + }, + ), "Should return true when the version is equal to the maximum" ); assert!( - !match_version("", "41.0.0", "42.0.0"), + !matches_user_environment( + &crate::JSONVariantEnvironment { + min_version: "".to_string(), + max_version: "41.0.0".to_string(), + ..Default::default() + }, + &SearchUserEnvironment { + version: "42.0.0".to_string(), + ..Default::default() + }, + ), "Should return false when the version is above the maximum" ); assert!( - !match_version("41.0.0", "43.0.0", "2.0.0"), + !matches_user_environment( + &crate::JSONVariantEnvironment { + min_version: "41.0.0".to_string(), + max_version: "43.0.0".to_string(), + ..Default::default() + }, + &SearchUserEnvironment { + version: "2.0.0".to_string(), + ..Default::default() + }, + ), "Should return false when the version is below the minimum and both are specified" ); assert!( - match_version("41.0.0", "43.0.0", "41.0.0"), + matches_user_environment( + &crate::JSONVariantEnvironment { + min_version: "41.0.0".to_string(), + max_version: "43.0.0".to_string(), + ..Default::default() + }, + &SearchUserEnvironment { + version: "41.0.0".to_string(), + ..Default::default() + }, + ), "Should return true when the version is equal to the minimum and both are specified" ); assert!( - match_version("41.0.0", "43.0.0", "42.0.0"), + matches_user_environment( + &crate::JSONVariantEnvironment { + min_version: "41.0.0".to_string(), + max_version: "43.0.0".to_string(), + ..Default::default() + }, + &SearchUserEnvironment { + version: "42.0.0".to_string(), + ..Default::default() + }, + ), "Should return true when the version is between the minimum and maximum" ); assert!( - match_version("41.0.0", "43.0.0", "43.0.0"), + matches_user_environment( + &crate::JSONVariantEnvironment { + min_version: "41.0.0".to_string(), + max_version: "43.0.0".to_string(), + ..Default::default() + }, + &SearchUserEnvironment { + version: "43.0.0".to_string(), + ..Default::default() + }, + ), "Should return true when the version is equal to the maximum and both are specified" ); assert!( - !match_version("41.0.0", "43.0.0", "44.0.0"), + !matches_user_environment( + &crate::JSONVariantEnvironment { + min_version: "41.0.0".to_string(), + max_version: "43.0.0".to_string(), + ..Default::default() + }, + &SearchUserEnvironment { + version: "44.0.0".to_string(), + ..Default::default() + }, + ), "Should return false when the version is above the maximum and both are specified" ); } @@ -1356,29 +946,12 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), device_type: vec![SearchDeviceType::None], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Nightly, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return true when the device type matches one in the environment" @@ -1387,29 +960,12 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), device_type: vec![SearchDeviceType::Smartphone, SearchDeviceType::Tablet], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Release, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), device_type: SearchDeviceType::Tablet, + ..Default::default() } ), "Should return true when the device type matches one in the environment when there are multiple" @@ -1418,29 +974,12 @@ mod tests { assert!( !matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], - regions: vec![], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), device_type: vec![SearchDeviceType::Smartphone], + ..Default::default() }, &SearchUserEnvironment { - locale: "fi".into(), - region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: "distro-4".into(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), device_type: SearchDeviceType::None, + ..Default::default() } ), "Should return false when the device type does not match any in the environment" @@ -1449,29 +988,15 @@ mod tests { assert!( matches_user_environment( &crate::JSONVariantEnvironment { - all_regions_and_locales: false, - excluded_locales: vec![], - excluded_regions: vec![], - locales: vec![], regions: vec!["fr".to_string()], - distributions: vec![], - excluded_distributions: vec![], - applications: vec![], - experiment: "".to_string(), - channels: vec![], - min_version: "".to_string(), - max_version: "".to_string(), device_type: vec![SearchDeviceType::Tablet], + ..Default::default() }, &SearchUserEnvironment { locale: "fi".into(), region: "fr".into(), - update_channel: SearchUpdateChannel::Default, - distribution_id: String::new(), - experiment: String::new(), - app_name: SearchApplicationName::Firefox, - version: String::new(), device_type: SearchDeviceType::Tablet, + ..Default::default() } ), "Should return true when the device type and region matches the environment" diff --git a/components/search/src/types.rs b/components/search/src/types.rs index f106ec78be..d9e648f846 100644 --- a/components/search/src/types.rs +++ b/components/search/src/types.rs @@ -7,14 +7,16 @@ use serde::Deserialize; /// The list of possible application names that are currently supported. -#[derive(Clone, Debug, Deserialize, PartialEq, uniffi::Enum)] +#[derive(Clone, Debug, Default, Deserialize, PartialEq, uniffi::Enum)] #[serde(rename_all = "kebab-case")] pub enum SearchApplicationName { - Firefox = 1, - FirefoxAndroid = 2, - FirefoxIos = 3, - FocusAndroid = 4, - FocusIos = 5, + FirefoxAndroid = 1, + FirefoxIos = 2, + FocusAndroid = 3, + FocusIos = 4, + // The default doesn't really matter here, so we pick desktop. + #[default] + Firefox = 5, } impl SearchApplicationName { @@ -31,7 +33,7 @@ impl SearchApplicationName { /// The list of possible update channels for a user's build. /// Use `default` for a self-build or an unknown channel. -#[derive(Clone, Debug, Deserialize, PartialEq, uniffi::Enum)] +#[derive(Clone, Debug, Default, Deserialize, PartialEq, uniffi::Enum)] #[serde(rename_all = "lowercase")] pub enum SearchUpdateChannel { Nightly = 1, @@ -39,21 +41,21 @@ pub enum SearchUpdateChannel { Beta = 3, Release = 4, Esr = 5, - #[serde(other)] + #[default] Default = 6, } -#[derive(Clone, Debug, Deserialize, PartialEq, uniffi::Enum)] +#[derive(Clone, Debug, Default, Deserialize, PartialEq, uniffi::Enum)] #[serde(rename_all = "camelCase")] pub enum SearchDeviceType { Smartphone = 1, Tablet = 2, - #[serde(other)] + #[default] None = 3, } /// The user's environment that is used for filtering the search configuration. -#[derive(Clone, Debug, uniffi::Record)] +#[derive(Clone, Debug, uniffi::Record, Default)] pub struct SearchUserEnvironment { /// The current locale of the application that the user is using. pub locale: String,