WebDriver: add support for accept/dismiss and notify unhandled prompt behavior
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Dec 2017 13:14:36 +0000 (13:14 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Dec 2017 13:14:36 +0000 (13:14 +0000)
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.

18. 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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225970 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebDriver/Capabilities.h
Source/WebDriver/ChangeLog
Source/WebDriver/Session.cpp
Source/WebDriver/Session.h
Source/WebDriver/WebDriverService.cpp

index 91a507d..0d37468 100644 (file)
@@ -47,6 +47,8 @@ enum class PageLoadStrategy {
 enum class UnhandledPromptBehavior {
     Dismiss,
     Accept,
+    DismissAndNotify,
+    AcceptAndNotify,
     Ignore
 };
 
index ae2258e..e814fad 100644 (file)
@@ -1,3 +1,26 @@
+2017-12-15  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        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.
+
+        18. 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.
+
 2017-12-11  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         WebDriver: get active element should return no such element error when there isn't an active element
index b4696d0..bb69e96 100644 (file)
@@ -190,32 +190,51 @@ void Session::handleUserPrompts(Function<void (CommandResult&&)>&& completionHan
 
 void Session::handleUnexpectedAlertOpen(Function<void (CommandResult&&)>&& completionHandler)
 {
-    if (!capabilities().unhandledPromptBehavior) {
-        reportUnexpectedAlertOpen([this, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
-            dismissAlert([this, errorResult = WTFMove(result), completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
-                if (result.isError()) {
-                    completionHandler(WTFMove(result));
-                    return;
-                }
-                completionHandler(WTFMove(errorResult));
-            });
-        });
-        return;
-    }
-
-    switch (capabilities().unhandledPromptBehavior.value()) {
+    switch (capabilities().unhandledPromptBehavior.value_or(UnhandledPromptBehavior::DismissAndNotify)) {
     case UnhandledPromptBehavior::Dismiss:
         dismissAlert(WTFMove(completionHandler));
         break;
     case UnhandledPromptBehavior::Accept:
         acceptAlert(WTFMove(completionHandler));
         break;
+    case UnhandledPromptBehavior::DismissAndNotify:
+        dismissAndNotifyAlert(WTFMove(completionHandler));
+        break;
+    case UnhandledPromptBehavior::AcceptAndNotify:
+        acceptAndNotifyAlert(WTFMove(completionHandler));
+        break;
     case UnhandledPromptBehavior::Ignore:
         reportUnexpectedAlertOpen(WTFMove(completionHandler));
         break;
     }
 }
 
+void Session::dismissAndNotifyAlert(Function<void (CommandResult&&)>&& completionHandler)
+{
+    reportUnexpectedAlertOpen([this, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
+        dismissAlert([this, errorResult = WTFMove(result), completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
+            if (result.isError()) {
+                completionHandler(WTFMove(result));
+                return;
+            }
+            completionHandler(WTFMove(errorResult));
+        });
+    });
+}
+
+void Session::acceptAndNotifyAlert(Function<void (CommandResult&&)>&& completionHandler)
+{
+    reportUnexpectedAlertOpen([this, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
+        acceptAlert([this, errorResult = WTFMove(result), completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
+            if (result.isError()) {
+                completionHandler(WTFMove(result));
+                return;
+            }
+            completionHandler(WTFMove(errorResult));
+        });
+    });
+}
+
 void Session::reportUnexpectedAlertOpen(Function<void (CommandResult&&)>&& completionHandler)
 {
     getAlertText([this, completionHandler = WTFMove(completionHandler)](CommandResult&& result) {
index f7b1ce9..9ebdaf2 100644 (file)
@@ -124,6 +124,8 @@ private:
 
     void handleUserPrompts(Function<void (CommandResult&&)>&&);
     void handleUnexpectedAlertOpen(Function<void (CommandResult&&)>&&);
+    void dismissAndNotifyAlert(Function<void (CommandResult&&)>&&);
+    void acceptAndNotifyAlert(Function<void (CommandResult&&)>&&);
     void reportUnexpectedAlertOpen(Function<void (CommandResult&&)>&&);
 
     RefPtr<JSON::Object> createElement(RefPtr<JSON::Value>&&);
index 1221584..63118cb 100644 (file)
@@ -313,6 +313,10 @@ static std::optional<UnhandledPromptBehavior> deserializeUnhandledPromptBehavior
         return UnhandledPromptBehavior::Dismiss;
     if (unhandledPromptBehavior == "accept")
         return UnhandledPromptBehavior::Accept;
+    if (unhandledPromptBehavior == "dismiss and notify")
+        return UnhandledPromptBehavior::DismissAndNotify;
+    if (unhandledPromptBehavior == "accept and notify")
+        return UnhandledPromptBehavior::AcceptAndNotify;
     if (unhandledPromptBehavior == "ignore")
         return UnhandledPromptBehavior::Ignore;
     return std::nullopt;
@@ -651,6 +655,12 @@ void WebDriverService::newSession(RefPtr<JSON::Object>&& parameters, Function<vo
                 case UnhandledPromptBehavior::Accept:
                     capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "accept");
                     break;
+                case UnhandledPromptBehavior::DismissAndNotify:
+                    capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "dismiss and notify");
+                    break;
+                case UnhandledPromptBehavior::AcceptAndNotify:
+                    capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "accept and notify");
+                    break;
                 case UnhandledPromptBehavior::Ignore:
                     capabilitiesObject->setString(ASCIILiteral("unhandledPromptBehavior"), "ignore");
                     break;