Bug 1926311 - [geckodriver] Add flag to allow installing an add-on that is enabled in Private Browsing mode. r=webdriver-reviewers,jgraham

Differential Revision: https://phabricator.services.mozilla.com/D229146
This commit is contained in:
Alexandra Borovova 2024-11-18 10:24:53 +00:00
parent fd375939b9
commit ded5faf235
2 changed files with 52 additions and 0 deletions

View File

@ -108,6 +108,8 @@ pub struct AddonBase64 {
#[serde(deserialize_with = "deserialize_base64")]
pub addon: Vec<u8>,
pub temporary: Option<bool>,
#[serde(rename = "allowPrivateBrowsing")]
pub allow_private_browsing: Option<bool>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
@ -115,6 +117,8 @@ pub struct AddonBase64 {
pub struct AddonPath {
pub path: String,
pub temporary: Option<bool>,
#[serde(rename = "allowPrivateBrowsing")]
pub allow_private_browsing: Option<bool>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
@ -183,6 +187,7 @@ mod tests {
let params = AddonPath {
path: "/path/to.xpi".to_string(),
temporary: Some(true),
allow_private_browsing: None,
};
assert_de(
&AddonInstallParameters::AddonPath(params),
@ -195,6 +200,7 @@ mod tests {
let params = AddonPath {
path: "/path/to.xpi".to_string(),
temporary: None,
allow_private_browsing: None,
};
assert_de(
&AddonInstallParameters::AddonPath(params),
@ -202,12 +208,31 @@ mod tests {
);
}
#[test]
fn test_json_addon_install_parameters_with_path_and_allow_private_browsing() {
let params = AddonPath {
path: "/path/to.xpi".to_string(),
temporary: None,
allow_private_browsing: Some(true),
};
assert_de(
&AddonInstallParameters::AddonPath(params),
json!({"path": "/path/to.xpi", "allowPrivateBrowsing": true}),
);
}
#[test]
fn test_json_addon_install_parameters_with_path_invalid_type() {
let json = json!({"path": true, "temporary": true});
assert!(serde_json::from_value::<AddonInstallParameters>(json).is_err());
}
#[test]
fn test_json_addon_install_parameters_with_path_and_allow_private_browsing_invalid_type() {
let json = json!({"path": "/path/to.xpi", "allowPrivateBrowsing": "foo"});
assert!(serde_json::from_value::<AddonInstallParameters>(json).is_err());
}
#[test]
fn test_json_addon_install_parameters_with_path_and_temporary_invalid_type() {
let json = json!({"path": "/path/to.xpi", "temporary": "foo"});
@ -228,6 +253,20 @@ mod tests {
}
}
#[test]
fn test_json_addon_install_parameters_with_addon_and_allow_private_browsing() {
let json = json!({"addon": "aGVsbG8=", "allowPrivateBrowsing": true});
let data = serde_json::from_value::<AddonInstallParameters>(json).unwrap();
match data {
AddonInstallParameters::AddonBase64(data) => {
assert_eq!(data.allow_private_browsing, Some(true));
assert_eq!(String::from_utf8(data.addon).unwrap(), "hello");
}
_ => (),
}
}
#[test]
fn test_json_addon_install_parameters_with_addon_only() {
let json = json!({"addon": "aGVsbG8="});
@ -254,6 +293,12 @@ mod tests {
assert!(serde_json::from_value::<AddonInstallParameters>(json).is_err());
}
#[test]
fn test_json_addon_install_parameters_with_addon_and_allow_private_browsing_invalid_type() {
let json = json!({"addon": "aGVsbG8=", "allowPrivateBrowsing": "foo"});
assert!(serde_json::from_value::<AddonInstallParameters>(json).is_err());
}
#[test]
fn test_json_install_parameters_with_temporary_only() {
let json = json!({"temporary": true});

View File

@ -1115,6 +1115,7 @@ impl MarionetteCommand {
let addon = AddonPath {
path: browser.create_file(&data.addon)?,
temporary: data.temporary,
allow_private_browsing: data.allow_private_browsing,
};
(Some("Addon:Install"), Some(addon.to_marionette()))
}
@ -1459,6 +1460,12 @@ impl ToMarionette<Map<String, Value>> for AddonPath {
serde_json::to_value(self.temporary)?,
);
}
if self.allow_private_browsing.is_some() {
data.insert(
"allowPrivateBrowsing".to_string(),
serde_json::to_value(self.allow_private_browsing)?,
);
}
Ok(data)
}
}