webdriver_server/
capabilities.rs1use serde_json::{Map, Value};
6use webdriver::capabilities::{BrowserCapabilities, Capabilities};
7use webdriver::error::{ErrorStatus, WebDriverError, WebDriverResult};
8
9pub(crate) struct ServoCapabilities {
10 pub(crate) browser_name: String,
11 pub(crate) browser_version: String,
12 pub(crate) platform_name: Option<String>,
13 pub(crate) set_window_rect: bool,
14 accept_insecure_certs: bool,
15 strict_file_interactability: bool,
16 accept_proxy: bool,
17 accept_custom: bool,
18}
19
20impl ServoCapabilities {
21 pub(crate) fn new() -> ServoCapabilities {
22 ServoCapabilities {
23 browser_name: "servo".to_string(),
24 browser_version: "0.0.1".to_string(),
25 platform_name: get_platform_name(),
26 set_window_rect: true,
27 accept_insecure_certs: false,
28 strict_file_interactability: false,
29 accept_proxy: false,
30 accept_custom: true,
31 }
32 }
33}
34
35impl BrowserCapabilities for ServoCapabilities {
36 fn init(&mut self, _: &Capabilities) {}
37
38 fn browser_name(&mut self, _: &Capabilities) -> WebDriverResult<Option<String>> {
39 Ok(Some(self.browser_name.clone()))
40 }
41
42 fn browser_version(&mut self, _: &Capabilities) -> WebDriverResult<Option<String>> {
43 Ok(Some(self.browser_version.clone()))
44 }
45
46 fn compare_browser_version(&mut self, _: &str, _: &str) -> WebDriverResult<bool> {
47 Ok(true)
48 }
49
50 fn platform_name(&mut self, _: &Capabilities) -> WebDriverResult<Option<String>> {
51 Ok(self.platform_name.clone())
52 }
53
54 fn accept_insecure_certs(&mut self, _: &Capabilities) -> WebDriverResult<bool> {
55 Ok(self.accept_insecure_certs)
56 }
57
58 fn set_window_rect(&mut self, _: &Capabilities) -> WebDriverResult<bool> {
59 Ok(self.set_window_rect)
60 }
61
62 fn strict_file_interactability(&mut self, value: &Capabilities) -> WebDriverResult<bool> {
63 if let Some(Value::Bool(strict_file_interactability)) =
64 value.get("strictFileInteractability")
65 {
66 self.strict_file_interactability = *strict_file_interactability;
67 }
68
69 Ok(self.strict_file_interactability)
70 }
71
72 fn accept_proxy(&mut self, _: &Map<String, Value>, _: &Capabilities) -> WebDriverResult<bool> {
73 Ok(self.accept_proxy)
74 }
75
76 fn accept_custom(&mut self, _: &str, _: &Value, _: &Capabilities) -> WebDriverResult<bool> {
77 Ok(self.accept_custom)
78 }
79
80 fn validate_custom(&mut self, _: &str, _: &Value) -> WebDriverResult<()> {
81 Ok(())
82 }
83
84 fn web_socket_url(
85 &mut self,
86 _: &serde_json::Map<std::string::String, Value>,
87 ) -> Result<bool, WebDriverError> {
88 Err(WebDriverError::new(ErrorStatus::UnsupportedOperation, ""))
89 }
90
91 fn webauthn_virtual_authenticators(
92 &mut self,
93 _: &serde_json::Map<std::string::String, Value>,
94 ) -> Result<bool, WebDriverError> {
95 Err(WebDriverError::new(ErrorStatus::UnsupportedOperation, ""))
96 }
97
98 fn webauthn_extension_uvm(
99 &mut self,
100 _: &serde_json::Map<std::string::String, Value>,
101 ) -> Result<bool, WebDriverError> {
102 Err(WebDriverError::new(ErrorStatus::UnsupportedOperation, ""))
103 }
104
105 fn webauthn_extension_prf(
106 &mut self,
107 _: &serde_json::Map<std::string::String, Value>,
108 ) -> Result<bool, WebDriverError> {
109 Err(WebDriverError::new(ErrorStatus::UnsupportedOperation, ""))
110 }
111
112 fn webauthn_extension_large_blob(
113 &mut self,
114 _: &serde_json::Map<std::string::String, Value>,
115 ) -> Result<bool, WebDriverError> {
116 Err(WebDriverError::new(ErrorStatus::UnsupportedOperation, ""))
117 }
118
119 fn webauthn_extension_cred_blob(
120 &mut self,
121 _: &serde_json::Map<std::string::String, Value>,
122 ) -> Result<bool, WebDriverError> {
123 Err(WebDriverError::new(ErrorStatus::UnsupportedOperation, ""))
124 }
125}
126
127fn get_platform_name() -> Option<String> {
129 if cfg!(target_os = "windows") {
130 Some("windows".to_string())
131 } else if cfg!(target_os = "linux") {
132 Some("linux".to_string())
133 } else if cfg!(target_os = "macos") {
134 Some("mac".to_string())
135 } else {
136 None
137 }
138}