Title: [252356] trunk
Revision
252356
Author
[email protected]
Date
2019-11-12 00:12:40 -0800 (Tue, 12 Nov 2019)

Log Message

[GTK] WebDriver: implement new window command
https://bugs.webkit.org/show_bug.cgi?id=203994

Reviewed by Carlos Alberto Lopez Perez.

Source/WebDriver:

* Session.cpp:
(WebDriver::Session::newWindow):
* Session.h:
* WebDriverService.cpp:
(WebDriver::WebDriverService::newWindow):
* WebDriverService.h:

Source/WebKit:

Add new API to support new window command. The WebKitAutomationSession::create-web-view signal can now receive a
detail that can be "window" or "tab". Applications can use that to decide whether to add the new webview to a
new window or tab. WebKitWebView has a new construct only property automation-presentation-type, which is an
enum that can be either window or tab value. Appplications should use the new property when creating the web
view for automation to indicate whether the web view was added to a new window or tab.

* UIProcess/API/glib/WebKitAutomationSession.cpp:
(webkit_automation_session_class_init):
* UIProcess/API/glib/WebKitWebView.cpp:
(webkitWebViewSetProperty):
(webkitWebViewGetProperty):
(webkit_web_view_class_init):
(webkit_web_view_get_automation_presentation_type):
* UIProcess/API/gtk/WebKitAutomationSession.h:
* UIProcess/API/gtk/WebKitWebView.h:
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
* UIProcess/API/wpe/WebKitWebView.h:
* UIProcess/API/wpe/docs/wpe-1.0-sections.txt:

Tools:

Add support for new window command to MiniBrowser and a test case to check the new API to unit tests.

* MiniBrowser/gtk/BrowserWindow.c:
(findActiveWindow):
(browser_window_get_or_create_web_view_for_automation):
(browser_window_create_web_view_in_new_tab_for_automation):
* MiniBrowser/gtk/BrowserWindow.h:
* MiniBrowser/gtk/main.c:
(createWebViewForAutomationInWindowCallback):
(createWebViewForAutomationInTabCallback):
(automationStartedCallback):
(createWebViewForAutomationCallback): Deleted.
* TestWebKitAPI/Tests/WebKitGLib/TestAutomationSession.cpp:
(testAutomationSessionRequestSession):

Modified Paths

Diff

Modified: trunk/Source/WebDriver/ChangeLog (252355 => 252356)


--- trunk/Source/WebDriver/ChangeLog	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebDriver/ChangeLog	2019-11-12 08:12:40 UTC (rev 252356)
@@ -1,3 +1,17 @@
+2019-11-12  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] WebDriver: implement new window command
+        https://bugs.webkit.org/show_bug.cgi?id=203994
+
+        Reviewed by Carlos Alberto Lopez Perez.
+
+        * Session.cpp:
+        (WebDriver::Session::newWindow):
+        * Session.h:
+        * WebDriverService.cpp:
+        (WebDriver::WebDriverService::newWindow):
+        * WebDriverService.h:
+
 2019-11-11  Carlos Garcia Campos  <[email protected]>
 
         WebDriver: implement proxy support

Modified: trunk/Source/WebDriver/Session.cpp (252355 => 252356)


--- trunk/Source/WebDriver/Session.cpp	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebDriver/Session.cpp	2019-11-12 08:12:40 UTC (rev 252356)
@@ -586,6 +586,47 @@
     });
 }
 
