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 "net/base/cookie_monster_store_test.h" | 5 #include "net/base/cookie_monster_store_test.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 MockPersistentCookieStore::MockPersistentCookieStore() | 15 MockPersistentCookieStore::MockPersistentCookieStore() |
16 : load_return_value_(true) { | 16 : load_return_value_(true) { |
17 } | 17 } |
18 | 18 |
19 MockPersistentCookieStore::~MockPersistentCookieStore() {} | 19 MockPersistentCookieStore::~MockPersistentCookieStore() {} |
20 | 20 |
21 void MockPersistentCookieStore::SetLoadExpectation( | 21 void MockPersistentCookieStore::SetLoadExpectation( |
22 bool return_value, | 22 bool return_value, |
23 const std::vector<CookieMonster::CanonicalCookie*>& result) { | 23 const std::vector<CookieMonster::CanonicalCookie*>& result) { |
24 load_return_value_ = return_value; | 24 load_return_value_ = return_value; |
25 load_result_ = result; | 25 load_result_ = result; |
26 } | 26 } |
27 | 27 |
28 bool MockPersistentCookieStore::Load( | 28 bool MockPersistentCookieStore::Load(const LoadedCallback& loaded_callback) { |
29 std::vector<CookieMonster::CanonicalCookie*>* out_cookies) { | |
30 bool ok = load_return_value_; | 29 bool ok = load_return_value_; |
31 if (ok) | 30 std::vector<CookieMonster::CanonicalCookie*> out_cookies; |
32 *out_cookies = load_result_; | 31 if (ok) { |
| 32 out_cookies = load_result_; |
| 33 } |
| 34 loaded_callback.Run(out_cookies); |
33 return ok; | 35 return ok; |
34 } | 36 } |
35 | 37 |
36 void MockPersistentCookieStore::AddCookie( | 38 void MockPersistentCookieStore::AddCookie( |
37 const CookieMonster::CanonicalCookie& cookie) { | 39 const CookieMonster::CanonicalCookie& cookie) { |
38 commands_.push_back( | 40 commands_.push_back( |
39 CookieStoreCommand(CookieStoreCommand::ADD, cookie)); | 41 CookieStoreCommand(CookieStoreCommand::ADD, cookie)); |
40 } | 42 } |
41 | 43 |
42 void MockPersistentCookieStore::UpdateCookieAccessTime( | 44 void MockPersistentCookieStore::UpdateCookieAccessTime( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 !cookie_expires.is_null())); | 103 !cookie_expires.is_null())); |
102 | 104 |
103 out_list->push_back(cookie.release()); | 105 out_list->push_back(cookie.release()); |
104 } | 106 } |
105 | 107 |
106 MockSimplePersistentCookieStore::MockSimplePersistentCookieStore() {} | 108 MockSimplePersistentCookieStore::MockSimplePersistentCookieStore() {} |
107 | 109 |
108 MockSimplePersistentCookieStore::~MockSimplePersistentCookieStore() {} | 110 MockSimplePersistentCookieStore::~MockSimplePersistentCookieStore() {} |
109 | 111 |
110 bool MockSimplePersistentCookieStore::Load( | 112 bool MockSimplePersistentCookieStore::Load( |
111 std::vector<CookieMonster::CanonicalCookie*>* out_cookies) { | 113 const LoadedCallback& loaded_callback) { |
| 114 std::vector<CookieMonster::CanonicalCookie*> out_cookies; |
112 for (CanonicalCookieMap::const_iterator it = cookies_.begin(); | 115 for (CanonicalCookieMap::const_iterator it = cookies_.begin(); |
113 it != cookies_.end(); it++) | 116 it != cookies_.end(); it++) |
114 out_cookies->push_back( | 117 out_cookies.push_back( |
115 new CookieMonster::CanonicalCookie(it->second)); | 118 new CookieMonster::CanonicalCookie(it->second)); |
| 119 loaded_callback.Run(out_cookies); |
116 return true; | 120 return true; |
117 } | 121 } |
118 | 122 |
119 void MockSimplePersistentCookieStore::AddCookie( | 123 void MockSimplePersistentCookieStore::AddCookie( |
120 const CookieMonster::CanonicalCookie& cookie) { | 124 const CookieMonster::CanonicalCookie& cookie) { |
121 int64 creation_time = cookie.CreationDate().ToInternalValue(); | 125 int64 creation_time = cookie.CreationDate().ToInternalValue(); |
122 EXPECT_TRUE(cookies_.find(creation_time) == cookies_.end()); | 126 EXPECT_TRUE(cookies_.find(creation_time) == cookies_.end()); |
123 cookies_[creation_time] = cookie; | 127 cookies_[creation_time] = cookie; |
124 } | 128 } |
125 | 129 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 GURL(), "a", "1", base::StringPrintf("h%05d.izzle", i), "/path", | 175 GURL(), "a", "1", base::StringPrintf("h%05d.izzle", i), "/path", |
172 mac_key, mac_algorithm, creation_time, expiration_time, | 176 mac_key, mac_algorithm, creation_time, expiration_time, |
173 last_access_time, false, false, true); | 177 last_access_time, false, false, true); |
174 store->AddCookie(cc); | 178 store->AddCookie(cc); |
175 } | 179 } |
176 | 180 |
177 return new CookieMonster(store, NULL); | 181 return new CookieMonster(store, NULL); |
178 } | 182 } |
179 | 183 |
180 } // namespace net | 184 } // namespace net |
OLD | NEW |