[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 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_WEBDRIVER_ERROR_H_ |
| 6 | #define CHROME_TEST_WEBDRIVER_WEBDRIVER_ERROR_H_ |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/basictypes.h" |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 11 | |
[email protected] | b56da61 | 2011-12-16 23:10:58 | [diff] [blame] | 12 | namespace automation { |
| 13 | class Error; |
| 14 | } |
| 15 | |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 16 | namespace webdriver { |
| 17 | |
| 18 | // Error codes defined by the WebDriver wire protcol. |
| 19 | // If you add a code here, don't forget to add it to |ErrorCodeToString|. |
| 20 | enum ErrorCode { |
| 21 | kSuccess = 0, |
| 22 | kNoSuchElement = 7, |
| 23 | kNoSuchFrame = 8, |
| 24 | kUnknownCommand = 9, |
| 25 | kStaleElementReference = 10, |
| 26 | kElementNotVisible = 11, |
| 27 | kInvalidElementState = 12, |
| 28 | kUnknownError = 13, |
| 29 | kElementNotSelectable = 15, |
| 30 | kXPathLookupError = 19, |
| 31 | kNoSuchWindow = 23, |
| 32 | kInvalidCookieDomain = 24, |
| 33 | kUnableToSetCookie = 25, |
[email protected] | b56da61 | 2011-12-16 23:10:58 | [diff] [blame] | 34 | kUnexpectedAlertOpen = 26, |
| 35 | kNoAlertOpenError = 27, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 36 | |
| 37 | // HTTP status codes. |
| 38 | kSeeOther = 303, |
| 39 | kBadRequest = 400, |
| 40 | kSessionNotFound = 404, |
| 41 | kMethodNotAllowed = 405, |
| 42 | kInternalServerError = 500, |
| 43 | }; |
| 44 | |
| 45 | // Represents a WebDriver error and the context within which the error occurred. |
| 46 | class Error { |
| 47 | public: |
[email protected] | b56da61 | 2011-12-16 23:10:58 | [diff] [blame] | 48 | static Error* FromAutomationError(const automation::Error& error); |
| 49 | |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 50 | explicit Error(ErrorCode code); |
| 51 | |
| 52 | Error(ErrorCode code, const std::string& details); |
| 53 | |
| 54 | virtual ~Error(); |
| 55 | |
| 56 | void AddDetails(const std::string& details); |
| 57 | |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 58 | ErrorCode code() const; |
| 59 | const std::string& details() const; |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 60 | |
| 61 | private: |
| 62 | ErrorCode code_; |
| 63 | std::string details_; |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 64 | |
| 65 | DISALLOW_COPY_AND_ASSIGN(Error); |
| 66 | }; |
| 67 | |
| 68 | } // namespace webdriver |
| 69 | |
| 70 | #endif // CHROME_TEST_WEBDRIVER_WEBDRIVER_ERROR_H_ |