+void Session::newWindow(Optional<String> typeHint, Function<void (CommandResult&&)>&& completionHandler)
+{
+    if (!m_toplevelBrowsingContext) {
+        completionHandler(CommandResult::fail(CommandResult::ErrorCode::NoSuchWindow));
+        return;
+    }
+
+    handleUserPrompts([this, protectedThis = makeRef(*this), typeHint, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
+        if (result.isError()) {
+            completionHandler(WTFMove(result));
+            return;
+        }
+
+        RefPtr<JSON::Object> parameters;
+        if (typeHint) {
+            parameters = JSON::Object::create();
+            parameters->setString("presentationHint"_s, typeHint.value() == "window" ? "Window"_s : "Tab"_s);
+        }
+        m_host->sendCommandToBackend("createBrowsingContext"_s, WTFMove(parameters), [this, protectedThis = protectedThis.copyRef(), completionHandler = WTFMove(completionHandler)](SessionHost::CommandResponse&& response) {
+            if (response.isError || !response.responseObject) {
+                completionHandler(CommandResult::fail(WTFMove(response.responseObject)));
+                return;
+            }
+            String handle;
+            if (!response.responseObject->getString("handle"_s, handle)) {
+                completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
+                return;
+            }
+            String presentation;
+            if (!response.responseObject->getString("presentation"_s, presentation)) {
+                completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
+                return;
+            }
+            RefPtr<JSON::Object> result = JSON::Object::create();
+            result->setString("handle"_s, handle);
+            result->setString("type"_s, presentation == "Window"_s ? "window"_s : "tab"_s);
+            completionHandler(CommandResult::success(WTFMove(result)));
+        });
+    });
+}
+
 void Session::switchToFrame(RefPtr<JSON::Value>&& frameID, Function<void (CommandResult&&)>&& completionHandler)
 {
     if (!m_toplevelBrowsingContext) {

Modified: trunk/Source/WebDriver/Session.h (252355 => 252356)


--- trunk/Source/WebDriver/Session.h	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebDriver/Session.h	2019-11-12 08:12:40 UTC (rev 252356)
@@ -86,6 +86,7 @@
     void closeWindow(Function<void (CommandResult&&)>&&);
     void switchToWindow(const String& windowHandle, Function<void (CommandResult&&)>&&);
     void getWindowHandles(Function<void (CommandResult&&)>&&);
+    void newWindow(Optional<String> typeHint, Function<void (CommandResult&&)>&&);
     void switchToFrame(RefPtr<JSON::Value>&&, Function<void (CommandResult&&)>&&);
     void switchToParentFrame(Function<void (CommandResult&&)>&&);
     void getWindowRect(Function<void (CommandResult&&)>&&);

Modified: trunk/Source/WebDriver/WebDriverService.cpp (252355 => 252356)


--- trunk/Source/WebDriver/WebDriverService.cpp	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebDriver/WebDriverService.cpp	2019-11-12 08:12:40 UTC (rev 252356)
@@ -126,6 +126,7 @@
     { HTTPMethod::Delete, "/session/$sessionId/window", &WebDriverService::closeWindow },
     { HTTPMethod::Post, "/session/$sessionId/window", &WebDriverService::switchToWindow },
     { HTTPMethod::Get, "/session/$sessionId/window/handles", &WebDriverService::getWindowHandles },
+    { HTTPMethod::Post, "/session/$sessionId/window/new", &WebDriverService::newWindow },
     { HTTPMethod::Post, "/session/$sessionId/frame", &WebDriverService::switchToFrame },
     { HTTPMethod::Post, "/session/$sessionId/frame/parent", &WebDriverService::switchToParentFrame },
     { HTTPMethod::Get, "/session/$sessionId/window/rect", &WebDriverService::getWindowRect },
@@ -1139,6 +1140,29 @@
         m_session->getWindowHandles(WTFMove(completionHandler));
 }
 
+void WebDriverService::newWindow(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
+{
+    // §11.5 New Window
+    // https://w3c.github.io/webdriver/#new-window
+    if (!findSessionOrCompleteWithError(*parameters, completionHandler))
+        return;
+
+    Optional<String> typeHint;
+    RefPtr<JSON::Value> value;
+    if (parameters->getValue("type"_s, value)) {
+        String valueString;
+        if (value->asString(valueString)) {
+            if (valueString == "window" || valueString == "tab")
+                typeHint = valueString;
+        } else if (!value->isNull()) {
+            completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
+            return;
+        }
+    }
+
+    m_session->newWindow(typeHint, WTFMove(completionHandler));
+}
+
 void WebDriverService::switchToFrame(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
 {
     // §10.5 Switch To Frame.

Modified: trunk/Source/WebDriver/WebDriverService.h (252355 => 252356)


--- trunk/Source/WebDriver/WebDriverService.h	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebDriver/WebDriverService.h	2019-11-12 08:12:40 UTC (rev 252356)
@@ -75,6 +75,7 @@
     void closeWindow(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void switchToWindow(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void getWindowHandles(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
+    void newWindow(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void switchToFrame(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void switchToParentFrame(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void getWindowRect(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);

Modified: trunk/Source/WebKit/ChangeLog (252355 => 252356)


--- trunk/Source/WebKit/ChangeLog	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebKit/ChangeLog	2019-11-12 08:12:40 UTC (rev 252356)
@@ -1,5 +1,31 @@
 2019-11-12  Carlos Garcia Campos  <[email protected]>
 
+        [GTK] WebDriver: implement new window command
+        https://bugs.webkit.org/show_bug.cgi?id=203994
+
+        Reviewed by Carlos Alberto Lopez Perez.
+
+        Add new API to support new window command. The WebKitAutomationSession::create-web-view signal can now receive a
+        detail that can be "window" or "tab". Applications can use that to decide whether to add the new webview to a
+        new window or tab. WebKitWebView has a new construct only property automation-presentation-type, which is an
+        enum that can be either window or tab value. Appplications should use the new property when creating the web
+        view for automation to indicate whether the web view was added to a new window or tab.
+
+        * UIProcess/API/glib/WebKitAutomationSession.cpp:
+        (webkit_automation_session_class_init):
+        * UIProcess/API/glib/WebKitWebView.cpp:
+        (webkitWebViewSetProperty):
+        (webkitWebViewGetProperty):
+        (webkit_web_view_class_init):
+        (webkit_web_view_get_automation_presentation_type):
+        * UIProcess/API/gtk/WebKitAutomationSession.h:
+        * UIProcess/API/gtk/WebKitWebView.h:
+        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
+        * UIProcess/API/wpe/WebKitWebView.h:
+        * UIProcess/API/wpe/docs/wpe-1.0-sections.txt:
+
+2019-11-12  Carlos Garcia Campos  <[email protected]>
+
         REGRESSION(r250707): [GTK] UIClient::setWindowFrame only works the first time
         https://bugs.webkit.org/show_bug.cgi?id=204068
 

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitAutomationSession.cpp (252355 => 252356)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitAutomationSession.cpp	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitAutomationSession.cpp	2019-11-12 08:12:40 UTC (rev 252356)
@@ -90,10 +90,11 @@
 #endif
     }
 
-    void requestNewPageWithOptions(WebAutomationSession&, API::AutomationSessionBrowsingContextOptions, CompletionHandler<void(WebPageProxy*)>&& completionHandler) override
+    void requestNewPageWithOptions(WebAutomationSession&, API::AutomationSessionBrowsingContextOptions options, CompletionHandler<void(WebPageProxy*)>&& completionHandler) override
     {
         WebKitWebView* webView = nullptr;
-        g_signal_emit(m_session, signals[CREATE_WEB_VIEW], 0, &webView);
+        GQuark detail = options & API::AutomationSessionBrowsingContextOptionsPreferNewTab ? g_quark_from_string("tab") : g_quark_from_string("window");
+        g_signal_emit(m_session, signals[CREATE_WEB_VIEW], detail, &webView);
         if (!webView || !webkit_web_view_is_controlled_by_automation(webView))
             completionHandler(nullptr);
         else
@@ -187,6 +188,22 @@
         return WTF::nullopt;
     }
 
+    API::AutomationSessionClient::BrowsingContextPresentation currentPresentationOfPage(WebAutomationSession&, WebPageProxy& page) override
+    {
+        auto* webView = webkitWebContextGetWebViewForPage(m_session->priv->webContext, &page);
+        if (!webView)
+            return API::AutomationSessionClient::BrowsingContextPresentation::Window;
+
+        switch (webkit_web_view_get_automation_presentation_type(webView)) {
+        case WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_WINDOW:
+            return API::AutomationSessionClient::BrowsingContextPresentation::Window;
+        case WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_TAB:
+            return API::AutomationSessionClient::BrowsingContextPresentation::Tab;
+        }
+
+        RELEASE_ASSERT_NOT_REACHED();
+    }
+
     WebKitAutomationSession* m_session;
 };
 
@@ -273,9 +290,16 @@
      * This signal is emitted when the automation client requests a new
      * browsing context to interact with it. The callback handler should
      * return a #WebKitWebView created with #WebKitWebView:is-controlled-by-automation
-     * construct property enabled. The returned #WebKitWebView could be an existing
-     * web view or a new one created and added to a new tab or window.
+     * construct property enabled and #WebKitWebView:automation-presentation-type construct
+     * property set if needed.
      *
+     * If the signal is emitted with "tab" detail, the returned #WebKitWebView should be
+     * a new web view added to a new tab of the current browsing context window.
+     * If the signal is emitted with "window" detail, the returned #WebKitWebView should be
+     * a new web view added to a new window.
+     * When creating a new web view and there's an active browsing context, the new window
+     * or tab shouldn't be focused.
+     *
      * Returns: (transfer none): a #WebKitWebView widget.
      *
      * Since: 2.18
@@ -283,7 +307,7 @@
     signals[CREATE_WEB_VIEW] = g_signal_new(
         "create-web-view",
         G_TYPE_FROM_CLASS(sessionClass),
-        G_SIGNAL_RUN_LAST,
+        static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED),
         0,
         nullptr, nullptr,
         g_cclosure_marshal_generic,

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp (252355 => 252356)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp	2019-11-12 08:12:40 UTC (rev 252356)
@@ -195,6 +195,7 @@
     PROP_IS_PLAYING_AUDIO,
     PROP_IS_EPHEMERAL,
     PROP_IS_CONTROLLED_BY_AUTOMATION,
+    PROP_AUTOMATION_PRESENTATION_TYPE,
     PROP_EDITABLE,
     PROP_PAGE_ID
 };
@@ -258,6 +259,7 @@
     bool isLoading;
     bool isEphemeral;
     bool isControlledByAutomation;
+    WebKitAutomationBrowsingContextPresentation automationPresentationType;
 
     std::unique_ptr<PageLoadStateObserver> loadObserver;
 
@@ -820,6 +822,9 @@
     case PROP_IS_CONTROLLED_BY_AUTOMATION:
         webView->priv->isControlledByAutomation = g_value_get_boolean(value);
         break;
+    case PROP_AUTOMATION_PRESENTATION_TYPE:
+        webView->priv->automationPresentationType = static_cast<WebKitAutomationBrowsingContextPresentation>(g_value_get_enum(value));
+        break;
     case PROP_EDITABLE:
         webkit_web_view_set_editable(webView, g_value_get_boolean(value));
         break;
@@ -876,6 +881,9 @@
     case PROP_IS_CONTROLLED_BY_AUTOMATION:
         g_value_set_boolean(value, webkit_web_view_is_controlled_by_automation(webView));
         break;
+    case PROP_AUTOMATION_PRESENTATION_TYPE:
+        g_value_set_enum(value, webkit_web_view_get_automation_presentation_type(webView));
+        break;
     case PROP_EDITABLE:
         g_value_set_boolean(value, webkit_web_view_is_editable(webView));
         break;
@@ -1196,6 +1204,27 @@
             static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
 
     /**
+     * WebKitWebView:automation-presentation-type:
+     *
+     * The #WebKitAutomationBrowsingContextPresentation of #WebKitWebView. This should only be used when
+     * creating a new #WebKitWebView as a response to #WebKitAutomationSession::create-web-view
+     * signal request. If the new WebView was added to a new tab of current browsing context window
+     * %WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_TAB should be used.
+     *
+     * Since: 2.28
+     */
+    g_object_class_install_property(
+        gObjectClass,
+        PROP_AUTOMATION_PRESENTATION_TYPE,
+        g_param_spec_enum(
+            "automation-presentation-type",
+            "Automation Presentation Type",
+            _("The browsing context presentation type for automation"),
+            WEBKIT_TYPE_AUTOMATION_BROWSING_CONTEXT_PRESENTATION,
+            WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_WINDOW,
+            static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
+
+    /**
      * WebKitWebView:editable:
      *
      * Whether the pages loaded inside #WebKitWebView are editable. For more
@@ -2748,6 +2777,23 @@
 }
 
 /**
+ * webkit_web_view_get_automation_presentation_type:
+ * @web_view: a #WebKitWebView
+ *
+ * Get the presentation type of #WebKitWebView when created for automation.
+ *
+ * Returns: a #WebKitAutomationBrowsingContextPresentation.
+ *
+ * Since: 2.28
+ */
+WebKitAutomationBrowsingContextPresentation webkit_web_view_get_automation_presentation_type(WebKitWebView* webView)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_WINDOW);
+
+    return webView->priv->automationPresentationType;
+}
+
+/**
  * webkit_web_view_get_website_data_manager:
  * @web_view: a #WebKitWebView
  *

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitAutomationSession.h (252355 => 252356)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitAutomationSession.h	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitAutomationSession.h	2019-11-12 08:12:40 UTC (rev 252356)
@@ -37,6 +37,20 @@
 #define WEBKIT_IS_AUTOMATION_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_AUTOMATION_SESSION))
 #define WEBKIT_AUTOMATION_SESSION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_AUTOMATION_SESSION, WebKitAutomationSessionClass))
 
+/**
+ * WebKitAutomationBrowsingContextPresentation:
+ * @WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_WINDOW: a window
+ * @WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_TAB: a tab
+ *
+ * Enum values used for determining the automation browsing context presentation.
+ *
+ * Since: 2.28
+ */
+typedef enum {
+    WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_WINDOW,
+    WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_TAB
+} WebKitAutomationBrowsingContextPresentation;
+
 typedef struct _WebKitAutomationSession        WebKitAutomationSession;
 typedef struct _WebKitAutomationSessionClass   WebKitAutomationSessionClass;
 typedef struct _WebKitAutomationSessionPrivate WebKitAutomationSessionPrivate;

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebView.h (252355 => 252356)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebView.h	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebView.h	2019-11-12 08:12:40 UTC (rev 252356)
@@ -300,6 +300,9 @@
 WEBKIT_API gboolean
 webkit_web_view_is_controlled_by_automation          (WebKitWebView             *web_view);
 
+WEBKIT_API WebKitAutomationBrowsingContextPresentation
+webkit_web_view_get_automation_presentation_type     (WebKitWebView             *web_view);
+
 WEBKIT_API WebKitWebsiteDataManager *
 webkit_web_view_get_website_data_manager             (WebKitWebView             *web_view);
 

Modified: trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt (252355 => 252356)


--- trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2019-11-12 08:12:40 UTC (rev 252356)
@@ -215,6 +215,7 @@
 webkit_web_view_new_with_user_content_manager
 webkit_web_view_is_ephemeral
 webkit_web_view_is_controlled_by_automation
+webkit_web_view_get_automation_presentation_type
 webkit_web_view_get_context
 webkit_web_view_get_user_content_manager
 webkit_web_view_get_website_data_manager
@@ -1483,6 +1484,7 @@
 <SECTION>
 <FILE>WebKitAutomationSession</FILE>
 WebKitAutomationSession
+WebKitAutomationBrowsingContextPresentation
 webkit_automation_session_get_id
 webkit_automation_session_set_application_info
 webkit_automation_session_get_application_info

Modified: trunk/Source/WebKit/UIProcess/API/wpe/WebKitAutomationSession.h (252355 => 252356)


--- trunk/Source/WebKit/UIProcess/API/wpe/WebKitAutomationSession.h	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WebKitAutomationSession.h	2019-11-12 08:12:40 UTC (rev 252356)
@@ -37,6 +37,20 @@
 #define WEBKIT_IS_AUTOMATION_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_AUTOMATION_SESSION))
 #define WEBKIT_AUTOMATION_SESSION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_AUTOMATION_SESSION, WebKitAutomationSessionClass))
 
+/**
+ * WebKitAutomationBrowsingContextPresentation:
+ * @WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_WINDOW: a window
+ * @WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_TAB: a tab
+ *
+ * Enum values used for determining the automation browsing context presentation.
+ *
+ * Since: 2.28
+ */
+typedef enum {
+    WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_WINDOW,
+    WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_TAB
+} WebKitAutomationBrowsingContextPresentation;
+
 typedef struct _WebKitAutomationSession        WebKitAutomationSession;
 typedef struct _WebKitAutomationSessionClass   WebKitAutomationSessionClass;
 typedef struct _WebKitAutomationSessionPrivate WebKitAutomationSessionPrivate;

Modified: trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebView.h (252355 => 252356)


--- trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebView.h	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebView.h	2019-11-12 08:12:40 UTC (rev 252356)
@@ -286,6 +286,9 @@
 WEBKIT_API gboolean
 webkit_web_view_is_controlled_by_automation          (WebKitWebView             *web_view);
 
+WEBKIT_API WebKitAutomationBrowsingContextPresentation
+webkit_web_view_get_automation_presentation_type     (WebKitWebView             *web_view);
+
 WEBKIT_API WebKitWebsiteDataManager *
 webkit_web_view_get_website_data_manager             (WebKitWebView             *web_view);
 

Modified: trunk/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt (252355 => 252356)


--- trunk/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt	2019-11-12 08:12:40 UTC (rev 252356)
@@ -192,6 +192,7 @@
 webkit_web_view_get_backend
 webkit_web_view_is_ephemeral
 webkit_web_view_is_controlled_by_automation
+webkit_web_view_get_automation_presentation_type
 webkit_web_view_get_context
 webkit_web_view_get_user_content_manager
 webkit_web_view_get_website_data_manager
@@ -1368,6 +1369,7 @@
 <SECTION>
 <FILE>WebKitAutomationSession</FILE>
 WebKitAutomationSession
+WebKitAutomationBrowsingContextPresentation
 webkit_automation_session_get_id
 webkit_automation_session_set_application_info
 webkit_automation_session_get_application_info

Modified: trunk/Tools/ChangeLog (252355 => 252356)


--- trunk/Tools/ChangeLog	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Tools/ChangeLog	2019-11-12 08:12:40 UTC (rev 252356)
@@ -1,3 +1,25 @@
+2019-11-12  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] WebDriver: implement new window command
+        https://bugs.webkit.org/show_bug.cgi?id=203994
+
+        Reviewed by Carlos Alberto Lopez Perez.
+
+        Add support for new window command to MiniBrowser and a test case to check the new API to unit tests.
+
+        * MiniBrowser/gtk/BrowserWindow.c:
+        (findActiveWindow):
+        (browser_window_get_or_create_web_view_for_automation):
+        (browser_window_create_web_view_in_new_tab_for_automation):
+        * MiniBrowser/gtk/BrowserWindow.h:
+        * MiniBrowser/gtk/main.c:
+        (createWebViewForAutomationInWindowCallback):
+        (createWebViewForAutomationInTabCallback):
+        (automationStartedCallback):
+        (createWebViewForAutomationCallback): Deleted.
+        * TestWebKitAPI/Tests/WebKitGLib/TestAutomationSession.cpp:
+        (testAutomationSessionRequestSession):
+
 2019-11-11  Alex Christensen  <[email protected]>
 
         Add SPI to access a WebsiteDataStore without instantiating it, and its configuration

Modified: trunk/Tools/MiniBrowser/gtk/BrowserWindow.c (252355 => 252356)


--- trunk/Tools/MiniBrowser/gtk/BrowserWindow.c	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Tools/MiniBrowser/gtk/BrowserWindow.c	2019-11-12 08:12:40 UTC (rev 252356)
@@ -1224,12 +1224,25 @@
     gtk_widget_set_app_paintable(GTK_WIDGET(window), TRUE);
 }
 
+static BrowserWindow *findActiveWindow(void)
+{
+    GList *l;
+
+    for (l = windowList; l; l = g_list_next(l)) {
+        BrowserWindow *window = (BrowserWindow *)l->data;
+        if (gtk_window_is_active(GTK_WINDOW(window)))
+            return window;
+    }
+
+    return windowList ? (BrowserWindow *)windowList->data : NULL;
+}
+
 WebKitWebView *browser_window_get_or_create_web_view_for_automation(void)
 {
-    if (!windowList)
+    BrowserWindow *window = findActiveWindow();
+    if (!window)
         return NULL;
 
-    BrowserWindow *window = (BrowserWindow *)windowList->data;
     WebKitWebView *webView = browser_tab_get_web_view(window->activeTab);
     if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(window->notebook)) == 1 && !webkit_web_view_get_uri(webView)) {
         webkit_web_view_load_uri(webView, "about:blank");
@@ -1242,8 +1255,29 @@
         "user-content-manager", webkit_web_view_get_user_content_manager(webView),
         "is-controlled-by-automation", TRUE,
         NULL));
+    GtkWidget *newWindow = browser_window_new(GTK_WINDOW(window), window->webContext);
+    gtk_window_set_focus_on_map(GTK_WINDOW(newWindow), FALSE);
+    browser_window_append_view(BROWSER_WINDOW(newWindow), newWebView);
+    webkit_web_view_load_uri(newWebView, "about:blank");
+    gtk_widget_show(newWindow);
+    return newWebView;
+}
+
+WebKitWebView *browser_window_create_web_view_in_new_tab_for_automation(void)
+{
+    BrowserWindow *window = findActiveWindow();
+    if (!window)
+        return NULL;
+
+    WebKitWebView *webView = browser_tab_get_web_view(window->activeTab);
+    WebKitWebView *newWebView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+        "web-context", webkit_web_view_get_context(webView),
+        "settings", webkit_web_view_get_settings(webView),
+        "user-content-manager", webkit_web_view_get_user_content_manager(webView),
+        "is-controlled-by-automation", TRUE,
+        "automation-presentation-type", WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_TAB,
+        NULL));
     browser_window_append_view(window, newWebView);
     webkit_web_view_load_uri(newWebView, "about:blank");
-    gtk_widget_grab_focus(GTK_WIDGET(newWebView));
     return newWebView;
 }

