Changeset 225970 in webkit


Ignore:
Timestamp:
Dec 15, 2017, 5:14:36 AM (8 years ago)
Author:
Carlos Garcia Campos
Message:

WebDriver: add support for accept/dismiss and notify unhandled prompt behavior
https://bugs.webkit.org/show_bug.cgi?id=179999

Reviewed by Carlos Alberto Lopez Perez.

They work as accept and dismiss, but unexpected alert open is still reported.

  1. User Prompts

https://w3c.github.io/webdriver/webdriver-spec.html#dfn-known-prompt-handling-approaches-table

  • Capabilities.h: Add DismissAndNotify and AcceptAndNotify to UnhandledPromptBehavior enum.
  • Session.cpp:

(WebDriver::Session::handleUnexpectedAlertOpen): Move default implementation to dismissAndNotifyAlert and
acceptAndNotifyAlert and use dismissAndNotifyAlert by default.
(WebDriver::Session::dismissAndNotifyAlert):
(WebDriver::Session::acceptAndNotifyAlert):

  • Session.h:
  • WebDriverService.cpp:

(WebDriver::deserializeUnhandledPromptBehavior): Handle accept/dismiss and notify.
(WebDriver::WebDriverService::newSession): Ditto.

Location:
trunk/Source/WebDriver
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebDriver/Capabilities.h

    r224913 r225970  
    4848    Dismiss,
    4949    Accept,
     50    DismissAndNotify,
     51    AcceptAndNotify,
    5052    Ignore
    5153};
  • trunk/Source/WebDriver/ChangeLog

    r225739 r225970  
     12017-12-15  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        WebDriver: add support for accept/dismiss and notify unhandled prompt behavior
     4        https://bugs.webkit.org/show_bug.cgi?id=179999
     5
     6        Reviewed by Carlos Alberto Lopez Perez.
     7
     8        They work as accept and dismiss, but unexpected alert open is still reported.
     9
     10        18. User Prompts
     11        https://w3c.github.io/webdriver/webdriver-spec.html#dfn-known-prompt-handling-approaches-table
     12
     13        * Capabilities.h: Add DismissAndNotify and AcceptAndNotify to UnhandledPromptBehavior enum.
     14        * Session.cpp:
     15        (WebDriver::Session::handleUnexpectedAlertOpen): Move default implementation to dismissAndNotifyAlert and
     16        acceptAndNotifyAlert and use dismissAndNotifyAlert by default.
     17        (WebDriver::Session::dismissAndNotifyAlert):
     18        (WebDriver::Session::acceptAndNotifyAlert):
     19        * Session.h:
     20        * WebDriverService.cpp:
     21        (WebDriver::deserializeUnhandledPromptBehavior): Handle accept/dismiss and notify.
     22        (WebDriver::WebDriverService::newSession): Ditto.
     23
    1242017-12-11  Carlos Garcia Campos  <cgarcia@igalia.com>
    225
  • trunk/Source/WebDriver/Session.cpp

    r225739 r225970  
    191191void Session::handleUnexpectedAlertOpen(Function<void (CommandResult&&)>&& completionHandler)
    192192{
    193     if (!capabilities().unhandledPromptBehavior) {
    194         reportUnexpectedAlertOpen([this, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
    195             dismissAlert([this, errorResult = WTFMove(result), completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
    196                 if (result.isError()) {
    197                     completionHandler(WTFMove(result));
    198                     return;
    199                 }
    200                 completionHandler(WTFMove(errorResult));
    201             });
    202         });
    203         return;
    204     }
    205 
    206     switch (capabilities().unhandledPromptBehavior.value()) {
     193    switch (capabilities().unhandledPromptBehavior.value_or(UnhandledPromptBehavior::DismissAndNotify)) {
    207194    case UnhandledPromptBehavior::Dismiss:
    208195        dismissAlert(WTFMove(completionHandler));
     
    211198        acceptAlert(WTFMove(completionHandler));
    212199        break;
     200    case UnhandledPromptBehavior::DismissAndNotify:
     201        dismissAndNotifyAlert(WTFMove(completionHandler));
     202        break;
     203    case UnhandledPromptBehavior::AcceptAndNotify:
     204        acceptAndNotifyAlert(WTFMove(completionHandler));
     205        break;
    213206    case UnhandledPromptBehavior::Ignore:
    214207        reportUnexpectedAlertOpen(WTFMove(completionHandler));
    215208        break;
    216209    }
     210}
     211
     212void Session::dismissAndNotifyAlert(Function<void (CommandResult&&)>&& completionHandler)
     213{
     214    reportUnexpectedAlertOpen([this, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
     215        dismissAlert([this, errorResult = WTFMove(result), completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
     216            if (result.isError()) {
     217                completionHandler(WTFMove(result));
     218                return;
     219            }
     220            completionHandler(WTFMove(errorResult));
     221        });
     222    });
     223}
     224
     225void Session::acceptAndNotifyAlert(Function<void (CommandResult&&)>&& completionHandler)
     226{
     227    reportUnexpectedAlertOpen([this, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
     228        acceptAlert([this, errorResult = WTFMove(result), completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
     229            if (result.isError()) {
     230                completionHandler(WTFMove(result));
     231                return;
     232            }
     233            completionHandler(WTFMove(errorResult));
     234        });
     235    });
    217236}
    218237
  • trunk/Source/WebDriver/Session.h

    r225474 r225970  
    125125    void handleUserPrompts(Function<void (CommandResult&&)>&&);
    126126    void handleUnexpectedAlertOpen(Function<void (CommandResult&&)>&&);
     127    void dismissAndNotifyAlert(Function<void (CommandResult&&)>&&);
     128    void acceptAndNotifyAlert(Function<void (CommandResult&&)>&&);
    127129    void reportUnexpectedAlertOpen(Function<void (CommandResult&&)>&&);
    128130
  • trunk/Source/WebDriver/WebDriverService.cpp

    r225474 r225970  
    314314    if (unhandledPromptBehavior == "accept")
    315315        return UnhandledPromptBehavior::Accept;
     316    if (unhandledPromptBehavior == "dismiss and notify")
     317        return UnhandledPromptBehavior::DismissAndNotify;
     318    if (unhandledPromptBehavior == "accept and notify")
     319        return UnhandledPromptBehavior::AcceptAndNotify;
    316320    if (unhandledPromptBehavior == "ignore")
    317321        return UnhandledPromptBehavior::Ignore;
     
    652656                    capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "accept");
    653657                    break;
     658                case UnhandledPromptBehavior::DismissAndNotify:
     659                    capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "dismiss and notify");
     660                    break;
     661                case UnhandledPromptBehavior::AcceptAndNotify:
     662                    capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "accept and notify");
     663                    break;
    654664                case UnhandledPromptBehavior::Ignore:
    655665                    capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "ignore");
Note: See TracChangeset for help on using the changeset viewer.