Changeset 198740 in webkit


Ignore:
Timestamp:
Mar 28, 2016 8:57:49 AM (8 years ago)
Author:
timothy@apple.com
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.

Location:
trunk/Source/WebKit2
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r198739 r198740  
     12016-03-25  Timothy Hatcher  <timothy@apple.com>
     2
     3        Web Automation: Add Automation protocol commands to handle JavaScript dialogs
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=155888
     6        rdar://problem/25360218
     7
     8        Reviewed by Brian Burg.
     9
     10        * UIProcess/API/APIAutomationSessionClient.h:
     11        (API::AutomationSessionClient::isShowingJavaScriptDialogOnPage): Added.
     12        (API::AutomationSessionClient::dismissCurrentJavaScriptDialogOnPage): Added.
     13        (API::AutomationSessionClient::acceptCurrentJavaScriptDialogOnPage): Added.
     14        (API::AutomationSessionClient::messageOfCurrentJavaScriptDialogOnPage): Added.
     15        (API::AutomationSessionClient::setUserInputForCurrentJavaScriptPromptOnPage): Added.
     16
     17        * UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h:
     18
     19        * UIProcess/Automation/Automation.json: Added new commands.
     20
     21        * UIProcess/Automation/WebAutomationSession.cpp:
     22        (WebKit::WebAutomationSession::isShowingJavaScriptDialog): Added.
     23        (WebKit::WebAutomationSession::dismissCurrentJavaScriptDialog): Added.
     24        (WebKit::WebAutomationSession::acceptCurrentJavaScriptDialog): Added.
     25        (WebKit::WebAutomationSession::messageOfCurrentJavaScriptDialog): Added.
     26        (WebKit::WebAutomationSession::setUserInputForCurrentJavaScriptPrompt): Added.
     27        * UIProcess/Automation/WebAutomationSession.h:
     28
     29        * UIProcess/Cocoa/AutomationSessionClient.h:
     30        * UIProcess/Cocoa/AutomationSessionClient.mm:
     31        (WebKit::AutomationSessionClient::AutomationSessionClient): Added.
     32        (WebKit::AutomationSessionClient::isShowingJavaScriptDialogOnPage): Added.
     33        (WebKit::AutomationSessionClient::dismissCurrentJavaScriptDialogOnPage): Added.
     34        (WebKit::AutomationSessionClient::acceptCurrentJavaScriptDialogOnPage): Added.
     35        (WebKit::AutomationSessionClient::messageOfCurrentJavaScriptDialogOnPage): Added.
     36        (WebKit::AutomationSessionClient::setUserInputForCurrentJavaScriptPromptOnPage): Added.
     37
    1382016-03-24  Timothy Hatcher  <timothy@apple.com>
    239
  • trunk/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h

    r197621 r198740  
    4343    virtual void didDisconnectFromRemote(WebKit::WebAutomationSession*) { }
    4444    virtual WebKit::WebPageProxy* didRequestNewWindow(WebKit::WebAutomationSession*) { return nullptr; }
     45    virtual bool isShowingJavaScriptDialogOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*) { return false; }
     46    virtual void dismissCurrentJavaScriptDialogOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*) { }
     47    virtual void acceptCurrentJavaScriptDialogOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*) { }
     48    virtual String messageOfCurrentJavaScriptDialogOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*) { return String(); }
     49    virtual void setUserInputForCurrentJavaScriptPromptOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*, const String&) { }
    4550};
    4651
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h

    r197621 r198740  
    3737- (WKPageRef)_automationSessionDidRequestNewWindow:(_WKAutomationSession *)automationSession;
    3838- (void)_automationSessionDidDisconnectFromRemote:(_WKAutomationSession *)automationSession;
     39
     40- (BOOL)_automationSession:(_WKAutomationSession *)automationSession isShowingJavaScriptDialogOnPage:(WKPageRef)page;
     41- (void)_automationSession:(_WKAutomationSession *)automationSession dismissCurrentJavaScriptDialogOnPage:(WKPageRef)page;
     42- (void)_automationSession:(_WKAutomationSession *)automationSession acceptCurrentJavaScriptDialogOnPage:(WKPageRef)page;
     43- (NSString *)_automationSession:(_WKAutomationSession *)automationSession messageOfCurrentJavaScriptDialogOnPage:(WKPageRef)page;
     44- (void)_automationSession:(_WKAutomationSession *)automationSession setUserInput:(NSString *)value forCurrentJavaScriptDialogOnPage:(WKPageRef)page;
    3945@end
    4046
  • trunk/Source/WebKit2/UIProcess/Automation/Automation.json

    r198739 r198740  
    5252                "FrameNotFound",
    5353                "NodeNotFound",
     54                "NoJavaScriptDialog",
    5455                "NotImplemented",
    5556                "MissingParameter"
     
    192193            ],
    193194            "async": true
     195        },
     196        {
     197            "name": "isShowingJavaScriptDialog",
     198            "description": "Checks if a browsing context is showing a JavaScript alert, confirm, or prompt dialog.",
     199            "parameters": [
     200                { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." }
     201            ],
     202            "returns": [
     203                { "name": "result", "type": "boolean", "description": "If the browsing context is showing a JavaScript dialog or not." }
     204            ]
     205        },
     206        {
     207            "name": "dismissCurrentJavaScriptDialog",
     208            "description": "Dismisses a JavaScript alert, confirm, or prompt dialog currently showing in a browsing context. Equivalent to clicking the 'Cancel' button.",
     209            "parameters": [
     210                { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." }
     211            ]
     212        },
     213        {
     214            "name": "acceptCurrentJavaScriptDialog",
     215            "description": "Accepts a JavaScript alert, confirm, or prompt dialog currently showing in a browsing context. Equivalent to clicking the 'OK' button.",
     216            "parameters": [
     217                { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." }
     218            ]
     219        },
     220        {
     221            "name": "messageOfCurrentJavaScriptDialog",
     222            "description": "Returns the text displayed in a JavaScript alert, confirm, or prompt dialog currently showing in a browsing context.",
     223            "parameters": [
     224                { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." }
     225            ],
     226            "returns": [
     227                { "name": "message", "type": "string", "description": "Text being displayed in the current JavaScript dialog." }
     228            ]
     229        },
     230        {
     231            "name": "setUserInputForCurrentJavaScriptPrompt",
     232            "description": "Sets the user entered value in a JavaScript prompt dialog currently showing in a browsing context.",
     233            "parameters": [
     234                { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." },
     235                { "name": "userInput", "type": "string", "description": "The text to enter in the prompt." }
     236            ]
    194237        }
    195238    ]
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp

    r198739 r198740  
    466466}
    467467
     468void WebAutomationSession::isShowingJavaScriptDialog(Inspector::ErrorString& errorString, const String& browsingContextHandle, bool* result)
     469{
     470    ASSERT(m_client);
     471    if (!m_client)
     472        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
     473
     474    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
     475    if (!page)
     476        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     477
     478    *result = m_client->isShowingJavaScriptDialogOnPage(this, page);
     479}
     480
     481void WebAutomationSession::dismissCurrentJavaScriptDialog(Inspector::ErrorString& errorString, const String& browsingContextHandle)
     482{
     483    ASSERT(m_client);
     484    if (!m_client)
     485        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
     486
     487    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
     488    if (!page)
     489        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     490
     491    if (!m_client->isShowingJavaScriptDialogOnPage(this, page))
     492        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NoJavaScriptDialog);
     493
     494    m_client->dismissCurrentJavaScriptDialogOnPage(this, page);
     495}
     496
     497void WebAutomationSession::acceptCurrentJavaScriptDialog(Inspector::ErrorString& errorString, const String& browsingContextHandle)
     498{
     499    ASSERT(m_client);
     500    if (!m_client)
     501        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
     502
     503    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
     504    if (!page)
     505        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     506
     507    if (!m_client->isShowingJavaScriptDialogOnPage(this, page))
     508        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NoJavaScriptDialog);
     509
     510    m_client->acceptCurrentJavaScriptDialogOnPage(this, page);
     511}
     512
     513void WebAutomationSession::messageOfCurrentJavaScriptDialog(Inspector::ErrorString& errorString, const String& browsingContextHandle, String* text)
     514{
     515    ASSERT(m_client);
     516    if (!m_client)
     517        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
     518
     519    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
     520    if (!page)
     521        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     522
     523    if (!m_client->isShowingJavaScriptDialogOnPage(this, page))
     524        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NoJavaScriptDialog);
     525
     526    *text = m_client->messageOfCurrentJavaScriptDialogOnPage(this, page);
     527}
     528
     529void WebAutomationSession::setUserInputForCurrentJavaScriptPrompt(Inspector::ErrorString& errorString, const String& browsingContextHandle, const String& promptValue)
     530{
     531    ASSERT(m_client);
     532    if (!m_client)
     533        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
     534
     535    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
     536    if (!page)
     537        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     538
     539    if (!m_client->isShowingJavaScriptDialogOnPage(this, page))
     540        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NoJavaScriptDialog);
     541
     542    m_client->setUserInputForCurrentJavaScriptPromptOnPage(this, page, promptValue);
     543}
     544
    468545} // namespace WebKit
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h

    r198739 r198740  
    9696    void resolveParentFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, Ref<ResolveParentFrameHandleCallback>&&) override;
    9797    void computeElementLayout(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, const String& nodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* useViewportCoordinates, Ref<Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback>&&) override;
     98    void isShowingJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle, bool* result) override;
     99    void dismissCurrentJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle) override;
     100    void acceptCurrentJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle) override;
     101    void messageOfCurrentJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle, String* text) override;
     102    void setUserInputForCurrentJavaScriptPrompt(Inspector::ErrorString&, const String& browsingContextHandle, const String& text) override;
    98103
    99104private:
  • trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.h

    r197621 r198740  
    4444private:
    4545    // From API::AutomationSessionClient
    46     WebPageProxy* didRequestNewWindow(WebKit::WebAutomationSession*) override;
    47     void didDisconnectFromRemote(WebKit::WebAutomationSession *) override;
     46    WebPageProxy* didRequestNewWindow(WebAutomationSession*) override;
     47    void didDisconnectFromRemote(WebAutomationSession *) override;
     48
     49    bool isShowingJavaScriptDialogOnPage(WebAutomationSession*, WebPageProxy*) override;
     50    void dismissCurrentJavaScriptDialogOnPage(WebAutomationSession*, WebPageProxy*) override;
     51    void acceptCurrentJavaScriptDialogOnPage(WebAutomationSession*, WebPageProxy*) override;
     52    String messageOfCurrentJavaScriptDialogOnPage(WebAutomationSession*, WebPageProxy*) override;
     53    void setUserInputForCurrentJavaScriptPromptOnPage(WebAutomationSession*, WebPageProxy*, const String&) override;
    4854
    4955    WeakObjCPtr<id <_WKAutomationSessionDelegate>> m_delegate;
     
    5258        bool didRequestNewWindow : 1;
    5359        bool didDisconnectFromRemote : 1;
     60        bool isShowingJavaScriptDialogOnPage : 1;
     61        bool dismissCurrentJavaScriptDialogOnPage : 1;
     62        bool acceptCurrentJavaScriptDialogOnPage : 1;
     63        bool messageOfCurrentJavaScriptDialogOnPage : 1;
     64        bool setUserInputForCurrentJavaScriptPromptOnPage : 1;
    5465    } m_delegateMethods;
    5566};
  • trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.mm

    r197621 r198740  
    4242    m_delegateMethods.didRequestNewWindow = [delegate respondsToSelector:@selector(_automationSessionDidRequestNewWindow:)];
    4343    m_delegateMethods.didDisconnectFromRemote = [delegate respondsToSelector:@selector(_automationSessionDidDisconnectFromRemote:)];
     44    m_delegateMethods.isShowingJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:isShowingJavaScriptDialogOnPage:)];
     45    m_delegateMethods.dismissCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:dismissCurrentJavaScriptDialogOnPage:)];
     46    m_delegateMethods.acceptCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:acceptCurrentJavaScriptDialogOnPage:)];
     47    m_delegateMethods.messageOfCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:messageOfCurrentJavaScriptDialogOnPage:)];
     48    m_delegateMethods.setUserInputForCurrentJavaScriptPromptOnPage = [delegate respondsToSelector:@selector(_automationSession:setUserInput:forCurrentJavaScriptDialogOnPage:)];
    4449}
    4550
     
    5762}
    5863
     64bool AutomationSessionClient::isShowingJavaScriptDialogOnPage(WebAutomationSession* session, WebPageProxy* page)
     65{
     66    if (m_delegateMethods.isShowingJavaScriptDialogOnPage)
     67        return [m_delegate.get() _automationSession:wrapper(*session) isShowingJavaScriptDialogOnPage:toAPI(page)];
     68    return false;
     69}
     70
     71void AutomationSessionClient::dismissCurrentJavaScriptDialogOnPage(WebAutomationSession* session, WebPageProxy* page)
     72{
     73    if (m_delegateMethods.dismissCurrentJavaScriptDialogOnPage)
     74        [m_delegate.get() _automationSession:wrapper(*session) dismissCurrentJavaScriptDialogOnPage:toAPI(page)];
     75}
     76
     77void AutomationSessionClient::acceptCurrentJavaScriptDialogOnPage(WebAutomationSession* session, WebPageProxy* page)
     78{
     79    if (m_delegateMethods.acceptCurrentJavaScriptDialogOnPage)
     80        [m_delegate.get() _automationSession:wrapper(*session) acceptCurrentJavaScriptDialogOnPage:toAPI(page)];
     81}
     82
     83String AutomationSessionClient::messageOfCurrentJavaScriptDialogOnPage(WebAutomationSession* session, WebPageProxy* page)
     84{
     85    if (m_delegateMethods.messageOfCurrentJavaScriptDialogOnPage)
     86        return [m_delegate.get() _automationSession:wrapper(*session) messageOfCurrentJavaScriptDialogOnPage:toAPI(page)];
     87    return String();
     88}
     89
     90void AutomationSessionClient::setUserInputForCurrentJavaScriptPromptOnPage(WebAutomationSession* session, WebPageProxy* page, const String& value)
     91{
     92    if (m_delegateMethods.setUserInputForCurrentJavaScriptPromptOnPage)
     93        [m_delegate.get() _automationSession:wrapper(*session) setUserInput:value forCurrentJavaScriptDialogOnPage:toAPI(page)];
     94}
     95
    5996} // namespace WebKit
    6097
Note: See TracChangeset for help on using the changeset viewer.