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

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: need to push again to make sure rietveld didn't screw up Created 9 years, 9 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/base64.h"
7 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 11
11 namespace webdriver { 12 namespace webdriver {
12 13
13 namespace { 14 namespace {
14 15
15 // Error message taken from: 16 // Error message taken from:
16 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#Response_Status_Codes 17 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#Response_Status_Codes
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 stack->SetString(kStackTraceMethodNameKey, ""); 68 stack->SetString(kStackTraceMethodNameKey, "");
68 stack->SetInteger(kStackTraceLineNumberKey, line); 69 stack->SetInteger(kStackTraceLineNumberKey, line);
69 ListValue* stack_list = new ListValue; 70 ListValue* stack_list = new ListValue;
70 stack_list->Append(stack); 71 stack_list->Append(stack);
71 error->Set(kStackTraceKey, stack_list); 72 error->Set(kStackTraceKey, stack_list);
72 73
73 SetStatus(error_code); 74 SetStatus(error_code);
74 SetValue(error); 75 SetValue(error);
75 } 76 }
76 77
78 void Response::SetError(ErrorCode error_code,
79 const std::string& message,
80 const std::string& file,
81 int line,
82 const std::string& png) {
83 DictionaryValue* error = new DictionaryValue;
84
85 error->SetString(kMessageKey, message);
86 error->SetString(kStackTraceFileNameKey, file);
87 error->SetInteger(kStackTraceLineNumberKey, line);
88 std::string base64_png;
89
90 // Convert the raw binary data to base 64 encoding for webdriver.
91 if (!base::Base64Encode(png, &base64_png)) {
92 LOG(ERROR) << "Failed to encode screenshot to base64 "
93 << "sending back an empty string instead.";
94 } else {
95 error->SetString(kScreenKey, base64_png);
96 }
97
98 SetStatus(error_code);
99 SetValue(error);
100 }
101
102
77 void Response::SetField(const std::string& key, Value* value) { 103 void Response::SetField(const std::string& key, Value* value) {
78 data_.Set(key, value); 104 data_.Set(key, value);
79 } 105 }
80 106
81 std::string Response::ToJSON() const { 107 std::string Response::ToJSON() const {
82 std::string json; 108 std::string json;
83 base::JSONWriter::Write(&data_, false, &json); 109 base::JSONWriter::Write(&data_, false, &json);
84 return json; 110 return json;
85 } 111 }
86 112
87 } // namespace webdriver 113 } // namespace webdriver
OLDNEW
« no previous file with comments | « chrome/test/webdriver/commands/response.h ('k') | chrome/test/webdriver/commands/screenshot_command.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698