Home | History | Annotate | Download | only in commands
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_
      6 #define CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_
      7 
      8 #include <sstream>
      9 #include <string>
     10 
     11 #include "base/values.h"
     12 #include "chrome/test/webdriver/webdriver_error.h"
     13 
     14 namespace webdriver {
     15 
     16 // A simple class that encapsulates the information describing the response to
     17 // a |Command|. In Webdriver all responses must be sent back as a JSON value,
     18 // conforming to the spec found at:
     19 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#Messages
     20 class Response {
     21  public:
     22   // Creates a new |Response| with a default status of |kSuccess| and a
     23   // |NullValue|.
     24   Response();
     25   ~Response();
     26 
     27   ErrorCode GetStatus() const;
     28   void SetStatus(ErrorCode status);
     29 
     30   // Ownership of the returned pointer is kept by this object.
     31   const base::Value* GetValue() const;
     32 
     33   // Sets the |value| of this response, assuming ownership of the object in the
     34   // process.
     35   void SetValue(base::Value* value);
     36 
     37   // Configures this response to report the given error. Ownership of the error
     38   // is taken from the caller.
     39   void SetError(Error* error);
     40 
     41   // Sets a JSON field in this response. The |key| may be a "." delimitted
     42   // string to indicate the value should be set in a nested object. Any
     43   // previously set value for the |key| will be deleted.
     44   // This object assumes ownership of |value|.
     45   void SetField(const std::string& key, base::Value* value);
     46 
     47   // Returns a pointer to the actual response dictionary.
     48   const base::Value* GetDictionary() const;
     49 
     50   // Returns this response as a JSON string.
     51   std::string ToJSON() const;
     52 
     53  private:
     54   base::DictionaryValue data_;
     55 
     56   DISALLOW_COPY_AND_ASSIGN(Response);
     57 };
     58 
     59 }  // namespace webdriver
     60 
     61 #endif  // CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_
     62