mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
WebDriver timeout settings are not optional.
Not setting one of them in a SetTimeouts requests should not remove it. This fixes a panicking `unwrap()`.
This commit is contained in:
parent
c05d30d116
commit
4acdb81197
1 changed files with 24 additions and 23 deletions
|
@ -107,14 +107,14 @@ struct WebDriverSession {
|
||||||
|
|
||||||
/// Time to wait for injected scripts to run before interrupting them. A [`None`] value
|
/// Time to wait for injected scripts to run before interrupting them. A [`None`] value
|
||||||
/// specifies that the script should run indefinitely.
|
/// specifies that the script should run indefinitely.
|
||||||
script_timeout: Option<u64>,
|
script_timeout: u64,
|
||||||
|
|
||||||
/// Time to wait for a page to finish loading upon navigation.
|
/// Time to wait for a page to finish loading upon navigation.
|
||||||
load_timeout: Option<u64>,
|
load_timeout: u64,
|
||||||
|
|
||||||
/// Time to wait for the element location strategy when retrieving elements, and when
|
/// Time to wait for the element location strategy when retrieving elements, and when
|
||||||
/// waiting for an element to become interactable.
|
/// waiting for an element to become interactable.
|
||||||
implicit_wait_timeout: Option<u64>,
|
implicit_wait_timeout: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebDriverSession {
|
impl WebDriverSession {
|
||||||
|
@ -127,9 +127,9 @@ impl WebDriverSession {
|
||||||
browsing_context_id: browsing_context_id,
|
browsing_context_id: browsing_context_id,
|
||||||
top_level_browsing_context_id: top_level_browsing_context_id,
|
top_level_browsing_context_id: top_level_browsing_context_id,
|
||||||
|
|
||||||
script_timeout: Some(30_000),
|
script_timeout: 30_000,
|
||||||
load_timeout: Some(300_000),
|
load_timeout: 300_000,
|
||||||
implicit_wait_timeout: Some(0),
|
implicit_wait_timeout: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ struct Handler {
|
||||||
resize_timeout: u32,
|
resize_timeout: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
enum ServoExtensionRoute {
|
enum ServoExtensionRoute {
|
||||||
GetPrefs,
|
GetPrefs,
|
||||||
SetPrefs,
|
SetPrefs,
|
||||||
|
@ -171,7 +171,7 @@ impl WebDriverExtensionRoute for ServoExtensionRoute {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
enum ServoExtensionCommand {
|
enum ServoExtensionCommand {
|
||||||
GetPrefs(GetPrefsParameters),
|
GetPrefs(GetPrefsParameters),
|
||||||
SetPrefs(SetPrefsParameters),
|
SetPrefs(SetPrefsParameters),
|
||||||
|
@ -188,7 +188,7 @@ impl WebDriverExtensionCommand for ServoExtensionCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
struct GetPrefsParameters {
|
struct GetPrefsParameters {
|
||||||
prefs: Vec<String>
|
prefs: Vec<String>
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ impl ToJson for GetPrefsParameters {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
struct SetPrefsParameters {
|
struct SetPrefsParameters {
|
||||||
prefs: Vec<(String, PrefValue)>
|
prefs: Vec<(String, PrefValue)>
|
||||||
}
|
}
|
||||||
|
@ -371,7 +371,7 @@ impl Handler {
|
||||||
-> WebDriverResult<WebDriverResponse> {
|
-> WebDriverResult<WebDriverResponse> {
|
||||||
let timeout = self.session()?.load_timeout;
|
let timeout = self.session()?.load_timeout;
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
thread::sleep(Duration::from_millis(timeout.unwrap()));
|
thread::sleep(Duration::from_millis(timeout));
|
||||||
let _ = sender.send(LoadStatus::LoadTimeout);
|
let _ = sender.send(LoadStatus::LoadTimeout);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -720,9 +720,15 @@ impl Handler {
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.ok_or(WebDriverError::new(ErrorStatus::SessionNotCreated, ""))?;
|
.ok_or(WebDriverError::new(ErrorStatus::SessionNotCreated, ""))?;
|
||||||
|
|
||||||
session.script_timeout = parameters.script;
|
if let Some(timeout) = parameters.script {
|
||||||
session.load_timeout = parameters.page_load;
|
session.script_timeout = timeout
|
||||||
session.implicit_wait_timeout = parameters.implicit;
|
}
|
||||||
|
if let Some(timeout) = parameters.page_load {
|
||||||
|
session.load_timeout = timeout
|
||||||
|
}
|
||||||
|
if let Some(timeout) = parameters.implicit {
|
||||||
|
session.implicit_wait_timeout = timeout
|
||||||
|
}
|
||||||
|
|
||||||
Ok(WebDriverResponse::Void)
|
Ok(WebDriverResponse::Void)
|
||||||
}
|
}
|
||||||
|
@ -750,15 +756,10 @@ impl Handler {
|
||||||
let func_body = ¶meters.script;
|
let func_body = ¶meters.script;
|
||||||
let args_string = "window.webdriverCallback";
|
let args_string = "window.webdriverCallback";
|
||||||
|
|
||||||
let script = match self.session()?.script_timeout {
|
let script = format!("setTimeout(webdriverTimeout, {}); (function(callback) {{ {} }})({})",
|
||||||
Some(timeout) => {
|
self.session()?.script_timeout,
|
||||||
format!("setTimeout(webdriverTimeout, {}); (function(callback) {{ {} }})({})",
|
|
||||||
timeout,
|
|
||||||
func_body,
|
func_body,
|
||||||
args_string)
|
args_string);
|
||||||
}
|
|
||||||
None => format!("(function(callback) {{ {} }})({})", func_body, args_string),
|
|
||||||
};
|
|
||||||
|
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
let command = WebDriverScriptCommand::ExecuteAsyncScript(script, sender);
|
let command = WebDriverScriptCommand::ExecuteAsyncScript(script, sender);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue