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

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

Issue 7864008: Split initial load of cookies by domains (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
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/bind.h"
7 #include "base/message_loop.h" 8 #include "base/message_loop.h"
8 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
9 #include "base/time.h" 10 #include "base/time.h"
10 #include "googleurl/src/gurl.h" 11 #include "googleurl/src/gurl.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace net { 14 namespace net {
14
15 MockPersistentCookieStore::MockPersistentCookieStore() 15 MockPersistentCookieStore::MockPersistentCookieStore()
16 : load_return_value_(true) { 16 : load_return_value_(true),
17 loaded_(false) {
17 } 18 }
18 19
19 MockPersistentCookieStore::~MockPersistentCookieStore() {} 20 MockPersistentCookieStore::~MockPersistentCookieStore() {}
20 21
21 void MockPersistentCookieStore::SetLoadExpectation( 22 void MockPersistentCookieStore::SetLoadExpectation(
22 bool return_value, 23 bool return_value,
23 const std::vector<CookieMonster::CanonicalCookie*>& result) { 24 const std::vector<CookieMonster::CanonicalCookie*>& result) {
24 load_return_value_ = return_value; 25 load_return_value_ = return_value;
25 load_result_ = result; 26 load_result_ = result;
26 } 27 }
27 28
28 bool MockPersistentCookieStore::Load(const LoadedCallback& loaded_callback) { 29 void MockPersistentCookieStore::Load(const LoadedCallback& loaded_callback) {
29 bool ok = load_return_value_;
30 std::vector<CookieMonster::CanonicalCookie*> out_cookies; 30 std::vector<CookieMonster::CanonicalCookie*> out_cookies;
31 if (ok) { 31 if (load_return_value_) {
32 out_cookies = load_result_; 32 out_cookies = load_result_;
33 loaded_ = true;
33 } 34 }
34 loaded_callback.Run(out_cookies); 35 MessageLoop::current()->PostTask(FROM_HERE,
35 return ok; 36 base::Bind(&LoadedCallbackTask::Run,
37 new LoadedCallbackTask(loaded_callback, out_cookies)));
38 }
39
40 void MockPersistentCookieStore::LoadCookiesForKey(const std::string& key,
41 const LoadedCallback& loaded_callback) {
42 if (!loaded_) {
43 Load(loaded_callback);
44 } else {
45 MessageLoop::current()->PostTask(FROM_HERE,
46 base::Bind(&LoadedCallbackTask::Run,
47 new LoadedCallbackTask(loaded_callback,
48 std::vector<CookieMonster::CanonicalCookie*>())));
49 }
36 } 50 }
37 51
38 void MockPersistentCookieStore::AddCookie( 52 void MockPersistentCookieStore::AddCookie(
39 const CookieMonster::CanonicalCookie& cookie) { 53 const CookieMonster::CanonicalCookie& cookie) {
40 commands_.push_back( 54 commands_.push_back(
41 CookieStoreCommand(CookieStoreCommand::ADD, cookie)); 55 CookieStoreCommand(CookieStoreCommand::ADD, cookie));
42 } 56 }
43 57
44 void MockPersistentCookieStore::UpdateCookieAccessTime( 58 void MockPersistentCookieStore::UpdateCookieAccessTime(
45 const CookieMonster::CanonicalCookie& cookie) { 59 const CookieMonster::CanonicalCookie& cookie) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 std::string cookie_path = pc.Path(); 120 std::string cookie_path = pc.Path();
107 121
108 return CookieMonster::CanonicalCookie( 122 return CookieMonster::CanonicalCookie(
109 GURL(), pc.Name(), pc.Value(), key, cookie_path, 123 GURL(), pc.Name(), pc.Value(), key, cookie_path,
110 pc.MACKey(), pc.MACAlgorithm(), 124 pc.MACKey(), pc.MACAlgorithm(),
111 creation_time, creation_time, cookie_expires, 125 creation_time, creation_time, cookie_expires,
112 pc.IsSecure(), pc.IsHttpOnly(), 126 pc.IsSecure(), pc.IsHttpOnly(),
113 !cookie_expires.is_null()); 127 !cookie_expires.is_null());
114 } 128 }
115 129
116 MockSimplePersistentCookieStore::MockSimplePersistentCookieStore() {} 130 MockSimplePersistentCookieStore::MockSimplePersistentCookieStore()
131 : loaded_(false) {}
117 132
118 MockSimplePersistentCookieStore::~MockSimplePersistentCookieStore() {} 133 MockSimplePersistentCookieStore::~MockSimplePersistentCookieStore() {}
119 134
120 bool MockSimplePersistentCookieStore::Load( 135 void MockSimplePersistentCookieStore::Load(
121 const LoadedCallback& loaded_callback) { 136 const LoadedCallback& loaded_callback) {
122 std::vector<CookieMonster::CanonicalCookie*> out_cookies; 137 std::vector<CookieMonster::CanonicalCookie*> out_cookies;
138
123 for (CanonicalCookieMap::const_iterator it = cookies_.begin(); 139 for (CanonicalCookieMap::const_iterator it = cookies_.begin();
124 it != cookies_.end(); it++) 140 it != cookies_.end(); it++)
125 out_cookies.push_back( 141 out_cookies.push_back(
126 new CookieMonster::CanonicalCookie(it->second)); 142 new CookieMonster::CanonicalCookie(it->second));
127 loaded_callback.Run(out_cookies); 143
128 return true; 144 MessageLoop::current()->PostTask(FROM_HERE,
145 base::Bind(&LoadedCallbackTask::Run,
146 new LoadedCallbackTask(loaded_callback, out_cookies)));
147 loaded_ = true;
148 }
149
150 void MockSimplePersistentCookieStore::LoadCookiesForKey(const std::string& key,
151 const LoadedCallback& loaded_callback) {
152 if (!loaded_) {
153 Load(loaded_callback);
154 } else {
155 MessageLoop::current()->PostTask(FROM_HERE,
156 base::Bind(&LoadedCallbackTask::Run,
157 new LoadedCallbackTask(loaded_callback,
158 std::vector<CookieMonster::CanonicalCookie*>())));
159 }
129 } 160 }
130 161
131 void MockSimplePersistentCookieStore::AddCookie( 162 void MockSimplePersistentCookieStore::AddCookie(
132 const CookieMonster::CanonicalCookie& cookie) { 163 const CookieMonster::CanonicalCookie& cookie) {
133 int64 creation_time = cookie.CreationDate().ToInternalValue(); 164 int64 creation_time = cookie.CreationDate().ToInternalValue();
134 EXPECT_TRUE(cookies_.find(creation_time) == cookies_.end()); 165 EXPECT_TRUE(cookies_.find(creation_time) == cookies_.end());
135 cookies_[creation_time] = cookie; 166 cookies_[creation_time] = cookie;
136 } 167 }
137 168
138 void MockSimplePersistentCookieStore::UpdateCookieAccessTime( 169 void MockSimplePersistentCookieStore::UpdateCookieAccessTime(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 GURL(), "a", "1", base::StringPrintf("h%05d.izzle", i), "/path", 214 GURL(), "a", "1", base::StringPrintf("h%05d.izzle", i), "/path",
184 mac_key, mac_algorithm, creation_time, expiration_time, 215 mac_key, mac_algorithm, creation_time, expiration_time,
185 last_access_time, false, false, true); 216 last_access_time, false, false, true);
186 store->AddCookie(cc); 217 store->AddCookie(cc);
187 } 218 }
188 219
189 return new CookieMonster(store, NULL); 220 return new CookieMonster(store, NULL);
190 } 221 }
191 222
192 } // namespace net 223 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698