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/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" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 LOG(ERROR) << "Executed javascript but received no 'result'"; | 180 LOG(ERROR) << "Executed javascript but received no 'result'"; |
181 return false; | 181 return false; |
182 } | 182 } |
183 // Wrap |json| in an array before deserializing because valid JSON has an | 183 // Wrap |json| in an array before deserializing because valid JSON has an |
184 // array or an object as the root. | 184 // array or an object as the root. |
185 json.insert(0, "["); | 185 json.insert(0, "["); |
186 json.append("]"); | 186 json.append("]"); |
187 | 187 |
188 JSONStringValueSerializer deserializer(json); | 188 JSONStringValueSerializer deserializer(json); |
189 Value* value = deserializer.Deserialize(NULL, NULL); | 189 Value* value = deserializer.Deserialize(NULL, NULL); |
190 if (!value || !value->AsList()) { | 190 if (!value || !value->IsType(Value::TYPE_LIST)) { |
191 LOG(ERROR) << "Unable to deserialize returned JSON"; | 191 LOG(ERROR) << "Unable to deserialize returned JSON"; |
192 return false; | 192 return false; |
193 } | 193 } |
194 scoped_ptr<ListValue> list(value->AsList()); | 194 scoped_ptr<ListValue> list(static_cast<ListValue*>(value)); |
195 return list->Remove(0, result); | 195 return list->Remove(0, result); |
196 } | 196 } |
197 | 197 |
198 bool SendGoForwardJSONRequest( | 198 bool SendGoForwardJSONRequest( |
199 AutomationMessageSender* sender, | 199 AutomationMessageSender* sender, |
200 int browser_index, | 200 int browser_index, |
201 int tab_index, | 201 int tab_index, |
202 std::string* error_msg) { | 202 std::string* error_msg) { |
203 DictionaryValue dict; | 203 DictionaryValue dict; |
204 dict.SetString("command", "GoForward"); | 204 dict.SetString("command", "GoForward"); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 DictionaryValue dict; | 290 DictionaryValue dict; |
291 dict.SetString("command", "GetCookies"); | 291 dict.SetString("command", "GetCookies"); |
292 dict.SetString("url", url); | 292 dict.SetString("url", url); |
293 DictionaryValue reply_dict; | 293 DictionaryValue reply_dict; |
294 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) | 294 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) |
295 return false; | 295 return false; |
296 Value* cookies_unscoped_value; | 296 Value* cookies_unscoped_value; |
297 if (!reply_dict.Remove("cookies", &cookies_unscoped_value)) | 297 if (!reply_dict.Remove("cookies", &cookies_unscoped_value)) |
298 return false; | 298 return false; |
299 scoped_ptr<Value> cookies_value(cookies_unscoped_value); | 299 scoped_ptr<Value> cookies_value(cookies_unscoped_value); |
300 if (!cookies_value->AsList()) | 300 if (!cookies_value->IsType(Value::TYPE_LIST)) |
301 return false; | 301 return false; |
302 *cookies = cookies_value->AsList(); | 302 *cookies = static_cast<ListValue*>(cookies_value.release()); |
303 return true; | 303 return true; |
304 } | 304 } |
305 | 305 |
306 bool SendDeleteCookieJSONRequest( | 306 bool SendDeleteCookieJSONRequest( |
307 AutomationMessageSender* sender, | 307 AutomationMessageSender* sender, |
308 const std::string& url, | 308 const std::string& url, |
309 const std::string& cookie_name, | 309 const std::string& cookie_name, |
310 std::string* error_msg) { | 310 std::string* error_msg) { |
311 DictionaryValue dict; | 311 DictionaryValue dict; |
312 dict.SetString("command", "DeleteCookie"); | 312 dict.SetString("command", "DeleteCookie"); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 AutomationMessageSender* sender, | 602 AutomationMessageSender* sender, |
603 int* version, | 603 int* version, |
604 std::string* error_msg) { | 604 std::string* error_msg) { |
605 DictionaryValue dict; | 605 DictionaryValue dict; |
606 dict.SetString("command", "GetChromeDriverAutomationVersion"); | 606 dict.SetString("command", "GetChromeDriverAutomationVersion"); |
607 DictionaryValue reply_dict; | 607 DictionaryValue reply_dict; |
608 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) | 608 if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) |
609 return false; | 609 return false; |
610 return reply_dict.GetInteger("version", version); | 610 return reply_dict.GetInteger("version", version); |
611 } | 611 } |
OLD | NEW |