Title: [219652] trunk/Source
Revision
219652
Author
carlo...@webkit.org
Date
2017-07-18 23:11:50 -0700 (Tue, 18 Jul 2017)

Log Message

WebDriver: handle invalid selector errors
https://bugs.webkit.org/show_bug.cgi?id=174619

Reviewed by Brian Burg.

Source/WebDriver:

Add InvalidSelector error and handle it in case of protocol server error.

* CommandResult.cpp:
(WebDriver::CommandResult::CommandResult):
(WebDriver::CommandResult::httpStatusCode):
(WebDriver::CommandResult::errorString):
* CommandResult.h:

Source/WebKit:

We are currently handling only XPathException and only when it's an invalid _expression_. In the xpath case, the
spec also says "If any item in result is not an element return an error with error code invalid selector.", so
we should also handle TYPE_ERR (The _expression_ could not be converted to return the specified type.). However,
since the spec says "or other error", I think we can simplify this and simply throw InvalidSelector inside the
catch, without checking any specific error. This is causing 14 failures in selenium tests.

§12. Element Retrieval. Step 6: If a DOMException, SyntaxError, XPathException, or other error occurs during the
execution of the element location strategy, return error invalid selector.
https://www.w3.org/TR/webdriver/#dfn-find

* UIProcess/Automation/Automation.json: Add InvalidSelector error.
* UIProcess/Automation/atoms/FindNodes.js:
(tryToFindNode): Raise InvalidSelector in case of error.
* WebProcess/Automation/WebAutomationSessionProxy.cpp:
(WebKit::WebAutomationSessionProxy::evaluateJavaScriptFunction): Handle InvalidSelector exceptions.

Modified Paths

Diff

Modified: trunk/Source/WebDriver/ChangeLog (219651 => 219652)


--- trunk/Source/WebDriver/ChangeLog	2017-07-19 06:10:12 UTC (rev 219651)
+++ trunk/Source/WebDriver/ChangeLog	2017-07-19 06:11:50 UTC (rev 219652)
@@ -1,3 +1,18 @@
+2017-07-18  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        WebDriver: handle invalid selector errors
+        https://bugs.webkit.org/show_bug.cgi?id=174619
+
+        Reviewed by Brian Burg.
+
+        Add InvalidSelector error and handle it in case of protocol server error.
+
+        * CommandResult.cpp:
+        (WebDriver::CommandResult::CommandResult):
+        (WebDriver::CommandResult::httpStatusCode):
+        (WebDriver::CommandResult::errorString):
+        * CommandResult.h:
+
 2017-07-18  Carlos Alberto Lopez Perez  <clo...@igalia.com>
 
         [GTK] Fix build with Clang after r219605.

Modified: trunk/Source/WebDriver/CommandResult.cpp (219651 => 219652)


--- trunk/Source/WebDriver/CommandResult.cpp	2017-07-19 06:10:12 UTC (rev 219651)
+++ trunk/Source/WebDriver/CommandResult.cpp	2017-07-19 06:11:50 UTC (rev 219652)
@@ -98,6 +98,8 @@
             m_errorCode = ErrorCode::InvalidArgument;
         else if (errorName == "InvalidElementState")
             m_errorCode = ErrorCode::InvalidElementState;
+        else if (errorName == "InvalidSelector")
+            m_errorCode = ErrorCode::InvalidSelector;
 
         break;
     }