Modified: trunk/Tools/MiniBrowser/gtk/BrowserWindow.h (252355 => 252356)


--- trunk/Tools/MiniBrowser/gtk/BrowserWindow.h	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Tools/MiniBrowser/gtk/BrowserWindow.h	2019-11-12 08:12:40 UTC (rev 252356)
@@ -52,6 +52,7 @@
 void browser_window_load_session(BrowserWindow *, const char *sessionFile);
 void browser_window_set_background_color(BrowserWindow*, GdkRGBA*);
 WebKitWebView* browser_window_get_or_create_web_view_for_automation(void);
+WebKitWebView *browser_window_create_web_view_in_new_tab_for_automation(void);
 
 G_END_DECLS
 

Modified: trunk/Tools/MiniBrowser/gtk/main.c (252355 => 252356)


--- trunk/Tools/MiniBrowser/gtk/main.c	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Tools/MiniBrowser/gtk/main.c	2019-11-12 08:12:40 UTC (rev 252356)
@@ -465,11 +465,16 @@
     }
 }
 
-static GtkWidget *createWebViewForAutomationCallback(WebKitAutomationSession* session)
+static GtkWidget *createWebViewForAutomationInWindowCallback(WebKitAutomationSession* session)
 {
     return GTK_WIDGET(browser_window_get_or_create_web_view_for_automation());
 }
 
