summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorVictor Song <vms2@rice.edu>2022-11-24 20:32:53 -0600
committerTim Flynn <trflynn89@pm.me>2022-12-04 09:33:55 -0500
commit88ecc4a1e58a7c8f5e2fb6e3d1d7c7b26332e50c (patch)
treefee2d58923f6401048ba76ec8776504c8a7f5110 /Userland
parentb04cf15b3ed432d64679cc9f438404fa58040059 (diff)
downloadserenity-88ecc4a1e58a7c8f5e2fb6e3d1d7c7b26332e50c.zip
WebContent+WebDriver: Implement `POST /session/{id}/window` endpoint
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/WebDriver/Client.cpp1
-rw-r--r--Userland/Libraries/LibWeb/WebDriver/Client.h1
-rw-r--r--Userland/Services/WebContent/WebDriverClient.ipc1
-rw-r--r--Userland/Services/WebContent/WebDriverConnection.cpp30
-rw-r--r--Userland/Services/WebContent/WebDriverConnection.h1
-rw-r--r--Userland/Services/WebDriver/Client.cpp9
-rw-r--r--Userland/Services/WebDriver/Client.h1
7 files changed, 44 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/WebDriver/Client.cpp b/Userland/Libraries/LibWeb/WebDriver/Client.cpp
index 1024fde061..175e6bc87f 100644
--- a/Userland/Libraries/LibWeb/WebDriver/Client.cpp
+++ b/Userland/Libraries/LibWeb/WebDriver/Client.cpp
@@ -63,6 +63,7 @@ static constexpr auto s_webdriver_endpoints = Array {
ROUTE(GET, "/session/:session_id/title"sv, get_title),
ROUTE(GET, "/session/:session_id/window"sv, get_window_handle),
ROUTE(DELETE, "/session/:session_id/window"sv, close_window),
+ ROUTE(POST, "/session/:session_id/window"sv, switch_to_window),
ROUTE(GET, "/session/:session_id/window/handles"sv, get_window_handles),
ROUTE(GET, "/session/:session_id/window/rect"sv, get_window_rect),
ROUTE(POST, "/session/:session_id/window/rect"sv, set_window_rect),
diff --git a/Userland/Libraries/LibWeb/WebDriver/Client.h b/Userland/Libraries/LibWeb/WebDriver/Client.h
index f170246def..5fbfb19b2b 100644
--- a/Userland/Libraries/LibWeb/WebDriver/Client.h
+++ b/Userland/Libraries/LibWeb/WebDriver/Client.h
@@ -49,6 +49,7 @@ public:
// 11. Contexts, https://w3c.github.io/webdriver/#contexts
virtual Response get_window_handle(Parameters parameters, JsonValue payload) = 0;
virtual Response close_window(Parameters parameters, JsonValue payload) = 0;
+ virtual Response switch_to_window(Parameters parameters, JsonValue payload) = 0;
virtual Response get_window_handles(Parameters parameters, JsonValue payload) = 0;
virtual Response get_window_rect(Parameters parameters, JsonValue payload) = 0;
virtual Response set_window_rect(Parameters parameters, JsonValue payload) = 0;
diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc
index adb4d4f150..0a97686e8e 100644
--- a/Userland/Services/WebContent/WebDriverClient.ipc
+++ b/Userland/Services/WebContent/WebDriverClient.ipc
@@ -17,6 +17,7 @@ endpoint WebDriverClient {
get_title() => (Web::WebDriver::Response response)
get_window_handle() => (Web::WebDriver::Response response)
close_window() => (Web::WebDriver::Response response)
+ switch_to_window(JsonValue payload) => (Web::WebDriver::Response response)
get_window_handles() => (Web::WebDriver::Response response)
get_window_rect() => (Web::WebDriver::Response response)
set_window_rect(JsonValue payload) => (Web::WebDriver::Response response)
diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp
index a4f60e0888..9dc12d2b2e 100644
--- a/Userland/Services/WebContent/WebDriverConnection.cpp
+++ b/Userland/Services/WebContent/WebDriverConnection.cpp
@@ -481,6 +481,36 @@ Messages::WebDriverClient::CloseWindowResponse WebDriverConnection::close_window
return get_window_handles().take_response();
}
+// 11.3 Switch to Window, https://w3c.github.io/webdriver/#dfn-switch-to-window
+Messages::WebDriverClient::SwitchToWindowResponse WebDriverConnection::switch_to_window(JsonValue const& payload)
+{
+ // 1. Let handle be the result of getting the property "handle" from the parameters argument.
+ // 2. If handle is undefined, return error with error code invalid argument.
+ auto handle = TRY(get_property(payload, "handle"sv));
+
+ // 3. If there is an active user prompt, that prevents the focusing of another top-level browsing
+ // context, return error with error code unexpected alert open.
+ if (m_page_client.page().has_pending_dialog())
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnexpectedAlertOpen, "A user dialog is open"sv);
+
+ // 4. If handle is equal to the associated window handle for some top-level browsing context in the
+ // current session, let context be the that browsing context, and set the current top-level
+ // browsing context with context.
+ // Otherwise, return error with error code no such window.
+ auto const& maybe_window = m_windows.get(handle);
+
+ if (!maybe_window.has_value())
+ return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchWindow, "Window not found");
+
+ m_current_window_handle = handle;
+
+ // FIXME: 5. Update any implementation-specific state that would result from the user selecting the current
+ // browsing context for interaction, without altering OS-level focus.
+
+ // 6. Return success with data null.
+ return JsonValue {};
+}
+
// 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles
Messages::WebDriverClient::GetWindowHandlesResponse WebDriverConnection::get_window_handles()
{
diff --git a/Userland/Services/WebContent/WebDriverConnection.h b/Userland/Services/WebContent/WebDriverConnection.h
index c66e7c19be..4135cbe124 100644
--- a/Userland/Services/WebContent/WebDriverConnection.h
+++ b/Userland/Services/WebContent/WebDriverConnection.h
@@ -52,6 +52,7 @@ private:
virtual Messages::WebDriverClient::GetTitleResponse get_title() override;
virtual Messages::WebDriverClient::GetWindowHandleResponse get_window_handle() override;
virtual Messages::WebDriverClient::CloseWindowResponse close_window() override;
+ virtual Messages::WebDriverClient::SwitchToWindowResponse switch_to_window(JsonValue const& payload) override;
virtual Messages::WebDriverClient::GetWindowHandlesResponse get_window_handles() override;
virtual Messages::WebDriverClient::GetWindowRectResponse get_window_rect() override;
virtual Messages::WebDriverClient::SetWindowRectResponse set_window_rect(JsonValue const& payload) override;
diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp
index c3023386ae..daccee320a 100644
--- a/Userland/Services/WebDriver/Client.cpp
+++ b/Userland/Services/WebDriver/Client.cpp
@@ -322,6 +322,15 @@ Web::WebDriver::Response Client::close_window(Web::WebDriver::Parameters paramet
return open_windows;
}
+// 11.3 Switch to Window, https://w3c.github.io/webdriver/#dfn-switch-to-window
+// POST /session/{session id}/window
+Web::WebDriver::Response Client::switch_to_window(Web::WebDriver::Parameters parameters, AK::JsonValue payload)
+{
+ dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/window");
+ auto* session = TRY(find_session_with_id(parameters[0]));
+ return session->web_content_connection().switch_to_window(payload);
+}
+
// 11.4 Get Window Handles, https://w3c.github.io/webdriver/#dfn-get-window-handles
// GET /session/{session id}/window/handles
Web::WebDriver::Response Client::get_window_handles(Web::WebDriver::Parameters parameters, JsonValue)
diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h
index df951a1c96..d590ba87ff 100644
--- a/Userland/Services/WebDriver/Client.h
+++ b/Userland/Services/WebDriver/Client.h
@@ -46,6 +46,7 @@ private:
virtual Web::WebDriver::Response get_title(Web::WebDriver::Parameters parameters, JsonValue payload) override;
virtual Web::WebDriver::Response get_window_handle(Web::WebDriver::Parameters parameters, JsonValue payload) override;
virtual Web::WebDriver::Response close_window(Web::WebDriver::Parameters parameters, JsonValue payload) override;
+ virtual Web::WebDriver::Response switch_to_window(Web::WebDriver::Parameters parameters, JsonValue payload) override;
virtual Web::WebDriver::Response get_window_handles(Web::WebDriver::Parameters parameters, JsonValue payload) override;
virtual Web::WebDriver::Response get_window_rect(Web::WebDriver::Parameters parameters, JsonValue payload) override;
virtual Web::WebDriver::Response set_window_rect(Web::WebDriver::Parameters parameters, JsonValue payload) override;