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

Side by Side Diff: chrome/test/pyautolib/pyautolib.cc

Issue 10855161: Improve pyautolib errors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 4 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
« no previous file with comments | « chrome/test/pyautolib/pyautolib.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "base/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/json/json_writer.h" 6 #include "base/json/json_writer.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 97 }
98 98
99 AutomationProxy* PyUITestBase::automation() const { 99 AutomationProxy* PyUITestBase::automation() const {
100 AutomationProxy* automation_proxy = UITestBase::automation(); 100 AutomationProxy* automation_proxy = UITestBase::automation();
101 if (!automation_proxy) { 101 if (!automation_proxy) {
102 LOG(FATAL) << "The automation proxy is NULL."; 102 LOG(FATAL) << "The automation proxy is NULL.";
103 } 103 }
104 return automation_proxy; 104 return automation_proxy;
105 } 105 }
106 106
107 scoped_refptr<BrowserProxy> PyUITestBase::GetBrowserWindow(int window_index) {
108 return automation()->GetBrowserWindow(window_index);
109 }
110
111 std::string PyUITestBase::_SendJSONRequest(int window_index, 107 std::string PyUITestBase::_SendJSONRequest(int window_index,
112 const std::string& request, 108 const std::string& request,
113 int timeout) { 109 int timeout) {
114 std::string response; 110 std::string response;
115 bool success; 111 bool success;
116 AutomationMessageSender* automation_sender = automation(); 112 AutomationProxy* automation_sender = automation();
117 base::TimeTicks time = base::TimeTicks::Now(); 113 base::TimeTicks time = base::TimeTicks::Now();
118 114
119 if (!automation_sender) { 115 if (!automation_sender) {
120 ErrorResponse("The automation proxy does not exist", request, &response); 116 ErrorResponse("Automation proxy does not exist", request, &response);
117 } else if (!automation_sender->channel()) {
118 ErrorResponse("Chrome automation IPC channel was found already broken",
119 request, &response);
121 } else if (!automation_sender->Send( 120 } else if (!automation_sender->Send(
122 new AutomationMsg_SendJSONRequest(window_index, request, &response, 121 new AutomationMsg_SendJSONRequest(window_index, request, &response,
123 &success), 122 &success),
124 timeout)) { 123 timeout)) {
125 RequestFailureResponse(request, base::TimeTicks::Now() - time, 124 RequestFailureResponse(request, base::TimeTicks::Now() - time,
126 base::TimeDelta::FromMilliseconds(timeout), 125 base::TimeDelta::FromMilliseconds(timeout),
127 &response); 126 &response);
128 } 127 }
129 return response; 128 return response;
130 } 129 }
131 130
132 void PyUITestBase::ErrorResponse( 131 void PyUITestBase::ErrorResponse(
133 const std::string& error_string, 132 const std::string& error_string,
134 const std::string& request, 133 const std::string& request,
135 std::string* response) { 134 std::string* response) {
136 base::DictionaryValue error_dict; 135 base::DictionaryValue error_dict;
137 std::string error_msg = StringPrintf("%s for %s", error_string.c_str(), 136 std::string error_msg = StringPrintf("%s for %s", error_string.c_str(),
138 request.c_str()); 137 request.c_str());
139 LOG(ERROR) << "Error during automation: " << error_msg; 138 LOG(ERROR) << "Error during automation: " << error_msg;
140 error_dict.SetString("error", error_msg); 139 error_dict.SetString("error", error_msg);
140 error_dict.SetBoolean("is_interface_error", true);
141 base::JSONWriter::Write(&error_dict, response); 141 base::JSONWriter::Write(&error_dict, response);
142 } 142 }
143 143
144 void PyUITestBase::RequestFailureResponse( 144 void PyUITestBase::RequestFailureResponse(
145 const std::string& request, 145 const std::string& request,
146 const base::TimeDelta& duration, 146 const base::TimeDelta& duration,
147 const base::TimeDelta& timeout, 147 const base::TimeDelta& timeout,
148 std::string* response) { 148 std::string* response) {
149 // TODO(craigdh): Determine timeout directly from IPC's Send(). 149 // TODO(craigdh): Determine timeout directly from IPC's Send().
150 if (duration >= timeout) { 150 if (duration >= timeout) {
151 ErrorResponse( 151 ErrorResponse(
152 StringPrintf("Request timed out after %d seconds", 152 StringPrintf("Chrome automation timed out after %d seconds",
153 static_cast<int>(duration.InSeconds())), 153 static_cast<int>(duration.InSeconds())),
154 request, response); 154 request, response);
155 } else { 155 } else {
156 // TODO(craigdh): Determine specific cause. 156 // TODO(craigdh): Determine specific cause.
157 ErrorResponse("Chrome failed to respond", request, response); 157 ErrorResponse(
158 "Chrome automation failed prior to timing out, did chrome crash?",
159 request, response);
158 } 160 }
159 } 161 }
OLDNEW
« no previous file with comments | « chrome/test/pyautolib/pyautolib.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698