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

Side by Side Diff: chrome/test/automation/automation_json_requests.cc

Issue 7104085: In chromedriver, add /log handler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/automation/automation_json_requests.h ('k') | chrome/test/webdriver/automation.cc » ('j') | 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) 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/automation/automation_json_requests.h" 5 #include "chrome/test/automation/automation_json_requests.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/test/test_timeouts.h" 14 #include "base/test/test_timeouts.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/common/automation_messages.h" 17 #include "chrome/common/automation_messages.h"
18 #include "chrome/test/automation/automation_proxy.h" 18 #include "chrome/test/automation/automation_proxy.h"
19 #include "content/common/json_value_serializer.h" 19 #include "content/common/json_value_serializer.h"
20 20
21 namespace { 21 namespace {
22 22
23 bool SendAutomationJSONRequest(AutomationMessageSender* sender, 23 bool SendAutomationJSONRequest(AutomationMessageSender* sender,
24 const DictionaryValue& request_dict, 24 const DictionaryValue& request_dict,
25 DictionaryValue* reply_dict, 25 DictionaryValue* reply_dict,
26 std::string* error_msg) { 26 std::string* error_msg) {
27 std::string request, reply; 27 std::string request, reply;
28 base::JSONWriter::Write(&request_dict, false, &request); 28 base::JSONWriter::Write(&request_dict, false, &request);
29 std::string command;
30 request_dict.GetString("command", &command);
31 LOG(INFO) << "Sending '" << command << "' command.";
32
33 base::Time before_sending = base::Time::Now();
29 bool success = false; 34 bool success = false;
30 int timeout_ms = TestTimeouts::action_max_timeout_ms(); 35 if (!SendAutomationJSONRequestWithDefaultTimeout(
31 base::Time before_sending = base::Time::Now(); 36 sender, request, &reply, &success)) {
32 if (!SendAutomationJSONRequest( 37 *error_msg = base::StringPrintf(
33 sender, request, timeout_ms, &reply, &success)) { 38 "Chrome did not respond to '%s'. Elapsed time was %" PRId64 " ms. "
34 int64 elapsed_ms = (base::Time::Now() - before_sending).InMilliseconds(); 39 "Request details: (%s).",
35 std::string command; 40 command.c_str(),
36 request_dict.GetString("command", &command); 41 (base::Time::Now() - before_sending).InMilliseconds(),
37 if (elapsed_ms >= timeout_ms) { 42 request.c_str());
38 *error_msg = base::StringPrintf(
39 "Chrome did not respond to '%s'. Request may have timed out. "
40 "Elapsed time was %" PRId64 " ms. Request timeout was %d ms. "
41 "Request details: (%s).",
42 command.c_str(),
43 elapsed_ms,
44 timeout_ms,
45 request.c_str());
46 } else {
47 *error_msg = base::StringPrintf(
48 "Chrome did not respond to '%s'. Elapsed time was %" PRId64 " ms. "
49 "Request details: (%s).",
50 command.c_str(),
51 elapsed_ms,
52 request.c_str());
53 }
54 return false; 43 return false;
55 } 44 }
56 scoped_ptr<Value> value(base::JSONReader::Read(reply, true)); 45 scoped_ptr<Value> value(base::JSONReader::Read(reply, true));
57 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) { 46 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) {
58 std::string command;
59 request_dict.GetString("command", &command);
60 LOG(ERROR) << "JSON request did not return dict: " << command << "\n"; 47 LOG(ERROR) << "JSON request did not return dict: " << command << "\n";
61 return false; 48 return false;
62 } 49 }
63 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); 50 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get());
64 if (!success) { 51 if (!success) {
65 std::string command, error; 52 std::string error;
66 request_dict.GetString("command", &command);
67 dict->GetString("error", &error); 53 dict->GetString("error", &error);
68 *error_msg = base::StringPrintf( 54 *error_msg = base::StringPrintf(
69 "Internal Chrome error during '%s': (%s). Request details: (%s).", 55 "Internal Chrome error during '%s': (%s). Request details: (%s).",
70 command.c_str(), 56 command.c_str(),
71 error.c_str(), 57 error.c_str(),
72 request.c_str()); 58 request.c_str());
73 LOG(ERROR) << "JSON request failed: " << command << "\n" 59 LOG(ERROR) << "JSON request failed: " << command << "\n"
74 << " with error: " << error; 60 << " with error: " << error;
75 return false; 61 return false;
76 } 62 }
(...skipping 16 matching lines...) Expand all
93 79
94 bool SendAutomationJSONRequest(AutomationMessageSender* sender, 80 bool SendAutomationJSONRequest(AutomationMessageSender* sender,
95 const std::string& request, 81 const std::string& request,
96 int timeout_ms, 82 int timeout_ms,
97 std::string* reply, 83 std::string* reply,
98 bool* success) { 84 bool* success) {
99 return sender->Send(new AutomationMsg_SendJSONRequest( 85 return sender->Send(new AutomationMsg_SendJSONRequest(
100 -1, request, reply, success), timeout_ms); 86 -1, request, reply, success), timeout_ms);
101 } 87 }
102 88
89 bool SendAutomationJSONRequestWithDefaultTimeout(
90 AutomationMessageSender* sender,
91 const std::string& request,
92 std::string* reply,
93 bool* success) {
94 return sender->Send(new AutomationMsg_SendJSONRequest(
95 -1, request, reply, success));
96 }
97
103 bool SendGetIndicesFromTabIdJSONRequest( 98 bool SendGetIndicesFromTabIdJSONRequest(
104 AutomationMessageSender* sender, 99 AutomationMessageSender* sender,
105 int tab_id, 100 int tab_id,
106 int* browser_index, 101 int* browser_index,
107 int* tab_index, 102 int* tab_index,
108 std::string* error_msg) { 103 std::string* error_msg) {
109 DictionaryValue request_dict; 104 DictionaryValue request_dict;
110 request_dict.SetString("command", "GetIndicesFromTab"); 105 request_dict.SetString("command", "GetIndicesFromTab");
111 request_dict.SetInteger("tab_id", tab_id); 106 request_dict.SetInteger("tab_id", tab_id);
112 DictionaryValue reply_dict; 107 DictionaryValue reply_dict;
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 AutomationMessageSender* sender, 623 AutomationMessageSender* sender,
629 int* version, 624 int* version,
630 std::string* error_msg) { 625 std::string* error_msg) {
631 DictionaryValue dict; 626 DictionaryValue dict;
632 dict.SetString("command", "GetChromeDriverAutomationVersion"); 627 dict.SetString("command", "GetChromeDriverAutomationVersion");
633 DictionaryValue reply_dict; 628 DictionaryValue reply_dict;
634 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) 629 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg))
635 return false; 630 return false;
636 return reply_dict.GetInteger("version", version); 631 return reply_dict.GetInteger("version", version);
637 } 632 }
OLDNEW
« no previous file with comments | « chrome/test/automation/automation_json_requests.h ('k') | chrome/test/webdriver/automation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698