mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
WebContent+WebDriver: Move the Navigate To command to WebContent
This commit is contained in:
parent
2d5381fd91
commit
31bb79295d
8 changed files with 69 additions and 37 deletions
|
@ -19,6 +19,21 @@
|
|||
|
||||
namespace WebContent {
|
||||
|
||||
#define DRIVER_TRY(expression) \
|
||||
({ \
|
||||
auto _temporary_result = (expression); \
|
||||
if (_temporary_result.is_error()) [[unlikely]] \
|
||||
return { _temporary_result.release_error() }; \
|
||||
_temporary_result.release_value(); \
|
||||
})
|
||||
|
||||
static JsonValue make_success_response(JsonValue value)
|
||||
{
|
||||
JsonObject result;
|
||||
result.set("value", move(value));
|
||||
return result;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<WebDriverConnection>> WebDriverConnection::connect(PageHost& page_host, String const& webdriver_ipc_path)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Trying to connect to {}", webdriver_ipc_path);
|
||||
|
@ -39,4 +54,45 @@ void WebDriverConnection::set_is_webdriver_active(bool is_webdriver_active)
|
|||
m_page_host.set_is_webdriver_active(is_webdriver_active);
|
||||
}
|
||||
|
||||
// 10.1 Navigate To, https://w3c.github.io/webdriver/#navigate-to
|
||||
Messages::WebDriverClient::NavigateToResponse WebDriverConnection::navigate_to(JsonValue const& payload)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection::navigate_to {}", payload);
|
||||
|
||||
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
|
||||
DRIVER_TRY(ensure_open_top_level_browsing_context());
|
||||
|
||||
// 2. Let url be the result of getting the property url from the parameters argument.
|
||||
if (!payload.is_object() || !payload.as_object().has_string("url"sv))
|
||||
return { Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload doesn't have a string `url`"sv) };
|
||||
URL url(payload.as_object().get_ptr("url"sv)->as_string());
|
||||
|
||||
// FIXME: 3. If url is not an absolute URL or is not an absolute URL with fragment or not a local scheme, return error with error code invalid argument.
|
||||
// FIXME: 4. Handle any user prompts and return its value if it is an error.
|
||||
// FIXME: 5. Let current URL be the current top-level browsing context’s active document’s URL.
|
||||
// FIXME: 6. If current URL and url do not have the same absolute URL:
|
||||
// FIXME: a. If timer has not been started, start a timer. If this algorithm has not completed before timer reaches the session’s session page load timeout in milliseconds, return an error with error code timeout.
|
||||
|
||||
// 7. Navigate the current top-level browsing context to url.
|
||||
m_page_host.page().load(url);
|
||||
|
||||
// FIXME: 8. If url is special except for file and current URL and URL do not have the same absolute URL:
|
||||
// FIXME: a. Try to wait for navigation to complete.
|
||||
// FIXME: b. Try to run the post-navigation checks.
|
||||
// FIXME: 9. Set the current browsing context with the current top-level browsing context.
|
||||
// FIXME: 10. If the current top-level browsing context contains a refresh state pragma directive of time 1 second or less, wait until the refresh timeout has elapsed, a new navigate has begun, and return to the first step of this algorithm.
|
||||
|
||||
// 11. Return success with data null.
|
||||
return { make_success_response({}) };
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-no-longer-open
|
||||
ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context()
|
||||
{
|
||||
// A browsing context is said to be no longer open if it has been discarded.
|
||||
if (m_page_host.page().top_level_browsing_context().has_been_discarded())
|
||||
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::NoSuchWindow, "Window not found"sv);
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue