Skip to content

Commit

Permalink
[rust] Support for automatic management of Firefox ESR (#12946)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia authored Oct 16, 2023
1 parent 0074a7c commit 8fee675
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
29 changes: 20 additions & 9 deletions rust/src/firefox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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"#,
Expand All @@ -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"),
])
}

Expand Down Expand Up @@ -358,32 +368,33 @@ impl SeleniumManager for FirefoxManager {

fn request_fixed_browser_version_from_online(
&mut self,
_browser_version: &str,
browser_version: &str,
) -> Result<String, Error> {
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()
Expand All @@ -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(),
)));
}
Expand Down
19 changes: 16 additions & 3 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -202,7 +203,10 @@ pub trait SeleniumManager {
}
}

fn download_browser(&mut self) -> Result<Option<PathBuf>, Error> {
fn download_browser(
&mut self,
original_browser_version: String,
) -> Result<Option<PathBuf>, 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,
Expand All @@ -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();
Expand Down Expand Up @@ -421,6 +424,7 @@ pub trait SeleniumManager {
fn discover_driver_version_and_download_browser_if_necessary(
&mut self,
) -> Result<String, Error> {
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();

Expand Down Expand Up @@ -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 {}",
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions rust/tests/browser_download_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit 8fee675

Please sign in to comment.