Title: [239988] trunk/Source/WebKit
Revision
239988
Author
[email protected]
Date
2019-01-15 09:15:44 -0800 (Tue, 15 Jan 2019)

Log Message

WebDriver: update Create Window implementation to support newest specification
https://bugs.webkit.org/show_bug.cgi?id=193333
<rdar://problem/45649489>

Reviewed by Carlos Garcia Campos.

Spec link: https://w3c.github.io/webdriver/#create-window

The command as specified returns a value indicating whether the new browsing context
was presented as a new tab or new window. Add a new delegate method to query the current
'presentation' of the browsing context. The presentation can change over time due to
things such as screen orientation, so the value that is returned by the command only
reflects how the browsing context was initially presented to the user.

This is covered by existing WPT and internal tests. More will be added when Selenium
exposes this command in its various bindings.

* UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h:
Add new SPI delegate method to query the 'presentation' (tab or window) for an automated WKWebView.

* UIProcess/API/APIAutomationSessionClient.h:
(API::AutomationSessionClient::currentPresentationOfPage):
* UIProcess/Cocoa/AutomationSessionClient.h:
* UIProcess/Cocoa/AutomationSessionClient.mm:
(WebKit::AutomationSessionClient::AutomationSessionClient):
(WebKit::toImpl):
(WebKit::AutomationSessionClient::currentPresentationOfPage):
* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::toProtocol):
(WebKit::WebAutomationSession::createBrowsingContext):
Add plumbing between ObjC delegate and C++.

* UIProcess/Automation/Automation.json:
Include the initial presentation in the createBrowsingContext command result.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (239987 => 239988)


--- trunk/Source/WebKit/ChangeLog	2019-01-15 16:31:05 UTC (rev 239987)
+++ trunk/Source/WebKit/ChangeLog	2019-01-15 17:15:44 UTC (rev 239988)
@@ -1,3 +1,40 @@
+2019-01-15  Brian Burg  <[email protected]>
+
+        WebDriver: update Create Window implementation to support newest specification
+        https://bugs.webkit.org/show_bug.cgi?id=193333
+        <rdar://problem/45649489>
+
+        Reviewed by Carlos Garcia Campos.
+
+        Spec link: https://w3c.github.io/webdriver/#create-window
+
+        The command as specified returns a value indicating whether the new browsing context
+        was presented as a new tab or new window. Add a new delegate method to query the current
+        'presentation' of the browsing context. The presentation can change over time due to
+        things such as screen orientation, so the value that is returned by the command only
+        reflects how the browsing context was initially presented to the user.
+
+        This is covered by existing WPT and internal tests. More will be added when Selenium
+        exposes this command in its various bindings.
+
+        * UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h:
+        Add new SPI delegate method to query the 'presentation' (tab or window) for an automated WKWebView.
+
+        * UIProcess/API/APIAutomationSessionClient.h:
+        (API::AutomationSessionClient::currentPresentationOfPage):
+        * UIProcess/Cocoa/AutomationSessionClient.h:
+        * UIProcess/Cocoa/AutomationSessionClient.mm:
+        (WebKit::AutomationSessionClient::AutomationSessionClient):
+        (WebKit::toImpl):
+        (WebKit::AutomationSessionClient::currentPresentationOfPage):
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::toProtocol):
+        (WebKit::WebAutomationSession::createBrowsingContext):
+        Add plumbing between ObjC delegate and C++.
+
+        * UIProcess/Automation/Automation.json:
+        Include the initial presentation in the createBrowsingContext command result.
+
 2019-01-14  Alex Christensen  <[email protected]>
 
         Split headerValueForVary into specialized functions for NetworkProcess and WebProcess/WebKitLegacy

Modified: trunk/Source/WebKit/UIProcess/API/APIAutomationSessionClient.h (239987 => 239988)


--- trunk/Source/WebKit/UIProcess/API/APIAutomationSessionClient.h	2019-01-15 16:31:05 UTC (rev 239987)
+++ trunk/Source/WebKit/UIProcess/API/APIAutomationSessionClient.h	2019-01-15 17:15:44 UTC (rev 239988)
@@ -49,6 +49,11 @@
         BeforeUnloadConfirm
     };
 