+static GtkWidget *createWebViewForAutomationInTabCallback(WebKitAutomationSession* session)
+{
+    return GTK_WIDGET(browser_window_create_web_view_in_new_tab_for_automation());
+}
+
 static void automationStartedCallback(WebKitWebContext *webContext, WebKitAutomationSession *session)
 {
     WebKitApplicationInfo *info = webkit_application_info_new();
@@ -477,7 +482,8 @@
     webkit_automation_session_set_application_info(session, info);
     webkit_application_info_unref(info);
 
-    g_signal_connect(session, "create-web-view", G_CALLBACK(createWebViewForAutomationCallback), NULL);
+    g_signal_connect(session, "create-web-view::window", G_CALLBACK(createWebViewForAutomationInWindowCallback), NULL);
+    g_signal_connect(session, "create-web-view::tab", G_CALLBACK(createWebViewForAutomationInTabCallback), NULL);
 }
 
 typedef struct {

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestAutomationSession.cpp (252355 => 252356)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestAutomationSession.cpp	2019-11-12 08:07:55 UTC (rev 252355)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestAutomationSession.cpp	2019-11-12 08:12:40 UTC (rev 252356)
@@ -166,6 +166,18 @@
         return test->m_webViewForAutomation;
     }
 
+    static WebKitWebView* createWebViewInWindowCallback(WebKitAutomationSession* session, AutomationTest* test)
+    {
+        test->m_createWebViewInWindowWasCalled = true;
+        return test->m_webViewForAutomation;
+    }
+
+    static WebKitWebView* createWebViewInTabCallback(WebKitAutomationSession* session, AutomationTest* test)
+    {
+        test->m_createWebViewInTabWasCalled = true;
+        return test->m_webViewForAutomation;
+    }
+
     void automationStarted(WebKitAutomationSession* session)
     {
         m_session = session;
@@ -262,6 +274,42 @@
         return false;
     }
 
