diff --git a/rust/src/firefox.rs b/rust/src/firefox.rs index 0e9d707f81c22..4bdcd177ea5b3 100644 --- a/rust/src/firefox.rs +++ b/rust/src/firefox.rs @@ -28,7 +28,7 @@ use crate::metadata::{ }; use crate::{ create_http_client, format_three_args, format_two_args, Logger, SeleniumManager, BETA, - DASH_VERSION, DEV, NIGHTLY, OFFLINE_REQUEST_ERR_MSG, REG_CURRENT_VERSION_ARG, STABLE, + DASH_VERSION, DEV, ESR, NIGHTLY, OFFLINE_REQUEST_ERR_MSG, REG_CURRENT_VERSION_ARG, STABLE, }; use anyhow::anyhow; use anyhow::Error; @@ -49,6 +49,7 @@ const FIREFOX_STABLE_LABEL: &str = "LATEST_FIREFOX_VERSION"; const FIREFOX_BETA_LABEL: &str = "LATEST_FIREFOX_RELEASED_DEVEL_VERSION"; const FIREFOX_DEV_LABEL: &str = "FIREFOX_DEVEDITION"; const FIREFOX_CANARY_LABEL: &str = "FIREFOX_NIGHTLY"; +const FIREFOX_ESR_LABEL: &str = "FIREFOX_ESR"; const FIREFOX_VERSIONS_ENDPOINT: &str = "firefox_versions.json"; const FIREFOX_HISTORY_ENDPOINT: &str = "firefox_history_stability_releases.json"; const FIREFOX_HISTORY_DEV_ENDPOINT: &str = "firefox_history_development_releases.json"; @@ -146,6 +147,10 @@ impl SeleniumManager for FirefoxManager { BrowserPath::new(WINDOWS, NIGHTLY), r#"Firefox Nightly\firefox.exe"#, ), + ( + BrowserPath::new(WINDOWS, ESR), + r#"Mozilla Firefox\firefox.exe"#, + ), ( BrowserPath::new(MACOS, STABLE), r#"/Applications/Firefox.app/Contents/MacOS/firefox"#, @@ -162,10 +167,15 @@ impl SeleniumManager for FirefoxManager { BrowserPath::new(MACOS, NIGHTLY), r#"/Applications/Firefox Nightly.app/Contents/MacOS/firefox"#, ), + ( + BrowserPath::new(MACOS, ESR), + r#"/Applications/Firefox.app/Contents/MacOS/firefox"#, + ), (BrowserPath::new(LINUX, STABLE), "/usr/bin/firefox"), (BrowserPath::new(LINUX, BETA), "/usr/bin/firefox"), (BrowserPath::new(LINUX, DEV), "/usr/bin/firefox"), (BrowserPath::new(LINUX, NIGHTLY), "/usr/bin/firefox-trunk"), + (BrowserPath::new(LINUX, ESR), "/usr/bin/firefox"), ]) } @@ -358,32 +368,33 @@ impl SeleniumManager for FirefoxManager { fn request_fixed_browser_version_from_online( &mut self, - _browser_version: &str, + browser_version: &str, ) -> Result { let browser_name = self.browser_name; - let browser_version = self.get_browser_version().to_string(); self.get_logger().trace(format!( "Using Firefox endpoints to find out {} {}", browser_name, browser_version )); - if self.is_browser_version_unstable() { + if self.is_unstable(browser_version) { let firefox_versions_url = self.create_firefox_details_url(FIREFOX_VERSIONS_ENDPOINT); let firefox_versions = parse_generic_json_from_url(self.get_http_client(), firefox_versions_url)?; - let version_label = if browser_version.eq_ignore_ascii_case(BETA) { + let version_label = if self.is_beta(browser_version) { FIREFOX_BETA_LABEL - } else if browser_version.eq_ignore_ascii_case(DEV) { + } else if self.is_dev(browser_version) { FIREFOX_DEV_LABEL + } else if self.is_esr(browser_version) { + FIREFOX_ESR_LABEL } else { FIREFOX_CANARY_LABEL }; - let browser_version = firefox_versions + let discovered_browser_version = firefox_versions .get(version_label) .unwrap() .as_str() .unwrap(); - Ok(browser_version.to_string()) + Ok(discovered_browser_version.to_string()) } else { let major_browser_version = self .get_major_browser_version() @@ -395,7 +406,7 @@ impl SeleniumManager for FirefoxManager { return Err(anyhow!(format_three_args( UNAVAILABLE_DOWNLOAD_ERROR_MESSAGE, browser_name, - &browser_version, + browser_version, &min_downloadable_version.to_string(), ))); } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index ddbc0017dca12..8ab7ccaa2dda8 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -68,6 +68,7 @@ pub const BETA: &str = "beta"; pub const DEV: &str = "dev"; pub const CANARY: &str = "canary"; pub const NIGHTLY: &str = "nightly"; +pub const ESR: &str = "esr"; pub const WMIC_COMMAND: &str = r#"wmic datafile where name='{}' get Version /value"#; pub const WMIC_COMMAND_OS: &str = r#"wmic os get osarchitecture"#; pub const REG_VERSION_ARG: &str = "version"; @@ -202,7 +203,10 @@ pub trait SeleniumManager { } } - fn download_browser(&mut self) -> Result, Error> { + fn download_browser( + &mut self, + original_browser_version: String, + ) -> Result, Error> { if WINDOWS.is(self.get_os()) && self.is_edge() && !self.is_windows_admin() { return Err(anyhow!(format_one_arg( NOT_ADMIN_FOR_EDGE_INSTALLER_ERR_MSG, @@ -211,7 +215,6 @@ pub trait SeleniumManager { } let browser_version; - let original_browser_version = self.get_config().browser_version.clone(); let cache_path = self.get_cache_path()?; let mut metadata = get_metadata(self.get_logger(), &cache_path); let major_browser_version = self.get_major_browser_version(); @@ -421,6 +424,7 @@ pub trait SeleniumManager { fn discover_driver_version_and_download_browser_if_necessary( &mut self, ) -> Result { + let original_browser_version = self.get_config().browser_version.clone(); let mut download_browser = self.is_force_browser_download(); let major_browser_version = self.get_major_browser_version(); @@ -498,7 +502,7 @@ pub trait SeleniumManager { && !self.is_safari() && !self.is_webview2() { - let browser_path = self.download_browser()?; + let browser_path = self.download_browser(original_browser_version)?; if browser_path.is_some() { self.get_logger().debug(format!( "{} {} is available at {}", @@ -669,11 +673,20 @@ pub trait SeleniumManager { || browser_version.eq_ignore_ascii_case(CANARY) } + fn is_browser_version_esr(&self) -> bool { + self.is_esr(self.get_browser_version()) + } + + fn is_esr(&self, browser_version: &str) -> bool { + browser_version.eq_ignore_ascii_case(ESR) + } + fn is_unstable(&self, browser_version: &str) -> bool { browser_version.eq_ignore_ascii_case(BETA) || browser_version.eq_ignore_ascii_case(DEV) || browser_version.eq_ignore_ascii_case(NIGHTLY) || browser_version.eq_ignore_ascii_case(CANARY) + || browser_version.eq_ignore_ascii_case(ESR) } fn is_browser_version_unstable(&self) -> bool { diff --git a/rust/tests/browser_download_tests.rs b/rust/tests/browser_download_tests.rs index 12875debb1fe1..534831f7bba51 100644 --- a/rust/tests/browser_download_tests.rs +++ b/rust/tests/browser_download_tests.rs @@ -51,6 +51,7 @@ fn browser_latest_download_test(#[case] browser: String) { #[case("chrome", "beta")] #[case("firefox", "116")] #[case("firefox", "beta")] +#[case("firefox", "esr")] #[case("edge", "beta")] fn browser_version_download_test(#[case] browser: String, #[case] browser_version: String) { let mut cmd = Command::new(env!("CARGO_BIN_EXE_selenium-manager"));