+    enum class BrowsingContextPresentation {
+        Tab,
+        Window,
+    };
+
     virtual ~AutomationSessionClient() { }
 
     virtual WTF::String sessionIdentifier() const { return WTF::String(); }
@@ -64,6 +69,7 @@
     virtual WTF::String messageOfCurrentJavaScriptDialogOnPage(WebKit::WebAutomationSession&, WebKit::WebPageProxy&) { return WTF::String(); }
     virtual void setUserInputForCurrentJavaScriptPromptOnPage(WebKit::WebAutomationSession&, WebKit::WebPageProxy&, const WTF::String&) { }
     virtual Optional<_javascript_DialogType> typeOfCurrentJavaScriptDialogOnPage(WebKit::WebAutomationSession&, WebKit::WebPageProxy&) { return WTF::nullopt; }
+    virtual BrowsingContextPresentation currentPresentationOfPage(WebKit::WebAutomationSession&, WebKit::WebPageProxy&) { return BrowsingContextPresentation::Window; }
 };
 
 } // namespace API

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h (239987 => 239988)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h	2019-01-15 16:31:05 UTC (rev 239987)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h	2019-01-15 17:15:44 UTC (rev 239988)
@@ -46,6 +46,11 @@
     _WKAutomationSessionBrowsingContextOptionsPreferNewTab = 1 << 0,
 } WK_API_AVAILABLE(macosx(10.14), ios(12.0));
 
+typedef NS_ENUM(NSInteger, _WKAutomationSessionBrowsingContextPresentation) {
+    _WKAutomationSessionBrowsingContextPresentationTab,
+    _WKAutomationSessionBrowsingContextPresentationWindow,
+} WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @protocol _WKAutomationSessionDelegate <NSObject>
 @optional
 
@@ -62,6 +67,7 @@
 - (nullable NSString *)_automationSession:(_WKAutomationSession *)automationSession messageOfCurrentJavaScriptDialogForWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 - (void)_automationSession:(_WKAutomationSession *)automationSession setUserInput:(NSString *)value forCurrentJavaScriptDialogForWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 - (_WKAutomationSessionJavaScriptDialogType)_automationSession:(_WKAutomationSession *)automationSession typeOfCurrentJavaScriptDialogForWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(10.14), ios(12.0));
+- (_WKAutomationSessionBrowsingContextPresentation)_automationSession:(_WKAutomationSession *)automationSession currentPresentationForWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @end
 

Modified: trunk/Source/WebKit/UIProcess/Automation/Automation.json (239987 => 239988)


--- trunk/Source/WebKit/UIProcess/Automation/Automation.json	2019-01-15 16:31:05 UTC (rev 239987)
+++ trunk/Source/WebKit/UIProcess/Automation/Automation.json	2019-01-15 17:15:44 UTC (rev 239988)
@@ -42,6 +42,15 @@
             "description": "An opaque identifier for a browsing context."
         },
         {
+            "id": "BrowsingContextPresentation",
+            "type": "string",
+            "description": "How a browsing context is presented by the user agent. A browsing context is considered a tab if it shares an OS-level window with another browsing context.",
+            "enum": [
+                "Window",
+                "Tab"
+            ]
+        },
+        {
             "id": "FrameHandle",
             "type": "string",
             "description": "An opaque identifier for a frame in a page."
@@ -323,10 +332,11 @@
             "name": "createBrowsingContext",
             "description": "Opens a new browsing context in the automation session and makes it the active browsing context for user interaction. This command creates a browsing context in a new window rather than adding a tab to an existing window.",
             "parameters": [
-                { "name": "preferNewTab", "type": "boolean", "optional": true, "description": "Create the new browsing context as a tab in an existing Automation window, if possible."}
+                { "name": "presentationHint", "$ref": "BrowsingContextPresentation", "optional": true, "description": "A hint for the desired presentation of new browsing context (new tab or new window)."}
             ],
             "returns": [
-                { "name": "handle", "$ref": "BrowsingContextHandle", "description": "An opaque handle for the newly created browsing context." }
+                { "name": "handle", "$ref": "BrowsingContextHandle", "description": "An opaque handle for the newly created browsing context." },
+                { "name": "presentation", "$ref": "BrowsingContextPresentation", "description": "How the browser presented the new browsing context (new tab or new window)." }
             ],
             "async": true
         },

