OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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_COMMAND_H_ |
| 6 #define CHROME_TEST_WEBDRIVER_COMMANDS_COMMAND_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/logging.h" |
| 13 #include "base/scoped_ptr.h" |
| 14 #include "base/values.h" |
| 15 #include "base/json/json_writer.h" |
| 16 #include "chrome/test/webdriver/error_codes.h" |
| 17 #include "chrome/test/webdriver/commands/response.h" |
| 18 |
| 19 namespace webdriver { |
| 20 |
| 21 // Base class for a command mapped to a URL in the WebDriver REST API. Each |
| 22 // URL may respond to commands sent with a DELETE, GET/HEAD, or POST HTTP |
| 23 // request. For more information on the WebDriver REST API, see |
| 24 // http://code.google.com/p/selenium/wiki/JsonWireProtocol |
| 25 class Command { |
| 26 public: |
| 27 inline Command(const std::vector<std::string>& path_segments, |
| 28 const DictionaryValue* const parameters) |
| 29 : path_segments_(path_segments), |
| 30 parameters_(parameters) {} |
| 31 virtual ~Command() {} |
| 32 |
| 33 // Indicates which HTTP methods this command URL responds to. |
| 34 virtual bool DoesDelete() { return false; } |
| 35 virtual bool DoesGet() { return false; } |
| 36 virtual bool DoesPost() { return false; } |
| 37 |
| 38 // Initializes this command for execution. If initialization fails, will |
| 39 // return |false| and populate the |response| with the necessary information |
| 40 // to return to the client. |
| 41 virtual bool Init(Response* const response) { return true; } |
| 42 |
| 43 // Executes the corresponding variant of this command URL. |
| 44 // Always called after |Init()| and called from the Execute function. |
| 45 // Any failure is handled as a return code found in Response. |
| 46 virtual void ExecuteDelete(Response* const response) {} |
| 47 virtual void ExecuteGet(Response* const response) {} |
| 48 virtual void ExecutePost(Response* const response) {} |
| 49 |
| 50 protected: |
| 51 |
| 52 // Returns the path variable encoded at the |i|th index (0-based) in the |
| 53 // request URL for this command. If the index is out of bounds, an empty |
| 54 // string will be returned. |
| 55 inline std::string GetPathVariable(const size_t i) const { |
| 56 return i < path_segments_.size() ? path_segments_.at(i) : ""; |
| 57 } |
| 58 |
| 59 // Returns the command parameter with the given |key| as a string. Returns |
| 60 // false if there is no such parameter, or if it is not a string. |
| 61 bool GetStringASCIIParameter(const std::string& key, std::string* out) const; |
| 62 |
| 63 private: |
| 64 const std::vector<std::string> path_segments_; |
| 65 const scoped_ptr<const DictionaryValue> parameters_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(Command); |
| 68 }; |
| 69 } // namespace webdriver |
| 70 #endif // CHROME_TEST_WEBDRIVER_COMMANDS_COMMAND_H_ |
| 71 |
OLD | NEW |