diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index a6fa76babd4..8199891c51b 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -87,6 +87,15 @@ static Gfx::IntRect compute_window_rect(Web::Page const& page) }; } +// https://w3c.github.io/webdriver/#dfn-no-longer-open +static ErrorOr ensure_browsing_context_is_open(JS::GCPtr browsing_context) +{ + // A browsing context is said to be no longer open if its navigable has been destroyed. + if (!browsing_context || browsing_context->has_navigable_been_destroyed()) + return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchWindow, "Window not found"sv); + return {}; +} + // https://w3c.github.io/webdriver/#dfn-scrolls-into-view static ErrorOr scroll_element_into_view(Web::DOM::Element& element) { @@ -572,26 +581,31 @@ Messages::WebDriverClient::SwitchToFrameResponse WebDriverConnection::switch_to_ // 11.7 Switch To Parent Frame, https://w3c.github.io/webdriver/#dfn-switch-to-parent-frame Messages::WebDriverClient::SwitchToParentFrameResponse WebDriverConnection::switch_to_parent_frame(JsonValue const&) { - dbgln("FIXME: WebDriverConnection::switch_to_parent_frame()"); + // 1. If session's current browsing context is already the top-level browsing context: + if (¤t_browsing_context() == current_top_level_browsing_context()) { + // 1. If session's current browsing context is no longer open, return error with error code no such window. + TRY(ensure_current_browsing_context_is_open()); - // FIXME: 1. If session's current browsing context is already the top-level browsing context: - - { - // FIXME: 1. If session's current browsing context is no longer open, return error with error code no such window. - - // FIXME: 2. Return success with data null. + // 2. Return success with data null. + return JsonValue {}; } - // FIXME: 2. If session's current parent browsing context is no longer open, return error with error code no such window. + auto parent_browsing_context = current_parent_browsing_context(); - // FIXME: 3. Try to handle any user prompts with session. + // 2. If session's current parent browsing context is no longer open, return error with error code no such window. + TRY(ensure_browsing_context_is_open(parent_browsing_context)); - // FIXME: 4. If session's current parent browsing context is not null, set the current browsing context with session and current parent browsing context. + // 3. Try to handle any user prompts with session. + TRY(handle_any_user_prompts()); + + // 4. If session's current parent browsing context is not null, set the current browsing context with session and + // current parent browsing context. + if (parent_browsing_context) + m_current_browsing_context = *parent_browsing_context; // FIXME: 5. Update any implementation-specific state that would result from the user selecting session's current browsing context for interaction, without altering OS-level focus. - // FIXME: 6. Return success with data null. - + // 6. Return success with data null. return JsonValue {}; } @@ -2215,21 +2229,22 @@ Messages::WebDriverClient::PrintPageResponse WebDriverConnection::print_page() return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnsupportedOperation, "Print not implemented"sv); } -// https://w3c.github.io/webdriver/#dfn-no-longer-open -static ErrorOr ensure_browsing_context_is_open(JS::GCPtr browsing_context) -{ - // A browsing context is said to be no longer open if its navigable has been destroyed. - if (!browsing_context || browsing_context->has_navigable_been_destroyed()) - return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchWindow, "Window not found"sv); - return {}; -} - Messages::WebDriverClient::EnsureTopLevelBrowsingContextIsOpenResponse WebDriverConnection::ensure_top_level_browsing_context_is_open() { TRY(ensure_current_top_level_browsing_context_is_open()); return JsonValue {}; } +// https://w3c.github.io/webdriver/#dfn-current-parent-browsing-context +JS::GCPtr WebDriverConnection::current_parent_browsing_context() +{ + auto current_navigable = current_browsing_context().active_document()->navigable(); + if (!current_navigable || !current_navigable->parent()) + return {}; + + return current_navigable->parent()->active_browsing_context(); +} + // https://w3c.github.io/webdriver/#dfn-current-top-level-browsing-context JS::GCPtr WebDriverConnection::current_top_level_browsing_context() { diff --git a/Userland/Services/WebContent/WebDriverConnection.h b/Userland/Services/WebContent/WebDriverConnection.h index 44b3f32b2a8..079c2407419 100644 --- a/Userland/Services/WebContent/WebDriverConnection.h +++ b/Userland/Services/WebContent/WebDriverConnection.h @@ -105,6 +105,7 @@ private: virtual Messages::WebDriverClient::EnsureTopLevelBrowsingContextIsOpenResponse ensure_top_level_browsing_context_is_open() override; Web::HTML::BrowsingContext& current_browsing_context() { return *m_current_browsing_context; } + JS::GCPtr current_parent_browsing_context(); JS::GCPtr current_top_level_browsing_context(); ErrorOr ensure_current_browsing_context_is_open();