#![allow(missing_docs)]
use std::collections::HashMap;
use base::id::{BrowsingContextId, WebViewId};
use cookie::Cookie;
use euclid::default::Rect as UntypedRect;
use euclid::{Rect, Size2D};
use hyper_serde::Serde;
use ipc_channel::ipc::IpcSender;
use keyboard_types::KeyboardEvent;
use keyboard_types::webdriver::Event as WebDriverInputEvent;
use pixels::Image;
use serde::{Deserialize, Serialize};
use servo_url::ServoUrl;
use style_traits::CSSPixel;
use webdriver::common::{WebElement, WebFrame, WebWindow};
use webdriver::error::ErrorStatus;
use webrender_api::units::DeviceIntSize;
use crate::{MouseButton, MouseButtonAction};
#[derive(Debug, Deserialize, Serialize)]
pub enum WebDriverCommandMsg {
GetWindowSize(WebViewId, IpcSender<Size2D<f32, CSSPixel>>),
LoadUrl(WebViewId, ServoUrl, IpcSender<WebDriverLoadStatus>),
Refresh(WebViewId, IpcSender<WebDriverLoadStatus>),
ScriptCommand(BrowsingContextId, WebDriverScriptCommand),
SendKeys(BrowsingContextId, Vec<WebDriverInputEvent>),
KeyboardAction(BrowsingContextId, KeyboardEvent),
MouseButtonAction(WebViewId, MouseButtonAction, MouseButton, f32, f32),
MouseMoveAction(WebViewId, f32, f32),
SetWindowSize(WebViewId, DeviceIntSize, IpcSender<Size2D<f32, CSSPixel>>),
TakeScreenshot(
WebViewId,
Option<Rect<f32, CSSPixel>>,
IpcSender<Option<Image>>,
),
NewWebView(
WebViewId,
IpcSender<WebViewId>,
IpcSender<WebDriverLoadStatus>,
),
CloseWebView(WebViewId),
FocusWebView(WebViewId),
}
#[derive(Debug, Deserialize, Serialize)]
pub enum WebDriverScriptCommand {
AddCookie(
#[serde(
deserialize_with = "::hyper_serde::deserialize",
serialize_with = "::hyper_serde::serialize"
)]
Cookie<'static>,
IpcSender<Result<(), WebDriverCookieError>>,
),
DeleteCookies(IpcSender<Result<(), ErrorStatus>>),
ExecuteScript(String, IpcSender<WebDriverJSResult>),
ExecuteAsyncScript(String, IpcSender<WebDriverJSResult>),
FindElementCSS(String, IpcSender<Result<Option<String>, ErrorStatus>>),
FindElementLinkText(String, bool, IpcSender<Result<Option<String>, ErrorStatus>>),
FindElementTagName(String, IpcSender<Result<Option<String>, ErrorStatus>>),
FindElementsCSS(String, IpcSender<Result<Vec<String>, ErrorStatus>>),
FindElementsLinkText(String, bool, IpcSender<Result<Vec<String>, ErrorStatus>>),
FindElementsTagName(String, IpcSender<Result<Vec<String>, ErrorStatus>>),
FindElementElementCSS(
String,
String,
IpcSender<Result<Option<String>, ErrorStatus>>,
),
FindElementElementLinkText(
String,
String,
bool,
IpcSender<Result<Option<String>, ErrorStatus>>,
),
FindElementElementTagName(
String,
String,
IpcSender<Result<Option<String>, ErrorStatus>>,
),
FindElementElementsCSS(String, String, IpcSender<Result<Vec<String>, ErrorStatus>>),
FindElementElementsLinkText(
String,
String,
bool,
IpcSender<Result<Vec<String>, ErrorStatus>>,
),
FindElementElementsTagName(String, String, IpcSender<Result<Vec<String>, ErrorStatus>>),
FocusElement(String, IpcSender<Result<(), ErrorStatus>>),
ElementClick(String, IpcSender<Result<Option<String>, ErrorStatus>>),
GetActiveElement(IpcSender<Option<String>>),
GetCookie(String, IpcSender<Vec<Serde<Cookie<'static>>>>),
GetCookies(IpcSender<Vec<Serde<Cookie<'static>>>>),
GetElementAttribute(
String,
String,
IpcSender<Result<Option<String>, ErrorStatus>>,
),
GetElementProperty(
String,
String,
IpcSender<Result<WebDriverJSValue, ErrorStatus>>,
),
GetElementCSS(String, String, IpcSender<Result<String, ErrorStatus>>),
GetElementRect(String, IpcSender<Result<UntypedRect<f64>, ErrorStatus>>),
GetElementTagName(String, IpcSender<Result<String, ErrorStatus>>),
GetElementText(String, IpcSender<Result<String, ErrorStatus>>),
GetElementInViewCenterPoint(String, IpcSender<Result<Option<(i64, i64)>, ErrorStatus>>),
GetBoundingClientRect(String, IpcSender<Result<UntypedRect<f32>, ErrorStatus>>),
GetBrowsingContextId(
WebDriverFrameId,
IpcSender<Result<BrowsingContextId, ErrorStatus>>,
),
GetUrl(IpcSender<ServoUrl>),
GetPageSource(IpcSender<Result<String, ErrorStatus>>),
IsEnabled(String, IpcSender<Result<bool, ErrorStatus>>),
IsSelected(String, IpcSender<Result<bool, ErrorStatus>>),
GetTitle(IpcSender<String>),
}
#[derive(Debug, Deserialize, Serialize)]
pub enum WebDriverCookieError {
InvalidDomain,
UnableToSetCookie,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum WebDriverJSValue {
Undefined,
Null,
Boolean(bool),
Int(i32),
Number(f64),
String(String),
Element(WebElement),
Frame(WebFrame),
Window(WebWindow),
ArrayLike(Vec<WebDriverJSValue>),
Object(HashMap<String, WebDriverJSValue>),
}
#[derive(Debug, Deserialize, Serialize)]
pub enum WebDriverJSError {
BrowsingContextNotFound,
JSError,
StaleElementReference,
Timeout,
UnknownType,
}
pub type WebDriverJSResult = Result<WebDriverJSValue, WebDriverJSError>;
#[derive(Debug, Deserialize, Serialize)]
pub enum WebDriverFrameId {
Short(u16),
Element(String),
Parent,
}
#[derive(Debug, Deserialize, Serialize)]
pub enum WebDriverLoadStatus {
Complete,
Timeout,
Canceled,
}