Auto merge of #6401 - jgraham:load_timeout, r=metajack

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6401)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-06-17 10:16:27 -06:00
commit ee54c89e3f
4 changed files with 23 additions and 11 deletions

View file

@ -190,7 +190,7 @@ pub struct SendableFrameTree {
}
struct WebDriverData {
load_channel: Option<(PipelineId, Sender<webdriver_msg::LoadComplete>)>
load_channel: Option<(PipelineId, Sender<webdriver_msg::LoadStatus>)>
}
impl WebDriverData {
@ -709,7 +709,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
let mut webdriver_reset = false;
if let Some((ref expected_pipeline_id, ref reply_chan)) = self.webdriver.load_channel {
if expected_pipeline_id == pipeline_id {
reply_chan.send(webdriver_msg::LoadComplete).unwrap();
let _ = reply_chan.send(webdriver_msg::LoadStatus::LoadComplete);
webdriver_reset = true;
}
}

View file

@ -19,7 +19,7 @@ use std::collections::HashMap;
use std::sync::mpsc::{channel, Sender, Receiver};
use style::viewport::ViewportConstraints;
use url::Url;
use webdriver_msg::{WebDriverScriptCommand, LoadComplete};
use webdriver_msg::{WebDriverScriptCommand, LoadStatus};
#[derive(Clone)]
pub struct ConstellationChan(pub Sender<Msg>);
@ -328,7 +328,7 @@ impl MozBrowserEvent {
}
pub enum WebDriverCommandMsg {
LoadUrl(PipelineId, LoadData, Sender<LoadComplete>),
LoadUrl(PipelineId, LoadData, Sender<LoadStatus>),
ScriptCommand(PipelineId, WebDriverScriptCommand),
TakeScreenshot(PipelineId, Sender<Option<png::Image>>)
}

View file

@ -53,4 +53,7 @@ impl ToJson for WebDriverJSValue {
}
}
pub struct LoadComplete;
pub enum LoadStatus {
LoadComplete,
LoadTimeout
}

View file

@ -22,7 +22,7 @@ use msg::constellation_msg::{ConstellationChan, LoadData, FrameId, PipelineId, N
WebDriverCommandMsg};
use msg::constellation_msg::Msg as ConstellationMsg;
use std::sync::mpsc::{channel, Receiver};
use msg::webdriver_msg::{WebDriverFrameId, WebDriverScriptCommand, WebDriverJSError, WebDriverJSResult};
use msg::webdriver_msg::{WebDriverFrameId, WebDriverScriptCommand, WebDriverJSError, WebDriverJSResult, LoadStatus};
use url::Url;
use webdriver::command::{WebDriverMessage, WebDriverCommand};
@ -42,7 +42,7 @@ use rustc_serialize::base64::{Config, ToBase64, CharacterSet, Newline};
use std::collections::BTreeMap;
use std::net::SocketAddr;
use std::thread::sleep_ms;
use std::thread::{self, sleep_ms};
pub fn start_server(port: u16, constellation_chan: ConstellationChan) {
let handler = Handler::new(constellation_chan);
@ -172,13 +172,22 @@ impl Handler {
let load_data = LoadData::new(url);
let ConstellationChan(ref const_chan) = self.constellation_chan;
let cmd_msg = WebDriverCommandMsg::LoadUrl(pipeline_id, load_data, sender);
let cmd_msg = WebDriverCommandMsg::LoadUrl(pipeline_id, load_data, sender.clone());
const_chan.send(ConstellationMsg::WebDriverCommand(cmd_msg)).unwrap();
//Wait to get a load event
reciever.recv().unwrap();
let timeout = self.load_timeout;
let timeout_chan = sender.clone();
thread::spawn(move || {
sleep_ms(timeout);
let _ = timeout_chan.send(LoadStatus::LoadTimeout);
});
Ok(WebDriverResponse::Void)
//Wait to get a load event
match reciever.recv().unwrap() {
LoadStatus::LoadComplete => Ok(WebDriverResponse::Void),
LoadStatus::LoadTimeout => Err(WebDriverError::new(ErrorStatus::Timeout,
"Load timed out"))
}
}
fn handle_go_back(&self) -> WebDriverResult<WebDriverResponse> {