Skip to content

Commit

Permalink
Bug 1639230: Remove vendor prefix for printing with webdriver r=jgrah…
Browse files Browse the repository at this point in the history
…am,webdriver-reviewers

This removes the vendor prefix for printing to PDF as it has landed in
the WebDriver specification[1]. It moves the wpt to the main test suite.

[1] https://w3c.github.io/webdriver/#print

Differential Revision: https://phabricator.services.mozilla.com/D76294
  • Loading branch information
AutomatedTester committed May 23, 2020
1 parent a76816c commit d5d4abf
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 152 deletions.
2 changes: 2 additions & 0 deletions testing/geckodriver/marionette/src/webdriver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ pub enum Command {
MinimizeWindow,
#[serde(rename = "WebDriver:NewWindow")]
NewWindow(NewWindow),
#[serde(rename = "WebDriver:Print")]
Print,
#[serde(rename = "WebDriver:Refresh")]
Refresh,
#[serde(rename = "WebDriver:ReleaseActions")]
Expand Down
143 changes: 0 additions & 143 deletions testing/geckodriver/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ pub fn extension_routes() -> Vec<(Method, &'static str, GeckoExtensionRoute)> {
"/session/{sessionId}/moz/screenshot/full",
GeckoExtensionRoute::TakeFullScreenshot,
),
(
Method::POST,
"/session/{sessionId}/moz/print",
GeckoExtensionRoute::Print,
),
];
}

Expand All @@ -69,7 +64,6 @@ pub enum GeckoExtensionRoute {
InstallAddon,
UninstallAddon,
TakeFullScreenshot,
Print,
}

impl WebDriverExtensionRoute for GeckoExtensionRoute {
Expand Down Expand Up @@ -114,7 +108,6 @@ impl WebDriverExtensionRoute for GeckoExtensionRoute {
GeckoExtensionCommand::UninstallAddon(serde_json::from_value(body_data.clone())?)
}
TakeFullScreenshot => GeckoExtensionCommand::TakeFullScreenshot,
Print => GeckoExtensionCommand::Print(serde_json::from_value(body_data.clone())?),
};

Ok(WebDriverCommand::Extension(command))
Expand All @@ -130,7 +123,6 @@ pub enum GeckoExtensionCommand {
InstallAddon(AddonInstallParameters),
UninstallAddon(AddonUninstallParameters),
TakeFullScreenshot,
Print(PrintParameters),
}

