Title: [198740] trunk/Source/WebKit2
Revision
198740
Author
timo...@apple.com
Date
2016-03-28 08:57:49 -0700 (Mon, 28 Mar 2016)

Log Message

Web Automation: Add Automation protocol commands to handle _javascript_ dialogs

https://bugs.webkit.org/show_bug.cgi?id=155888
rdar://problem/25360218

Reviewed by Brian Burg.

* UIProcess/API/APIAutomationSessionClient.h:
(API::AutomationSessionClient::isShowingJavaScriptDialogOnPage): Added.
(API::AutomationSessionClient::dismissCurrentJavaScriptDialogOnPage): Added.
(API::AutomationSessionClient::acceptCurrentJavaScriptDialogOnPage): Added.
(API::AutomationSessionClient::messageOfCurrentJavaScriptDialogOnPage): Added.
(API::AutomationSessionClient::setUserInputForCurrentJavaScriptPromptOnPage): Added.

* UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h:

* UIProcess/Automation/Automation.json: Added new commands.

* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::isShowingJavaScriptDialog): Added.
(WebKit::WebAutomationSession::dismissCurrentJavaScriptDialog): Added.
(WebKit::WebAutomationSession::acceptCurrentJavaScriptDialog): Added.
(WebKit::WebAutomationSession::messageOfCurrentJavaScriptDialog): Added.
(WebKit::WebAutomationSession::setUserInputForCurrentJavaScriptPrompt): Added.
* UIProcess/Automation/WebAutomationSession.h:

* UIProcess/Cocoa/AutomationSessionClient.h:
* UIProcess/Cocoa/AutomationSessionClient.mm:
(WebKit::AutomationSessionClient::AutomationSessionClient): Added.
(WebKit::AutomationSessionClient::isShowingJavaScriptDialogOnPage): Added.
(WebKit::AutomationSessionClient::dismissCurrentJavaScriptDialogOnPage): Added.
(WebKit::AutomationSessionClient::acceptCurrentJavaScriptDialogOnPage): Added.
(WebKit::AutomationSessionClient::messageOfCurrentJavaScriptDialogOnPage): Added.
(WebKit::AutomationSessionClient::setUserInputForCurrentJavaScriptPromptOnPage): Added.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (198739 => 198740)


--- trunk/Source/WebKit2/ChangeLog	2016-03-28 15:57:37 UTC (rev 198739)
+++ trunk/Source/WebKit2/ChangeLog	2016-03-28 15:57:49 UTC (rev 198740)
@@ -1,3 +1,40 @@
+2016-03-25  Timothy Hatcher  <timo...@apple.com>
+
+        Web Automation: Add Automation protocol commands to handle _javascript_ dialogs
+
+        https://bugs.webkit.org/show_bug.cgi?id=155888
+        rdar://problem/25360218
+
+        Reviewed by Brian Burg.
+
+        * UIProcess/API/APIAutomationSessionClient.h:
+        (API::AutomationSessionClient::isShowingJavaScriptDialogOnPage): Added.
+        (API::AutomationSessionClient::dismissCurrentJavaScriptDialogOnPage): Added.
+        (API::AutomationSessionClient::acceptCurrentJavaScriptDialogOnPage): Added.
+        (API::AutomationSessionClient::messageOfCurrentJavaScriptDialogOnPage): Added.
+        (API::AutomationSessionClient::setUserInputForCurrentJavaScriptPromptOnPage): Added.
+
+        * UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h:
+
+        * UIProcess/Automation/Automation.json: Added new commands.
+
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::WebAutomationSession::isShowingJavaScriptDialog): Added.
+        (WebKit::WebAutomationSession::dismissCurrentJavaScriptDialog): Added.
+        (WebKit::WebAutomationSession::acceptCurrentJavaScriptDialog): Added.
+        (WebKit::WebAutomationSession::messageOfCurrentJavaScriptDialog): Added.
+        (WebKit::WebAutomationSession::setUserInputForCurrentJavaScriptPrompt): Added.
+        * UIProcess/Automation/WebAutomationSession.h:
+
+        * UIProcess/Cocoa/AutomationSessionClient.h:
+        * UIProcess/Cocoa/AutomationSessionClient.mm:
+        (WebKit::AutomationSessionClient::AutomationSessionClient): Added.
+        (WebKit::AutomationSessionClient::isShowingJavaScriptDialogOnPage): Added.
+        (WebKit::AutomationSessionClient::dismissCurrentJavaScriptDialogOnPage): Added.
+        (WebKit::AutomationSessionClient::acceptCurrentJavaScriptDialogOnPage): Added.
+        (WebKit::AutomationSessionClient::messageOfCurrentJavaScriptDialogOnPage): Added.
+        (WebKit::AutomationSessionClient::setUserInputForCurrentJavaScriptPromptOnPage): Added.
+
 2016-03-24  Timothy Hatcher  <timo...@apple.com>
 
         Web Automation: Add commands to compute layout of an element

