WebDriver: failing to process capabilities should produce InvalidArgument error not...
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Oct 2017 07:10:55 +0000 (07:10 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Oct 2017 07:10:55 +0000 (07:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178864

Reviewed by Brian Burg.

Fixes most of the tests in imported/w3c/webdriver/tests/sessions/new_session/invalid_capabilities.py.

7.2 Processing Capabilities
https://w3c.github.io/webdriver/webdriver-spec.html#processing-capabilities

* WebDriverService.cpp:
(WebDriver::WebDriverService::processCapabilities const):

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

Source/WebDriver/ChangeLog
Source/WebDriver/WebDriverService.cpp

index 63beffb..c39f0f2 100644 (file)
@@ -1,3 +1,18 @@
+2017-10-27  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        WebDriver: failing to process capabilities should produce InvalidArgument error not SessionNotCreated
+        https://bugs.webkit.org/show_bug.cgi?id=178864
+
+        Reviewed by Brian Burg.
+
+        Fixes most of the tests in imported/w3c/webdriver/tests/sessions/new_session/invalid_capabilities.py.
+
+        7.2 Processing Capabilities
+        https://w3c.github.io/webdriver/webdriver-spec.html#processing-capabilities
+
+        * WebDriverService.cpp:
+        (WebDriver::WebDriverService::processCapabilities const):
+
 2017-10-10  Sam Weinig  <sam@webkit.org>
 
         Replace copyKeysToVector/copyValuesToVector with copyToVector(map.keys())/copyToVector(map.values())
index 5eec2f0..4862eac 100644 (file)
@@ -476,7 +476,7 @@ RefPtr<InspectorObject> WebDriverService::processCapabilities(const InspectorObj
     // 1. Let capabilities request be the result of getting the property "capabilities" from parameters.
     RefPtr<InspectorObject> capabilitiesObject;
     if (!parameters.getObject(ASCIILiteral("capabilities"), capabilitiesObject)) {
-        completionHandler(CommandResult::fail(CommandResult::ErrorCode::SessionNotCreated));
+        completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return nullptr;
     }
 
@@ -487,14 +487,14 @@ RefPtr<InspectorObject> WebDriverService::processCapabilities(const InspectorObj
         // 2.1. If required capabilities is undefined, set the value to an empty JSON Object.
         requiredCapabilities = InspectorObject::create();
     else if (!requiredCapabilitiesValue->asObject(requiredCapabilities)) {
-        completionHandler(CommandResult::fail(CommandResult::ErrorCode::SessionNotCreated, String("alwaysMatch is invalid in capabilities")));
+        completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument, String("alwaysMatch is invalid in capabilities")));
         return nullptr;
     }
 
     // 2.2. Let required capabilities be the result of trying to validate capabilities with argument required capabilities.
     requiredCapabilities = validatedCapabilities(*requiredCapabilities);
     if (!requiredCapabilities) {
-        completionHandler(CommandResult::fail(CommandResult::ErrorCode::SessionNotCreated, String("Invalid alwaysMatch capabilities")));
+        completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument, String("Invalid alwaysMatch capabilities")));
         return nullptr;
     }
 
@@ -507,7 +507,7 @@ RefPtr<InspectorObject> WebDriverService::processCapabilities(const InspectorObj
         firstMatchCapabilitiesList->pushObject(InspectorObject::create());
     } else if (!firstMatchCapabilitiesValue->asArray(firstMatchCapabilitiesList)) {
         // 3.2. If all first match capabilities is not a JSON List, return error with error code invalid argument.
-        completionHandler(CommandResult::fail(CommandResult::ErrorCode::SessionNotCreated, String("firstMatch is invalid in capabilities")));
+        completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument, String("firstMatch is invalid in capabilities")));
         return nullptr;
     }
 
@@ -520,13 +520,13 @@ RefPtr<InspectorObject> WebDriverService::processCapabilities(const InspectorObj
         RefPtr<InspectorValue> firstMatchCapabilitiesValue = firstMatchCapabilitiesList->get(i);
         RefPtr<InspectorObject> firstMatchCapabilities;
         if (!firstMatchCapabilitiesValue->asObject(firstMatchCapabilities)) {
-            completionHandler(CommandResult::fail(CommandResult::ErrorCode::SessionNotCreated, String("Invalid capabilities found in firstMatch")));
+            completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument, String("Invalid capabilities found in firstMatch")));
             return nullptr;
         }
         // 5.1. Let validated capabilities be the result of trying to validate capabilities with argument first match capabilities.
         firstMatchCapabilities = validatedCapabilities(*firstMatchCapabilities);
         if (!firstMatchCapabilities) {
-            completionHandler(CommandResult::fail(CommandResult::ErrorCode::SessionNotCreated, String("Invalid firstMatch capabilities")));
+            completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument, String("Invalid firstMatch capabilities")));
             return nullptr;
         }
         // 5.2. Append validated capabilities to validated first match capabilities.
@@ -539,7 +539,7 @@ RefPtr<InspectorObject> WebDriverService::processCapabilities(const InspectorObj
         // 6.1. Let merged capabilities be the result of trying to merge capabilities with required capabilities and first match capabilities as arguments.
         auto mergedCapabilities = mergeCapabilities(*requiredCapabilities, *validatedFirstMatchCapabilies);
         if (!mergedCapabilities) {
-            completionHandler(CommandResult::fail(CommandResult::ErrorCode::SessionNotCreated, String("Same capability found in firstMatch and alwaysMatch")));
+            completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument, String("Same capability found in firstMatch and alwaysMatch")));
             return nullptr;
         }
         // 6.2. Let matched capabilities be the result of trying to match capabilities with merged capabilities as an argument.
@@ -550,7 +550,7 @@ RefPtr<InspectorObject> WebDriverService::processCapabilities(const InspectorObj
         }
     }
 
-    completionHandler(CommandResult::fail(CommandResult::ErrorCode::SessionNotCreated, errorString ? errorString.value() : String("Invalid capabilities")));
+    completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument, errorString ? errorString.value() : String("Invalid capabilities")));
     return nullptr;
 }