+    bool createNewWindow(WebKitWebView* webView)
+    {
+        m_webViewForAutomation = webView;
+        m_createWebViewInWindowWasCalled = false;
+        m_message = { };
+        auto signalID = g_signal_connect(m_session, "create-web-view::window", G_CALLBACK(createWebViewInWindowCallback), this);
+        sendCommandToBackend("createBrowsingContext", "{\"presentationHint\":\"Window\"}");
+        g_main_loop_run(m_mainLoop.get());
+        g_signal_handler_disconnect(m_session, signalID);
+        g_assert_true(m_createWebViewInWindowWasCalled);
+        g_assert_false(m_message.isNull());
+        m_webViewForAutomation = nullptr;
+
+        if (strstr(m_message.data(), "\"presentation\":\"Window\""))
+            return true;
+        return false;
+    }
+
+    bool createNewTab(WebKitWebView* webView)
+    {
+        m_webViewForAutomation = webView;
+        m_createWebViewInTabWasCalled = false;
+        m_message = { };
+        auto signalID = g_signal_connect(m_session, "create-web-view::tab", G_CALLBACK(createWebViewInTabCallback), this);
+        sendCommandToBackend("createBrowsingContext", "{\"presentationHint\":\"Tab\"}");
+        g_main_loop_run(m_mainLoop.get());
+        g_signal_handler_disconnect(m_session, signalID);
+        g_assert_true(m_createWebViewInTabWasCalled);
+        g_assert_false(m_message.isNull());
+        m_webViewForAutomation = nullptr;
+
+        if (strstr(m_message.data(), "\"presentation\":\"Tab\""))
+            return true;
+        return false;
+    }
+
     GRefPtr<GMainLoop> m_mainLoop;
     GRefPtr<GDBusConnection> m_connection;
     WebKitAutomationSession* m_session;