Modified: trunk/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h (198739 => 198740)


--- trunk/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h	2016-03-28 15:57:37 UTC (rev 198739)
+++ trunk/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h	2016-03-28 15:57:49 UTC (rev 198740)
@@ -42,6 +42,11 @@
     virtual String sessionIdentifier() const { return String(); }
     virtual void didDisconnectFromRemote(WebKit::WebAutomationSession*) { }
     virtual WebKit::WebPageProxy* didRequestNewWindow(WebKit::WebAutomationSession*) { return nullptr; }
+    virtual bool isShowingJavaScriptDialogOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*) { return false; }
+    virtual void dismissCurrentJavaScriptDialogOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*) { }
+    virtual void acceptCurrentJavaScriptDialogOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*) { }
+    virtual String messageOfCurrentJavaScriptDialogOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*) { return String(); }
+    virtual void setUserInputForCurrentJavaScriptPromptOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*, const String&) { }
 };
 
 } // namespace API

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h (198739 => 198740)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h	2016-03-28 15:57:37 UTC (rev 198739)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h	2016-03-28 15:57:49 UTC (rev 198740)
@@ -36,6 +36,12 @@
 @optional
 - (WKPageRef)_automationSessionDidRequestNewWindow:(_WKAutomationSession *)automationSession;
 - (void)_automationSessionDidDisconnectFromRemote:(_WKAutomationSession *)automationSession;
+
+- (BOOL)_automationSession:(_WKAutomationSession *)automationSession isShowingJavaScriptDialogOnPage:(WKPageRef)page;
+- (void)_automationSession:(_WKAutomationSession *)automationSession dismissCurrentJavaScriptDialogOnPage:(WKPageRef)page;
+- (void)_automationSession:(_WKAutomationSession *)automationSession acceptCurrentJavaScriptDialogOnPage:(WKPageRef)page;
+- (NSString *)_automationSession:(_WKAutomationSession *)automationSession messageOfCurrentJavaScriptDialogOnPage:(WKPageRef)page;
+- (void)_automationSession:(_WKAutomationSession *)automationSession setUserInput:(NSString *)value forCurrentJavaScriptDialogOnPage:(WKPageRef)page;
 @end
 
 #endif // WK_API_ENABLED

Modified: trunk/Source/WebKit2/UIProcess/Automation/Automation.json (198739 => 198740)


--- trunk/Source/WebKit2/UIProcess/Automation/Automation.json	2016-03-28 15:57:37 UTC (rev 198739)
+++ trunk/Source/WebKit2/UIProcess/Automation/Automation.json	2016-03-28 15:57:49 UTC (rev 198740)
@@ -51,6 +51,7 @@
                 "WindowNotFound",
                 "FrameNotFound",
                 "NodeNotFound",
+                "NoJavaScriptDialog",
                 "NotImplemented",
                 "MissingParameter"
             ]
@@ -191,6 +192,48 @@
                 { "name": "rect", "$ref": "Rect", "description": "The layout rect for the requested element. Specified in page or viewport coordinates based on the useViewportCoordinates parameter." }
             ],
             "async": true
