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.
5 #include "chrome/test/chromedriver/chrome/status.h"
7 #include "base/strings/stringprintf.h"
11 // Returns the string equivalent of the given |ErrorCode|.
12 const char* DefaultMessageForStatusCode(StatusCode code) {
17 return "no such session";
19 return "no such element";
21 return "no such frame";
23 return "unknown command";
24 case kStaleElementReference:
25 return "stale element reference";
26 case kElementNotVisible:
27 return "element not visible";
28 case kInvalidElementState:
29 return "invalid element state";
31 return "unknown error";
32 case kJavaScriptError:
33 return "javascript error";
34 case kXPathLookupError:
35 return "xpath lookup error";
39 return "no such window";
40 case kInvalidCookieDomain:
41 return "invalid cookie domain";
42 case kUnexpectedAlertOpen:
43 return "unexpected alert open";
45 return "no alert open";
47 return "asynchronous script timeout";
48 case kInvalidSelector:
49 return "invalid selector";
50 case kSessionNotCreatedException:
51 return "session not created exception";
52 case kNoSuchExecutionContext:
53 return "no such execution context";
54 case kChromeNotReachable:
55 return "chrome not reachable";
57 return "disconnected";
69 Status::Status(StatusCode code)
70 : code_(code), msg_(DefaultMessageForStatusCode(code)) {}
72 Status::Status(StatusCode code, const std::string& details)
74 msg_(DefaultMessageForStatusCode(code) + std::string(": ") + details) {
77 Status::Status(StatusCode code, const Status& cause)
79 msg_(DefaultMessageForStatusCode(code) + std::string("\nfrom ") +
82 Status::Status(StatusCode code,
83 const std::string& details,
86 msg_(DefaultMessageForStatusCode(code) + std::string(": ") + details +
87 "\nfrom " + cause.message()) {
92 void Status::AddDetails(const std::string& details) {
93 msg_ += base::StringPrintf("\n (%s)", details.c_str());
96 bool Status::IsOk() const {
100 bool Status::IsError() const {
104 StatusCode Status::code() const {
108 const std::string& Status::message() const {