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

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: changed PageSnapshotTaker to use JSON interface 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 const std::string& file, int line) { 58 const std::string& file, int line) {
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
63 SetStatus(error_code); 64 SetStatus(error_code);
64 SetValue(error); 65 SetValue(error);
65 } 66 }
66 67
68 void Response::SetError(ErrorCode error_code,
69 const std::string& message,
70 const std::string& file,
71 int line,
72 const std::string& png) {
73 DictionaryValue* error = new DictionaryValue;
74
75 error->SetString(kMessageKey, message);
76 error->SetString(kStackTraceFileNameKey, file);
77 error->SetInteger(kStackTraceLineNumberKey, line);
78 std::string base64_png;
79
80 // Convert the raw binary data to base 64 encoding for webdriver.
81 if (!base::Base64Encode(png, &base64_png)) {
82 LOG(ERROR) << "Failed to encode screenshot to base64 "
83 << "sending back an empty string instead.";
84 error->SetString(kScreenKey, "");
kkania 2011/03/22 21:08:56 I think it might be better to just not set kScreen
Joe 2011/03/22 22:08:19 Done.
85 } else {
86 error->SetString(kScreenKey, base64_png);
87 }
88
89 SetStatus(error_code);
90 SetValue(error);
91 }
92
93
67 void Response::SetField(const std::string& key, Value* value) { 94 void Response::SetField(const std::string& key, Value* value) {
68 data_.Set(key, value); 95 data_.Set(key, value);
69 } 96 }
70 97
71 std::string Response::ToJSON() const { 98 std::string Response::ToJSON() const {
72 std::string json; 99 std::string json;
73 base::JSONWriter::Write(&data_, false, &json); 100 base::JSONWriter::Write(&data_, false, &json);
74 return json; 101 return json;
75 } 102 }
76 103
77 } // namespace webdriver 104 } // namespace webdriver
78 105
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698