impl WebDriverExtensionCommand for GeckoExtensionCommand {
Expand All @@ -144,7 +136,6 @@ impl WebDriverExtensionCommand for GeckoExtensionCommand {
XblAnonymousByAttribute(_, x) => Some(serde_json::to_value(x).unwrap()),
XblAnonymousChildren(_) => None,
TakeFullScreenshot => None,
Print(x) => Some(serde_json::to_value(x).unwrap()),
}
}
}
Expand Down Expand Up @@ -241,109 +232,7 @@ pub struct LogOptions {
pub level: Option<logging::Level>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct PrintParameters {
pub orientation: PrintOrientation,
#[serde(deserialize_with = "deserialize_to_print_scale_f64")]
pub scale: f64,
pub background: bool,
pub page: PrintPage,
pub margin: PrintMargins,
pub page_ranges: Vec<String>,
pub shrink_to_fit: bool,
}

impl Default for PrintParameters {
fn default() -> Self {
PrintParameters {
orientation: PrintOrientation::default(),
scale: 1.0,
background: false,
page: PrintPage::default(),
margin: PrintMargins::default(),
page_ranges: Vec::new(),
shrink_to_fit: true,
}
}
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum PrintOrientation {
Landscape,
Portrait,
}

impl Default for PrintOrientation {
fn default() -> Self {
PrintOrientation::Portrait
}
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct PrintPage {
#[serde(deserialize_with = "deserialize_to_positive_f64")]
pub width: f64,
#[serde(deserialize_with = "deserialize_to_positive_f64")]
pub height: f64,
}

impl Default for PrintPage {
fn default() -> Self {
PrintPage {
width: 21.59,
height: 27.94,
}
}
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct PrintMargins {
#[serde(deserialize_with = "deserialize_to_positive_f64")]
pub top: f64,
#[serde(deserialize_with = "deserialize_to_positive_f64")]
pub bottom: f64,
#[serde(deserialize_with = "deserialize_to_positive_f64")]
pub left: f64,
#[serde(deserialize_with = "deserialize_to_positive_f64")]
pub right: f64,
}

impl Default for PrintMargins {
fn default() -> Self {
PrintMargins {
top: 1.0,
bottom: 1.0,
left: 1.0,
right: 1.0,
}
}
}

fn deserialize_to_positive_f64<'de, D>(deserializer: D) -> Result<f64, D::Error>
where
D: Deserializer<'de>,
{
let val = f64::deserialize(deserializer)?;
if val < 0.0 {
return Err(de::Error::custom(format!("{} is negative", val)));
};
Ok(val)
}

fn deserialize_to_print_scale_f64<'de, D>(deserializer: D) -> Result<f64, D::Error>
where
D: Deserializer<'de>,
{
let val = f64::deserialize(deserializer)?;
if val < 0.1 || val > 2.0 {
return Err(de::Error::custom(format!("{} is outside range 0.1-2", val)));
};
Ok(val)
}

#[cfg(test)]
mod tests {
Expand Down Expand Up @@ -503,36 +392,4 @@ mod tests {
assert!(serde_json::from_value::<P>(json!({"name": "foo"})).is_err());
assert!(serde_json::from_value::<P>(json!({"name": "foo", "value": null})).is_err());
}

#[test]
fn test_json_gecko_print_defaults() {
let params = PrintParameters::default();
assert_de(&params, json!({}));
}

#[test]
fn test_json_gecko_print() {
let params = PrintParameters {
orientation: PrintOrientation::Landscape,
page: PrintPage {
width: 10.0,
..Default::default()
},
margin: PrintMargins {
top: 10.0,
..Default::default()
},
scale: 1.5,
..Default::default()
};
assert_de(
&params,
json!({"orientation": "landscape", "page": {"width": 10}, "margin": {"top": 10}, "scale": 1.5}),
);
}

#[test]
fn test_json_gecko_scale_invalid() {
assert!(serde_json::from_value::<AddonInstallParameters>(json!({"scale": 3})).is_err());
}
}
14 changes: 7 additions & 7 deletions testing/geckodriver/src/marionette.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::android::AndroidHandler;
use crate::command::{
AddonInstallParameters, AddonUninstallParameters, GeckoContextParameters,
GeckoExtensionCommand, GeckoExtensionRoute, PrintParameters, XblLocatorParameters,
GeckoExtensionCommand, GeckoExtensionRoute, XblLocatorParameters,
CHROME_ELEMENT_KEY,
};
use marionette_rs::common::{
Expand Down Expand Up @@ -40,15 +40,15 @@ use webdriver::command::WebDriverCommand::{
GetElementProperty, GetElementRect, GetElementTagName, GetElementText, GetNamedCookie,
GetPageSource, GetTimeouts, GetTitle, GetWindowHandle, GetWindowHandles, GetWindowRect, GoBack,
GoForward, IsDisplayed, IsEnabled, IsSelected, MaximizeWindow, MinimizeWindow, NewSession,
NewWindow, PerformActions, Refresh, ReleaseActions, SendAlertText, SetTimeouts, SetWindowRect,
Status, SwitchToFrame, SwitchToParentFrame, SwitchToWindow, TakeElementScreenshot,
NewWindow, PerformActions, Print, Refresh, ReleaseActions, SendAlertText, SetTimeouts,
SetWindowRect, Status, SwitchToFrame, SwitchToParentFrame, SwitchToWindow, TakeElementScreenshot,
TakeScreenshot,
};
use webdriver::command::{
ActionsParameters, AddCookieParameters, GetNamedCookieParameters, GetParameters,
JavascriptCommandParameters, LocatorParameters, NewSessionParameters, NewWindowParameters,
SendKeysParameters, SwitchToFrameParameters, SwitchToWindowParameters, TimeoutsParameters,
WindowRectParameters,
PrintParameters, SendKeysParameters, SwitchToFrameParameters, SwitchToWindowParameters,
TimeoutsParameters, WindowRectParameters,
};
use webdriver::command::{WebDriverCommand, WebDriverMessage};
use webdriver::common::{
Expand Down Expand Up @@ -579,6 +579,7 @@ impl MarionetteSession {
| ExecuteAsyncScript(_)
| GetAlertText
| TakeScreenshot
| Print(_)
| TakeElementScreenshot(_) => {
WebDriverResponse::Generic(resp.into_value_response(true)?)
}
Expand Down Expand Up @@ -888,7 +889,6 @@ impl MarionetteSession {
InstallAddon(_) => WebDriverResponse::Generic(resp.into_value_response(true)?),
UninstallAddon(_) => WebDriverResponse::Void,
TakeFullScreenshot => WebDriverResponse::Generic(resp.into_value_response(true)?),
Print(_) => WebDriverResponse::Generic(resp.into_value_response(true)?),
},
})
}
Expand Down Expand Up @@ -1043,6 +1043,7 @@ fn try_convert_to_marionette_message(
NewWindow(ref x) => Some(Command::WebDriver(MarionetteWebDriverCommand::NewWindow(
x.to_marionette()?,
))),
Print(ref x) => Some(Command::WebDriver(MarionetteWebDriverCommand::Print)),
Refresh => Some(Command::WebDriver(MarionetteWebDriverCommand::Refresh)),
ReleaseActions => Some(Command::WebDriver(
MarionetteWebDriverCommand::ReleaseActions,
Expand Down Expand Up @@ -1163,7 +1164,6 @@ impl MarionetteCommand {
Extension(ref extension) => match extension {
GetContext => (Some("Marionette:GetContext"), None),
InstallAddon(x) => (Some("Addon:Install"), Some(x.to_marionette())),
Print(x) => (Some("WebDriver:Print"), Some(x.to_marionette())),
SetContext(x) => (Some("Marionette:SetContext"), Some(x.to_marionette())),
UninstallAddon(x) => (Some("Addon:Uninstall"), Some(x.to_marionette())),
XblAnonymousByAttribute(e, x) => {
Expand Down
3 changes: 3 additions & 0 deletions testing/web-platform/tests/lint.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -757,3 +757,6 @@ TESTHARNESS-IN-OTHER-TYPE: svg/extensibility/foreignObject/foreign-object-circul
TESTHARNESS-IN-OTHER-TYPE: svg/extensibility/foreignObject/foreign-object-under-clip-path-crash.html
TESTHARNESS-IN-OTHER-TYPE: svg/extensibility/foreignObject/foreign-object-under-defs-crash.html
TESTHARNESS-IN-OTHER-TYPE: svg/svg-in-svg/svg-in-svg-circular-filter-reference-crash.html

PRINT STATEMENT: webdriver/tests/print/printcmd.py
PRINT STATEMENT: webdriver/tests/print/user_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def do_print(session, options):
return session.transport.send(
"POST", "session/{session_id}/moz/print".format(**vars(session)),
"POST", "session/{session_id}/print".format(**vars(session)),
options)


Expand Down
Loading

0 comments on commit d5d4abf

Please sign in to comment.