Changeset 220394 in webkit


Ignore:
Timestamp:
Aug 8, 2017 1:29:19 AM (7 years ago)
Author:
Carlos Garcia Campos
Message:

Web Automation: setUserInputForCurrentJavaScriptPrompt should fail if current dialog is not a prompt
https://bugs.webkit.org/show_bug.cgi?id=175261

Reviewed by Brian Burg.

Source/WebDriver:

  • CommandResult.cpp:

(WebDriver::CommandResult::CommandResult): Handle ElementNotInteractable protocol error.

Source/WebKit:

According to the spec, send alert text command should fail if the current dialog is not a prompt. This patch
adds JavaScriptDialogType enum to API::AutomationSessionClient and a new virtual method to ask the client about
the type of the current dialog. WebAutomationSession::setUserInputForCurrentJavaScriptPrompt() uses the new
client method to check the type of the current dialog and fail in case it's not a prompt. Cocoa needs an
implementation, for now it always returns Prompt as the type to keep compatibility.

18.4 Send Alert Text.
https://w3c.github.io/webdriver/webdriver-spec.html#send-alert-text

This fixes selenium test testSettingTheValueOfAnAlertThrows.

  • UIProcess/API/APIAutomationSessionClient.h:

(API::AutomationSessionClient::typeOfCurrentJavaScriptDialogOnPage):

  • UIProcess/API/glib/WebKitAutomationSession.cpp:
  • UIProcess/API/glib/WebKitWebView.cpp:

(webkitWebViewGetCurrentScriptDialogType):

  • UIProcess/API/glib/WebKitWebViewPrivate.h:
  • UIProcess/Automation/Automation.json:
  • UIProcess/Automation/WebAutomationSession.cpp:

(WebKit::WebAutomationSession::setUserInputForCurrentJavaScriptPrompt):

  • UIProcess/Cocoa/AutomationSessionClient.h:
  • UIProcess/Cocoa/AutomationSessionClient.mm:

(WebKit::AutomationSessionClient::typeOfCurrentJavaScriptDialogOnPage):

