Changeset 222255 in webkit
- Timestamp:
- Sep 19, 2017 11:29:17 PM (7 years ago)
- Location:
- trunk/Source/WebDriver
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebDriver/ChangeLog
r222204 r222255 1 2017-09-19 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 WebDriver: wrong response in case of errors 4 https://bugs.webkit.org/show_bug.cgi?id=177127 5 6 Reviewed by Brian Burg. 7 8 I misunderstood the spec when I implemented this, so we either return a "value" key with the result in case of 9 success or the error object as the body in case of error. We should always add a "value" key to the body and set 10 it with either the result or the error object. 11 12 https://w3c.github.io/webdriver/webdriver-spec.html#dfn-send-an-error 13 14 * WebDriverService.cpp: 15 (WebDriver::WebDriverService::sendResponse const): 16 1 17 2017-09-18 Carlos Garcia Campos <cgarcia@igalia.com> 2 18 -
trunk/Source/WebDriver/WebDriverService.cpp
r222204 r222255 249 249 void WebDriverService::sendResponse(Function<void (HTTPRequestHandler::Response&&)>&& replyHandler, CommandResult&& result) const 250 250 { 251 RefPtr<InspectorObject> responseObject; 251 // §6.3 Processing Model. 252 // https://w3c.github.io/webdriver/webdriver-spec.html#processing-model 253 RefPtr<InspectorValue> resultValue; 252 254 if (result.isError()) { 253 responseObject = InspectorObject::create(); 254 responseObject->setString(ASCIILiteral("error"), result.errorString()); 255 responseObject->setString(ASCIILiteral("message"), result.errorMessage().value_or(emptyString())); 256 responseObject->setString(ASCIILiteral("stacktrace"), emptyString()); 255 // When required to send an error. 256 // https://w3c.github.io/webdriver/webdriver-spec.html#dfn-send-an-error 257 // Let body be a new JSON Object initialised with the following properties: "error", "message", "stacktrace". 258 auto errorObject = InspectorObject::create(); 259 errorObject->setString(ASCIILiteral("error"), result.errorString()); 260 errorObject->setString(ASCIILiteral("message"), result.errorMessage().value_or(emptyString())); 261 errorObject->setString(ASCIILiteral("stacktrace"), emptyString()); 262 // If the error data dictionary contains any entries, set the "data" field on body to a new JSON Object populated with the dictionary. 257 263 if (auto& additionalData = result.additionalErrorData()) 258 responseObject->setObject(ASCIILiteral("data"), RefPtr<InspectorObject> { additionalData }); 259 } else { 260 responseObject = InspectorObject::create(); 261 auto resultValue = result.result(); 262 responseObject->setValue(ASCIILiteral("value"), resultValue ? WTFMove(resultValue) : InspectorValue::null()); 263 } 264 errorObject->setObject(ASCIILiteral("data"), RefPtr<InspectorObject> { additionalData }); 265 // Send a response with status and body as arguments. 266 resultValue = WTFMove(errorObject); 267 } else if (auto value = result.result()) 268 resultValue = WTFMove(value); 269 else 270 resultValue = InspectorValue::null(); 271 272 // When required to send a response. 273 // https://w3c.github.io/webdriver/webdriver-spec.html#dfn-send-a-response 274 RefPtr<InspectorObject> responseObject = InspectorObject::create(); 275 responseObject->setValue(ASCIILiteral("value"), WTFMove(resultValue)); 264 276 replyHandler({ result.httpStatusCode(), responseObject->toJSONString().utf8(), ASCIILiteral("application/json; charset=utf-8") }); 265 277 }
Note: See TracChangeset
for help on using the changeset viewer.