@@ -270,6 +318,8 @@
 
     WebKitWebView* m_webViewForAutomation { nullptr };
     bool m_createWebViewWasCalled { false };
+    bool m_createWebViewInWindowWasCalled { false };
+    bool m_createWebViewInTabWasCalled { false };
     CString m_message;
 };
 
@@ -314,8 +364,32 @@
         "is-controlled-by-automation", TRUE,
         nullptr));
     g_assert_true(webkit_web_view_is_controlled_by_automation(webView.get()));
+    g_assert_cmpuint(webkit_web_view_get_automation_presentation_type(webView.get()), ==, WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_WINDOW);
     g_assert_true(test->createTopLevelBrowsingContext(webView.get()));
 
+    auto newWebViewInWindow = Test::adoptView(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+#if PLATFORM(WPE)
+        "backend", Test::createWebViewBackend(),
+#endif
+        "web-context", test->m_webContext.get(),
+        "is-controlled-by-automation", TRUE,
+        nullptr));
+    g_assert_true(webkit_web_view_is_controlled_by_automation(newWebViewInWindow.get()));
+    g_assert_cmpuint(webkit_web_view_get_automation_presentation_type(newWebViewInWindow.get()), ==, WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_WINDOW);
+    g_assert_true(test->createNewWindow(newWebViewInWindow.get()));
+
+    auto newWebViewInTab = Test::adoptView(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+#if PLATFORM(WPE)
+        "backend", Test::createWebViewBackend(),
+#endif
+        "web-context", test->m_webContext.get(),
+        "is-controlled-by-automation", TRUE,
+        "automation-presentation-type", WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_TAB,
+        nullptr));
+    g_assert_true(webkit_web_view_is_controlled_by_automation(newWebViewInTab.get()));
+    g_assert_cmpuint(webkit_web_view_get_automation_presentation_type(newWebViewInTab.get()), ==, WEBKIT_AUTOMATION_BROWSING_CONTEXT_PRESENTATION_TAB);
+    g_assert_true(test->createNewTab(newWebViewInTab.get()));
+
     webkit_web_context_set_automation_allowed(test->m_webContext.get(), FALSE);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to