Location:
trunk/Source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebDriver/ChangeLog

    r220388 r220394  
     12017-08-07  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Web Automation: setUserInputForCurrentJavaScriptPrompt should fail if current dialog is not a prompt
     4        https://bugs.webkit.org/show_bug.cgi?id=175261
     5
     6        Reviewed by Brian Burg.
     7
     8        * CommandResult.cpp:
     9        (WebDriver::CommandResult::CommandResult): Handle ElementNotInteractable protocol error.
     10
    1112017-08-07  Carlos Garcia Campos  <cgarcia@igalia.com>
    212
  • trunk/Source/WebDriver/CommandResult.cpp

    r220388 r220394  
    8989        else if (errorName == "NotImplemented")
    9090            m_errorCode = ErrorCode::UnsupportedOperation;
     91        else if (errorName == "ElementNotInteractable")
     92            m_errorCode = ErrorCode::ElementNotInteractable;
    9193        else if (errorName == "JavaScriptError")
    9294            m_errorCode = ErrorCode::JavascriptError;
  • trunk/Source/WebKit/ChangeLog

    r220393 r220394  
     12017-08-07  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Web Automation: setUserInputForCurrentJavaScriptPrompt should fail if current dialog is not a prompt
     4        https://bugs.webkit.org/show_bug.cgi?id=175261
     5
     6        Reviewed by Brian Burg.
     7
     8        According to the spec, send alert text command should fail if the current dialog is not a prompt. This patch
     9        adds JavaScriptDialogType enum to API::AutomationSessionClient and a new virtual method to ask the client about
     10        the type of the current dialog. WebAutomationSession::setUserInputForCurrentJavaScriptPrompt() uses the new
     11        client method to check the type of the current dialog and fail in case it's not a prompt. Cocoa needs an
     12        implementation, for now it always returns Prompt as the type to keep compatibility.
     13
     14        18.4 Send Alert Text.
     15        https://w3c.github.io/webdriver/webdriver-spec.html#send-alert-text
     16
     17        This fixes selenium test testSettingTheValueOfAnAlertThrows.
     18
     19        * UIProcess/API/APIAutomationSessionClient.h:
     20        (API::AutomationSessionClient::typeOfCurrentJavaScriptDialogOnPage):
     21        * UIProcess/API/glib/WebKitAutomationSession.cpp:
     22        * UIProcess/API/glib/WebKitWebView.cpp:
     23        (webkitWebViewGetCurrentScriptDialogType):
     24        * UIProcess/API/glib/WebKitWebViewPrivate.h:
     25        * UIProcess/Automation/Automation.json:
     26        * UIProcess/Automation/WebAutomationSession.cpp:
     27        (WebKit::WebAutomationSession::setUserInputForCurrentJavaScriptPrompt):
     28        * UIProcess/Cocoa/AutomationSessionClient.h:
     29        * UIProcess/Cocoa/AutomationSessionClient.mm:
     30        (WebKit::AutomationSessionClient::typeOfCurrentJavaScriptDialogOnPage):
     31
    1322017-08-08  Wenson Hsieh  <wenson_hsieh@apple.com>
    233
  • trunk/Source/WebKit/UIProcess/API/APIAutomationSessionClient.h

    r213304 r220394  
    3838class AutomationSessionClient {
    3939public:
     40    enum class JavaScriptDialogType {
     41        Alert,
     42        Confirm,
     43        Prompt,
     44        BeforeUnloadConfirm
     45    };
     46
    4047    virtual ~AutomationSessionClient() { }
    4148
     
    4855    virtual String messageOfCurrentJavaScriptDialogOnPage(WebKit::WebAutomationSession&, WebKit::WebPageProxy&) { return String(); }
    4956    virtual void setUserInputForCurrentJavaScriptPromptOnPage(WebKit::WebAutomationSession&, WebKit::WebPageProxy&, const String&) { }
     57    virtual std::optional<JavaScriptDialogType> typeOfCurrentJavaScriptDialogOnPage(WebKit::WebAutomationSession&, WebKit::WebPageProxy&) { return std::nullopt; }
    5058};
    5159
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitAutomationSession.cpp

    r220387 r220394  
    131131            return;
    132132        webkitWebViewSetCurrentScriptDialogUserInput(webView, userInput);
     133    }
     134
     135    std::optional<API::AutomationSessionClient::JavaScriptDialogType> typeOfCurrentJavaScriptDialogOnPage(WebAutomationSession&, WebPageProxy& page) override
     136    {
     137        auto* webView = webkitWebContextGetWebViewForPage(m_session->priv->webContext, &page);
     138        if (!webView)
     139            return std::nullopt;
     140        auto dialogType = webkitWebViewGetCurrentScriptDialogType(webView);
     141        if (!dialogType)
     142            return std::nullopt;
     143        switch (dialogType.value()) {
     144        case WEBKIT_SCRIPT_DIALOG_ALERT:
     145            return API::AutomationSessionClient::JavaScriptDialogType::Alert;
     146        case WEBKIT_SCRIPT_DIALOG_CONFIRM:
     147            return API::AutomationSessionClient::JavaScriptDialogType::Confirm;
     148        case WEBKIT_SCRIPT_DIALOG_PROMPT:
     149            return API::AutomationSessionClient::JavaScriptDialogType::Prompt;
     150        case WEBKIT_SCRIPT_DIALOG_BEFORE_UNLOAD_CONFIRM:
     151            return API::AutomationSessionClient::JavaScriptDialogType::BeforeUnloadConfirm;
     152        }
     153
     154        ASSERT_NOT_REACHED();
     155        return std::nullopt;
    133156    }
    134157
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp

    r220387 r220394  
    20912091}
    20922092
     2093std::optional<WebKitScriptDialogType> webkitWebViewGetCurrentScriptDialogType(WebKitWebView* webView)
     2094{
     2095    if (!webView->priv->currentScriptDialog)
     2096        return std::nullopt;
     2097
     2098    return static_cast<WebKitScriptDialogType>(webView->priv->currentScriptDialog->type);
     2099}
     2100
    20932101void webkitWebViewMakePolicyDecision(WebKitWebView* webView, WebKitPolicyDecisionType type, WebKitPolicyDecision* decision)
    20942102{
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitWebViewPrivate.h

    r220387 r220394  
    6060void webkitWebViewAcceptCurrentScriptDialog(WebKitWebView*);
    6161void webkitWebViewDismissCurrentScriptDialog(WebKitWebView*);
     62std::optional<WebKitScriptDialogType> webkitWebViewGetCurrentScriptDialogType(WebKitWebView*);
    6263void webkitWebViewMakePermissionRequest(WebKitWebView*, WebKitPermissionRequest*);
    6364void webkitWebViewMakePolicyDecision(WebKitWebView*, WebKitPolicyDecisionType, WebKitPolicyDecision*);
  • trunk/Source/WebKit/UIProcess/Automation/Automation.json

    r220314 r220394  
    5959                "MissingParameter",
    6060                "InvalidParameter",
    61                 "InvalidSelector"
     61                "InvalidSelector",
     62                "ElementNotInteractable"
    6263            ]
    6364        },
  • trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp

    r220317 r220394  
    920920        FAIL_WITH_PREDEFINED_ERROR(NoJavaScriptDialog);
    921921
     922    // §18.4 Send Alert Text.
     923    // https://w3c.github.io/webdriver/webdriver-spec.html#send-alert-text
     924    // 3. Run the substeps of the first matching current user prompt:
     925    auto scriptDialogType = m_client->typeOfCurrentJavaScriptDialogOnPage(*this, *page);
     926    ASSERT(scriptDialogType);
     927    switch (scriptDialogType.value()) {
     928    case API::AutomationSessionClient::JavaScriptDialogType::Alert:
     929    case API::AutomationSessionClient::JavaScriptDialogType::Confirm:
     930        // Return error with error code element not interactable.
     931        FAIL_WITH_PREDEFINED_ERROR(ElementNotInteractable);
     932    case API::AutomationSessionClient::JavaScriptDialogType::Prompt:
     933        // Do nothing.
     934        break;
     935    case API::AutomationSessionClient::JavaScriptDialogType::BeforeUnloadConfirm:
     936        // Return error with error code unsupported operation.
     937        FAIL_WITH_PREDEFINED_ERROR(NotImplemented);
     938    }
     939
    922940    m_client->setUserInputForCurrentJavaScriptPromptOnPage(*this, *page, promptValue);
    923941}
  • trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.h

    r213304 r220394  
    5252    String messageOfCurrentJavaScriptDialogOnPage(WebAutomationSession&, WebPageProxy&) override;
    5353    void setUserInputForCurrentJavaScriptPromptOnPage(WebAutomationSession&, WebPageProxy&, const String&) override;
     54    std::optional<API::AutomationSessionClient::JavaScriptDialogType> typeOfCurrentJavaScriptDialogOnPage(WebAutomationSession&, WebPageProxy&) override;
    5455
    5556    WeakObjCPtr<id <_WKAutomationSessionDelegate>> m_delegate;
  • trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.mm

    r213304 r220394  
    124124}
    125125
     126std::optional<API::AutomationSessionClient::JavaScriptDialogType> AutomationSessionClient::typeOfCurrentJavaScriptDialogOnPage(WebAutomationSession&, WebPageProxy&)
     127{
     128    // FIXME: Implement it. This is only used in WebAutomationSession::setUserInputForCurrentJavaScriptPrompt() so for now we return
     129    // always Prompt type for compatibility.
     130    return API::AutomationSessionClient::JavaScriptDialogType::Prompt;
     131}
     132
    126133} // namespace WebKit
    127134
Note: See TracChangeset for help on using the changeset viewer.