mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 17:49:40 +00:00
LibWeb: Move AO to check if a browsing context is open to a helper file
This will be needed outside of WebDriverConnection.cpp.
This commit is contained in:
parent
0fe30886f5
commit
28fb30b22f
Notes:
github-actions[bot]
2025-02-05 11:34:54 +00:00
Author: https://github.com/trflynn89
Commit: 28fb30b22f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3439
Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 16 additions and 13 deletions
|
@ -127,4 +127,13 @@ ErrorOr<GC::Ref<HTML::WindowProxy>, WebDriver::Error> deserialize_web_window(JS:
|
||||||
return *navigable->active_window_proxy();
|
return *navigable->active_window_proxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/webdriver/#dfn-no-longer-open
|
||||||
|
ErrorOr<void, WebDriver::Error> ensure_browsing_context_is_open(GC::Ptr<HTML::BrowsingContext> 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 {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,4 +22,6 @@ ErrorOr<GC::Ref<HTML::WindowProxy>, WebDriver::Error> deserialize_web_frame(JS::
|
||||||
bool represents_a_web_window(JS::Value);
|
bool represents_a_web_window(JS::Value);
|
||||||
ErrorOr<GC::Ref<HTML::WindowProxy>, WebDriver::Error> deserialize_web_window(JS::Object const&);
|
ErrorOr<GC::Ref<HTML::WindowProxy>, WebDriver::Error> deserialize_web_window(JS::Object const&);
|
||||||
|
|
||||||
|
ErrorOr<void, WebDriver::Error> ensure_browsing_context_is_open(GC::Ptr<HTML::BrowsingContext>);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
#include <LibWeb/UIEvents/EventNames.h>
|
#include <LibWeb/UIEvents/EventNames.h>
|
||||||
#include <LibWeb/UIEvents/MouseEvent.h>
|
#include <LibWeb/UIEvents/MouseEvent.h>
|
||||||
#include <LibWeb/WebDriver/Actions.h>
|
#include <LibWeb/WebDriver/Actions.h>
|
||||||
|
#include <LibWeb/WebDriver/Contexts.h>
|
||||||
#include <LibWeb/WebDriver/ElementReference.h>
|
#include <LibWeb/WebDriver/ElementReference.h>
|
||||||
#include <LibWeb/WebDriver/HeapTimer.h>
|
#include <LibWeb/WebDriver/HeapTimer.h>
|
||||||
#include <LibWeb/WebDriver/InputState.h>
|
#include <LibWeb/WebDriver/InputState.h>
|
||||||
|
@ -113,15 +114,6 @@ static Gfx::IntRect compute_window_rect(Web::Page const& page)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/webdriver/#dfn-no-longer-open
|
|
||||||
static ErrorOr<void, Web::WebDriver::Error> ensure_browsing_context_is_open(GC::Ptr<Web::HTML::BrowsingContext> 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
|
// https://w3c.github.io/webdriver/#dfn-scrolls-into-view
|
||||||
static void scroll_element_into_view(Web::DOM::Element& element)
|
static void scroll_element_into_view(Web::DOM::Element& element)
|
||||||
{
|
{
|
||||||
|
@ -769,7 +761,7 @@ Messages::WebDriverClient::SwitchToParentFrameResponse WebDriverConnection::swit
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. If session's current parent browsing context is no longer open, return error with error code no such window.
|
// 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(current_parent_browsing_context()));
|
TRY(Web::WebDriver::ensure_browsing_context_is_open(current_parent_browsing_context()));
|
||||||
|
|
||||||
// 3. Try to handle any user prompts with session.
|
// 3. Try to handle any user prompts with session.
|
||||||
handle_any_user_prompts([this]() {
|
handle_any_user_prompts([this]() {
|
||||||
|
@ -2623,12 +2615,12 @@ Messages::WebDriverClient::EnsureTopLevelBrowsingContextIsOpenResponse WebDriver
|
||||||
|
|
||||||
ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_current_browsing_context_is_open()
|
ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_current_browsing_context_is_open()
|
||||||
{
|
{
|
||||||
return ensure_browsing_context_is_open(current_browsing_context());
|
return Web::WebDriver::ensure_browsing_context_is_open(current_browsing_context());
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_current_top_level_browsing_context_is_open()
|
ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_current_top_level_browsing_context_is_open()
|
||||||
{
|
{
|
||||||
return ensure_browsing_context_is_open(current_top_level_browsing_context());
|
return Web::WebDriver::ensure_browsing_context_is_open(current_top_level_browsing_context());
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/webdriver/#dfn-handle-any-user-prompts
|
// https://w3c.github.io/webdriver/#dfn-handle-any-user-prompts
|
||||||
|
@ -2696,7 +2688,7 @@ void WebDriverConnection::wait_for_navigation_to_complete(OnNavigationComplete o
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. If the current browsing context is no longer open, return success with data null.
|
// 2. If the current browsing context is no longer open, return success with data null.
|
||||||
if (ensure_browsing_context_is_open(current_browsing_context()).is_error()) {
|
if (Web::WebDriver::ensure_browsing_context_is_open(current_browsing_context()).is_error()) {
|
||||||
on_complete->function()(JsonValue {});
|
on_complete->function()(JsonValue {});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue