Chromium Code Reviews| Index: chrome/test/pyautolib/pyautolib.cc |
| diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc |
| index 37a32491aba38f7eecd62521e609654aa3410739..b864a2aaebd8d94210f2ff70a1230d511d74ac66 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,49 @@ 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_SendJSONRequestWithIndex(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; |
| + 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/14 22:16:42
please add a test for timeout in test_pyauto.py
Nirnimesh
2012/06/14 22:16:42
There should be better way to determine if it time
craigdh
2012/06/15 19:24:53
Done.
craigdh
2012/06/15 19:24:53
Yes, but right now this is still going through the
|
| + ErrorResponse("Request timed out", request, response); |
|
Nirnimesh
2012/06/14 22:16:42
print out duration as well
craigdh
2012/06/15 19:24:53
Done.
|
| + } else { |
| + // TODO(craigdh): Determine specific cause. |
| + ErrorResponse("Chrome failed to respond", request, response); |
| + } |
| +} |
| + |
| bool PyUITestBase::ResetToDefaultTheme() { |
| return automation()->ResetToDefaultTheme(); |
| } |