diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-11-16 07:15:57 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-16 17:23:56 +0000 |
commit | 7cf2feb04739e79ef84b0585a1cdca26c111167f (patch) | |
tree | 208b30b018e357591511f49e28cf2287ed1e79ba /Userland/Services | |
parent | 159dcb950718ad5784a3172ec9fbefdb8e5d60d6 (diff) | |
download | serenity-7cf2feb04739e79ef84b0585a1cdca26c111167f.zip |
LibWeb+WebContent+WebDriver: Implement Dismiss Alert
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/WebContent/WebDriverClient.ipc | 1 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.cpp | 17 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.h | 1 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Client.cpp | 9 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Client.h | 1 |
5 files changed, 29 insertions, 0 deletions
diff --git a/Userland/Services/WebContent/WebDriverClient.ipc b/Userland/Services/WebContent/WebDriverClient.ipc index 570cc133c9..39a6430608 100644 --- a/Userland/Services/WebContent/WebDriverClient.ipc +++ b/Userland/Services/WebContent/WebDriverClient.ipc @@ -43,6 +43,7 @@ endpoint WebDriverClient { add_cookie(JsonValue payload) => (Web::WebDriver::Response response) delete_cookie(String name) => (Web::WebDriver::Response response) delete_all_cookies() => (Web::WebDriver::Response response) + dismiss_alert() => (Web::WebDriver::Response response) take_screenshot() => (Web::WebDriver::Response response) take_element_screenshot(String element_id) => (Web::WebDriver::Response response) } diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index d63b1da4bc..984221f543 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -1343,6 +1343,23 @@ Messages::WebDriverClient::DeleteAllCookiesResponse WebDriverConnection::delete_ return JsonValue {}; } +// 16.1 Dismiss Alert, https://w3c.github.io/webdriver/#dismiss-alert +Messages::WebDriverClient::DismissAlertResponse WebDriverConnection::dismiss_alert() +{ + // 1. If the current top-level browsing context is no longer open, return error with error code no such window. + TRY(ensure_open_top_level_browsing_context()); + + // 2. If there is no current user prompt, return error with error code no such alert. + if (!m_page_host.has_pending_dialog()) + return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchAlert, "No user dialog is currently open"sv); + + // 3. Dismiss the current user prompt. + m_page_host.dismiss_dialog(); + + // 4. Return success with data null. + return JsonValue {}; +} + // 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot Messages::WebDriverClient::TakeScreenshotResponse WebDriverConnection::take_screenshot() { diff --git a/Userland/Services/WebContent/WebDriverConnection.h b/Userland/Services/WebContent/WebDriverConnection.h index 6c31d61c95..d010c9bf3b 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -78,6 +78,7 @@ private: virtual Messages::WebDriverClient::AddCookieResponse add_cookie(JsonValue const& payload) override; virtual Messages::WebDriverClient::DeleteCookieResponse delete_cookie(String const& name) override; virtual Messages::WebDriverClient::DeleteAllCookiesResponse delete_all_cookies() override; + virtual Messages::WebDriverClient::DismissAlertResponse dismiss_alert() override; virtual Messages::WebDriverClient::TakeScreenshotResponse take_screenshot() override; virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override; diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index bde5912f22..935e2a5523 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -539,6 +539,15 @@ Web::WebDriver::Response Client::delete_all_cookies(Web::WebDriver::Parameters p return session->web_content_connection().delete_all_cookies(); } +// 16.1 Dismiss Alert, https://w3c.github.io/webdriver/#dismiss-alert +// POST /session/{session id}/alert/dismiss +Web::WebDriver::Response Client::dismiss_alert(Web::WebDriver::Parameters parameters, JsonValue) +{ + dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/alert/dismiss"); + auto* session = TRY(find_session_with_id(parameters[0])); + return session->web_content_connection().dismiss_alert(); +} + // 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot // GET /session/{session id}/screenshot Web::WebDriver::Response Client::take_screenshot(Web::WebDriver::Parameters parameters, JsonValue) diff --git a/Userland/Services/WebDriver/Client.h b/Userland/Services/WebDriver/Client.h index 2b168d8494..e0efa85b22 100644 --- a/Userland/Services/WebDriver/Client.h +++ b/Userland/Services/WebDriver/Client.h @@ -76,6 +76,7 @@ private: virtual Web::WebDriver::Response add_cookie(Web::WebDriver::Parameters parameters, JsonValue payload) override; virtual Web::WebDriver::Response delete_cookie(Web::WebDriver::Parameters parameters, JsonValue payload) override; virtual Web::WebDriver::Response delete_all_cookies(Web::WebDriver::Parameters parameters, JsonValue payload) override; + virtual Web::WebDriver::Response dismiss_alert(Web::WebDriver::Parameters parameters, JsonValue payload) override; virtual Web::WebDriver::Response take_screenshot(Web::WebDriver::Parameters parameters, JsonValue payload) override; virtual Web::WebDriver::Response take_element_screenshot(Web::WebDriver::Parameters parameters, JsonValue payload) override; |