浏览代码

WebContent: Implement the WebDriver concept of current browsing context

When we create a WebDriverConnection object, we currently hand it the
page client for which it was opened, and perform all actions on that
client. However, some WebDriver endpoints change the browsing context
(and therefore page client) on which future commands should be executed.
For example, the switch-frame endpoint will switch the current browsing
context to a frame/iframe context.

This patch implements the current browsing context (and current top-
level browsing context) concepts. They are initialized to that of the
original page. Most of this patch is making sure we execute actions on
the correct context.
Timothy Flynn 10 月之前
父节点
当前提交
c4da022864
共有 2 个文件被更改,包括 158 次插入160 次删除
  1. 145 155
      Userland/Services/WebContent/WebDriverConnection.cpp
  2. 13 5
      Userland/Services/WebContent/WebDriverConnection.h

文件差异内容过多而无法显示
+ 145 - 155
Userland/Services/WebContent/WebDriverConnection.cpp


+ 13 - 5
Userland/Services/WebContent/WebDriverConnection.h

@@ -1,7 +1,7 @@
 /*
  * Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
  * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
- * Copyright (c) 2022-2023, Tim Flynn <trflynn89@serenityos.org>
+ * Copyright (c) 2022-2024, Tim Flynn <trflynn89@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -102,9 +102,13 @@ private:
     virtual Messages::WebDriverClient::TakeScreenshotResponse take_screenshot() override;
     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();
+
+    Web::HTML::BrowsingContext& current_browsing_context() { return *m_current_browsing_context; }
+    JS::GCPtr<Web::HTML::BrowsingContext> current_top_level_browsing_context();
+
+    ErrorOr<void, Web::WebDriver::Error> ensure_current_browsing_context_is_open();
+    ErrorOr<void, Web::WebDriver::Error> ensure_current_top_level_browsing_context_is_open();
 
     ErrorOr<void, Web::WebDriver::Error> handle_any_user_prompts();
     void restore_the_window();
@@ -113,6 +117,9 @@ private:
 
     ErrorOr<void, Web::WebDriver::Error> wait_for_navigation_to_complete();
 
+    Gfx::IntPoint calculate_absolute_position_of_element(JS::NonnullGCPtr<Web::Geometry::DOMRect> rect);
+    Gfx::IntRect calculate_absolute_rect_of_element(Web::DOM::Element const& element);
+
     using StartNodeGetter = Function<ErrorOr<Web::DOM::ParentNode*, Web::WebDriver::Error>()>;
     ErrorOr<JsonArray, Web::WebDriver::Error> find(StartNodeGetter&& start_node_getter, Web::WebDriver::LocationStrategy using_, StringView value);
 
@@ -123,8 +130,6 @@ private:
     static ErrorOr<ScriptArguments, Web::WebDriver::Error> extract_the_script_arguments_from_a_request(JS::VM&, JsonValue const& payload);
     void delete_cookies(Optional<StringView> const& name = {});
 
-    JS::NonnullGCPtr<Web::PageClient> m_page_client;
-
     // https://w3c.github.io/webdriver/#dfn-page-load-strategy
     Web::WebDriver::PageLoadStrategy m_page_load_strategy { Web::WebDriver::PageLoadStrategy::Normal };
 
@@ -136,6 +141,9 @@ private:
 
     // https://w3c.github.io/webdriver/#dfn-session-script-timeout
     Web::WebDriver::TimeoutsConfiguration m_timeouts_configuration;
+
+    // https://w3c.github.io/webdriver/#dfn-current-browsing-context
+    JS::Handle<Web::HTML::BrowsingContext> m_current_browsing_context;
 };
 
 }

部分文件因为文件数量过多而无法显示