Kaynağa Gözat

WebContent+WebDriver: Ensure Get Window Handle checks for closed BCs

Timothy Flynn 2 yıl önce
ebeveyn
işleme
0524bc1d13

+ 1 - 0
Userland/Services/WebContent/WebDriverClient.ipc

@@ -55,4 +55,5 @@ endpoint WebDriverClient {
     take_screenshot() => (Web::WebDriver::Response response)
     take_element_screenshot(String element_id) => (Web::WebDriver::Response response)
     print_page() => (Web::WebDriver::Response response)
+    ensure_top_level_browsing_context_is_open() => (Web::WebDriver::Response response)
 }

+ 8 - 1
Userland/Services/WebContent/WebDriverConnection.cpp

@@ -1745,11 +1745,18 @@ Messages::WebDriverClient::PrintPageResponse WebDriverConnection::print_page()
 }
 
 // https://w3c.github.io/webdriver/#dfn-no-longer-open
-ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context()
+Messages::WebDriverClient::EnsureTopLevelBrowsingContextIsOpenResponse WebDriverConnection::ensure_top_level_browsing_context_is_open()
 {
     // A browsing context is said to be no longer open if it has been discarded.
     if (m_page_client.page().top_level_browsing_context().has_been_discarded())
         return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchWindow, "Window not found"sv);
+    return JsonValue {};
+}
+
+// https://w3c.github.io/webdriver/#dfn-no-longer-open
+ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context()
+{
+    TRY(ensure_top_level_browsing_context_is_open().take_response());
     return {};
 }
 

+ 2 - 0
Userland/Services/WebContent/WebDriverConnection.h

@@ -93,7 +93,9 @@ private:
     virtual Messages::WebDriverClient::TakeElementScreenshotResponse take_element_screenshot(String const& element_id) override;
     virtual Messages::WebDriverClient::PrintPageResponse print_page() override;
 
+    virtual Messages::WebDriverClient::EnsureTopLevelBrowsingContextIsOpenResponse ensure_top_level_browsing_context_is_open() override;
     ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context();
+
     ErrorOr<void, Web::WebDriver::Error> handle_any_user_prompts();
     void restore_the_window();
     Gfx::IntRect maximize_the_window();

+ 2 - 1
Userland/Services/WebDriver/Client.cpp

@@ -290,7 +290,8 @@ Web::WebDriver::Response Client::get_window_handle(Web::WebDriver::Parameters pa
     dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/window");
     auto session = TRY(find_session_with_id(parameters[0]));
 
-    // FIXME: 1. If the current top-level browsing context is no longer open, return error with error code no such window.
+    // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
+    TRY(session->web_content_connection().ensure_top_level_browsing_context_is_open());
 
     // 2. Return success with data being the window handle associated with the current top-level browsing context.
     return JsonValue { session->current_window_handle() };