Diff
Modified: releases/WebKitGTK/webkit-2.18/Source/WebDriver/ChangeLog (226028 => 226029)
--- releases/WebKitGTK/webkit-2.18/Source/WebDriver/ChangeLog 2017-12-18 11:47:44 UTC (rev 226028)
+++ releases/WebKitGTK/webkit-2.18/Source/WebDriver/ChangeLog 2017-12-18 11:47:49 UTC (rev 226029)
@@ -1,3 +1,22 @@
+2017-11-27 Carlos Garcia Campos <cgar...@igalia.com>
+
+ WebDriver: Implement get active element command
+ https://bugs.webkit.org/show_bug.cgi?id=180001
+
+ Reviewed by Brian Burg.
+
+ 12.6 Get Active Element
+ https://w3c.github.io/webdriver/webdriver-spec.html#get-active-element
+
+ Fixes imported/w3c/webdriver/tests/element_retrieval/get_active_element.py.
+
+ * Session.cpp:
+ (WebDriver::Session::getActiveElement):
+ * Session.h:
+ * WebDriverService.cpp:
+ (WebDriver::WebDriverService::getActiveElement):
+ * WebDriverService.h:
+
2017-11-21 Carlos Garcia Campos <cgar...@igalia.com>
WebDriver: do not try to parse http body if method is not POST
Modified: releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.cpp (226028 => 226029)
--- releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.cpp 2017-12-18 11:47:44 UTC (rev 226028)
+++ releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.cpp 2017-12-18 11:47:49 UTC (rev 226029)
@@ -961,6 +961,47 @@
});
}
+void Session::getActiveElement(Function<void (CommandResult&&)>&& completionHandler)
+{
+ if (!m_toplevelBrowsingContext) {
+ completionHandler(CommandResult::fail(CommandResult::ErrorCode::NoSuchWindow));
+ return;
+ }
+
+ handleUserPrompts([this, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
+ if (result.isError()) {
+ completionHandler(WTFMove(result));
+ return;
+ }
+ RefPtr<InspectorObject> parameters = InspectorObject::create();
+ parameters->setString(ASCIILiteral("browsingContextHandle"), m_toplevelBrowsingContext.value());
+ parameters->setString(ASCIILiteral("function"), ASCIILiteral("function() { return document.activeElement; }"));
+ parameters->setArray(ASCIILiteral("arguments"), InspectorArray::create());
+ m_host->sendCommandToBackend(ASCIILiteral("evaluateJavaScriptFunction"), WTFMove(parameters), [this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)](SessionHost::CommandResponse&& response) {
+ if (response.isError || !response.responseObject) {
+ completionHandler(CommandResult::fail(WTFMove(response.responseObject)));
+ return;
+ }
+ String valueString;
+ if (!response.responseObject->getString(ASCIILiteral("result"), valueString)) {
+ completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
+ return;
+ }
+ RefPtr<InspectorValue> resultValue;
+ if (!InspectorValue::parseJSON(valueString, resultValue)) {
+ completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
+ return;
+ }
+ RefPtr<InspectorObject> elementObject = createElement(WTFMove(resultValue));
+ if (!elementObject) {
+ completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
+ return;
+ }
+ completionHandler(CommandResult::success(WTFMove(elementObject)));
+ });
+ });
+}
+
void Session::isElementSelected(const String& elementID, Function<void (CommandResult&&)>&& completionHandler)
{
if (!m_toplevelBrowsingContext) {
Modified: releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.h (226028 => 226029)
--- releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.h 2017-12-18 11:47:44 UTC (rev 226028)
+++ releases/WebKitGTK/webkit-2.18/Source/WebDriver/Session.h 2017-12-18 11:47:49 UTC (rev 226029)
@@ -90,6 +90,7 @@
void getWindowRect(Function<void (CommandResult&&)>&&);
void setWindowRect(std::optional<double> x, std::optional<double> y, std::optional<double> width, std::optional<double> height, Function<void (CommandResult&&)>&&);
void findElements(const String& strategy, const String& selector, FindElementsMode, const String& rootElementID, Function<void (CommandResult&&)>&&);
+ void getActiveElement(Function<void (CommandResult&&)>&&);
void isElementSelected(const String& elementID, Function<void (CommandResult&&)>&&);
void getElementText(const String& elementID, Function<void (CommandResult&&)>&&);
void getElementTagName(const String& elementID, Function<void (CommandResult&&)>&&);
Modified: releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.cpp (226028 => 226029)
--- releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.cpp 2017-12-18 11:47:44 UTC (rev 226028)
+++ releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.cpp 2017-12-18 11:47:49 UTC (rev 226029)
@@ -125,6 +125,7 @@
{ HTTPMethod::Post, "/session/$sessionId/elements", &WebDriverService::findElements },
{ HTTPMethod::Post, "/session/$sessionId/element/$elementId/element", &WebDriverService::findElementFromElement },
{ HTTPMethod::Post, "/session/$sessionId/element/$elementId/elements", &WebDriverService::findElementsFromElement },
+ { HTTPMethod::Get, "/session/$sessionId/element/active", &WebDriverService::getActiveElement },
{ HTTPMethod::Get, "/session/$sessionId/element/$elementId/selected", &WebDriverService::isElementSelected },
{ HTTPMethod::Get, "/session/$sessionId/element/$elementId/attribute/$name", &WebDriverService::getElementAttribute },
@@ -1082,6 +1083,23 @@
session->findElements(strategy, selector, Session::FindElementsMode::Multiple, elementID.value(), WTFMove(completionHandler));
}
+void WebDriverService::getActiveElement(RefPtr<InspectorObject>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
+{
+ // §12.6 Get Active Element.
+ // https://w3c.github.io/webdriver/webdriver-spec.html#get-active-element
+ auto session = findSessionOrCompleteWithError(*parameters, completionHandler);
+ if (!session)
+ return;
+
+ session->waitForNavigationToComplete([session, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
+ if (result.isError()) {
+ completionHandler(WTFMove(result));
+ return;
+ }
+ session->getActiveElement(WTFMove(completionHandler));
+ });
+}
+
void WebDriverService::isElementSelected(RefPtr<InspectorObject>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
{
// §13.1 Is Element Selected.
Modified: releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.h (226028 => 226029)
--- releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.h 2017-12-18 11:47:44 UTC (rev 226028)
+++ releases/WebKitGTK/webkit-2.18/Source/WebDriver/WebDriverService.h 2017-12-18 11:47:49 UTC (rev 226029)
@@ -85,6 +85,7 @@
void findElements(RefPtr<Inspector::InspectorObject>&&, Function<void (CommandResult&&)>&&);
void findElementFromElement(RefPtr<Inspector::InspectorObject>&&, Function<void (CommandResult&&)>&&);
void findElementsFromElement(RefPtr<Inspector::InspectorObject>&&, Function<void (CommandResult&&)>&&);
+ void getActiveElement(RefPtr<Inspector::InspectorObject>&&, Function<void (CommandResult&&)>&&);
void isElementSelected(RefPtr<Inspector::InspectorObject>&&, Function<void (CommandResult&&)>&&);
void getElementText(RefPtr<Inspector::InspectorObject>&&, Function<void (CommandResult&&)>&&);
void getElementTagName(RefPtr<Inspector::InspectorObject>&&, Function<void (CommandResult&&)>&&);