/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #![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}; /// Messages to the constellation originating from the WebDriver server. #[derive(Debug, Deserialize, Serialize)] pub enum WebDriverCommandMsg { /// Get the window size. GetWindowSize(WebViewId, IpcSender>), /// Load a URL in the top-level browsing context with the given ID. LoadUrl(WebViewId, ServoUrl, IpcSender), /// Refresh the top-level browsing context with the given ID. Refresh(WebViewId, IpcSender), /// Pass a webdriver command to the script thread of the current pipeline /// of a browsing context. ScriptCommand(BrowsingContextId, WebDriverScriptCommand), /// Act as if keys were pressed in the browsing context with the given ID. SendKeys(BrowsingContextId, Vec), /// Act as if keys were pressed or release in the browsing context with the given ID. KeyboardAction(BrowsingContextId, KeyboardEvent), /// Act as if the mouse was clicked in the browsing context with the given ID. MouseButtonAction(WebViewId, MouseButtonAction, MouseButton, f32, f32), /// Act as if the mouse was moved in the browsing context with the given ID. MouseMoveAction(WebViewId, f32, f32), /// Set the window size. SetWindowSize(WebViewId, DeviceIntSize, IpcSender>), /// Take a screenshot of the window. TakeScreenshot( WebViewId, Option>, IpcSender>, ), /// Create a new webview that loads about:blank. The constellation will use /// the provided channels to return the top level browsing context id /// associated with the new webview, and a notification when the initial /// load is complete. NewWebView( WebViewId, IpcSender, IpcSender, ), /// Close the webview associated with the provided id. CloseWebView(WebViewId), /// Focus the webview associated with the provided id. FocusWebView(WebViewId), } #[derive(Debug, Deserialize, Serialize)] pub enum WebDriverScriptCommand { AddCookie( #[serde( deserialize_with = "::hyper_serde::deserialize", serialize_with = "::hyper_serde::serialize" )] Cookie<'static>, IpcSender>, ), DeleteCookies(IpcSender>), DeleteCookie(String, IpcSender>), ExecuteScript(String, IpcSender), ExecuteAsyncScript(String, IpcSender), FindElementCSS(String, IpcSender, ErrorStatus>>), FindElementLinkText(String, bool, IpcSender, ErrorStatus>>), FindElementTagName(String, IpcSender, ErrorStatus>>), FindElementsCSS(String, IpcSender, ErrorStatus>>), FindElementsLinkText(String, bool, IpcSender, ErrorStatus>>), FindElementsTagName(String, IpcSender, ErrorStatus>>), FindElementElementCSS( String, String, IpcSender, ErrorStatus>>, ), FindElementElementLinkText( String, String, bool, IpcSender, ErrorStatus>>, ), FindElementElementTagName( String, String, IpcSender, ErrorStatus>>, ), FindElementElementsCSS(String, String, IpcSender, ErrorStatus>>), FindElementElementsLinkText( String, String, bool, IpcSender, ErrorStatus>>, ), FindElementElementsTagName(String, String, IpcSender, ErrorStatus>>), FocusElement(String, IpcSender>), ElementClick(String, IpcSender, ErrorStatus>>), GetActiveElement(IpcSender>), GetComputedRole(String, IpcSender, ErrorStatus>>), GetCookie(String, IpcSender>>>), GetCookies(IpcSender>>>), GetElementAttribute( String, String, IpcSender, ErrorStatus>>, ), GetElementProperty( String, String, IpcSender>, ), GetElementCSS(String, String, IpcSender>), GetElementRect(String, IpcSender, ErrorStatus>>), GetElementTagName(String, IpcSender>), GetElementText(String, IpcSender>), GetElementInViewCenterPoint(String, IpcSender, ErrorStatus>>), GetBoundingClientRect(String, IpcSender, ErrorStatus>>), GetBrowsingContextId( WebDriverFrameId, IpcSender>, ), GetUrl(IpcSender), GetPageSource(IpcSender>), IsEnabled(String, IpcSender>), IsSelected(String, IpcSender>), GetTitle(IpcSender), } #[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), Object(HashMap), } #[derive(Debug, Deserialize, Serialize)] pub enum WebDriverJSError { /// Occurs when handler received an event message for a layout channel that is not /// associated with the current script thread BrowsingContextNotFound, JSError, StaleElementReference, Timeout, UnknownType, } pub type WebDriverJSResult = Result; #[derive(Debug, Deserialize, Serialize)] pub enum WebDriverFrameId { Short(u16), Element(String), Parent, } #[derive(Debug, Deserialize, Serialize)] pub enum WebDriverLoadStatus { Complete, Timeout, Canceled, }