@@ -52,11 +52,6 @@ pub fn extension_routes() -> Vec<(Method, &'static str, GeckoExtensionRoute)> {
5252 "/session/{sessionId}/moz/screenshot/full" ,
5353 GeckoExtensionRoute :: TakeFullScreenshot ,
5454 ) ,
55- (
56- Method :: POST ,
57- "/session/{sessionId}/moz/print" ,
58- GeckoExtensionRoute :: Print ,
59- ) ,
6055 ] ;
6156}
6257
@@ -69,7 +64,6 @@ pub enum GeckoExtensionRoute {
6964 InstallAddon ,
7065 UninstallAddon ,
7166 TakeFullScreenshot ,
72- Print ,
7367}
7468
7569impl WebDriverExtensionRoute for GeckoExtensionRoute {
@@ -114,7 +108,6 @@ impl WebDriverExtensionRoute for GeckoExtensionRoute {
114108 GeckoExtensionCommand :: UninstallAddon ( serde_json:: from_value ( body_data. clone ( ) ) ?)
115109 }
116110 TakeFullScreenshot => GeckoExtensionCommand :: TakeFullScreenshot ,
117- Print => GeckoExtensionCommand :: Print ( serde_json:: from_value ( body_data. clone ( ) ) ?) ,
118111 } ;
119112
120113 Ok ( WebDriverCommand :: Extension ( command) )
@@ -130,7 +123,6 @@ pub enum GeckoExtensionCommand {
130123 InstallAddon ( AddonInstallParameters ) ,
131124 UninstallAddon ( AddonUninstallParameters ) ,
132125 TakeFullScreenshot ,
133- Print ( PrintParameters ) ,
134126}
135127
136128impl WebDriverExtensionCommand for GeckoExtensionCommand {
@@ -144,7 +136,6 @@ impl WebDriverExtensionCommand for GeckoExtensionCommand {
144136 XblAnonymousByAttribute ( _, x) => Some ( serde_json:: to_value ( x) . unwrap ( ) ) ,
145137 XblAnonymousChildren ( _) => None ,
146138 TakeFullScreenshot => None ,
147- Print ( x) => Some ( serde_json:: to_value ( x) . unwrap ( ) ) ,
148139 }
149140 }
150141}
@@ -241,113 +232,6 @@ pub struct LogOptions {
241232 pub level : Option < logging:: Level > ,
242233}
243234
244- #[ derive( Clone , Debug , PartialEq , Serialize , Deserialize ) ]
245- #[ serde( default , rename_all = "camelCase" ) ]
246- pub struct PrintParameters {
247- pub orientation : PrintOrientation ,
248- #[ serde( deserialize_with = "deserialize_to_print_scale_f64" ) ]
249- pub scale : f64 ,
250- pub background : bool ,
251- pub page : PrintPage ,
252- pub margin : PrintMargins ,
253- pub page_ranges : Vec < String > ,
254- pub shrink_to_fit : bool ,
255- }
256-
257- impl Default for PrintParameters {
258- fn default ( ) -> Self {
259- PrintParameters {
260- orientation : PrintOrientation :: default ( ) ,
261- scale : 1.0 ,
262- background : false ,
263- page : PrintPage :: default ( ) ,
264- margin : PrintMargins :: default ( ) ,
265- page_ranges : Vec :: new ( ) ,
266- shrink_to_fit : true ,
267- }
268- }
269- }
270-
271- #[ derive( Clone , Debug , PartialEq , Serialize , Deserialize ) ]
272- #[ serde( rename_all = "lowercase" ) ]
273- pub enum PrintOrientation {
274- Landscape ,
275- Portrait ,
276- }
277-
278- impl Default for PrintOrientation {
279- fn default ( ) -> Self {
280- PrintOrientation :: Portrait
281- }
282- }
283-
284- #[ derive( Clone , Debug , PartialEq , Serialize , Deserialize ) ]
285- #[ serde( default ) ]
286- pub struct PrintPage {
287- #[ serde( deserialize_with = "deserialize_to_positive_f64" ) ]
288- pub width : f64 ,
289- #[ serde( deserialize_with = "deserialize_to_positive_f64" ) ]
290- pub height : f64 ,
291- }
292-
293- impl Default for PrintPage {
294- fn default ( ) -> Self {
295- PrintPage {
296- width : 21.59 ,
297- height : 27.94 ,
298- }
299- }
300- }
301-
302- #[ derive( Clone , Debug , PartialEq , Serialize , Deserialize ) ]
303- #[ serde( default ) ]
304- pub struct PrintMargins {
305- #[ serde( deserialize_with = "deserialize_to_positive_f64" ) ]
306- pub top : f64 ,
307- #[ serde( deserialize_with = "deserialize_to_positive_f64" ) ]
308- pub bottom : f64 ,
309- #[ serde( deserialize_with = "deserialize_to_positive_f64" ) ]
310- pub left : f64 ,
311- #[ serde( deserialize_with = "deserialize_to_positive_f64" ) ]
312- pub right : f64 ,
313- }
314-
315- impl Default for PrintMargins {
316- fn default ( ) -> Self {
317- PrintMargins {
318- top : 1.0 ,
319- bottom : 1.0 ,
320- left : 1.0 ,
321- right : 1.0 ,
322- }
323- }
324- }
325-
326- fn deserialize_to_positive_f64 < ' de , D > ( deserializer : D ) -> Result < f64 , D :: Error >
327- where
328- D : Deserializer < ' de > ,
329- {
330- let val = f64:: deserialize ( deserializer) ?;
331- if val < 0.0 {
332- return Err ( de:: Error :: custom ( format ! ( "{} is negative" , val) ) ) ;
333- } ;
334- Ok ( val)
335- }
336-
337- fn deserialize_to_print_scale_f64 < ' de , D > ( deserializer : D ) -> Result < f64 , D :: Error >
338- where
339- D : Deserializer < ' de > ,
340- {
341- let val = f64:: deserialize ( deserializer) ?;
342- if val < 0.1 || val > 2.0 {
343- return Err ( de:: Error :: custom ( format ! (
344- "{} is outside range 0.1-2" ,
345- val
346- ) ) ) ;
347- } ;
348- Ok ( val)
349- }
350-
351235#[ cfg( test) ]
352236mod tests {
353237 use serde_json:: json;
@@ -506,36 +390,4 @@ mod tests {
506390 assert ! ( serde_json:: from_value:: <P >( json!( { "name" : "foo" } ) ) . is_err( ) ) ;
507391 assert ! ( serde_json:: from_value:: <P >( json!( { "name" : "foo" , "value" : null} ) ) . is_err( ) ) ;
508392 }
509-
510- #[ test]
511- fn test_json_gecko_print_defaults ( ) {
512- let params = PrintParameters :: default ( ) ;
513- assert_de ( & params, json ! ( { } ) ) ;
514- }
515-
516- #[ test]
517- fn test_json_gecko_print ( ) {
518- let params = PrintParameters {
519- orientation : PrintOrientation :: Landscape ,
520- page : PrintPage {
521- width : 10.0 ,
522- ..Default :: default ( )
523- } ,
524- margin : PrintMargins {
525- top : 10.0 ,
526- ..Default :: default ( )
527- } ,
528- scale : 1.5 ,
529- ..Default :: default ( )
530- } ;
531- assert_de (
532- & params,
533- json ! ( { "orientation" : "landscape" , "page" : { "width" : 10 } , "margin" : { "top" : 10 } , "scale" : 1.5 } ) ,
534- ) ;
535- }
536-
537- #[ test]
538- fn test_json_gecko_scale_invalid ( ) {
539- assert ! ( serde_json:: from_value:: <AddonInstallParameters >( json!( { "scale" : 3 } ) ) . is_err( ) ) ;
540- }
541393}
0 commit comments