mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Add support for timing out scripts
This commit is contained in:
parent
8d10fa1f2d
commit
50f59c8255
5 changed files with 82 additions and 49 deletions
|
@ -56,9 +56,6 @@
|
|||
|
||||
//void postMessage(any message, DOMString targetOrigin, optional sequence<Transferable> transfer);
|
||||
|
||||
// Shouldn't be public, but just to make things work for now
|
||||
void webdriverCallback(optional any result);
|
||||
|
||||
// also has obsolete members
|
||||
};
|
||||
Window implements GlobalEventHandlers;
|
||||
|
@ -131,6 +128,13 @@ partial interface Window {
|
|||
};
|
||||
Window implements OnErrorEventHandlerForWindow;
|
||||
|
||||
// WebDriver extensions
|
||||
partial interface Window {
|
||||
// Shouldn't be public, but just to make things work for now
|
||||
void webdriverCallback(optional any result);
|
||||
void webdriverTimeout();
|
||||
};
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-sessionstorage
|
||||
[NoInterfaceObject]
|
||||
interface WindowSessionStorage {
|
||||
|
|
|
@ -38,7 +38,7 @@ use timers::{IsInterval, TimerId, TimerManager, TimerCallback};
|
|||
use webdriver_handlers::jsval_to_webdriver;
|
||||
|
||||
use devtools_traits::{DevtoolsControlChan, TimelineMarker, TimelineMarkerType, TracingMetadata};
|
||||
use webdriver_traits::EvaluateJSReply;
|
||||
use webdriver_traits::{WebDriverJSError, WebDriverJSResult};
|
||||
use msg::compositor_msg::ScriptListener;
|
||||
use msg::constellation_msg::{LoadData, PipelineId, SubpageId, ConstellationChan, WindowSizeData, WorkerId};
|
||||
use net_traits::ResourceTask;
|
||||
|
@ -170,7 +170,7 @@ pub struct Window {
|
|||
pending_reflow_count: Cell<u32>,
|
||||
|
||||
/// A channel for communicating results of async scripts back to the webdriver server
|
||||
webdriver_script_chan: RefCell<Option<Sender<Result<EvaluateJSReply, ()>>>>
|
||||
webdriver_script_chan: RefCell<Option<Sender<WebDriverJSResult>>>
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
@ -491,13 +491,17 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
|
|||
|
||||
fn WebdriverCallback(self, cx: *mut JSContext, val: JSVal) {
|
||||
let rv = jsval_to_webdriver(cx, val);
|
||||
{
|
||||
let opt_chan = self.webdriver_script_chan.borrow();
|
||||
if let Some(ref chan) = *opt_chan {
|
||||
chan.send(rv).unwrap();
|
||||
}
|
||||
let opt_chan = self.webdriver_script_chan.borrow_mut().take();
|
||||
if let Some(chan) = opt_chan {
|
||||
chan.send(rv).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn WebdriverTimeout(self) {
|
||||
let opt_chan = self.webdriver_script_chan.borrow_mut().take();
|
||||
if let Some(chan) = opt_chan {
|
||||
chan.send(Err(WebDriverJSError::Timeout)).unwrap();
|
||||
}
|
||||
self.set_webdriver_script_chan(None);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -539,7 +543,7 @@ pub trait WindowHelpers {
|
|||
fn emit_timeline_marker(self, marker: TimelineMarker);
|
||||
fn set_devtools_timeline_marker(self, marker: TimelineMarkerType, reply: Sender<TimelineMarker>);
|
||||
fn drop_devtools_timeline_markers(self);
|
||||
fn set_webdriver_script_chan(self, chan: Option<Sender<Result<EvaluateJSReply, ()>>>);
|
||||
fn set_webdriver_script_chan(self, chan: Option<Sender<WebDriverJSResult>>);
|
||||
}
|
||||
|
||||
pub trait ScriptHelpers {
|
||||
|
@ -898,7 +902,7 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
|
|||
*self.devtools_marker_sender.borrow_mut() = None;
|
||||
}
|
||||
|
||||
fn set_webdriver_script_chan(self, chan: Option<Sender<Result<EvaluateJSReply, ()>>>) {
|
||||
fn set_webdriver_script_chan(self, chan: Option<Sender<WebDriverJSResult>>) {
|
||||
*self.webdriver_script_chan.borrow_mut() = chan;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use webdriver_traits::{EvaluateJSReply};
|
||||
use webdriver_traits::{WebDriverJSValue, WebDriverJSError, WebDriverJSResult};
|
||||
use dom::bindings::conversions::FromJSValConvertible;
|
||||
use dom::bindings::conversions::StringificationBehavior;
|
||||
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast};
|
||||
|
@ -37,24 +37,24 @@ fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String
|
|||
None
|
||||
}
|
||||
|
||||
pub fn jsval_to_webdriver(cx: *mut JSContext, val: JSVal) -> Result<EvaluateJSReply, ()> {
|
||||
pub fn jsval_to_webdriver(cx: *mut JSContext, val: JSVal) -> WebDriverJSResult {
|
||||
if val.is_undefined() {
|
||||
Ok(EvaluateJSReply::VoidValue)
|
||||
Ok(WebDriverJSValue::Undefined)
|
||||
} else if val.is_boolean() {
|
||||
Ok(EvaluateJSReply::BooleanValue(val.to_boolean()))
|
||||
Ok(WebDriverJSValue::Boolean(val.to_boolean()))
|
||||
} else if val.is_double() {
|
||||
Ok(EvaluateJSReply::NumberValue(FromJSValConvertible::from_jsval(cx, val, ()).unwrap()))
|
||||
Ok(WebDriverJSValue::Number(FromJSValConvertible::from_jsval(cx, val, ()).unwrap()))
|
||||
} else if val.is_string() {
|
||||
//FIXME: use jsstring_to_str when jsval grows to_jsstring
|
||||
Ok(EvaluateJSReply::StringValue(FromJSValConvertible::from_jsval(cx, val, StringificationBehavior::Default).unwrap()))
|
||||
Ok(WebDriverJSValue::String(FromJSValConvertible::from_jsval(cx, val, StringificationBehavior::Default).unwrap()))
|
||||
} else if val.is_null() {
|
||||
Ok(EvaluateJSReply::NullValue)
|
||||
Ok(WebDriverJSValue::Null)
|
||||
} else {
|
||||
Err(())
|
||||
Err(WebDriverJSError::UnknownType)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_execute_script(page: &Rc<Page>, pipeline: PipelineId, eval: String, reply: Sender<Result<EvaluateJSReply, ()>>) {
|
||||
pub fn handle_execute_script(page: &Rc<Page>, pipeline: PipelineId, eval: String, reply: Sender<WebDriverJSResult>) {
|
||||
let page = get_page(&*page, pipeline);
|
||||
let window = page.window().root();
|
||||
let cx = window.r().get_cx();
|
||||
|
@ -63,8 +63,7 @@ pub fn handle_execute_script(page: &Rc<Page>, pipeline: PipelineId, eval: String
|
|||
reply.send(jsval_to_webdriver(cx, rval)).unwrap();
|
||||
}
|
||||
|
||||
|
||||
pub fn handle_execute_async_script(page: &Rc<Page>, pipeline: PipelineId, eval: String, reply: Sender<Result<EvaluateJSReply, ()>>) {
|
||||
pub fn handle_execute_async_script(page: &Rc<Page>, pipeline: PipelineId, eval: String, reply: Sender<WebDriverJSResult>) {
|
||||
let page = get_page(&*page, pipeline);
|
||||
let window = page.window().root();
|
||||
window.r().set_webdriver_script_chan(Some(reply));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue