Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: chrome/test/webdriver/commands/response.cc

Issue 5572001: Send screenshots back to the client for debugging (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: for review Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 #include "chrome/test/webdriver/commands/response.h" 5 #include "chrome/test/webdriver/commands/response.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 10
11 namespace webdriver { 11 namespace webdriver {
12 12
13 namespace { 13 namespace {
14 14
15 // Error message taken from: 15 // Error message taken from:
16 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#Response_Status_Codes 16 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#Response_Status_Codes
17 const char* const kStatusKey = "status"; 17 const char* const kStatusKey = "status";
18 const char* const kValueKey = "value"; 18 const char* const kValueKey = "value";
19 const char* const kMessageKey = "message"; 19 const char* const kMessageKey = "message";
20 const char* const kScreenKey = "screen"; 20 const char* const kScreenKey = "screen";
21 const char* const kClassKey = "class"; 21 const char* const kClassKey = "class";
22 const char* const kStackTraceFileNameKey = "stackTrace.fileName"; 22 const char* const kStackTraceFileNameKey = "stackTrace.fileName";
23 const char* const kStackTraceLineNumberKey = "stackTrace.lineNumber"; 23 const char* const kStackTraceLineNumberKey = "stackTrace.lineNumber";
24 24
25 } // namespace 25 } // namespace
26 26
27 Response::Response() { 27 Response::Response() {
28 SetStatus(kSuccess); 28 SetStatus(kSuccess);
29 SetValue(Value::CreateNullValue()); 29 SetValue(Value::CreateNullValue());
30 screenshot_ = "";
30 } 31 }
31 32
32 Response::~Response() {} 33 Response::~Response() {}
33 34
34 ErrorCode Response::GetStatus() const { 35 ErrorCode Response::GetStatus() const {
35 int status; 36 int status;
36 if (!data_.GetInteger(kStatusKey, &status)) 37 if (!data_.GetInteger(kStatusKey, &status))
37 NOTREACHED(); 38 NOTREACHED();
38 return static_cast<ErrorCode>(status); 39 return static_cast<ErrorCode>(status);
39 } 40 }
40 41
41 void Response::SetStatus(ErrorCode status) { 42 void Response::SetStatus(ErrorCode status) {
42 data_.SetInteger(kStatusKey, status); 43 data_.SetInteger(kStatusKey, status);
43 } 44 }
44 45
45 const Value* Response::GetValue() const { 46 const Value* Response::GetValue() const {
46 Value* out = NULL; 47 Value* out = NULL;
47 LOG_IF(WARNING, !data_.Get(kValueKey, &out)) 48 LOG_IF(WARNING, !data_.Get(kValueKey, &out))
48 << "Accessing unset response value."; // Should never happen. 49 << "Accessing unset response value."; // Should never happen.
49 return out; 50 return out;
50 } 51 }
51 52
52 void Response::SetValue(Value* value) { 53 void Response::SetValue(Value* value) {
53 data_.Set(kValueKey, value); 54 data_.Set(kValueKey, value);
54 } 55 }
55 56
56 void Response::SetError(ErrorCode error_code, const std::string& message, 57 void Response::SetError(ErrorCode error_code, const std::string& message,
57 const std::string& file, int line) { 58 const std::string& file, int line) {
kkania 2011/02/24 22:05:02 add a 'const std::string& screenshot' as another a
Joe 2011/03/02 02:21:25 Done.
58 DictionaryValue* error = new DictionaryValue; 59 DictionaryValue* error = new DictionaryValue;
59 error->SetString(kMessageKey, message); 60 error->SetString(kMessageKey, message);
60 error->SetString(kStackTraceFileNameKey, file); 61 error->SetString(kStackTraceFileNameKey, file);
61 error->SetInteger(kStackTraceLineNumberKey, line); 62 error->SetInteger(kStackTraceLineNumberKey, line);
62 63
64 if (!screenshot_.empty()) {
65 error->SetString(kScreenKey, screenshot_);
66 }
67
63 SetStatus(error_code); 68 SetStatus(error_code);
64 SetValue(error); 69 SetValue(error);
65 } 70 }
66 71
67 void Response::SetField(const std::string& key, Value* value) { 72 void Response::SetField(const std::string& key, Value* value) {
68 data_.Set(key, value); 73 data_.Set(key, value);
69 } 74 }
70 75
76 void Response::SetScreenshot(const std::string& screenshot) {
77 screenshot_ = screenshot;
78 }
79
71 std::string Response::ToJSON() const { 80 std::string Response::ToJSON() const {
72 std::string json; 81 std::string json;
73 base::JSONWriter::Write(&data_, false, &json); 82 base::JSONWriter::Write(&data_, false, &json);
74 return json; 83 return json;
75 } 84 }
76 85
77 } // namespace webdriver 86 } // namespace webdriver
78 87
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698