Changeset 222255 in webkit


Ignore:
Timestamp:
Sep 19, 2017 11:29:17 PM (7 years ago)
Author:
Carlos Garcia Campos
Message:

WebDriver: wrong response in case of errors
https://bugs.webkit.org/show_bug.cgi?id=177127

Reviewed by Brian Burg.

I misunderstood the spec when I implemented this, so we either return a "value" key with the result in case of
success or the error object as the body in case of error. We should always add a "value" key to the body and set
it with either the result or the error object.

https://w3c.github.io/webdriver/webdriver-spec.html#dfn-send-an-error

  • WebDriverService.cpp:

(WebDriver::WebDriverService::sendResponse const):

Location:
trunk/Source/WebDriver
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebDriver/ChangeLog

    r222204 r222255  
     12017-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
    1172017-09-18  Carlos Garcia Campos  <cgarcia@igalia.com>
    218
  • trunk/Source/WebDriver/WebDriverService.cpp

    r222204 r222255  
    249249void WebDriverService::sendResponse(Function<void (HTTPRequestHandler::Response&&)>&& replyHandler, CommandResult&& result) const
    250250{
    251     RefPtr<InspectorObject> responseObject;
     251    // §6.3 Processing Model.
     252    // https://w3c.github.io/webdriver/webdriver-spec.html#processing-model
     253    RefPtr<InspectorValue> resultValue;
    252254    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.
    257263        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));
    264276    replyHandler({ result.httpStatusCode(), responseObject->toJSONString().utf8(), ASCIILiteral("application/json; charset=utf-8") });
    265277}
Note: See TracChangeset for help on using the changeset viewer.