@@ -120,6 +122,7 @@
     switch (m_errorCode.value()) {
     case ErrorCode::InvalidArgument:
     case ErrorCode::InvalidElementState:
+    case ErrorCode::InvalidSelector:
     case ErrorCode::NoSuchElement:
     case ErrorCode::NoSuchFrame:
     case ErrorCode::NoSuchWindow:
@@ -150,6 +153,8 @@
         return ASCIILiteral("invalid argument");
     case ErrorCode::InvalidElementState:
         return ASCIILiteral("invalid element state");
+    case ErrorCode::InvalidSelector:
+        return ASCIILiteral("invalid selector");
     case ErrorCode::InvalidSessionID:
         return ASCIILiteral("invalid session id");
     case ErrorCode::_javascript_Error:

Modified: trunk/Source/WebDriver/CommandResult.h (219651 => 219652)


--- trunk/Source/WebDriver/CommandResult.h	2017-07-19 06:10:12 UTC (rev 219651)
+++ trunk/Source/WebDriver/CommandResult.h	2017-07-19 06:11:50 UTC (rev 219652)
@@ -41,6 +41,7 @@
     enum class ErrorCode {
         InvalidArgument,
         InvalidElementState,
+        InvalidSelector,
         InvalidSessionID,
         _javascript_Error,
         NoSuchElement,

Modified: trunk/Source/WebKit/ChangeLog (219651 => 219652)


--- trunk/Source/WebKit/ChangeLog	2017-07-19 06:10:12 UTC (rev 219651)
+++ trunk/Source/WebKit/ChangeLog	2017-07-19 06:11:50 UTC (rev 219652)
@@ -1,5 +1,28 @@
 2017-07-18  Carlos Garcia Campos  <cgar...@igalia.com>
 
+        WebDriver: handle invalid selector errors
+        https://bugs.webkit.org/show_bug.cgi?id=174619
+
+        Reviewed by Brian Burg.
+
+        We are currently handling only XPathException and only when it's an invalid _expression_. In the xpath case, the
+        spec also says "If any item in result is not an element return an error with error code invalid selector.", so
+        we should also handle TYPE_ERR (The _expression_ could not be converted to return the specified type.). However,
+        since the spec says "or other error", I think we can simplify this and simply throw InvalidSelector inside the
+        catch, without checking any specific error. This is causing 14 failures in selenium tests.
+
+        §12. Element Retrieval. Step 6: If a DOMException, SyntaxError, XPathException, or other error occurs during the
+        execution of the element location strategy, return error invalid selector.
+        https://www.w3.org/TR/webdriver/#dfn-find
+
+        * UIProcess/Automation/Automation.json: Add InvalidSelector error.
+        * UIProcess/Automation/atoms/FindNodes.js:
+        (tryToFindNode): Raise InvalidSelector in case of error.
+        * WebProcess/Automation/WebAutomationSessionProxy.cpp:
+        (WebKit::WebAutomationSessionProxy::evaluateJavaScriptFunction): Handle InvalidSelector exceptions.
+
+2017-07-18  Carlos Garcia Campos  <cgar...@igalia.com>
+
         Web Automation: error details not passed to DidEvaluateJavaScriptFunction message when callback was not called before page unload
         https://bugs.webkit.org/show_bug.cgi?id=174624
 

Modified: trunk/Source/WebKit/UIProcess/Automation/Automation.json (219651 => 219652)


--- trunk/Source/WebKit/UIProcess/Automation/Automation.json	2017-07-19 06:10:12 UTC (rev 219651)
+++ trunk/Source/WebKit/UIProcess/Automation/Automation.json	2017-07-19 06:11:50 UTC (rev 219652)
@@ -57,7 +57,8 @@
                 "NoJavaScriptDialog",
                 "NotImplemented",
                 "MissingParameter",
-                "InvalidParameter"
+                "InvalidParameter",
+                "InvalidSelector"
             ]
         },
         {

Modified: trunk/Source/WebKit/UIProcess/Automation/atoms/FindNodes.js (219651 => 219652)


--- trunk/Source/WebKit/UIProcess/Automation/atoms/FindNodes.js	2017-07-19 06:10:12 UTC (rev 219651)
+++ trunk/Source/WebKit/UIProcess/Automation/atoms/FindNodes.js	2017-07-19 06:11:50 UTC (rev 219652)
@@ -100,11 +100,10 @@
                 return arrayResult;
             }
         } catch (error) {
-            if (error instanceof XPathException && error.code === XPathException.INVALID_EXPRESSION_ERR)
-                return "InvalidXPathExpression";
-            // FIXME: Bad CSS can throw an error that we should report back to the endpoint. There is no
-            // special error code for that though, so we just return an empty match.
-            return firstResultOnly ? null : [];
+            // §12. Element Retrieval. Step 6: If a DOMException, SyntaxError, XPathException, or other error occurs during
+            // the execution of the element location strategy, return error invalid selector.
+            // https://www.w3.org/TR/webdriver/#dfn-find
+            throw { name: "InvalidSelector", message: error.message };
         }
     }
 

Modified: trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp (219651 => 219652)


--- trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp	2017-07-19 06:10:12 UTC (rev 219651)
+++ trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp	2017-07-19 06:11:50 UTC (rev 219652)
@@ -281,6 +281,8 @@
             errorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::InvalidElementState);
         else if (exceptionName->string() == "InvalidParameter")
             errorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::InvalidParameter);
+        else if (exceptionName->string() == "InvalidSelector")
+            errorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::InvalidSelector);
 
         JSValueRef messageValue = JSObjectGetProperty(context, const_cast<JSObjectRef>(exception), toJSString(ASCIILiteral("message")).get(), nullptr);
         exceptionMessage.adopt(JSValueToStringCopy(context, messageValue, nullptr));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to