Title: [252238] trunk
Revision
252238
Author
carlo...@webkit.org
Date
2019-11-08 07:09:00 -0800 (Fri, 08 Nov 2019)

Log Message

WebDriver: implement get page source command
https://bugs.webkit.org/show_bug.cgi?id=180399

Reviewed by Carlos Alberto Lopez Perez.

Source/WebDriver:

* Session.cpp:
(WebDriver::Session::getPageSource):
* Session.h:
* WebDriverService.cpp:
(WebDriver::WebDriverService::getPageSource):
* WebDriverService.h:

WebDriverTests:

Unskip tests that are now passing.

* TestExpectations.json:

Modified Paths

Diff

Modified: trunk/Source/WebDriver/ChangeLog (252237 => 252238)


--- trunk/Source/WebDriver/ChangeLog	2019-11-08 15:04:25 UTC (rev 252237)
+++ trunk/Source/WebDriver/ChangeLog	2019-11-08 15:09:00 UTC (rev 252238)
@@ -1,3 +1,17 @@
+2019-11-08  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        WebDriver: implement get page source command
+        https://bugs.webkit.org/show_bug.cgi?id=180399
+
+        Reviewed by Carlos Alberto Lopez Perez.
+
+        * Session.cpp:
+        (WebDriver::Session::getPageSource):
+        * Session.h:
+        * WebDriverService.cpp:
+        (WebDriver::WebDriverService::getPageSource):
+        * WebDriverService.h:
+
 2019-11-07  Carlos Garcia Campos  <cgar...@igalia.com>
 
         WebDriver: correctly handle errors when focusing element before sending key events

Modified: trunk/Source/WebDriver/Session.cpp (252237 => 252238)


--- trunk/Source/WebDriver/Session.cpp	2019-11-08 15:04:25 UTC (rev 252237)
+++ trunk/Source/WebDriver/Session.cpp	2019-11-08 15:09:00 UTC (rev 252238)
@@ -1819,6 +1819,42 @@
     });
 }
 
+void Session::getPageSource(Function<void (CommandResult&&)>&& completionHandler)
+{
+    if (!m_toplevelBrowsingContext) {
+        completionHandler(CommandResult::fail(CommandResult::ErrorCode::NoSuchWindow));
+        return;
+    }
+
+    handleUserPrompts([this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
+        if (result.isError()) {
+            completionHandler(WTFMove(result));
+            return;
+        }
+        RefPtr<JSON::Object> parameters = JSON::Object::create();
+        parameters->setString("browsingContextHandle"_s, m_toplevelBrowsingContext.value());
+        parameters->setString("function"_s, "function() { return document.documentElement.outerHTML; }"_s);
+        parameters->setArray("arguments"_s, JSON::Array::create());
+        m_host->sendCommandToBackend("evaluateJavaScriptFunction"_s, WTFMove(parameters), [protectedThis = protectedThis.copyRef(), completionHandler = WTFMove(completionHandler)](SessionHost::CommandResponse&& response) {
+            if (response.isError || !response.responseObject) {
+                completionHandler(CommandResult::fail(WTFMove(response.responseObject)));
+                return;
+            }
+            String valueString;
+            if (!response.responseObject->getString("result"_s, valueString)) {
+                completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
+                return;
+            }
+            RefPtr<JSON::Value> resultValue;
+            if (!JSON::Value::parseJSON(valueString, resultValue)) {
+                completionHandler(CommandResult::fail(CommandResult::ErrorCode::UnknownError));
+                return;
+            }
+            completionHandler(CommandResult::success(WTFMove(resultValue)));
+        });
+    });
+}
+
 RefPtr<JSON::Value> Session::handleScriptResult(RefPtr<JSON::Value>&& resultValue)
 {
     RefPtr<JSON::Array> resultArray;

Modified: trunk/Source/WebDriver/Session.h (252237 => 252238)


--- trunk/Source/WebDriver/Session.h	2019-11-08 15:04:25 UTC (rev 252237)
+++ trunk/Source/WebDriver/Session.h	2019-11-08 15:09:00 UTC (rev 252238)
@@ -107,6 +107,7 @@
     void elementClick(const String& elementID, Function<void (CommandResult&&)>&&);
     void elementClear(const String& elementID, Function<void (CommandResult&&)>&&);
     void elementSendKeys(const String& elementID, const String& text, Function<void (CommandResult&&)>&&);
+    void getPageSource(Function<void (CommandResult&&)>&&);
     void executeScript(const String& script, RefPtr<JSON::Array>&& arguments, ExecuteScriptMode, Function<void (CommandResult&&)>&&);
     void getAllCookies(Function<void (CommandResult&&)>&&);
     void getNamedCookie(const String& name, Function<void (CommandResult&&)>&&);

Modified: trunk/Source/WebDriver/WebDriverService.cpp (252237 => 252238)


--- trunk/Source/WebDriver/WebDriverService.cpp	2019-11-08 15:04:25 UTC (rev 252237)
+++ trunk/Source/WebDriver/WebDriverService.cpp	2019-11-08 15:09:00 UTC (rev 252238)
@@ -153,6 +153,7 @@
     { HTTPMethod::Post, "/session/$sessionId/element/$elementId/clear", &WebDriverService::elementClear },
     { HTTPMethod::Post, "/session/$sessionId/element/$elementId/value", &WebDriverService::elementSendKeys },
 
+    { HTTPMethod::Get, "/session/$sessionId/source", &WebDriverService::getPageSource },
     { HTTPMethod::Post, "/session/$sessionId/execute/sync", &WebDriverService::executeScript },
     { HTTPMethod::Post, "/session/$sessionId/execute/async", &WebDriverService::executeAsyncScript },
 
@@ -1395,6 +1396,16 @@
     m_session->elementSendKeys(elementID.value(), text, WTFMove(completionHandler));
 }
 
