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

Unified Diff: chrome/test/pyautolib/pyautolib.cc

Issue 10534163: First pass at refactoring pyautolib in preparation for removing proxy dependencies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Applied Nirnimesh's suggestions. Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/pyautolib/pyautolib.cc
diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc
index 37a32491aba38f7eecd62521e609654aa3410739..91176f1eb8f9d3409e9479e8669fc397f53e434c 100644
--- a/chrome/test/pyautolib/pyautolib.cc
+++ b/chrome/test/pyautolib/pyautolib.cc
@@ -11,6 +11,7 @@
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "chrome/common/automation_messages.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/automation/automation_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
@@ -365,35 +366,52 @@ std::string PyUITestBase::_SendJSONRequest(int window_index,
const std::string& request,
int timeout) {
std::string response;
- base::TimeTicks time;
- if (window_index < 0) { // Do not need to target a browser window.
- time = base::TimeTicks::Now();
- if (!automation()->SendJSONRequest(request, timeout, &response)) {
- LOG(WARNING) << "SendJSONRequest returned false after "
- << (base::TimeTicks::Now() - time).InSeconds()
- << " seconds: " << request;
- }
- } else {
- scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
- if (!browser_proxy.get()) {
- base::DictionaryValue error_dict;
- std::string error_string = StringPrintf(
- "No browser at windex=%d for %s", window_index, request.c_str());
- LOG(WARNING) << error_string;
- error_dict.SetString("error", error_string);
- base::JSONWriter::Write(&error_dict, &response);
- } else {
- time = base::TimeTicks::Now();
- if (!browser_proxy->SendJSONRequest(request, timeout, &response)) {
- LOG(WARNING) << "SendJSONRequest returned false after "
- << (base::TimeTicks::Now() - time).InSeconds()
- << " seconds: " << request;
- }
- }
+ bool success;
+ AutomationMessageSender* automation_sender = automation();
+ base::TimeTicks time = base::TimeTicks::Now();
+
+ if (!automation_sender) {
+ ErrorResponse("The automation proxy does not exist", request, &response);
+ } else if (!automation_sender->Send(
+ new AutomationMsg_SendJSONRequestWithBrowserIndex(window_index, request,
+ &response, &success),
+ timeout)) {
+ RequestFailureResponse(request, base::TimeTicks::Now() - time,
+ base::TimeDelta::FromMilliseconds(timeout),
+ &response);
}
return response;
}
+void PyUITestBase::ErrorResponse(
+ const std::string& error_string,
+ const std::string& request,
+ std::string* response) {
+ base::DictionaryValue error_dict;
+ LOG(WARNING) << "Error during automation: " << response;
Nirnimesh 2012/06/15 19:52:49 LOG(ERROR)?
craigdh 2012/06/19 00:19:35 Done.
+ error_dict.SetString("error",
+ StringPrintf("%s for %s",
+ error_string.c_str(),
+ request.c_str()));
+ base::JSONWriter::Write(&error_dict, response);
+}
+
+void PyUITestBase::RequestFailureResponse(
+ const std::string& request,
+ const base::TimeDelta& duration,
+ const base::TimeDelta& timeout,
+ std::string* response) {
+ if (duration >= timeout) {
Nirnimesh 2012/06/15 19:52:49 Add a TODO to deduce timeout from the ipc Send() c
craigdh 2012/06/19 00:19:35 Done.
+ ErrorResponse(
+ StringPrintf("Request timed out after %d seconds",
+ static_cast<int>(duration.InSeconds())),
+ request, response);
+ } else {
+ // TODO(craigdh): Determine specific cause.
+ ErrorResponse("Chrome failed to respond", request, response);
+ }
+}
+
bool PyUITestBase::ResetToDefaultTheme() {
return automation()->ResetToDefaultTheme();
}
« chrome/common/automation_messages_internal.h ('K') | « chrome/test/pyautolib/pyautolib.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698