Modified: trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp (239987 => 239988)


--- trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2019-01-15 16:31:05 UTC (rev 239987)
+++ trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2019-01-15 17:15:44 UTC (rev 239988)
@@ -298,21 +298,35 @@
     });
 }
 
-void WebAutomationSession::createBrowsingContext(const bool* preferNewTab, Ref<CreateBrowsingContextCallback>&& callback)
+static Inspector::Protocol::Automation::BrowsingContextPresentation toProtocol(API::AutomationSessionClient::BrowsingContextPresentation value)
 {
+    switch (value) {
+    case API::AutomationSessionClient::BrowsingContextPresentation::Tab:
+        return Inspector::Protocol::Automation::BrowsingContextPresentation::Tab;
+    case API::AutomationSessionClient::BrowsingContextPresentation::Window:
+        return Inspector::Protocol::Automation::BrowsingContextPresentation::Window;
+    }
+}
+
+void WebAutomationSession::createBrowsingContext(const String* optionalPresentationHint, Ref<CreateBrowsingContextCallback>&& callback)
+{
     ASSERT(m_client);
     if (!m_client)
         ASYNC_FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InternalError, "The remote session could not request a new browsing context.");
 
     uint16_t options = 0;
-    if (preferNewTab && *preferNewTab)
-        options |= API::AutomationSessionBrowsingContextOptionsPreferNewTab;
 
+    if (optionalPresentationHint) {
+        auto parsedPresentationHint = Inspector::Protocol::AutomationHelpers::parseEnumValueFromString<Inspector::Protocol::Automation::BrowsingContextPresentation>(*optionalPresentationHint);
+        if (parsedPresentationHint.hasValue() && parsedPresentationHint.value() == Inspector::Protocol::Automation::BrowsingContextPresentation::Tab)
+            options |= API::AutomationSessionBrowsingContextOptionsPreferNewTab;
+    }
+
     m_client->requestNewPageWithOptions(*this, static_cast<API::AutomationSessionBrowsingContextOptions>(options), [protectedThis = makeRef(*this), callback = WTFMove(callback)](WebPageProxy* page) {
-        if (page)
-            callback->sendSuccess(protectedThis->handleForWebPageProxy(*page));
-        else
+        if (!page)
             ASYNC_FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InternalError, "The remote session failed to create a new browsing context.");
+
+        callback->sendSuccess(protectedThis->handleForWebPageProxy(*page), toProtocol(protectedThis->m_client->currentPresentationOfPage(protectedThis.get(), *page)));
     });
 }
 

Modified: trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.h (239987 => 239988)


--- trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.h	2019-01-15 16:31:05 UTC (rev 239987)
+++ trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.h	2019-01-15 17:15:44 UTC (rev 239988)
@@ -147,7 +147,7 @@
     // Platform: Generic
     void getBrowsingContexts(Ref<GetBrowsingContextsCallback>&&) final;
     void getBrowsingContext(const String&, Ref<GetBrowsingContextCallback>&&) final;
-    void createBrowsingContext(const bool* preferNewTab, Ref<CreateBrowsingContextCallback>&&) final;
+    void createBrowsingContext(const String* optionalPresentationHint, Ref<CreateBrowsingContextCallback>&&) final;
     void closeBrowsingContext(Inspector::ErrorString&, const String&) final;
     void switchToBrowsingContext(const String& browsingContextHandle, const String* optionalFrameHandle, Ref<SwitchToBrowsingContextCallback>&&) final;
     void setWindowFrameOfBrowsingContext(const String& handle, const JSON::Object* origin, const JSON::Object* size, Ref<SetWindowFrameOfBrowsingContextCallback>&&) final;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.h (239987 => 239988)


--- trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.h	2019-01-15 16:31:05 UTC (rev 239987)
+++ trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.h	2019-01-15 17:15:44 UTC (rev 239988)
@@ -57,6 +57,7 @@
     String messageOfCurrentJavaScriptDialogOnPage(WebAutomationSession&, WebPageProxy&) override;
     void setUserInputForCurrentJavaScriptPromptOnPage(WebAutomationSession&, WebPageProxy&, const String&) override;
     Optional<API::AutomationSessionClient::_javascript_DialogType> typeOfCurrentJavaScriptDialogOnPage(WebAutomationSession&, WebPageProxy&) override;
+    API::AutomationSessionClient::BrowsingContextPresentation currentPresentationOfPage(WebAutomationSession&, WebPageProxy&) override;
 
     WeakObjCPtr<id <_WKAutomationSessionDelegate>> m_delegate;
 
@@ -74,6 +75,7 @@
         bool messageOfCurrentJavaScriptDialogForWebView : 1;
         bool setUserInputForCurrentJavaScriptPromptForWebView : 1;
         bool typeOfCurrentJavaScriptDialogForWebView : 1;
+        bool currentPresentationForWebView : 1;
     } m_delegateMethods;
 };
 

Modified: trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.mm (239987 => 239988)


--- trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.mm	2019-01-15 16:31:05 UTC (rev 239987)
+++ trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.mm	2019-01-15 17:15:44 UTC (rev 239988)
@@ -54,6 +54,7 @@
     m_delegateMethods.messageOfCurrentJavaScriptDialogForWebView = [delegate respondsToSelector:@selector(_automationSession:messageOfCurrentJavaScriptDialogForWebView:)];
     m_delegateMethods.setUserInputForCurrentJavaScriptPromptForWebView = [delegate respondsToSelector:@selector(_automationSession:setUserInput:forCurrentJavaScriptDialogForWebView:)];
     m_delegateMethods.typeOfCurrentJavaScriptDialogForWebView = [delegate respondsToSelector:@selector(_automationSession:typeOfCurrentJavaScriptDialogForWebView:)];
+    m_delegateMethods.currentPresentationForWebView = [delegate respondsToSelector:@selector(_automationSession:currentPresentationForWebView:)];
 }
 
 void AutomationSessionClient::didDisconnectFromRemote(WebAutomationSession& session)
@@ -153,6 +154,16 @@
     }
 }
 
+static API::AutomationSessionClient::BrowsingContextPresentation toImpl(_WKAutomationSessionBrowsingContextPresentation presentation)
+{
+    switch (presentation) {
+    case _WKAutomationSessionBrowsingContextPresentationTab:
+        return API::AutomationSessionClient::BrowsingContextPresentation::Tab;
+    case _WKAutomationSessionBrowsingContextPresentationWindow:
+        return API::AutomationSessionClient::BrowsingContextPresentation::Window;
+    }
+}
+
 Optional<API::AutomationSessionClient::_javascript_DialogType> AutomationSessionClient::typeOfCurrentJavaScriptDialogOnPage(WebAutomationSession& session, WebPageProxy& page)
 {
     if (m_delegateMethods.typeOfCurrentJavaScriptDialogForWebView)
@@ -161,6 +172,14 @@
     return API::AutomationSessionClient::_javascript_DialogType::Prompt;
 }
 
+API::AutomationSessionClient::BrowsingContextPresentation AutomationSessionClient::currentPresentationOfPage(WebAutomationSession& session, WebPageProxy& page)
+{
+    if (m_delegateMethods.currentPresentationForWebView)
+        return toImpl([m_delegate.get() _automationSession:wrapper(session) currentPresentationForWebView:fromWebPageProxy(page)]);
+
+    return API::AutomationSessionClient::BrowsingContextPresentation::Window;
+}
+
 } // namespace WebKit
 
 #endif // WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to