Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.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/test/test_timeouts.h" | |
| 12 #include "chrome/common/automation_messages.h" | 13 #include "chrome/common/automation_messages.h" |
| 13 #include "chrome/common/json_value_serializer.h" | 14 #include "chrome/common/json_value_serializer.h" |
| 14 #include "chrome/test/automation/automation_proxy.h" | 15 #include "chrome/test/automation/automation_proxy.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 bool SendAutomationJSONRequest(AutomationMessageSender* sender, | 19 bool SendAutomationJSONRequest(AutomationMessageSender* sender, |
| 19 const DictionaryValue& request_dict, | 20 const DictionaryValue& request_dict, |
| 20 DictionaryValue* reply_dict) { | 21 DictionaryValue* reply_dict) { |
| 21 std::string request, reply; | 22 std::string request, reply; |
| 22 base::JSONWriter::Write(&request_dict, false, &request); | 23 base::JSONWriter::Write(&request_dict, false, &request); |
| 23 bool success = false; | 24 bool success = false; |
| 24 if (!SendAutomationJSONRequest(sender, request, &reply, &success)) | 25 if (!SendAutomationJSONRequest(sender, request, |
| 26 TestTimeouts::action_max_timeout_ms(), &reply, &success)) | |
|
Paweł Hajdan Jr.
2011/04/08 11:04:53
nit: +4 indentation here please as said before.
Huyen
2011/04/09 00:08:15
Done.
| |
| 25 return false; | 27 return false; |
| 26 scoped_ptr<Value> value(base::JSONReader::Read(reply, true)); | 28 scoped_ptr<Value> value(base::JSONReader::Read(reply, true)); |
| 27 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) { | 29 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) { |
| 28 std::string command; | 30 std::string command; |
| 29 request_dict.GetString("command", &command); | 31 request_dict.GetString("command", &command); |
| 30 LOG(ERROR) << "JSON request did not return dict: " << command << "\n"; | 32 LOG(ERROR) << "JSON request did not return dict: " << command << "\n"; |
| 31 return false; | 33 return false; |
| 32 } | 34 } |
| 33 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 35 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
| 34 if (!success) { | 36 if (!success) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 51 const std::string& modified_text, | 53 const std::string& modified_text, |
| 52 int modifiers) | 54 int modifiers) |
| 53 : type(type), | 55 : type(type), |
| 54 key_code(key_code), | 56 key_code(key_code), |
| 55 unmodified_text(unmodified_text), | 57 unmodified_text(unmodified_text), |
| 56 modified_text(modified_text), | 58 modified_text(modified_text), |
| 57 modifiers(modifiers) {} | 59 modifiers(modifiers) {} |
| 58 | 60 |
| 59 bool SendAutomationJSONRequest(AutomationMessageSender* sender, | 61 bool SendAutomationJSONRequest(AutomationMessageSender* sender, |
| 60 const std::string& request, | 62 const std::string& request, |
| 63 int timeout_ms, | |
| 61 std::string* reply, | 64 std::string* reply, |
| 62 bool* success) { | 65 bool* success) { |
| 63 return sender->Send(new AutomationMsg_SendJSONRequest( | 66 return sender->Send(new AutomationMsg_SendJSONRequest( |
| 64 -1, request, reply, success)); | 67 -1, request, reply, success), timeout_ms); |
| 65 } | 68 } |
| 66 | 69 |
| 67 bool SendGetIndicesFromTabIdJSONRequest( | 70 bool SendGetIndicesFromTabIdJSONRequest( |
| 68 AutomationMessageSender* sender, | 71 AutomationMessageSender* sender, |
| 69 int tab_id, | 72 int tab_id, |
| 70 int* browser_index, | 73 int* browser_index, |
| 71 int* tab_index) { | 74 int* tab_index) { |
| 72 DictionaryValue request_dict; | 75 DictionaryValue request_dict; |
| 73 request_dict.SetString("command", "GetIndicesFromTab"); | 76 request_dict.SetString("command", "GetIndicesFromTab"); |
| 74 request_dict.SetInteger("tab_id", tab_id); | 77 request_dict.SetInteger("tab_id", tab_id); |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 return SendAutomationJSONRequest(sender, dict, &reply_dict); | 468 return SendAutomationJSONRequest(sender, dict, &reply_dict); |
| 466 } | 469 } |
| 467 | 470 |
| 468 bool SendWaitForAllTabsToStopLoadingJSONRequest( | 471 bool SendWaitForAllTabsToStopLoadingJSONRequest( |
| 469 AutomationMessageSender* sender) { | 472 AutomationMessageSender* sender) { |
| 470 DictionaryValue dict; | 473 DictionaryValue dict; |
| 471 dict.SetString("command", "WaitForAllTabsToStopLoading"); | 474 dict.SetString("command", "WaitForAllTabsToStopLoading"); |
| 472 DictionaryValue reply_dict; | 475 DictionaryValue reply_dict; |
| 473 return SendAutomationJSONRequest(sender, dict, &reply_dict); | 476 return SendAutomationJSONRequest(sender, dict, &reply_dict); |
| 474 } | 477 } |
| OLD | NEW |