From 98cb65ca0a7d6c940e69f77275b6941499a434a3 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 29 Apr 2015 19:47:38 +0100 Subject: [PATCH] Wait for the root pipeline to become ready before running webdriver commands. --- components/webdriver_server/lib.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index 282e707cb89..818bd48fb97 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -76,12 +76,25 @@ impl Handler { } } - fn get_root_pipeline(&self) -> PipelineId { - let (sender, reciever) = channel(); - let ConstellationChan(ref const_chan) = self.constellation_chan; - const_chan.send(ConstellationMsg::GetRootPipeline(sender)).unwrap(); + fn get_root_pipeline(&self) -> WebDriverResult { + let interval = Duration::milliseconds(20); + let iterations = 30_000 / interval.num_milliseconds(); - reciever.recv().unwrap().unwrap() + for _ in 0..iterations { + let (sender, reciever) = channel(); + let ConstellationChan(ref const_chan) = self.constellation_chan; + const_chan.send(ConstellationMsg::GetRootPipeline(sender)).unwrap(); + + + if let Some(x) = reciever.recv().unwrap() { + return Ok(x); + }; + + sleep(interval) + }; + + Err(WebDriverError::new(ErrorStatus::Timeout, + "Failed to get root window handle")) } fn handle_new_session(&mut self) -> WebDriverResult { @@ -109,7 +122,7 @@ impl Handler { "Invalid URL")) }; - let pipeline_id = self.get_root_pipeline(); + let pipeline_id = try!(self.get_root_pipeline()); let (sender, reciever) = channel();