Skip to content

Commit

Permalink
Merge r225970 - WebDriver: add support for accept/dismiss and notify …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
carlosgcampos committed Dec 18, 2017
1 parent d5eb393 commit 9d87846
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Source/WebDriver/Capabilities.h
Expand Up @@ -47,6 +47,8 @@ enum class PageLoadStrategy {
enum class UnhandledPromptBehavior {
Dismiss,
Accept,
DismissAndNotify,
AcceptAndNotify,
Ignore
};

Expand Down
23 changes: 23 additions & 0 deletions Source/WebDriver/ChangeLog
@@ -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
Expand Down
47 changes: 33 additions & 14 deletions Source/WebDriver/Session.cpp
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions Source/WebDriver/Session.h
Expand Up @@ -125,6 +125,8 @@ class Session : public RefCounted<Session> {

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>&&);
Expand Down
10 changes: 10 additions & 0 deletions Source/WebDriver/WebDriverService.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9d87846

Please sign in to comment.