WebDriver: several element_send_keys tests are failing since added
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Aug 2018 06:49:25 +0000 (06:49 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Aug 2018 06:49:25 +0000 (06:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181644

Reviewed by Michael Catanzaro.

This is because we are implementing an old version of the spec that received a "value" parameter to send keys
command, instead of the "text" one.

14.3 Element Send Keys
https://w3c.github.io/webdriver/#element-send-keys

* Session.cpp:
(WebDriver::Session::virtualKeyForKey): Receive a single character instead of a sequence.
(WebDriver::Session::elementSendKeys): It now receives a String and passes every character to virtualKeyForKey.
(WebDriver::Session::performActions): Pass first character of sequence to virtualKeyForKey.
* Session.h:
* WebDriverService.cpp:
(WebDriver::WebDriverService::elementSendKeys): Get text as a String, instead of value as an array.

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

Source/WebDriver/ChangeLog
Source/WebDriver/Session.cpp
Source/WebDriver/Session.h
Source/WebDriver/WebDriverService.cpp
WebDriverTests/ChangeLog
WebDriverTests/TestExpectations.json

index 7c012d3..cc80ff2 100644 (file)
@@ -1,3 +1,24 @@
+2018-08-13  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        WebDriver: several element_send_keys tests are failing since added
+        https://bugs.webkit.org/show_bug.cgi?id=181644
+
+        Reviewed by Michael Catanzaro.
+
+        This is because we are implementing an old version of the spec that received a "value" parameter to send keys
+        command, instead of the "text" one.
+
+        14.3 Element Send Keys
+        https://w3c.github.io/webdriver/#element-send-keys
+
+        * Session.cpp:
+        (WebDriver::Session::virtualKeyForKey): Receive a single character instead of a sequence.
+        (WebDriver::Session::elementSendKeys): It now receives a String and passes every character to virtualKeyForKey.
+        (WebDriver::Session::performActions): Pass first character of sequence to virtualKeyForKey.
+        * Session.h:
+        * WebDriverService.cpp:
+        (WebDriver::WebDriverService::elementSendKeys): Get text as a String, instead of value as an array.
+
 2018-08-12  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         WebDriver: do not handle prompts that appear while running scripts
index e766585..5c52e15 100644 (file)
@@ -1579,12 +1579,12 @@ void Session::elementClear(const String& elementID, Function<void (CommandResult
     });
 }
 
-String Session::virtualKeyForKeySequence(const String& keySequence, KeyModifier& modifier)
+String Session::virtualKeyForKey(UChar key, KeyModifier& modifier)
 {
     // ยง17.4.2 Keyboard Actions.
     // https://www.w3.org/TR/webdriver/#keyboard-actions
     modifier = KeyModifier::None;
-    switch (keySequence[0]) {
+    switch (key) {
     case 0xE001U:
         return "Cancel"_s;
     case 0xE002U:
@@ -1717,14 +1717,14 @@ String Session::virtualKeyForKeySequence(const String& keySequence, KeyModifier&
     return String();
 }
 
-void Session::elementSendKeys(const String& elementID, Vector<String>&& keys, Function<void (CommandResult&&)>&& completionHandler)
+void Session::elementSendKeys(const String& elementID, const String& text, Function<void (CommandResult&&)>&& completionHandler)
 {
     if (!m_toplevelBrowsingContext) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::NoSuchWindow));
         return;
     }
 
-    handleUserPrompts([this, elementID, keys = WTFMove(keys), completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
+    handleUserPrompts([this, elementID, text, completionHandler = WTFMove(completionHandler)](CommandResult&& result) mutable {
         if (result.isError()) {
             completionHandler(WTFMove(result));
             return;
@@ -1751,19 +1751,21 @@ void Session::elementSendKeys(const String& elementID, Vector<String>&& keys, Fu
             parameters->setString("frameHandle"_s, m_currentBrowsingContext.value());
         parameters->setString("function"_s, focusScript);
         parameters->setArray("arguments"_s, WTFMove(arguments));
-        m_host->sendCommandToBackend("evaluateJavaScriptFunction"_s, WTFMove(parameters), [this, protectedThis = makeRef(*this), keys = WTFMove(keys), completionHandler = WTFMove(completionHandler)](SessionHost::CommandResponse&& response) mutable {
+        m_host->sendCommandToBackend("evaluateJavaScriptFunction"_s, WTFMove(parameters), [this, protectedThis = makeRef(*this), text, completionHandler = WTFMove(completionHandler)](SessionHost::CommandResponse&& response) mutable {
             if (response.isError || !response.responseObject) {
                 completionHandler(CommandResult::fail(WTFMove(response.responseObject)));
                 return;
             }
 
             unsigned stickyModifiers = 0;
+            auto textLength = text.length();
             Vector<KeyboardInteraction> interactions;
-            interactions.reserveInitialCapacity(keys.size());
-            for (const auto& key : keys) {
+            interactions.reserveInitialCapacity(textLength);
+            for (unsigned i = 0; i < textLength; ++i) {
+                auto key = text[i];
                 KeyboardInteraction interaction;
                 KeyModifier modifier;
-                auto virtualKey = virtualKeyForKeySequence(key, modifier);
+                auto virtualKey = virtualKeyForKey(key, modifier);
                 if (!virtualKey.isNull()) {
                     interaction.key = virtualKey;
                     if (modifier != KeyModifier::None) {
@@ -1774,7 +1776,7 @@ void Session::elementSendKeys(const String& elementID, Vector<String>&& keys, Fu
                             interaction.type = KeyboardInteractionType::KeyRelease;
                     }
                 } else
-                    interaction.text = key;
+                    interaction.text = String(&key, 1);
                 interactions.uncheckedAppend(WTFMove(interaction));
             }
 
@@ -2299,7 +2301,7 @@ void Session::performActions(Vector<Vector<Action>>&& actionsByTick, Function<vo
                         break;
                     case Action::Subtype::KeyDown: {
                         KeyModifier modifier;
-                        auto virtualKey = virtualKeyForKeySequence(action.key.value(), modifier);
+                        auto virtualKey = virtualKeyForKey(action.key.value()[0], modifier);
                         if (!virtualKey.isNull())
                             currentState.pressedVirtualKey = virtualKey;
                         else
index 72ab07d..d3fbcb7 100644 (file)
@@ -106,7 +106,7 @@ public:
     void isElementDisplayed(const String& elementID, Function<void (CommandResult&&)>&&);
     void elementClick(const String& elementID, Function<void (CommandResult&&)>&&);
     void elementClear(const String& elementID, Function<void (CommandResult&&)>&&);
-    void elementSendKeys(const String& elementID, Vector<String>&& keys, Function<void (CommandResult&&)>&&);
+    void elementSendKeys(const String& elementID, const String& text, 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&&)>&&);
@@ -184,7 +184,7 @@ private:
         Alternate = 1 << 2,
         Meta = 1 << 3,
     };
-    String virtualKeyForKeySequence(const String& keySequence, KeyModifier&);
+    String virtualKeyForKey(UChar, KeyModifier&);
     void performKeyboardInteractions(Vector<KeyboardInteraction>&&, Function<void (CommandResult&&)>&&);
 
     struct InputSourceState {
index c33646f..076ca00 100644 (file)
@@ -1393,32 +1393,13 @@ void WebDriverService::elementSendKeys(RefPtr<JSON::Object>&& parameters, Functi
     if (!elementID)
         return;
 
-    RefPtr<JSON::Array> valueArray;
-    if (!parameters->getArray("value"_s, valueArray)) {
-        completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
-        return;
-    }
-
-    unsigned valueArrayLength = valueArray->length();
-    if (!valueArrayLength) {
-        completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
-        return;
-    }
-    Vector<String> value;
-    value.reserveInitialCapacity(valueArrayLength);
-    for (unsigned i = 0; i < valueArrayLength; ++i) {
-        if (auto keyValue = valueArray->get(i)) {
-            String key;
-            if (keyValue->asString(key))
-                value.uncheckedAppend(WTFMove(key));
-        }
-    }
-    if (!value.size()) {
+    String text;
+    if (!parameters->getString("text"_s, text) || text.isEmpty()) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return;
     }
 
-    m_session->elementSendKeys(elementID.value(), WTFMove(value), WTFMove(completionHandler));
+    m_session->elementSendKeys(elementID.value(), text, WTFMove(completionHandler));
 }
 
 static bool findScriptAndArgumentsOrCompleteWithError(JSON::Object& parameters, Function<void (CommandResult&&)>& completionHandler, String& script, RefPtr<JSON::Array>& arguments)
index 649ff4b..0b50ae6 100644 (file)
@@ -1,3 +1,14 @@
+2018-08-13  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        WebDriver: several element_send_keys tests are failing since added
+        https://bugs.webkit.org/show_bug.cgi?id=181644
+
+        Reviewed by Michael Catanzaro.
+
+        Update text expectations.
+
+        * TestExpectations.json:
+
 2018-08-12  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Unreviewed GTK test gardening
index 65b7449..fdb3d9a 100644 (file)
     "imported/w3c/webdriver/tests/element_send_keys/form_controls.py": {
         "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/182331"}}
     },
-    "imported/w3c/webdriver/tests/element_send_keys/interactability.py": {
-        "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/181644"}}
-    },
-    "imported/w3c/webdriver/tests/element_send_keys/scroll_into_view.py": {
-        "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/181644"}}
-    },
     "imported/w3c/webdriver/tests/execute_script/collections.py": {
         "subtests": {
             "test_arguments": {