Add support for timing out scripts

This commit is contained in:
James Graham 2015-04-30 16:26:04 +01:00
parent 8d10fa1f2d
commit 50f59c8255
5 changed files with 82 additions and 49 deletions

View file

@ -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 {

View file

@ -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;
}
}