+void WebDriverService::getPageSource(RefPtr<JSON::Object>&& parameters, Function<void (CommandResult&&)>&& completionHandler)
+{
+    // ยง15.1 Getting Page Source.
+    // https://w3c.github.io/webdriver/webdriver-spec.html#getting-page-source
+    if (!findSessionOrCompleteWithError(*parameters, completionHandler))
+        return;
+
+    m_session->getPageSource(WTFMove(completionHandler));
+}
+
 static bool findScriptAndArgumentsOrCompleteWithError(JSON::Object& parameters, Function<void (CommandResult&&)>& completionHandler, String& script, RefPtr<JSON::Array>& arguments)
 {
     if (!parameters.getString("script"_s, script)) {

Modified: trunk/Source/WebDriver/WebDriverService.h (252237 => 252238)


--- trunk/Source/WebDriver/WebDriverService.h	2019-11-08 15:04:25 UTC (rev 252237)
+++ trunk/Source/WebDriver/WebDriverService.h	2019-11-08 15:09:00 UTC (rev 252238)
@@ -99,6 +99,7 @@
     void elementClick(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void elementClear(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void elementSendKeys(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
+    void getPageSource(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void executeScript(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void executeAsyncScript(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);
     void getAllCookies(RefPtr<JSON::Object>&&, Function<void (CommandResult&&)>&&);

Modified: trunk/WebDriverTests/ChangeLog (252237 => 252238)


--- trunk/WebDriverTests/ChangeLog	2019-11-08 15:04:25 UTC (rev 252237)
+++ trunk/WebDriverTests/ChangeLog	2019-11-08 15:09:00 UTC (rev 252238)
@@ -1,3 +1,14 @@
+2019-11-08  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        WebDriver: implement get page source command
+        https://bugs.webkit.org/show_bug.cgi?id=180399
+
+        Reviewed by Carlos Alberto Lopez Perez.
+
+        Unskip tests that are now passing.
+
+        * TestExpectations.json:
+
 2019-11-07  Carlos Garcia Campos  <cgar...@igalia.com>
 
         WebDriver: correctly handle errors when focusing element before sending key events

Modified: trunk/WebDriverTests/TestExpectations.json (252237 => 252238)


--- trunk/WebDriverTests/TestExpectations.json	2019-11-08 15:04:25 UTC (rev 252237)
+++ trunk/WebDriverTests/TestExpectations.json	2019-11-08 15:09:00 UTC (rev 252238)
@@ -399,12 +399,6 @@
             }
         }
     },
-    "imported/w3c/webdriver/tests/get_page_source/source.py": {
-        "expected": {"all": {"status": ["SKIP"], "bug": "webkit.org/b/180399"}}
-    },
-    "imported/w3c/webdriver/tests/get_page_source/user_prompts.py": {
-        "expected": {"all": {"status": ["SKIP"], "bug": "webkit.org/b/180399"}}
-    },
     "imported/w3c/webdriver/tests/element_click/bubbling.py": {
         "subtests": {
             "test_spin_event_loop": {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to