Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_ | 5 #ifndef CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_ |
| 6 #define CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_ | 6 #define CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_ |
| 7 | 7 |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/test/webdriver/error_codes.h" | 12 #include "chrome/test/webdriver/error_codes.h" |
| 13 #include "chrome/test/webdriver/session_manager.h" | |
| 13 | 14 |
| 14 namespace webdriver { | 15 namespace webdriver { |
| 15 | 16 |
| 16 // All errors in webdriver must use this macro in order to send back | 17 // All errors in webdriver must use this macro in order to send back |
| 17 // a proper stack trace to the client | 18 // a proper stack trace to the client |
| 18 #define SET_WEBDRIVER_ERROR(response, msg, err) \ | 19 #define SET_WEBDRIVER_ERROR(response, msg, err) \ |
| 19 response->SetError(err, msg, __FILE__, __LINE__); \ | 20 response->SetError(err, msg, __FILE__, __LINE__,""); \ |
| 21 LOG(ERROR) << msg | |
| 22 | |
| 23 | |
| 24 // All errors in webdriver must use this macro in order to send back | |
| 25 // a proper stack trace to the client | |
| 26 #define SET_WEBDRIVER_ERROR2(response, session, msg, err) \ | |
| 27 { \ | |
| 28 std::string __screenshot__ = ""; \ | |
| 29 webdriver::SessionManager* sm = webdriver::SessionManager::GetInstance(); \ | |
| 30 if (sm->ScreenshotOnError()) { \ | |
|
kkania
2011/03/07 18:15:17
why not screenshot_on_error
Joe
2011/03/11 22:12:48
Not every error is a screen shot and since they ar
| |
| 31 session->ScreenshotAsBase64(&__screenshot__); \ | |
| 32 response->SetScreenshotAsBase64(__screenshot__); \ | |
| 33 } \ | |
| 34 response->SetError(err, msg, __FILE__, __LINE__, __screenshot__); \ | |
| 35 } \ | |
| 20 LOG(ERROR) << msg | 36 LOG(ERROR) << msg |
| 21 | 37 |
| 22 // A simple class that encapsulates the information describing the response to | 38 // A simple class that encapsulates the information describing the response to |
| 23 // a |Command|. In Webdriver all responses must be sent back as a JSON value, | 39 // a |Command|. In Webdriver all responses must be sent back as a JSON value, |
| 24 // conforming to the spec found at: | 40 // conforming to the spec found at: |
| 25 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#Messages | 41 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#Messages |
| 26 class Response { | 42 class Response { |
| 27 public: | 43 public: |
| 28 // Creates a new |Response| with a default status of |kSuccess| and a | 44 // Creates a new |Response| with a default status of |kSuccess| and a |
| 29 // |NullValue|. | 45 // |NullValue|. |
| 30 Response(); | 46 Response(); |
| 31 ~Response(); | 47 ~Response(); |
| 32 | 48 |
| 33 ErrorCode GetStatus() const; | 49 ErrorCode GetStatus() const; |
| 34 void SetStatus(ErrorCode status); | 50 void SetStatus(ErrorCode status); |
| 35 | 51 |
| 36 // Ownership of the returned pointer is kept by this object. | 52 // Ownership of the returned pointer is kept by this object. |
| 37 const Value* GetValue() const; | 53 const Value* GetValue() const; |
| 38 | 54 |
| 39 // Sets the |value| of this response, assuming ownership of the object in the | 55 // Sets the |value| of this response, assuming ownership of the object in the |
| 40 // process. | 56 // process. |
| 41 void SetValue(Value* value); | 57 void SetValue(Value* value); |
| 42 | 58 |
| 43 // Configures this response to report an error. The |file| and |line| | 59 // Configures this response to report an error. The |file| and |line| |
| 44 // parameters, which identify where in the source the error occurred, can be | 60 // parameters, which identify where in the source the error occurred, can be |
| 45 // set using the |SET_WEBDRIVER_ERROR| macro above. | 61 // set using the |SET_WEBDRIVER_ERROR| macro above. |
| 46 void SetError(ErrorCode error, const std::string& message, | 62 void SetError(ErrorCode error, |
| 47 const std::string& file, int line); | 63 const std::string& message, |
| 64 const std::string& file, | |
| 65 int line, | |
| 66 const std::string& screenshot); | |
| 48 | 67 |
| 49 // Sets a JSON field in this response. The |key| may be a "." delimitted | 68 // Sets a JSON field in this response. The |key| may be a "." delimitted |
| 50 // string to indicate the value should be set in a nested object. Any | 69 // string to indicate the value should be set in a nested object. Any |
| 51 // previously set value for the |key| will be deleted. | 70 // previously set value for the |key| will be deleted. |
| 52 // This object assumes ownership of |value|. | 71 // This object assumes ownership of |value|. |
| 53 void SetField(const std::string& key, Value* value); | 72 void SetField(const std::string& key, Value* value); |
| 54 | 73 |
| 55 // Returns this response as a JSON string. | 74 // Returns this response as a JSON string. |
| 56 std::string ToJSON() const; | 75 std::string ToJSON() const; |
| 57 | 76 |
| 58 private: | 77 private: |
| 59 DictionaryValue data_; | 78 DictionaryValue data_; |
|
kkania
2011/03/07 18:15:17
i don't really care that much, but I think the nor
Joe
2011/03/11 22:12:48
Done.
| |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(Response); | 79 DISALLOW_COPY_AND_ASSIGN(Response); |
| 62 }; | 80 }; |
| 63 | 81 |
| 64 } // namespace webdriver | 82 } // namespace webdriver |
| 65 | 83 |
| 66 #endif // CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_ | 84 #endif // CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_ |
| 67 | 85 |
| OLD | NEW |