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

Side by Side Diff: net/cookies/cookie_monster_store_test.cc

Issue 2383393002: Remove stl_util's deletion functions from net/cookies/ and net/extras/. (Closed)
Patch Set: removing Created 4 years, 2 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
« no previous file with comments | « net/cookies/cookie_monster_store_test.h ('k') | net/cookies/cookie_monster_unittest.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) 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 "net/cookies/cookie_monster_store_test.h" 5 #include "net/cookies/cookie_monster_store_test.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "net/cookies/cookie_constants.h" 14 #include "net/cookies/cookie_constants.h"
15 #include "net/cookies/cookie_util.h" 15 #include "net/cookies/cookie_util.h"
16 #include "net/cookies/parsed_cookie.h" 16 #include "net/cookies/parsed_cookie.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 namespace net { 20 namespace net {
21 21
22 LoadedCallbackTask::LoadedCallbackTask(LoadedCallback loaded_callback,
23 std::vector<CanonicalCookie*> cookies)
24 : loaded_callback_(loaded_callback), cookies_(cookies) {
25 }
26
27 LoadedCallbackTask::~LoadedCallbackTask() {
28 }
29
30 CookieStoreCommand::CookieStoreCommand( 22 CookieStoreCommand::CookieStoreCommand(
31 Type type, 23 Type type,
32 const CookieMonster::PersistentCookieStore::LoadedCallback& loaded_callback, 24 const CookieMonster::PersistentCookieStore::LoadedCallback& loaded_callback,
33 const std::string& key) 25 const std::string& key)
34 : type(type), loaded_callback(loaded_callback), key(key) {} 26 : type(type), loaded_callback(loaded_callback), key(key) {}
35 27
36 CookieStoreCommand::CookieStoreCommand(Type type, const CanonicalCookie& cookie) 28 CookieStoreCommand::CookieStoreCommand(Type type, const CanonicalCookie& cookie)
37 : type(type), cookie(cookie) {} 29 : type(type), cookie(cookie) {}
38 30
39 CookieStoreCommand::CookieStoreCommand(const CookieStoreCommand& other) = 31 CookieStoreCommand::CookieStoreCommand(const CookieStoreCommand& other) =
40 default; 32 default;
41 33
42 CookieStoreCommand::~CookieStoreCommand() {} 34 CookieStoreCommand::~CookieStoreCommand() {}
43 35
44 MockPersistentCookieStore::MockPersistentCookieStore() 36 MockPersistentCookieStore::MockPersistentCookieStore()
45 : store_load_commands_(false), load_return_value_(true), loaded_(false) {} 37 : store_load_commands_(false), load_return_value_(true), loaded_(false) {}
46 38
47 void MockPersistentCookieStore::SetLoadExpectation( 39 void MockPersistentCookieStore::SetLoadExpectation(
48 bool return_value, 40 bool return_value,
49 const std::vector<CanonicalCookie*>& result) { 41 std::vector<std::unique_ptr<CanonicalCookie>> result) {
50 load_return_value_ = return_value; 42 load_return_value_ = return_value;
51 load_result_ = result; 43 load_result_.swap(result);
52 } 44 }
53 45
54 void MockPersistentCookieStore::Load(const LoadedCallback& loaded_callback) { 46 void MockPersistentCookieStore::Load(const LoadedCallback& loaded_callback) {
55 if (store_load_commands_) { 47 if (store_load_commands_) {
56 commands_.push_back( 48 commands_.push_back(
57 CookieStoreCommand(CookieStoreCommand::LOAD, loaded_callback, "")); 49 CookieStoreCommand(CookieStoreCommand::LOAD, loaded_callback, ""));
58 return; 50 return;
59 } 51 }
60 std::vector<CanonicalCookie*> out_cookies; 52 std::vector<std::unique_ptr<CanonicalCookie>> out_cookies;
61 if (load_return_value_) { 53 if (load_return_value_) {
62 out_cookies = load_result_; 54 out_cookies.swap(load_result_);
63 loaded_ = true; 55 loaded_ = true;
64 } 56 }
65 base::ThreadTaskRunnerHandle::Get()->PostTask( 57 base::ThreadTaskRunnerHandle::Get()->PostTask(
66 FROM_HERE, 58 FROM_HERE, base::Bind(loaded_callback, base::Passed(&out_cookies)));
67 base::Bind(&LoadedCallbackTask::Run,
68 new LoadedCallbackTask(loaded_callback, out_cookies)));
69 } 59 }
70 60
71 void MockPersistentCookieStore::LoadCookiesForKey( 61 void MockPersistentCookieStore::LoadCookiesForKey(
72 const std::string& key, 62 const std::string& key,
73 const LoadedCallback& loaded_callback) { 63 const LoadedCallback& loaded_callback) {
74 if (store_load_commands_) { 64 if (store_load_commands_) {
75 commands_.push_back(CookieStoreCommand( 65 commands_.push_back(CookieStoreCommand(
76 CookieStoreCommand::LOAD_COOKIES_FOR_KEY, loaded_callback, key)); 66 CookieStoreCommand::LOAD_COOKIES_FOR_KEY, loaded_callback, key));
77 return; 67 return;
78 } 68 }
79 if (!loaded_) { 69 if (!loaded_) {
80 Load(loaded_callback); 70 Load(loaded_callback);
81 } else { 71 } else {
72 std::vector<std::unique_ptr<CanonicalCookie>> empty_cookies;
82 base::ThreadTaskRunnerHandle::Get()->PostTask( 73 base::ThreadTaskRunnerHandle::Get()->PostTask(
83 FROM_HERE, 74 FROM_HERE, base::Bind(loaded_callback, base::Passed(&empty_cookies)));
84 base::Bind(&LoadedCallbackTask::Run,
85 new LoadedCallbackTask(loaded_callback,
86 std::vector<CanonicalCookie*>())));
87 } 75 }
88 } 76 }
89 77
90 void MockPersistentCookieStore::AddCookie(const CanonicalCookie& cookie) { 78 void MockPersistentCookieStore::AddCookie(const CanonicalCookie& cookie) {
91 commands_.push_back(CookieStoreCommand(CookieStoreCommand::ADD, cookie)); 79 commands_.push_back(CookieStoreCommand(CookieStoreCommand::ADD, cookie));
92 } 80 }
93 81
94 void MockPersistentCookieStore::UpdateCookieAccessTime( 82 void MockPersistentCookieStore::UpdateCookieAccessTime(
95 const CanonicalCookie& cookie) { 83 const CanonicalCookie& cookie) {
96 } 84 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 132
145 return CanonicalCookie::Create(url, pc.Name(), pc.Value(), url.host(), 133 return CanonicalCookie::Create(url, pc.Name(), pc.Value(), url.host(),
146 cookie_path, creation_time, cookie_expires, 134 cookie_path, creation_time, cookie_expires,
147 pc.IsSecure(), pc.IsHttpOnly(), pc.SameSite(), 135 pc.IsSecure(), pc.IsHttpOnly(), pc.SameSite(),
148 false, pc.Priority()); 136 false, pc.Priority());
149 } 137 }
150 138
151 void AddCookieToList(const GURL& url, 139 void AddCookieToList(const GURL& url,
152 const std::string& cookie_line, 140 const std::string& cookie_line,
153 const base::Time& creation_time, 141 const base::Time& creation_time,
154 std::vector<CanonicalCookie*>* out_list) { 142 std::vector<std::unique_ptr<CanonicalCookie>>* out_list) {
155 std::unique_ptr<CanonicalCookie> cookie( 143 std::unique_ptr<CanonicalCookie> cookie(
156 BuildCanonicalCookie(url, cookie_line, creation_time)); 144 BuildCanonicalCookie(url, cookie_line, creation_time));
157 145
158 out_list->push_back(cookie.release()); 146 out_list->push_back(std::move(cookie));
159 } 147 }
160 148
161 MockSimplePersistentCookieStore::MockSimplePersistentCookieStore() 149 MockSimplePersistentCookieStore::MockSimplePersistentCookieStore()
162 : loaded_(false) { 150 : loaded_(false) {
163 } 151 }
164 152
165 void MockSimplePersistentCookieStore::Load( 153 void MockSimplePersistentCookieStore::Load(
166 const LoadedCallback& loaded_callback) { 154 const LoadedCallback& loaded_callback) {
167 std::vector<CanonicalCookie*> out_cookies; 155 std::vector<std::unique_ptr<CanonicalCookie>> out_cookies;
168 156
169 for (CanonicalCookieMap::const_iterator it = cookies_.begin(); 157 for (auto it = cookies_.begin(); it != cookies_.end(); it++)
170 it != cookies_.end(); it++) 158 out_cookies.push_back(base::MakeUnique<CanonicalCookie>(it->second));
171 out_cookies.push_back(new CanonicalCookie(it->second));
172 159
173 base::ThreadTaskRunnerHandle::Get()->PostTask( 160 base::ThreadTaskRunnerHandle::Get()->PostTask(
174 FROM_HERE, 161 FROM_HERE, base::Bind(loaded_callback, base::Passed(&out_cookies)));
175 base::Bind(&LoadedCallbackTask::Run,
176 new LoadedCallbackTask(loaded_callback, out_cookies)));
177 loaded_ = true; 162 loaded_ = true;
178 } 163 }
179 164
180 void MockSimplePersistentCookieStore::LoadCookiesForKey( 165 void MockSimplePersistentCookieStore::LoadCookiesForKey(
181 const std::string& key, 166 const std::string& key,
182 const LoadedCallback& loaded_callback) { 167 const LoadedCallback& loaded_callback) {
183 if (!loaded_) { 168 if (!loaded_) {
184 Load(loaded_callback); 169 Load(loaded_callback);
185 } else { 170 } else {
171 std::vector<std::unique_ptr<CanonicalCookie>> empty_cookies;
186 base::ThreadTaskRunnerHandle::Get()->PostTask( 172 base::ThreadTaskRunnerHandle::Get()->PostTask(
187 FROM_HERE, 173 FROM_HERE, base::Bind(loaded_callback, base::Passed(&empty_cookies)));
188 base::Bind(&LoadedCallbackTask::Run,
189 new LoadedCallbackTask(loaded_callback,
190 std::vector<CanonicalCookie*>())));
191 } 174 }
192 } 175 }
193 176
194 void MockSimplePersistentCookieStore::AddCookie(const CanonicalCookie& cookie) { 177 void MockSimplePersistentCookieStore::AddCookie(const CanonicalCookie& cookie) {
195 int64_t creation_time = cookie.CreationDate().ToInternalValue(); 178 int64_t creation_time = cookie.CreationDate().ToInternalValue();
196 EXPECT_TRUE(cookies_.find(creation_time) == cookies_.end()); 179 EXPECT_TRUE(cookies_.find(creation_time) == cookies_.end());
197 cookies_[creation_time] = cookie; 180 cookies_[creation_time] = cookie;
198 } 181 }
199 182
200 void MockSimplePersistentCookieStore::UpdateCookieAccessTime( 183 void MockSimplePersistentCookieStore::UpdateCookieAccessTime(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 store->AddCookie(*cc); 243 store->AddCookie(*cc);
261 } 244 }
262 245
263 return base::MakeUnique<CookieMonster>(store.get(), nullptr); 246 return base::MakeUnique<CookieMonster>(store.get(), nullptr);
264 } 247 }
265 248
266 MockSimplePersistentCookieStore::~MockSimplePersistentCookieStore() { 249 MockSimplePersistentCookieStore::~MockSimplePersistentCookieStore() {
267 } 250 }
268 251
269 } // namespace net 252 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster_store_test.h ('k') | net/cookies/cookie_monster_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698