Auto merge of #23581 - georgeroman:implement_get_page_source_wd_command, r=jdm

Implement GetPageSource WebDriver command

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23581)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-06-22 19:11:59 -04:00 committed by GitHub
commit 2cbd177082
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 1 deletions

View file

@ -1902,6 +1902,9 @@ impl ScriptThread {
WebDriverScriptCommand::GetActiveElement(reply) => {
webdriver_handlers::handle_get_active_element(&*documents, pipeline_id, reply)
},
WebDriverScriptCommand::GetPageSource(reply) => {
webdriver_handlers::handle_get_page_source(&*documents, pipeline_id, reply)
},
WebDriverScriptCommand::GetCookies(reply) => {
webdriver_handlers::handle_get_cookies(&*documents, pipeline_id, reply)
},

View file

@ -10,6 +10,7 @@ use crate::dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputE
use crate::dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods;
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::codegen::Bindings::XMLSerializerBinding::XMLSerializerMethods;
use crate::dom::bindings::conversions::{
ConversionResult, FromJSValConvertible, StringificationBehavior,
};
@ -24,6 +25,7 @@ use crate::dom::htmlinputelement::HTMLInputElement;
use crate::dom::htmloptionelement::HTMLOptionElement;
use crate::dom::node::{window_from_node, Node, ShadowIncluding};
use crate::dom::window::Window;
use crate::dom::xmlserializer::XMLSerializer;
use crate::script_thread::Documents;
use cookie::Cookie;
use euclid::{Point2D, Rect, Size2D};
@ -281,6 +283,31 @@ pub fn handle_get_active_element(
.unwrap();
}
pub fn handle_get_page_source(
documents: &Documents,
pipeline: PipelineId,
reply: IpcSender<Result<String, ()>>,
) {
reply
.send(documents.find_document(pipeline).ok_or(()).and_then(|doc| {
match doc.GetDocumentElement() {
Some(elem) => match elem.GetOuterHTML() {
Ok(source) => Ok(source.to_string()),
Err(_) => {
match XMLSerializer::new(doc.window())
.SerializeToString(elem.upcast::<Node>())
{
Ok(source) => Ok(source.to_string()),
Err(_) => Err(()),
}
},
},
None => Err(()),
}
}))
.unwrap();
}
pub fn handle_get_cookies(
documents: &Documents,
pipeline: PipelineId,

View file

@ -39,6 +39,7 @@ pub enum WebDriverScriptCommand {
GetElementText(String, IpcSender<Result<String, ()>>),
GetBrowsingContextId(WebDriverFrameId, IpcSender<Result<BrowsingContextId, ()>>),
GetUrl(IpcSender<ServoUrl>),
GetPageSource(IpcSender<Result<String, ()>>),
IsEnabled(String, IpcSender<Result<bool, ()>>),
IsSelected(String, IpcSender<Result<bool, ()>>),
GetTitle(IpcSender<String>),

View file

@ -1188,6 +1188,23 @@ impl Handler {
Ok(WebDriverResponse::Void)
}
fn handle_get_page_source(&self) -> WebDriverResult<WebDriverResponse> {
let (sender, receiver) = ipc::channel().unwrap();
let cmd = WebDriverScriptCommand::GetPageSource(sender);
self.browsing_context_script_command(cmd)?;
match receiver.recv().unwrap() {
Ok(source) => Ok(WebDriverResponse::Generic(ValueResponse(
serde_json::to_value(source)?,
))),
Err(_) => Err(WebDriverError::new(
ErrorStatus::UnknownError,
"Unknown error",
)),
}
}
fn handle_execute_script(
&self,
parameters: &JavascriptCommandParameters,
@ -1457,6 +1474,7 @@ impl WebDriverHandler<ServoExtensionRoute> for Handler {
WebDriverCommand::GetCSSValue(ref element, ref name) => {
self.handle_element_css(element, name)
},
WebDriverCommand::GetPageSource => self.handle_get_page_source(),
WebDriverCommand::ExecuteScript(ref x) => self.handle_execute_script(x),
WebDriverCommand::ExecuteAsyncScript(ref x) => self.handle_execute_async_script(x),
WebDriverCommand::ElementSendKeys(ref element, ref keys) => {

View file

@ -1,2 +1,4 @@
[source.py]
disabled: Unimplemented WebDriver command
[test_no_browsing_context]
expected: ERROR