OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 #include "chrome/test/chromedriver/status.h" | |
6 | |
7 #include "base/stringprintf.h" | |
8 | |
9 namespace { | |
10 | |
11 // Returns the string equivalent of the given |ErrorCode|. | |
12 const char* DefaultMessageForStatusCode(StatusCode code) { | |
13 switch (code) { | |
14 case kOk: | |
15 return "ok"; | |
16 case kNoSuchElement: | |
17 return "no such element"; | |
18 case kUnknownCommand: | |
19 return "unknown command"; | |
20 case kStaleElementReference: | |
21 return "stale element reference"; | |
22 case kElementNotVisible: | |
23 return "element not visible"; | |
24 case kInvalidElementState: | |
25 return "invalid element state"; | |
26 case kUnknownError: | |
27 return "unknown error"; | |
28 case kJavaScriptError: | |
29 return "javascript error"; | |
30 case kXPathLookupError: | |
31 return "xpath lookup error"; | |
32 case kNoSuchWindow: | |
33 return "no such window"; | |
34 case kInvalidCookieDomain: | |
35 return "invalid cookie domain"; | |
36 case kUnexpectedAlertOpen: | |
37 return "unexpected alert open"; | |
38 case kNoAlertOpen: | |
39 return "no alert open"; | |
40 case kScriptTimeout: | |
41 return "asynchronous script timeout"; | |
42 case kInvalidSelector: | |
43 return "invalid selector"; | |
44 case kSessionNotCreatedException: | |
45 return "session not created exception"; | |
46 case kNoSuchSession: | |
47 return "no such session"; | |
48 case kNoSuchFrame: | |
49 return "no such frame"; | |
50 case kChromeNotReachable: | |
51 return "chrome not reachable"; | |
52 case kDisconnected: | |
53 return "disconnected"; | |
54 default: | |
55 return "<unknown>"; | |
56 } | |
57 } | |
58 | |
59 } // namespace | |
60 | |
61 Status::Status(StatusCode code) | |
62 : code_(code), msg_(DefaultMessageForStatusCode(code)) {} | |
63 | |
64 Status::Status(StatusCode code, const std::string& details) | |
65 : code_(code), | |
66 msg_(DefaultMessageForStatusCode(code) + std::string(": ") + details) { | |
67 } | |
68 | |
69 Status::Status(StatusCode code, const Status& cause) | |
70 : code_(code), | |
71 msg_(DefaultMessageForStatusCode(code) + std::string("\nfrom ") + | |
72 cause.message()) {} | |
73 | |
74 Status::Status(StatusCode code, | |
75 const std::string& details, | |
76 const Status& cause) | |
77 : code_(code), | |
78 msg_(DefaultMessageForStatusCode(code) + std::string(": ") + details + | |
79 "\nfrom " + cause.message()) { | |
80 } | |
81 | |
82 Status::~Status() {} | |
83 | |
84 void Status::AddDetails(const std::string& details) { | |
85 msg_ += base::StringPrintf("\n (%s)", details.c_str()); | |
86 } | |
87 | |
88 bool Status::IsOk() const { | |
89 return code_ == kOk; | |
90 } | |
91 | |
92 bool Status::IsError() const { | |
93 return code_ != kOk; | |
94 } | |
95 | |
96 StatusCode Status::code() const { | |
97 return code_; | |
98 } | |
99 | |
100 const std::string& Status::message() const { | |
101 return msg_; | |
102 } | |
OLD | NEW |