+        },
+        {
+            "name": "isShowingJavaScriptDialog",
+            "description": "Checks if a browsing context is showing a _javascript_ alert, confirm, or prompt dialog.",
+            "parameters": [
+                { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." }
+            ],
+            "returns": [
+                { "name": "result", "type": "boolean", "description": "If the browsing context is showing a _javascript_ dialog or not." }
+            ]
+        },
+        {
+            "name": "dismissCurrentJavaScriptDialog",
+            "description": "Dismisses a _javascript_ alert, confirm, or prompt dialog currently showing in a browsing context. Equivalent to clicking the 'Cancel' button.",
+            "parameters": [
+                { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." }
+            ]
+        },
+        {
+            "name": "acceptCurrentJavaScriptDialog",
+            "description": "Accepts a _javascript_ alert, confirm, or prompt dialog currently showing in a browsing context. Equivalent to clicking the 'OK' button.",
+            "parameters": [
+                { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." }
+            ]
+        },
+        {
+            "name": "messageOfCurrentJavaScriptDialog",
+            "description": "Returns the text displayed in a _javascript_ alert, confirm, or prompt dialog currently showing in a browsing context.",
+            "parameters": [
+                { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." }
+            ],
+            "returns": [
+                { "name": "message", "type": "string", "description": "Text being displayed in the current _javascript_ dialog." }
+            ]
+        },
+        {
+            "name": "setUserInputForCurrentJavaScriptPrompt",
+            "description": "Sets the user entered value in a _javascript_ prompt dialog currently showing in a browsing context.",
+            "parameters": [
+                { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." },
+                { "name": "userInput", "type": "string", "description": "The text to enter in the prompt." }
+            ]
         }
     ]
 }

Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp (198739 => 198740)


--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp	2016-03-28 15:57:37 UTC (rev 198739)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp	2016-03-28 15:57:49 UTC (rev 198740)
@@ -465,4 +465,81 @@
     callback->sendSuccess(WTFMove(rectObject));
 }
 
+void WebAutomationSession::isShowingJavaScriptDialog(Inspector::ErrorString& errorString, const String& browsingContextHandle, bool* result)
+{
+    ASSERT(m_client);
+    if (!m_client)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
+
+    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    *result = m_client->isShowingJavaScriptDialogOnPage(this, page);
+}
+
+void WebAutomationSession::dismissCurrentJavaScriptDialog(Inspector::ErrorString& errorString, const String& browsingContextHandle)
+{
+    ASSERT(m_client);
+    if (!m_client)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
+
+    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    if (!m_client->isShowingJavaScriptDialogOnPage(this, page))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NoJavaScriptDialog);
+
+    m_client->dismissCurrentJavaScriptDialogOnPage(this, page);
+}
+
+void WebAutomationSession::acceptCurrentJavaScriptDialog(Inspector::ErrorString& errorString, const String& browsingContextHandle)
+{
+    ASSERT(m_client);
+    if (!m_client)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
+
+    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    if (!m_client->isShowingJavaScriptDialogOnPage(this, page))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NoJavaScriptDialog);
+
+    m_client->acceptCurrentJavaScriptDialogOnPage(this, page);
+}
+
+void WebAutomationSession::messageOfCurrentJavaScriptDialog(Inspector::ErrorString& errorString, const String& browsingContextHandle, String* text)
+{
+    ASSERT(m_client);
+    if (!m_client)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
+
+    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    if (!m_client->isShowingJavaScriptDialogOnPage(this, page))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NoJavaScriptDialog);
+
+    *text = m_client->messageOfCurrentJavaScriptDialogOnPage(this, page);
+}
+
+void WebAutomationSession::setUserInputForCurrentJavaScriptPrompt(Inspector::ErrorString& errorString, const String& browsingContextHandle, const String& promptValue)
+{
+    ASSERT(m_client);
+    if (!m_client)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
+
+    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    if (!m_client->isShowingJavaScriptDialogOnPage(this, page))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NoJavaScriptDialog);
+
+    m_client->setUserInputForCurrentJavaScriptPromptOnPage(this, page, promptValue);
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h (198739 => 198740)


--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h	2016-03-28 15:57:37 UTC (rev 198739)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h	2016-03-28 15:57:49 UTC (rev 198740)
@@ -95,6 +95,11 @@
     void resolveChildFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const int* optionalOrdinal, const String* optionalName, const String* optionalNodeHandle, Ref<ResolveChildFrameHandleCallback>&&) override;
     void resolveParentFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, Ref<ResolveParentFrameHandleCallback>&&) override;
     void computeElementLayout(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, const String& nodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* useViewportCoordinates, Ref<Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback>&&) override;
+    void isShowingJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle, bool* result) override;
+    void dismissCurrentJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle) override;
+    void acceptCurrentJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle) override;
+    void messageOfCurrentJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle, String* text) override;
+    void setUserInputForCurrentJavaScriptPrompt(Inspector::ErrorString&, const String& browsingContextHandle, const String& text) override;
 
 private:
     WebPageProxy* webPageProxyForHandle(const String&);

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.h (198739 => 198740)


--- trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.h	2016-03-28 15:57:37 UTC (rev 198739)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.h	2016-03-28 15:57:49 UTC (rev 198740)
@@ -43,14 +43,25 @@
 
 private:
     // From API::AutomationSessionClient
-    WebPageProxy* didRequestNewWindow(WebKit::WebAutomationSession*) override;
-    void didDisconnectFromRemote(WebKit::WebAutomationSession *) override;
+    WebPageProxy* didRequestNewWindow(WebAutomationSession*) override;
+    void didDisconnectFromRemote(WebAutomationSession *) override;
 
