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

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

Issue 7833042: Finalize a CL originally by departed intern ycxiao@ that detaches the loading of cookies from the... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "net/base/cookie_monster.h" 7 #include "base/bind.h"
8 8 #include "base/message_loop.h"
9 #include "base/perftimer.h" 9 #include "base/perftimer.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 #include "net/base/cookie_monster.h" 13 #include "net/base/cookie_monster.h"
14 #include "net/base/cookie_monster_store_test.h" 14 #include "net/base/cookie_monster_store_test.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace { 17 namespace {
18 class ParsedCookieTest : public testing::Test { }; 18 class CookieMonsterTest : public testing::Test {
Randy Smith (Not in Mondays) 2011/09/07 19:04:07 Why is it ok to get rid of this? (I'm assuming it
erikwright (departed) 2011/09/08 02:48:58 No one actually used it. The TEST definitions do n
19 class CookieMonsterTest : public testing::Test { }; 19 public:
20 CookieMonsterTest() : message_loop_(new MessageLoopForIO()) {}
21
22 private:
23 scoped_ptr<MessageLoop> message_loop_;
24 };
20 } 25 }
21 26
22 static const int kNumCookies = 20000; 27 static const int kNumCookies = 20000;
23 static const char kCookieLine[] = "A = \"b=;\\\"\" ;secure;;;"; 28 static const char kCookieLine[] = "A = \"b=;\\\"\" ;secure;;;";
24 29
25 namespace net { 30 namespace net {
26 31
27 TEST(ParsedCookieTest, TestParseCookies) { 32 TEST(ParsedCookieTest, TestParseCookies) {
28 std::string cookie(kCookieLine); 33 std::string cookie(kCookieLine);
29 PerfTimeLogger timer("Parsed_cookie_parse_cookies"); 34 PerfTimeLogger timer("Parsed_cookie_parse_cookies");
(...skipping 10 matching lines...) Expand all
40 PerfTimeLogger timer("Parsed_cookie_parse_big_cookies"); 45 PerfTimeLogger timer("Parsed_cookie_parse_big_cookies");
41 for (int i = 0; i < kNumCookies; ++i) { 46 for (int i = 0; i < kNumCookies; ++i) {
42 CookieMonster::ParsedCookie pc(cookie); 47 CookieMonster::ParsedCookie pc(cookie);
43 EXPECT_TRUE(pc.IsValid()); 48 EXPECT_TRUE(pc.IsValid());
44 } 49 }
45 timer.Done(); 50 timer.Done();
46 } 51 }
47 52
48 static const GURL kUrlGoogle("http://www.google.izzle"); 53 static const GURL kUrlGoogle("http://www.google.izzle");
49 54
50 TEST(CookieMonsterTest, TestAddCookiesOnSingleHost) { 55 class BaseCallback {
56 public:
57 BaseCallback() : run_(false) {}
58 bool run() { return run_; }
Randy Smith (Not in Mondays) 2011/09/07 19:04:07 nit: const?
erikwright (departed) 2011/09/08 02:48:58 Done.
59 void reset() { run_ = false; }
Randy Smith (Not in Mondays) 2011/09/07 19:04:07 nit: The semantic difference between BaseCallback:
erikwright (departed) 2011/09/08 02:48:58 Done.
60 protected:
61 bool run_;
62 };
63
64
65 class SetCookieCallback : public BaseCallback {
66 public:
67 void SetCookie(
68 CookieMonster* cm, const GURL& gurl, const std::string& cookie) {
69 cm->SetCookieWithOptionsAsync(gurl, cookie, options_, base::Bind(
70 &SetCookieCallback::Run, base::Unretained(this)));
71 MessageLoop::current()->RunAllPending();
72 EXPECT_TRUE(run());
73 reset();
74 }
75 private:
76 void Run(bool success) {
77 EXPECT_TRUE(success);
78 run_ = true;
79 }
80 net::CookieOptions options_;
81 };
82
83 class GetCookiesCallback : public BaseCallback {
84 public:
85 const std::string& GetCookies(CookieMonster* cm, const GURL& gurl) {
86 cm->GetCookiesWithOptionsAsync(gurl, options_, base::Bind(
87 &GetCookiesCallback::Run, base::Unretained(this)));
88 MessageLoop::current()->RunAllPending();
89 EXPECT_TRUE(run());
90 reset();
91 return cookies_;
92 }
93
94 private:
95 void Run(const std::string& cookies) {
96 run_ = true;
97 cookies_ = cookies;
98 }
99 std::string cookies_;
100 net::CookieOptions options_;
101 };
102
103 class GetCookiesWithInfoCallback : public BaseCallback {
104 public:
105 const std::string& GetCookiesWithInfo(CookieMonster* cm, const GURL& gurl) {
106 cm->GetCookiesWithInfoAsync(gurl, options_, base::Bind(
107 &GetCookiesWithInfoCallback::Run,
108 base::Unretained(this)));
109 MessageLoop::current()->RunAllPending();
Randy Smith (Not in Mondays) 2011/09/07 19:04:07 Does this guarantee that we've received the callba
erikwright (departed) 2011/09/08 02:48:58 Done.
110 EXPECT_TRUE(run());
111 reset();
112 return cookies_;
113 }
114
115 private:
116 void Run(
117 const std::string& cookie_line,
118 const std::vector<CookieStore::CookieInfo>& cookie_infos) {
119 cookies_ = cookie_line;
120 run_ = true;
121 }
122
123 std::string cookies_;
124 net::CookieOptions options_;
125 };
126
127
128 TEST_F(CookieMonsterTest, TestAddCookiesOnSingleHost) {
51 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 129 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
52 std::vector<std::string> cookies; 130 std::vector<std::string> cookies;
53 for (int i = 0; i < kNumCookies; i++) { 131 for (int i = 0; i < kNumCookies; i++) {
54 cookies.push_back(base::StringPrintf("a%03d=b", i)); 132 cookies.push_back(base::StringPrintf("a%03d=b", i));
55 } 133 }
56 134
135 SetCookieCallback setCookieCallback;
136
57 // Add a bunch of cookies on a single host 137 // Add a bunch of cookies on a single host
58 PerfTimeLogger timer("Cookie_monster_add_single_host"); 138 PerfTimeLogger timer("Cookie_monster_add_single_host");
139
59 for (std::vector<std::string>::const_iterator it = cookies.begin(); 140 for (std::vector<std::string>::const_iterator it = cookies.begin();
60 it != cookies.end(); ++it) { 141 it != cookies.end(); ++it) {
61 EXPECT_TRUE(cm->SetCookie(kUrlGoogle, *it)); 142 setCookieCallback.SetCookie(cm, kUrlGoogle, *it);
62 } 143 }
63 timer.Done(); 144 timer.Done();
64 145
146 GetCookiesCallback getCookiesCallback;
147
65 PerfTimeLogger timer2("Cookie_monster_query_single_host"); 148 PerfTimeLogger timer2("Cookie_monster_query_single_host");
66 for (std::vector<std::string>::const_iterator it = cookies.begin(); 149 for (std::vector<std::string>::const_iterator it = cookies.begin();
67 it != cookies.end(); ++it) { 150 it != cookies.end(); ++it) {
68 cm->GetCookies(kUrlGoogle); 151 getCookiesCallback.GetCookies(cm, kUrlGoogle);
69 } 152 }
70 timer2.Done(); 153 timer2.Done();
71 154
72 PerfTimeLogger timer3("Cookie_monster_deleteall_single_host"); 155 PerfTimeLogger timer3("Cookie_monster_deleteall_single_host");
73 cm->DeleteAll(false); 156 cm->DeleteAllAsync(CookieMonster::DeleteCallback());
157 MessageLoop::current()->RunAllPending();
74 timer3.Done(); 158 timer3.Done();
75 } 159 }
76 160
77 TEST(CookieMonsterTest, TestAddCookieOnManyHosts) { 161 TEST_F(CookieMonsterTest, TestAddCookieOnManyHosts) {
78 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 162 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
79 std::string cookie(kCookieLine); 163 std::string cookie(kCookieLine);
80 std::vector<GURL> gurls; // just wanna have ffffuunnn 164 std::vector<GURL> gurls; // just wanna have ffffuunnn
81 for (int i = 0; i < kNumCookies; ++i) { 165 for (int i = 0; i < kNumCookies; ++i) {
82 gurls.push_back(GURL(base::StringPrintf("http://a%04d.izzle", i))); 166 gurls.push_back(GURL(base::StringPrintf("https://a%04d.izzle", i)));
83 } 167 }
84 168
169 SetCookieCallback setCookieCallback;
170
85 // Add a cookie on a bunch of host 171 // Add a cookie on a bunch of host
86 PerfTimeLogger timer("Cookie_monster_add_many_hosts"); 172 PerfTimeLogger timer("Cookie_monster_add_many_hosts");
87 for (std::vector<GURL>::const_iterator it = gurls.begin(); 173 for (std::vector<GURL>::const_iterator it = gurls.begin();
88 it != gurls.end(); ++it) { 174 it != gurls.end(); ++it) {
89 EXPECT_TRUE(cm->SetCookie(*it, cookie)); 175 setCookieCallback.SetCookie(cm, *it, cookie);
90 } 176 }
91 timer.Done(); 177 timer.Done();
92 178
179 GetCookiesCallback getCookiesCallback;
180
93 PerfTimeLogger timer2("Cookie_monster_query_many_hosts"); 181 PerfTimeLogger timer2("Cookie_monster_query_many_hosts");
94 for (std::vector<GURL>::const_iterator it = gurls.begin(); 182 for (std::vector<GURL>::const_iterator it = gurls.begin();
95 it != gurls.end(); ++it) { 183 it != gurls.end(); ++it) {
96 cm->GetCookies(*it); 184 getCookiesCallback.GetCookies(cm, *it);
97 } 185 }
98 timer2.Done(); 186 timer2.Done();
99 187
100 PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts"); 188 PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts");
101 cm->DeleteAll(false); 189 cm->DeleteAllAsync(CookieMonster::DeleteCallback());
190 MessageLoop::current()->RunAllPending();
102 timer3.Done(); 191 timer3.Done();
103 } 192 }
104 193
105 TEST(CookieMonsterTest, TestGetCookiesWithOptions) { 194 TEST_F(CookieMonsterTest, TestGetCookiesWithInfo) {
106 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 195 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
107 std::string cookie(kCookieLine); 196
108 std::vector<GURL> gurls; 197 std::vector<GURL> gurls;
109 for (int i = 0; i < kNumCookies; ++i) 198 for (int i = 0; i < kNumCookies; ++i)
110 gurls.push_back(GURL(base::StringPrintf("http://a%04d.izzle", i))); 199 gurls.push_back(GURL(base::StringPrintf("https://a%04d.izzle", i)));
200
201 SetCookieCallback setCookieCallback;
111 202
112 for (std::vector<GURL>::const_iterator it = gurls.begin(); 203 for (std::vector<GURL>::const_iterator it = gurls.begin();
113 it != gurls.end(); ++it) { 204 it != gurls.end(); ++it) {
114 EXPECT_TRUE(cm->SetCookie(*it, cookie)); 205 setCookieCallback.SetCookie(cm, *it, kCookieLine);
115 } 206 }
116 207
208 GetCookiesWithInfoCallback getCookiesCallback;
209
117 PerfTimeLogger timer("Cookie_monster_get_cookie_info"); 210 PerfTimeLogger timer("Cookie_monster_get_cookie_info");
118 for (std::vector<GURL>::const_iterator it = gurls.begin(); 211 for (std::vector<GURL>::const_iterator it = gurls.begin();
119 it != gurls.end(); ++it) { 212 it != gurls.end(); ++it) {
120 CookieOptions options; 213 getCookiesCallback.GetCookiesWithInfo(cm, *it);
121 std::string cookie_line;
122 cookie_line = cm->GetCookiesWithOptions(*it, options);
123 } 214 }
124 timer.Done(); 215 timer.Done();
125 } 216 }
126
127 TEST(CookieMonsterTest, TestGetCookiesWithInfo) {
128 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
129 std::string cookie(kCookieLine);
130 std::vector<GURL> gurls;
131 for (int i = 0; i < kNumCookies; ++i)
132 gurls.push_back(GURL(base::StringPrintf("http://a%04d.izzle", i)));
133
134 for (std::vector<GURL>::const_iterator it = gurls.begin();
135 it != gurls.end(); ++it) {
136 EXPECT_TRUE(cm->SetCookie(*it, cookie));
137 }
138
139 PerfTimeLogger timer("Cookie_monster_get_cookie_info");
140 for (std::vector<GURL>::const_iterator it = gurls.begin();
141 it != gurls.end(); ++it) {
142 CookieOptions options;
143 std::string cookie_line;
144 std::vector<CookieStore::CookieInfo> cookie_infos;
145 cm->GetCookiesWithInfo(*it, options, &cookie_line, &cookie_infos);
146 }
147 timer.Done();
148 }
149 217
150 static int CountInString(const std::string& str, char c) { 218 static int CountInString(const std::string& str, char c) {
151 return std::count(str.begin(), str.end(), c); 219 return std::count(str.begin(), str.end(), c);
152 } 220 }
153 221
154 TEST(CookieMonsterTest, TestDomainTree) { 222 TEST_F(CookieMonsterTest, TestDomainTree) {
155 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 223 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
224 GetCookiesCallback getCookiesCallback;
225 SetCookieCallback setCookieCallback;
156 const char* domain_cookie_format_tree = "a=b; domain=%s"; 226 const char* domain_cookie_format_tree = "a=b; domain=%s";
157 const std::string domain_base("top.com"); 227 const std::string domain_base("top.com");
158 228
159 std::vector<std::string> domain_list; 229 std::vector<std::string> domain_list;
160 230
161 // Create a balanced binary tree of domains on which the cookie is set. 231 // Create a balanced binary tree of domains on which the cookie is set.
162 domain_list.push_back(domain_base); 232 domain_list.push_back(domain_base);
163 for (int i1 = 0; i1 < 2; i1++) { 233 for (int i1 = 0; i1 < 2; i1++) {
164 std::string domain_base_1((i1 ? "a." : "b.") + domain_base); 234 std::string domain_base_1((i1 ? "a." : "b.") + domain_base);
165 EXPECT_EQ("top.com", cm->GetKey(domain_base_1)); 235 EXPECT_EQ("top.com", cm->GetKey(domain_base_1));
(...skipping 15 matching lines...) Expand all
181 } 251 }
182 } 252 }
183 253
184 254
185 EXPECT_EQ(31u, domain_list.size()); 255 EXPECT_EQ(31u, domain_list.size());
186 for (std::vector<std::string>::const_iterator it = domain_list.begin(); 256 for (std::vector<std::string>::const_iterator it = domain_list.begin();
187 it != domain_list.end(); it++) { 257 it != domain_list.end(); it++) {
188 GURL gurl("https://" + *it + "/"); 258 GURL gurl("https://" + *it + "/");
189 const std::string cookie = base::StringPrintf(domain_cookie_format_tree, 259 const std::string cookie = base::StringPrintf(domain_cookie_format_tree,
190 it->c_str()); 260 it->c_str());
191 EXPECT_TRUE(cm->SetCookie(gurl, cookie)); 261 setCookieCallback.SetCookie(cm, gurl, cookie);
192 } 262 }
193 EXPECT_EQ(31u, cm->GetAllCookies().size()); 263 EXPECT_EQ(31u, cm->GetAllCookies().size());
194 264
195 GURL probe_gurl("https://b.a.b.a.top.com/"); 265 GURL probe_gurl("https://b.a.b.a.top.com/");
196 std::string cookie_line; 266 std::string cookie_line = getCookiesCallback.GetCookies(cm, probe_gurl);
197 cookie_line = cm->GetCookies(probe_gurl); 267 EXPECT_EQ(5, CountInString(cookie_line, '=')) << "Cookie line: " <<
198 EXPECT_EQ(5, CountInString(cookie_line, '=')) << "Cookie line: " 268 cookie_line;
199 << cookie_line;
200 PerfTimeLogger timer("Cookie_monster_query_domain_tree"); 269 PerfTimeLogger timer("Cookie_monster_query_domain_tree");
201 for (int i = 0; i < kNumCookies; i++) { 270 for (int i = 0; i < kNumCookies; i++) {
202 cm->GetCookies(probe_gurl); 271 getCookiesCallback.GetCookies(cm, probe_gurl);
203 } 272 }
204 timer.Done(); 273 timer.Done();
205
206 } 274 }
207 275
208 TEST(CookieMonsterTest, TestDomainLine) { 276 TEST_F(CookieMonsterTest, TestDomainLine) {
209 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 277 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
278 SetCookieCallback setCookieCallback;
279 GetCookiesCallback getCookiesCallback;
210 std::vector<std::string> domain_list; 280 std::vector<std::string> domain_list;
211 GURL probe_gurl("https://b.a.b.a.top.com/"); 281 GURL probe_gurl("https://b.a.b.a.top.com/");
212 std::string cookie_line; 282 std::string cookie_line;
213 283
214 // Create a line of 32 domain cookies such that all cookies stored 284 // Create a line of 32 domain cookies such that all cookies stored
215 // by effective TLD+1 will apply to probe GURL. 285 // by effective TLD+1 will apply to probe GURL.
216 // (TLD + 1 is the level above .com/org/net/etc, e.g. "top.com" 286 // (TLD + 1 is the level above .com/org/net/etc, e.g. "top.com"
217 // or "google.com". "Effective" is added to include sites like 287 // or "google.com". "Effective" is added to include sites like
218 // bbc.co.uk, where the effetive TLD+1 is more than one level 288 // bbc.co.uk, where the effetive TLD+1 is more than one level
219 // below the top level.) 289 // below the top level.)
220 domain_list.push_back("a.top.com"); 290 domain_list.push_back("a.top.com");
221 domain_list.push_back("b.a.top.com"); 291 domain_list.push_back("b.a.top.com");
222 domain_list.push_back("a.b.a.top.com"); 292 domain_list.push_back("a.b.a.top.com");
223 domain_list.push_back("b.a.b.a.top.com"); 293 domain_list.push_back("b.a.b.a.top.com");
224 EXPECT_EQ(4u, domain_list.size()); 294 EXPECT_EQ(4u, domain_list.size());
225 295
226 const char* domain_cookie_format_line = "a%03d=b; domain=%s"; 296 const char* domain_cookie_format_line = "a%03d=b; domain=%s";
227 for (int i = 0; i < 8; i++) { 297 for (int i = 0; i < 8; i++) {
228 for (std::vector<std::string>::const_iterator it = domain_list.begin(); 298 for (std::vector<std::string>::const_iterator it = domain_list.begin();
229 it != domain_list.end(); it++) { 299 it != domain_list.end(); it++) {
230 GURL gurl("https://" + *it + "/"); 300 GURL gurl("https://" + *it + "/");
231 const std::string cookie = base::StringPrintf(domain_cookie_format_line, 301 const std::string cookie = base::StringPrintf(domain_cookie_format_line,
232 i, it->c_str()); 302 i, it->c_str());
233 EXPECT_TRUE(cm->SetCookie(gurl, cookie)); 303 setCookieCallback.SetCookie(cm, gurl, cookie);
234 } 304 }
235 } 305 }
236 EXPECT_EQ(32u, cm->GetAllCookies().size());
237 306
238 cookie_line = cm->GetCookies(probe_gurl); 307 cookie_line = getCookiesCallback.GetCookies(cm, probe_gurl);
239 EXPECT_EQ(32, CountInString(cookie_line, '=')); 308 EXPECT_EQ(32, CountInString(cookie_line, '='));
240 PerfTimeLogger timer2("Cookie_monster_query_domain_line"); 309 PerfTimeLogger timer2("Cookie_monster_query_domain_line");
241 for (int i = 0; i < kNumCookies; i++) { 310 for (int i = 0; i < kNumCookies; i++) {
242 cm->GetCookies(probe_gurl); 311 getCookiesCallback.GetCookies(cm, probe_gurl);
243 } 312 }
244 timer2.Done(); 313 timer2.Done();
245 } 314 }
246 315
247 TEST(CookieMonsterTest, TestImport) { 316 TEST_F(CookieMonsterTest, TestImport) {
248 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); 317 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
249 std::vector<CookieMonster::CanonicalCookie*> initial_cookies; 318 std::vector<CookieMonster::CanonicalCookie*> initial_cookies;
319 GetCookiesCallback getCookiesCallback;
250 320
251 // We want to setup a fairly large backing store, with 300 domains of 50 321 // We want to setup a fairly large backing store, with 300 domains of 50
252 // cookies each. Creation times must be unique. 322 // cookies each. Creation times must be unique.
253 int64 time_tick(base::Time::Now().ToInternalValue()); 323 int64 time_tick(base::Time::Now().ToInternalValue());
254 324
255 for (int domain_num = 0; domain_num < 300; domain_num++) { 325 for (int domain_num = 0; domain_num < 300; domain_num++) {
256 std::string domain_name(base::StringPrintf(".Domain_%d.com", domain_num)); 326 std::string domain_name(base::StringPrintf(".Domain_%d.com", domain_num));
257 std::string gurl("www" + domain_name); 327 std::string gurl("www" + domain_name);
258 for (int cookie_num = 0; cookie_num < 50; cookie_num++) { 328 for (int cookie_num = 0; cookie_num < 50; cookie_num++) {
259 std::string cookie_line(base::StringPrintf("Cookie_%d=1; Path=/", 329 std::string cookie_line(base::StringPrintf("Cookie_%d=1; Path=/",
260 cookie_num)); 330 cookie_num));
261 AddCookieToList(gurl, cookie_line, 331 AddCookieToList(gurl, cookie_line,
262 base::Time::FromInternalValue(time_tick++), 332 base::Time::FromInternalValue(time_tick++),
263 &initial_cookies); 333 &initial_cookies);
264 } 334 }
265 } 335 }
266 336
267 store->SetLoadExpectation(true, initial_cookies); 337 store->SetLoadExpectation(true, initial_cookies);
268 338
269 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); 339 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL));
270 340
271 // Import will happen on first access. 341 // Import will happen on first access.
272 GURL gurl("www.google.com"); 342 GURL gurl("www.google.com");
273 CookieOptions options; 343 CookieOptions options;
274 PerfTimeLogger timer("Cookie_monster_import_from_store"); 344 PerfTimeLogger timer("Cookie_monster_import_from_store");
275 cm->GetCookiesWithOptions(gurl, options); 345 getCookiesCallback.GetCookies(cm, gurl);
276 timer.Done(); 346 timer.Done();
277 347
278 // Just confirm keys were set as expected. 348 // Just confirm keys were set as expected.
279 EXPECT_EQ("domain_1.com", cm->GetKey("www.Domain_1.com")); 349 EXPECT_EQ("domain_1.com", cm->GetKey("www.Domain_1.com"));
280 } 350 }
281 351
282 TEST(CookieMonsterTest, TestGetKey) { 352 TEST_F(CookieMonsterTest, TestGetKey) {
283 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 353 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
284 PerfTimeLogger timer("Cookie_monster_get_key"); 354 PerfTimeLogger timer("Cookie_monster_get_key");
285 for (int i = 0; i < kNumCookies; i++) 355 for (int i = 0; i < kNumCookies; i++)
286 cm->GetKey("www.google.com"); 356 cm->GetKey("www.google.com");
287 timer.Done(); 357 timer.Done();
288 } 358 }
289 359
290 // This test is probing for whether garbage collection happens when it 360 // This test is probing for whether garbage collection happens when it
291 // shouldn't. This will not in general be visible functionally, since 361 // shouldn't. This will not in general be visible functionally, since
292 // if GC runs twice in a row without any change to the store, the second 362 // if GC runs twice in a row without any change to the store, the second
293 // GC run will not do anything the first one didn't. That's why this is 363 // GC run will not do anything the first one didn't. That's why this is
294 // a performance test. The test should be considered to pass if all the 364 // a performance test. The test should be considered to pass if all the
295 // times reported are approximately the same--this indicates that no GC 365 // times reported are approximately the same--this indicates that no GC
296 // happened repeatedly for any case. 366 // happened repeatedly for any case.
297 TEST(CookieMonsterTest, TestGCTimes) { 367 TEST_F(CookieMonsterTest, TestGCTimes) {
368 SetCookieCallback setCookieCallback;
369
298 const struct TestCase { 370 const struct TestCase {
299 const char* name; 371 const char* name;
300 int num_cookies; 372 int num_cookies;
301 int num_old_cookies; 373 int num_old_cookies;
302 } test_cases[] = { 374 } test_cases[] = {
303 { 375 {
304 // A whole lot of recent cookies; gc shouldn't happen. 376 // A whole lot of recent cookies; gc shouldn't happen.
305 "all_recent", 377 "all_recent",
306 CookieMonster::kMaxCookies * 2, 378 CookieMonster::kMaxCookies * 2,
307 0, 379 0,
(...skipping 23 matching lines...) Expand all
331 for (int ci = 0; ci < static_cast<int>(ARRAYSIZE_UNSAFE(test_cases)); ++ci) { 403 for (int ci = 0; ci < static_cast<int>(ARRAYSIZE_UNSAFE(test_cases)); ++ci) {
332 const TestCase& test_case(test_cases[ci]); 404 const TestCase& test_case(test_cases[ci]);
333 scoped_refptr<CookieMonster> cm( 405 scoped_refptr<CookieMonster> cm(
334 CreateMonsterFromStoreForGC( 406 CreateMonsterFromStoreForGC(
335 test_case.num_cookies, test_case.num_old_cookies, 407 test_case.num_cookies, test_case.num_old_cookies,
336 CookieMonster::kSafeFromGlobalPurgeDays * 2)); 408 CookieMonster::kSafeFromGlobalPurgeDays * 2));
337 409
338 GURL gurl("http://google.com"); 410 GURL gurl("http://google.com");
339 std::string cookie_line("z=3"); 411 std::string cookie_line("z=3");
340 // Trigger the Garbage collection we're allowed. 412 // Trigger the Garbage collection we're allowed.
341 EXPECT_TRUE(cm->SetCookie(gurl, cookie_line)); 413 setCookieCallback.SetCookie(cm, gurl, cookie_line);
342 414
343 PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str()); 415 PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str());
344 for (int i = 0; i < kNumCookies; i++) 416 for (int i = 0; i < kNumCookies; i++)
345 EXPECT_TRUE(cm->SetCookie(gurl, cookie_line)); 417 setCookieCallback.SetCookie(cm, gurl, cookie_line);
346 timer.Done(); 418 timer.Done();
347 } 419 }
348 } 420 }
349 421
350 } // namespace 422 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698