OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/webdriver/commands/cookie_commands.h" | 5 #include "chrome/test/webdriver/commands/cookie_commands.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 return true; | 30 return true; |
31 } | 31 } |
32 | 32 |
33 bool CookieCommand::DoesPost() { | 33 bool CookieCommand::DoesPost() { |
34 return true; | 34 return true; |
35 } | 35 } |
36 | 36 |
37 void CookieCommand::ExecuteGet(Response* const response) { | 37 void CookieCommand::ExecuteGet(Response* const response) { |
38 std::string url; | 38 std::string url; |
39 Error* error = session_->GetURL(&url); | 39 Error* error = session_->GetURL(&url); |
40 ListValue* cookies = NULL; | 40 scoped_ptr<ListValue> cookies; |
41 if (!error) | 41 if (!error) |
42 error = session_->GetCookies(url, &cookies); | 42 error = session_->GetCookies(url, &cookies); |
43 if (error) { | 43 if (error) { |
44 response->SetError(error); | 44 response->SetError(error); |
45 return; | 45 return; |
46 } | 46 } |
47 response->SetValue(cookies); | 47 response->SetValue(cookies.release()); |
48 } | 48 } |
49 | 49 |
50 void CookieCommand::ExecutePost(Response* const response) { | 50 void CookieCommand::ExecutePost(Response* const response) { |
51 const DictionaryValue* cookie_dict; | 51 const DictionaryValue* cookie_dict; |
52 if (!GetDictionaryParameter("cookie", &cookie_dict)) { | 52 if (!GetDictionaryParameter("cookie", &cookie_dict)) { |
53 response->SetError(new Error( | 53 response->SetError(new Error( |
54 kBadRequest, "Missing or invalid |cookie| parameter")); | 54 kBadRequest, "Missing or invalid |cookie| parameter")); |
55 return; | 55 return; |
56 } | 56 } |
57 scoped_ptr<DictionaryValue> cookie_dict_copy(cookie_dict->DeepCopy()); | 57 scoped_ptr<DictionaryValue> cookie_dict_copy(cookie_dict->DeepCopy()); |
(...skipping 18 matching lines...) Expand all Loading... |
76 error = session_->SetCookie(url, cookie_dict_copy.get()); | 76 error = session_->SetCookie(url, cookie_dict_copy.get()); |
77 if (error) { | 77 if (error) { |
78 response->SetError(error); | 78 response->SetError(error); |
79 return; | 79 return; |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 void CookieCommand::ExecuteDelete(Response* const response) { | 83 void CookieCommand::ExecuteDelete(Response* const response) { |
84 std::string url; | 84 std::string url; |
85 Error* error = session_->GetURL(&url); | 85 Error* error = session_->GetURL(&url); |
86 ListValue* unscoped_cookies = NULL; | 86 scoped_ptr<ListValue> cookies; |
87 if (!error) | 87 if (!error) |
88 error = session_->GetCookies(url, &unscoped_cookies); | 88 error = session_->GetCookies(url, &cookies); |
89 scoped_ptr<ListValue> cookies(unscoped_cookies); | |
90 if (error) { | 89 if (error) { |
91 response->SetError(error); | 90 response->SetError(error); |
92 return; | 91 return; |
93 } | 92 } |
94 | 93 |
95 for (size_t i = 0; i < cookies->GetSize(); ++i) { | 94 for (size_t i = 0; i < cookies->GetSize(); ++i) { |
96 DictionaryValue* cookie_dict; | 95 DictionaryValue* cookie_dict; |
97 if (!cookies->GetDictionary(i, &cookie_dict)) { | 96 if (!cookies->GetDictionary(i, &cookie_dict)) { |
98 response->SetError(new Error( | 97 response->SetError(new Error( |
99 kUnknownError, "GetCookies returned non-dict type")); | 98 kUnknownError, "GetCookies returned non-dict type")); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 Error* error = session_->GetURL(&url); | 144 Error* error = session_->GetURL(&url); |
146 if (!error) | 145 if (!error) |
147 error = session_->DeleteCookie(url, cookie_name_); | 146 error = session_->DeleteCookie(url, cookie_name_); |
148 if (error) { | 147 if (error) { |
149 response->SetError(error); | 148 response->SetError(error); |
150 return; | 149 return; |
151 } | 150 } |
152 } | 151 } |
153 | 152 |
154 } // namespace webdriver | 153 } // namespace webdriver |
OLD | NEW |