+    bool isShowingJavaScriptDialogOnPage(WebAutomationSession*, WebPageProxy*) override;
+    void dismissCurrentJavaScriptDialogOnPage(WebAutomationSession*, WebPageProxy*) override;
+    void acceptCurrentJavaScriptDialogOnPage(WebAutomationSession*, WebPageProxy*) override;
+    String messageOfCurrentJavaScriptDialogOnPage(WebAutomationSession*, WebPageProxy*) override;
+    void setUserInputForCurrentJavaScriptPromptOnPage(WebAutomationSession*, WebPageProxy*, const String&) override;
+
     WeakObjCPtr<id <_WKAutomationSessionDelegate>> m_delegate;
 
     struct {
         bool didRequestNewWindow : 1;
         bool didDisconnectFromRemote : 1;
+        bool isShowingJavaScriptDialogOnPage : 1;
+        bool dismissCurrentJavaScriptDialogOnPage : 1;
+        bool acceptCurrentJavaScriptDialogOnPage : 1;
+        bool messageOfCurrentJavaScriptDialogOnPage : 1;
+        bool setUserInputForCurrentJavaScriptPromptOnPage : 1;
     } m_delegateMethods;
 };
 

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.mm (198739 => 198740)


--- trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.mm	2016-03-28 15:57:37 UTC (rev 198739)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.mm	2016-03-28 15:57:49 UTC (rev 198740)
@@ -41,6 +41,11 @@
 {
     m_delegateMethods.didRequestNewWindow = [delegate respondsToSelector:@selector(_automationSessionDidRequestNewWindow:)];
     m_delegateMethods.didDisconnectFromRemote = [delegate respondsToSelector:@selector(_automationSessionDidDisconnectFromRemote:)];
+    m_delegateMethods.isShowingJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:isShowingJavaScriptDialogOnPage:)];
+    m_delegateMethods.dismissCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:dismissCurrentJavaScriptDialogOnPage:)];
+    m_delegateMethods.acceptCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:acceptCurrentJavaScriptDialogOnPage:)];
+    m_delegateMethods.messageOfCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:messageOfCurrentJavaScriptDialogOnPage:)];
+    m_delegateMethods.setUserInputForCurrentJavaScriptPromptOnPage = [delegate respondsToSelector:@selector(_automationSession:setUserInput:forCurrentJavaScriptDialogOnPage:)];
 }
 
 WebPageProxy* AutomationSessionClient::didRequestNewWindow(WebAutomationSession* session)
@@ -56,6 +61,38 @@
         [m_delegate.get() _automationSessionDidDisconnectFromRemote:wrapper(*session)];
 }
 
+bool AutomationSessionClient::isShowingJavaScriptDialogOnPage(WebAutomationSession* session, WebPageProxy* page)
+{
+    if (m_delegateMethods.isShowingJavaScriptDialogOnPage)
+        return [m_delegate.get() _automationSession:wrapper(*session) isShowingJavaScriptDialogOnPage:toAPI(page)];
+    return false;
+}
+
+void AutomationSessionClient::dismissCurrentJavaScriptDialogOnPage(WebAutomationSession* session, WebPageProxy* page)
+{
+    if (m_delegateMethods.dismissCurrentJavaScriptDialogOnPage)
+        [m_delegate.get() _automationSession:wrapper(*session) dismissCurrentJavaScriptDialogOnPage:toAPI(page)];
+}
+
+void AutomationSessionClient::acceptCurrentJavaScriptDialogOnPage(WebAutomationSession* session, WebPageProxy* page)
+{
+    if (m_delegateMethods.acceptCurrentJavaScriptDialogOnPage)
+        [m_delegate.get() _automationSession:wrapper(*session) acceptCurrentJavaScriptDialogOnPage:toAPI(page)];
+}
+
+String AutomationSessionClient::messageOfCurrentJavaScriptDialogOnPage(WebAutomationSession* session, WebPageProxy* page)
+{
+    if (m_delegateMethods.messageOfCurrentJavaScriptDialogOnPage)
+        return [m_delegate.get() _automationSession:wrapper(*session) messageOfCurrentJavaScriptDialogOnPage:toAPI(page)];
+    return String();
+}
+
+void AutomationSessionClient::setUserInputForCurrentJavaScriptPromptOnPage(WebAutomationSession* session, WebPageProxy* page, const String& value)
+{
+    if (m_delegateMethods.setUserInputForCurrentJavaScriptPromptOnPage)
+        [m_delegate.get() _automationSession:wrapper(*session) setUserInput:value forCurrentJavaScriptDialogOnPage:toAPI(page)];
+}
+
 } // namespace WebKit
 
 #endif // WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to