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.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@198740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h b/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h
index 3ff00f3..f6c9273 100644
--- a/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h
+++ b/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h
@@ -42,6 +42,11 @@
virtual String sessionIdentifier() const { return String(); }
virtual void didDisconnectFromRemote(WebKit::WebAutomationSession*) { }
virtual WebKit::WebPageProxy* didRequestNewWindow(WebKit::WebAutomationSession*) { return nullptr; }
+ virtual bool isShowingJavaScriptDialogOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*) { return false; }
+ virtual void dismissCurrentJavaScriptDialogOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*) { }
+ virtual void acceptCurrentJavaScriptDialogOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*) { }
+ virtual String messageOfCurrentJavaScriptDialogOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*) { return String(); }
+ virtual void setUserInputForCurrentJavaScriptPromptOnPage(WebKit::WebAutomationSession*, WebKit::WebPageProxy*, const String&) { }
};
} // namespace API
diff --git a/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h b/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h
index 14c4c57..62c068e 100644
--- a/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h
+++ b/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h
@@ -36,6 +36,12 @@
@optional
- (WKPageRef)_automationSessionDidRequestNewWindow:(_WKAutomationSession *)automationSession;
- (void)_automationSessionDidDisconnectFromRemote:(_WKAutomationSession *)automationSession;
+
+- (BOOL)_automationSession:(_WKAutomationSession *)automationSession isShowingJavaScriptDialogOnPage:(WKPageRef)page;
+- (void)_automationSession:(_WKAutomationSession *)automationSession dismissCurrentJavaScriptDialogOnPage:(WKPageRef)page;
+- (void)_automationSession:(_WKAutomationSession *)automationSession acceptCurrentJavaScriptDialogOnPage:(WKPageRef)page;
+- (NSString *)_automationSession:(_WKAutomationSession *)automationSession messageOfCurrentJavaScriptDialogOnPage:(WKPageRef)page;
+- (void)_automationSession:(_WKAutomationSession *)automationSession setUserInput:(NSString *)value forCurrentJavaScriptDialogOnPage:(WKPageRef)page;
@end
#endif // WK_API_ENABLED
diff --git a/Source/WebKit2/UIProcess/Automation/Automation.json b/Source/WebKit2/UIProcess/Automation/Automation.json
index 54491de..91259ed 100644
--- a/Source/WebKit2/UIProcess/Automation/Automation.json
+++ b/Source/WebKit2/UIProcess/Automation/Automation.json
@@ -51,6 +51,7 @@
"WindowNotFound",
"FrameNotFound",
"NodeNotFound",
+ "NoJavaScriptDialog",
"NotImplemented",
"MissingParameter"
]
@@ -191,6 +192,48 @@
{ "name": "rect", "$ref": "Rect", "description": "The layout rect for the requested element. Specified in page or viewport coordinates based on the useViewportCoordinates parameter." }
],
"async": true
+ },
+ {
+ "name": "isShowingJavaScriptDialog",
+ "description": "Checks if a browsing context is showing a JavaScript alert, confirm, or prompt dialog.",
+ "parameters": [
+ { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." }
+ ],
+ "returns": [
+ { "name": "result", "type": "boolean", "description": "If the browsing context is showing a JavaScript dialog or not." }
+ ]
+ },
+ {
+ "name": "dismissCurrentJavaScriptDialog",
+ "description": "Dismisses a JavaScript alert, confirm, or prompt dialog currently showing in a browsing context. Equivalent to clicking the 'Cancel' button.",
+ "parameters": [
+ { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." }
+ ]
+ },
+ {
+ "name": "acceptCurrentJavaScriptDialog",
+ "description": "Accepts a JavaScript alert, confirm, or prompt dialog currently showing in a browsing context. Equivalent to clicking the 'OK' button.",
+ "parameters": [
+ { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." }
+ ]
+ },
+ {
+ "name": "messageOfCurrentJavaScriptDialog",
+ "description": "Returns the text displayed in a JavaScript alert, confirm, or prompt dialog currently showing in a browsing context.",
+ "parameters": [
+ { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." }
+ ],
+ "returns": [
+ { "name": "message", "type": "string", "description": "Text being displayed in the current JavaScript dialog." }
+ ]
+ },
+ {
+ "name": "setUserInputForCurrentJavaScriptPrompt",
+ "description": "Sets the user entered value in a JavaScript prompt dialog currently showing in a browsing context.",
+ "parameters": [
+ { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context." },
+ { "name": "userInput", "type": "string", "description": "The text to enter in the prompt." }
+ ]
}
]
}
diff --git a/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp b/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp
index aaa451b..1fc43be 100644
--- a/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp
+++ b/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp
@@ -465,4 +465,81 @@
callback->sendSuccess(WTFMove(rectObject));
}
+void WebAutomationSession::isShowingJavaScriptDialog(Inspector::ErrorString& errorString, const String& browsingContextHandle, bool* result)
+{
+ ASSERT(m_client);
+ if (!m_client)
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
+
+ WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+ if (!page)
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+ *result = m_client->isShowingJavaScriptDialogOnPage(this, page);
+}
+
+void WebAutomationSession::dismissCurrentJavaScriptDialog(Inspector::ErrorString& errorString, const String& browsingContextHandle)
+{
+ ASSERT(m_client);
+ if (!m_client)
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
+
+ WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+ if (!page)
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+ if (!m_client->isShowingJavaScriptDialogOnPage(this, page))
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NoJavaScriptDialog);
+
+ m_client->dismissCurrentJavaScriptDialogOnPage(this, page);
+}
+
+void WebAutomationSession::acceptCurrentJavaScriptDialog(Inspector::ErrorString& errorString, const String& browsingContextHandle)
+{
+ ASSERT(m_client);
+ if (!m_client)
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
+
+ WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+ if (!page)
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+ if (!m_client->isShowingJavaScriptDialogOnPage(this, page))
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NoJavaScriptDialog);
+
+ m_client->acceptCurrentJavaScriptDialogOnPage(this, page);
+}
+
+void WebAutomationSession::messageOfCurrentJavaScriptDialog(Inspector::ErrorString& errorString, const String& browsingContextHandle, String* text)
+{
+ ASSERT(m_client);
+ if (!m_client)
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
+
+ WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+ if (!page)
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+ if (!m_client->isShowingJavaScriptDialogOnPage(this, page))
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NoJavaScriptDialog);
+
+ *text = m_client->messageOfCurrentJavaScriptDialogOnPage(this, page);
+}
+
+void WebAutomationSession::setUserInputForCurrentJavaScriptPrompt(Inspector::ErrorString& errorString, const String& browsingContextHandle, const String& promptValue)
+{
+ ASSERT(m_client);
+ if (!m_client)
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
+
+ WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+ if (!page)
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+ if (!m_client->isShowingJavaScriptDialogOnPage(this, page))
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NoJavaScriptDialog);
+
+ m_client->setUserInputForCurrentJavaScriptPromptOnPage(this, page, promptValue);
+}
+
} // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h b/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h
index 9544aec..6d8baa1 100644
--- a/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h
+++ b/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h
@@ -95,6 +95,11 @@
void resolveChildFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const int* optionalOrdinal, const String* optionalName, const String* optionalNodeHandle, Ref<ResolveChildFrameHandleCallback>&&) override;
void resolveParentFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, Ref<ResolveParentFrameHandleCallback>&&) override;
void computeElementLayout(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, const String& nodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* useViewportCoordinates, Ref<Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback>&&) override;
+ void isShowingJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle, bool* result) override;
+ void dismissCurrentJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle) override;
+ void acceptCurrentJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle) override;
+ void messageOfCurrentJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle, String* text) override;
+ void setUserInputForCurrentJavaScriptPrompt(Inspector::ErrorString&, const String& browsingContextHandle, const String& text) override;
private:
WebPageProxy* webPageProxyForHandle(const String&);
diff --git a/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.h b/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.h
index 96cfe1e..7b3edb5 100644
--- a/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.h
+++ b/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.h
@@ -43,14 +43,25 @@
private:
// From API::AutomationSessionClient
- WebPageProxy* didRequestNewWindow(WebKit::WebAutomationSession*) override;
- void didDisconnectFromRemote(WebKit::WebAutomationSession *) override;
+ WebPageProxy* didRequestNewWindow(WebAutomationSession*) override;
+ void didDisconnectFromRemote(WebAutomationSession *) override;
+
+ bool isShowingJavaScriptDialogOnPage(WebAutomationSession*, WebPageProxy*) override;
+ void dismissCurrentJavaScriptDialogOnPage(WebAutomationSession*, WebPageProxy*) override;
+ void acceptCurrentJavaScriptDialogOnPage(WebAutomationSession*, WebPageProxy*) override;
+ String messageOfCurrentJavaScriptDialogOnPage(WebAutomationSession*, WebPageProxy*) override;
+ void setUserInputForCurrentJavaScriptPromptOnPage(WebAutomationSession*, WebPageProxy*, const String&) override;
WeakObjCPtr<id <_WKAutomationSessionDelegate>> m_delegate;
struct {
bool didRequestNewWindow : 1;
bool didDisconnectFromRemote : 1;
+ bool isShowingJavaScriptDialogOnPage : 1;
+ bool dismissCurrentJavaScriptDialogOnPage : 1;
+ bool acceptCurrentJavaScriptDialogOnPage : 1;
+ bool messageOfCurrentJavaScriptDialogOnPage : 1;
+ bool setUserInputForCurrentJavaScriptPromptOnPage : 1;
} m_delegateMethods;
};
diff --git a/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.mm b/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.mm
index 39c4889..3e954b6 100644
--- a/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.mm
+++ b/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.mm
@@ -41,6 +41,11 @@
{
m_delegateMethods.didRequestNewWindow = [delegate respondsToSelector:@selector(_automationSessionDidRequestNewWindow:)];
m_delegateMethods.didDisconnectFromRemote = [delegate respondsToSelector:@selector(_automationSessionDidDisconnectFromRemote:)];
+ m_delegateMethods.isShowingJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:isShowingJavaScriptDialogOnPage:)];
+ m_delegateMethods.dismissCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:dismissCurrentJavaScriptDialogOnPage:)];
+ m_delegateMethods.acceptCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:acceptCurrentJavaScriptDialogOnPage:)];
+ m_delegateMethods.messageOfCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:messageOfCurrentJavaScriptDialogOnPage:)];
+ m_delegateMethods.setUserInputForCurrentJavaScriptPromptOnPage = [delegate respondsToSelector:@selector(_automationSession:setUserInput:forCurrentJavaScriptDialogOnPage:)];
}
WebPageProxy* AutomationSessionClient::didRequestNewWindow(WebAutomationSession* session)
@@ -56,6 +61,38 @@
[m_delegate.get() _automationSessionDidDisconnectFromRemote:wrapper(*session)];
}
+bool AutomationSessionClient::isShowingJavaScriptDialogOnPage(WebAutomationSession* session, WebPageProxy* page)
+{
+ if (m_delegateMethods.isShowingJavaScriptDialogOnPage)
+ return [m_delegate.get() _automationSession:wrapper(*session) isShowingJavaScriptDialogOnPage:toAPI(page)];
+ return false;
+}
+
+void AutomationSessionClient::dismissCurrentJavaScriptDialogOnPage(WebAutomationSession* session, WebPageProxy* page)
+{
+ if (m_delegateMethods.dismissCurrentJavaScriptDialogOnPage)
+ [m_delegate.get() _automationSession:wrapper(*session) dismissCurrentJavaScriptDialogOnPage:toAPI(page)];
+}
+
+void AutomationSessionClient::acceptCurrentJavaScriptDialogOnPage(WebAutomationSession* session, WebPageProxy* page)
+{
+ if (m_delegateMethods.acceptCurrentJavaScriptDialogOnPage)
+ [m_delegate.get() _automationSession:wrapper(*session) acceptCurrentJavaScriptDialogOnPage:toAPI(page)];
+}
+
+String AutomationSessionClient::messageOfCurrentJavaScriptDialogOnPage(WebAutomationSession* session, WebPageProxy* page)
+{
+ if (m_delegateMethods.messageOfCurrentJavaScriptDialogOnPage)
+ return [m_delegate.get() _automationSession:wrapper(*session) messageOfCurrentJavaScriptDialogOnPage:toAPI(page)];
+ return String();
+}
+
+void AutomationSessionClient::setUserInputForCurrentJavaScriptPromptOnPage(WebAutomationSession* session, WebPageProxy* page, const String& value)
+{
+ if (m_delegateMethods.setUserInputForCurrentJavaScriptPromptOnPage)
+ [m_delegate.get() _automationSession:wrapper(*session) setUserInput:value forCurrentJavaScriptDialogOnPage:toAPI(page)];
+}
+
} // namespace WebKit
#endif // WK_API_ENABLED