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

Side by Side Diff: chrome/browser/net/predictor_unittest.cc

Issue 3032014: Support both preconnection, and pre-resolution for subresources... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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
« no previous file with comments | « chrome/browser/net/predictor_api.cc ('k') | chrome/browser/net/referrer.h » ('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) 2006-2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2010 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 <time.h> 5 #include <time.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <sstream> 8 #include <sstream>
9 #include <string> 9 #include <string>
10 10
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 //------------------------------------------------------------------------------ 108 //------------------------------------------------------------------------------
109 109
110 TEST_F(PredictorTest, StartupShutdownTest) { 110 TEST_F(PredictorTest, StartupShutdownTest) {
111 scoped_refptr<Predictor> testing_master = new Predictor(host_resolver_, 111 scoped_refptr<Predictor> testing_master = new Predictor(host_resolver_,
112 default_max_queueing_delay_, 112 default_max_queueing_delay_,
113 PredictorInit::kMaxPrefetchConcurrentLookups, 113 PredictorInit::kMaxPrefetchConcurrentLookups,
114 false); 114 false);
115 testing_master->Shutdown(); 115 testing_master->Shutdown();
116 } 116 }
117 117
118 TEST_F(PredictorTest, BenefitLookupTest) {
119 scoped_refptr<Predictor> testing_master = new Predictor(
120 host_resolver_,
121 default_max_queueing_delay_,
122 PredictorInit::kMaxPrefetchConcurrentLookups,
123 false);
124
125 GURL goog("http://www.google.com:80"),
126 goog2("http://gmail.google.com.com:80"),
127 goog3("http://mail.google.com:80"),
128 goog4("http://gmail.com:80");
129 UrlInfo goog_info, goog2_info, goog3_info, goog4_info;
130
131 // Simulate getting similar names from a network observer
132 goog_info.SetUrl(goog);
133 goog2_info.SetUrl(goog2);
134 goog3_info.SetUrl(goog3);
135 goog4_info.SetUrl(goog4);
136
137 goog_info.SetStartedState();
138 goog2_info.SetStartedState();
139 goog3_info.SetStartedState();
140 goog4_info.SetStartedState();
141
142 goog_info.SetFinishedState(true);
143 goog2_info.SetFinishedState(true);
144 goog3_info.SetFinishedState(true);
145 goog4_info.SetFinishedState(true);
146
147 UrlList names;
148 names.push_back(goog);
149 names.push_back(goog2);
150 names.push_back(goog3);
151 names.push_back(goog4);
152
153 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED);
154
155 WaitForResolution(testing_master, names);
156
157 EXPECT_TRUE(testing_master->WasFound(goog));
158 EXPECT_TRUE(testing_master->WasFound(goog2));
159 EXPECT_TRUE(testing_master->WasFound(goog3));
160 EXPECT_TRUE(testing_master->WasFound(goog4));
161
162 // With the mock DNS, each of these should have taken some time, and hence
163 // shown a benefit (i.e., prefetch cost more than network access time).
164
165 GURL referer; // Null host.
166
167 // Simulate actual navigation, and acrue the benefit for "helping" the DNS
168 // part of the navigation.
169 EXPECT_TRUE(testing_master->AccruePrefetchBenefits(referer, &goog_info));
170 EXPECT_TRUE(testing_master->AccruePrefetchBenefits(referer, &goog2_info));
171 EXPECT_TRUE(testing_master->AccruePrefetchBenefits(referer, &goog3_info));
172 EXPECT_TRUE(testing_master->AccruePrefetchBenefits(referer, &goog4_info));
173
174 // Benefits can ONLY be reported once (for the first navigation).
175 EXPECT_FALSE(testing_master->AccruePrefetchBenefits(referer, &goog_info));
176 EXPECT_FALSE(testing_master->AccruePrefetchBenefits(referer, &goog2_info));
177 EXPECT_FALSE(testing_master->AccruePrefetchBenefits(referer, &goog3_info));
178 EXPECT_FALSE(testing_master->AccruePrefetchBenefits(referer, &goog4_info));
179
180 testing_master->Shutdown();
181 }
182 118
183 TEST_F(PredictorTest, ShutdownWhenResolutionIsPendingTest) { 119 TEST_F(PredictorTest, ShutdownWhenResolutionIsPendingTest) {
184 scoped_refptr<net::WaitingHostResolverProc> resolver_proc = 120 scoped_refptr<net::WaitingHostResolverProc> resolver_proc =
185 new net::WaitingHostResolverProc(NULL); 121 new net::WaitingHostResolverProc(NULL);
186 host_resolver_->Reset(resolver_proc); 122 host_resolver_->Reset(resolver_proc);
187 123
188 scoped_refptr<Predictor> testing_master = new Predictor(host_resolver_, 124 scoped_refptr<Predictor> testing_master = new Predictor(host_resolver_,
189 default_max_queueing_delay_, 125 default_max_queueing_delay_,
190 PredictorInit::kMaxPrefetchConcurrentLookups, 126 PredictorInit::kMaxPrefetchConcurrentLookups,
191 false); 127 false);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 // Functions to help synthesize and test serializations of subresource referrer 256 // Functions to help synthesize and test serializations of subresource referrer
321 // lists. 257 // lists.
322 258
323 // Return a motivation_list if we can find one for the given motivating_host (or 259 // Return a motivation_list if we can find one for the given motivating_host (or
324 // NULL if a match is not found). 260 // NULL if a match is not found).
325 static ListValue* FindSerializationMotivation( 261 static ListValue* FindSerializationMotivation(
326 const GURL& motivation, const ListValue& referral_list) { 262 const GURL& motivation, const ListValue& referral_list) {
327 CHECK_LT(0u, referral_list.GetSize()); // Room for version. 263 CHECK_LT(0u, referral_list.GetSize()); // Room for version.
328 int format_version = -1; 264 int format_version = -1;
329 CHECK(referral_list.GetInteger(0, &format_version)); 265 CHECK(referral_list.GetInteger(0, &format_version));
330 CHECK_EQ(Predictor::DNS_REFERRER_VERSION, format_version); 266 CHECK_EQ(Predictor::PREDICTOR_REFERRER_VERSION, format_version);
331 ListValue* motivation_list(NULL); 267 ListValue* motivation_list(NULL);
332 for (size_t i = 1; i < referral_list.GetSize(); ++i) { 268 for (size_t i = 1; i < referral_list.GetSize(); ++i) {
333 referral_list.GetList(i, &motivation_list); 269 referral_list.GetList(i, &motivation_list);
334 std::string existing_spec; 270 std::string existing_spec;
335 EXPECT_TRUE(motivation_list->GetString(0, &existing_spec)); 271 EXPECT_TRUE(motivation_list->GetString(0, &existing_spec));
336 if (motivation == GURL(existing_spec)) 272 if (motivation == GURL(existing_spec))
337 return motivation_list; 273 return motivation_list;
338 } 274 }
339 return NULL; 275 return NULL;
340 } 276 }
341 277
342 // Create a new empty serialization list. 278 // Create a new empty serialization list.
343 static ListValue* NewEmptySerializationList() { 279 static ListValue* NewEmptySerializationList() {
344 ListValue* list = new ListValue; 280 ListValue* list = new ListValue;
345 list->Append(new FundamentalValue(Predictor::DNS_REFERRER_VERSION)); 281 list->Append(new FundamentalValue(Predictor::PREDICTOR_REFERRER_VERSION));
346 return list; 282 return list;
347 } 283 }
348 284
349 // Add a motivating_host and a subresource_host to a serialized list, using 285 // Add a motivating_url and a subresource_url to a serialized list, using
350 // this given latency. This is a helper function for quickly building these 286 // this given latency. This is a helper function for quickly building these
351 // lists. 287 // lists.
352 static void AddToSerializedList(const GURL& motivation, 288 static void AddToSerializedList(const GURL& motivation,
353 const GURL& subresource, 289 const GURL& subresource,
354 int latency, 290 double use_rate,
355 double rate,
356 ListValue* referral_list ) { 291 ListValue* referral_list ) {
357 // Find the motivation if it is already used. 292 // Find the motivation if it is already used.
358 ListValue* motivation_list = FindSerializationMotivation(motivation, 293 ListValue* motivation_list = FindSerializationMotivation(motivation,
359 *referral_list); 294 *referral_list);
360 if (!motivation_list) { 295 if (!motivation_list) {
361 // This is the first mention of this motivation, so build a list. 296 // This is the first mention of this motivation, so build a list.
362 motivation_list = new ListValue; 297 motivation_list = new ListValue;
363 motivation_list->Append(new StringValue(motivation.spec())); 298 motivation_list->Append(new StringValue(motivation.spec()));
364 // Provide empty subresource list. 299 // Provide empty subresource list.
365 motivation_list->Append(new ListValue()); 300 motivation_list->Append(new ListValue());
366 301
367 // ...and make it part of the serialized referral_list. 302 // ...and make it part of the serialized referral_list.
368 referral_list->Append(motivation_list); 303 referral_list->Append(motivation_list);
369 } 304 }
370 305
371 ListValue* subresource_list(NULL); 306 ListValue* subresource_list(NULL);
372 // 0 == url; 1 == subresource_list. 307 // 0 == url; 1 == subresource_list.
373 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list)); 308 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list));
374 309
375 // We won't bother to check for the subresource being there already. Worst 310 // We won't bother to check for the subresource being there already. Worst
376 // case, during deserialization, the latency value we supply plus the 311 // case, during deserialization, the latency value we supply plus the
377 // existing value(s) will be added to the referrer. 312 // existing value(s) will be added to the referrer.
378 313
379 subresource_list->Append(new StringValue(subresource.spec())); 314 subresource_list->Append(new StringValue(subresource.spec()));
380 subresource_list->Append(new FundamentalValue(latency)); 315 subresource_list->Append(new FundamentalValue(use_rate));
381 subresource_list->Append(new FundamentalValue(rate));
382 } 316 }
383 317
384 static const int kLatencyNotFound = -1; 318 static const int kLatencyNotFound = -1;
385 319
386 // For a given motivation, and subresource, find what latency is currently 320 // For a given motivation, and subresource, find what latency is currently
387 // listed. This assume a well formed serialization, which has at most one such 321 // listed. This assume a well formed serialization, which has at most one such
388 // entry for any pair of names. If no such pair is found, then return false. 322 // entry for any pair of names. If no such pair is found, then return false.
389 // Data is written into rate and latency arguments. 323 // Data is written into use_rate arguments.
390 static bool GetDataFromSerialization(const GURL& motivation, 324 static bool GetDataFromSerialization(const GURL& motivation,
391 const GURL& subresource, 325 const GURL& subresource,
392 const ListValue& referral_list, 326 const ListValue& referral_list,
393 double* rate, 327 double* use_rate) {
394 int* latency) {
395 ListValue* motivation_list = FindSerializationMotivation(motivation, 328 ListValue* motivation_list = FindSerializationMotivation(motivation,
396 referral_list); 329 referral_list);
397 if (!motivation_list) 330 if (!motivation_list)
398 return false; 331 return false;
399 ListValue* subresource_list; 332 ListValue* subresource_list;
400 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list)); 333 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list));
401 for (size_t i = 0; i < subresource_list->GetSize();) { 334 for (size_t i = 0; i < subresource_list->GetSize();) {
402 std::string url_spec; 335 std::string url_spec;
403 EXPECT_TRUE(subresource_list->GetString(i++, &url_spec)); 336 EXPECT_TRUE(subresource_list->GetString(i++, &url_spec));
404 EXPECT_TRUE(subresource_list->GetInteger(i++, latency)); 337 EXPECT_TRUE(subresource_list->GetReal(i++, use_rate));
405 EXPECT_TRUE(subresource_list->GetReal(i++, rate));
406 if (subresource == GURL(url_spec)) { 338 if (subresource == GURL(url_spec)) {
407 return true; 339 return true;
408 } 340 }
409 } 341 }
410 return false; 342 return false;
411 } 343 }
412 344
413 //------------------------------------------------------------------------------ 345 //------------------------------------------------------------------------------
414 346
415 // Make sure nil referral lists really have no entries, and no latency listed. 347 // Make sure nil referral lists really have no entries, and no latency listed.
416 TEST_F(PredictorTest, ReferrerSerializationNilTest) { 348 TEST_F(PredictorTest, ReferrerSerializationNilTest) {
417 scoped_refptr<Predictor> predictor = new Predictor(host_resolver_, 349 scoped_refptr<Predictor> predictor = new Predictor(host_resolver_,
418 default_max_queueing_delay_, 350 default_max_queueing_delay_,
419 PredictorInit::kMaxPrefetchConcurrentLookups, 351 PredictorInit::kMaxPrefetchConcurrentLookups,
420 false); 352 false);
421 scoped_ptr<ListValue> referral_list(NewEmptySerializationList()); 353 scoped_ptr<ListValue> referral_list(NewEmptySerializationList());
422 predictor->SerializeReferrers(referral_list.get()); 354 predictor->SerializeReferrers(referral_list.get());
423 EXPECT_EQ(1U, referral_list->GetSize()); 355 EXPECT_EQ(1U, referral_list->GetSize());
424 EXPECT_FALSE(GetDataFromSerialization( 356 EXPECT_FALSE(GetDataFromSerialization(
425 GURL("http://a.com:79"), GURL("http://b.com:78"), 357 GURL("http://a.com:79"), GURL("http://b.com:78"),
426 *referral_list.get(), NULL, NULL)); 358 *referral_list.get(), NULL));
427 359
428 predictor->Shutdown(); 360 predictor->Shutdown();
429 } 361 }
430 362
431 // Make sure that when a serialization list includes a value, that it can be 363 // Make sure that when a serialization list includes a value, that it can be
432 // deserialized into the database, and can be extracted back out via 364 // deserialized into the database, and can be extracted back out via
433 // serialization without being changed. 365 // serialization without being changed.
434 TEST_F(PredictorTest, ReferrerSerializationSingleReferrerTest) { 366 TEST_F(PredictorTest, ReferrerSerializationSingleReferrerTest) {
435 scoped_refptr<Predictor> predictor = new Predictor(host_resolver_, 367 scoped_refptr<Predictor> predictor = new Predictor(host_resolver_,
436 default_max_queueing_delay_, 368 default_max_queueing_delay_,
437 PredictorInit::kMaxPrefetchConcurrentLookups, 369 PredictorInit::kMaxPrefetchConcurrentLookups,
438 false); 370 false);
439 const GURL motivation_url("http://www.google.com:91"); 371 const GURL motivation_url("http://www.google.com:91");
440 const GURL subresource_url("http://icons.google.com:90"); 372 const GURL subresource_url("http://icons.google.com:90");
441 const int kLatency = 3; 373 const double kUseRate = 23.4;
442 const double kRate = 23.4;
443 scoped_ptr<ListValue> referral_list(NewEmptySerializationList()); 374 scoped_ptr<ListValue> referral_list(NewEmptySerializationList());
444 375
445 AddToSerializedList(motivation_url, subresource_url, 376 AddToSerializedList(motivation_url, subresource_url,
446 kLatency, kRate, referral_list.get()); 377 kUseRate, referral_list.get());
447 378
448 predictor->DeserializeReferrers(*referral_list.get()); 379 predictor->DeserializeReferrers(*referral_list.get());
449 380
450 ListValue recovered_referral_list; 381 ListValue recovered_referral_list;
451 predictor->SerializeReferrers(&recovered_referral_list); 382 predictor->SerializeReferrers(&recovered_referral_list);
452 EXPECT_EQ(2U, recovered_referral_list.GetSize()); 383 EXPECT_EQ(2U, recovered_referral_list.GetSize());
453 int latency;
454 double rate; 384 double rate;
455 EXPECT_TRUE(GetDataFromSerialization( 385 EXPECT_TRUE(GetDataFromSerialization(
456 motivation_url, subresource_url, recovered_referral_list, &rate, 386 motivation_url, subresource_url, recovered_referral_list, &rate));
457 &latency)); 387 EXPECT_EQ(rate, kUseRate);
458 EXPECT_EQ(rate, kRate);
459 EXPECT_EQ(latency, kLatency);
460 388
461 predictor->Shutdown(); 389 predictor->Shutdown();
462 } 390 }
463 391
464 // Make sure the Trim() functionality works as expected. 392 // Make sure the Trim() functionality works as expected.
465 TEST_F(PredictorTest, ReferrerSerializationTrimTest) { 393 TEST_F(PredictorTest, ReferrerSerializationTrimTest) {
466 scoped_refptr<Predictor> predictor = new Predictor(host_resolver_, 394 scoped_refptr<Predictor> predictor = new Predictor(host_resolver_,
467 default_max_queueing_delay_, 395 default_max_queueing_delay_,
468 PredictorInit::kMaxPrefetchConcurrentLookups, 396 PredictorInit::kMaxPrefetchConcurrentLookups,
469 false); 397 false);
470 GURL motivation_url("http://www.google.com:110"); 398 GURL motivation_url("http://www.google.com:110");
471 399
472 GURL icon_subresource_url("http://icons.google.com:111"); 400 GURL icon_subresource_url("http://icons.google.com:111");
473 const int kLatencyIcon = 10; 401 const double kRateIcon = 16.0 * Predictor::kPersistWorthyExpectedValue;
474 const double kRateIcon = 0.; // User low rate, so latency will dominate.
475 GURL img_subresource_url("http://img.google.com:118"); 402 GURL img_subresource_url("http://img.google.com:118");
476 const int kLatencyImg = 3; 403 const double kRateImg = 8.0 * Predictor::kPersistWorthyExpectedValue;
477 const double kRateImg = 0.;
478 404
479 scoped_ptr<ListValue> referral_list(NewEmptySerializationList()); 405 scoped_ptr<ListValue> referral_list(NewEmptySerializationList());
480 AddToSerializedList( 406 AddToSerializedList(
481 motivation_url, icon_subresource_url, 407 motivation_url, icon_subresource_url, kRateIcon, referral_list.get());
482 kLatencyIcon, kRateIcon, referral_list.get());
483 AddToSerializedList( 408 AddToSerializedList(
484 motivation_url, img_subresource_url, 409 motivation_url, img_subresource_url, kRateImg, referral_list.get());
485 kLatencyImg, kRateImg, referral_list.get());
486 410
487 predictor->DeserializeReferrers(*referral_list.get()); 411 predictor->DeserializeReferrers(*referral_list.get());
488 412
489 ListValue recovered_referral_list; 413 ListValue recovered_referral_list;
490 predictor->SerializeReferrers(&recovered_referral_list); 414 predictor->SerializeReferrers(&recovered_referral_list);
491 EXPECT_EQ(2U, recovered_referral_list.GetSize()); 415 EXPECT_EQ(2U, recovered_referral_list.GetSize());
492 int latency;
493 double rate; 416 double rate;
494 EXPECT_TRUE(GetDataFromSerialization( 417 EXPECT_TRUE(GetDataFromSerialization(
495 motivation_url, icon_subresource_url, recovered_referral_list, 418 motivation_url, icon_subresource_url, recovered_referral_list,
496 &rate, &latency)); 419 &rate));
497 EXPECT_EQ(latency, kLatencyIcon);
498 EXPECT_EQ(rate, kRateIcon); 420 EXPECT_EQ(rate, kRateIcon);
499 421
500 EXPECT_TRUE(GetDataFromSerialization( 422 EXPECT_TRUE(GetDataFromSerialization(
501 motivation_url, img_subresource_url, recovered_referral_list, 423 motivation_url, img_subresource_url, recovered_referral_list, &rate));
502 &rate, &latency));
503 EXPECT_EQ(latency, kLatencyImg);
504 EXPECT_EQ(rate, kRateImg); 424 EXPECT_EQ(rate, kRateImg);
505 425
506 // Each time we Trim, the latency figures should reduce by a factor of two, 426 // Each time we Trim, the user_rate figures should reduce by a factor of two,
507 // until they both are 0, an then a trim will delete the whole entry. 427 // until they both are small, an then a trim will delete the whole entry.
508 predictor->TrimReferrers(); 428 predictor->TrimReferrers();
509 predictor->SerializeReferrers(&recovered_referral_list); 429 predictor->SerializeReferrers(&recovered_referral_list);
510 EXPECT_EQ(2U, recovered_referral_list.GetSize()); 430 EXPECT_EQ(2U, recovered_referral_list.GetSize());
511 EXPECT_TRUE(GetDataFromSerialization( 431 EXPECT_TRUE(GetDataFromSerialization(
512 motivation_url, icon_subresource_url, recovered_referral_list, 432 motivation_url, icon_subresource_url, recovered_referral_list, &rate));
513 &rate, &latency)); 433 EXPECT_EQ(rate, kRateIcon / 2);
514 EXPECT_EQ(latency, kLatencyIcon / 2);
515 EXPECT_EQ(rate, kRateIcon);
516 434
517 EXPECT_TRUE(GetDataFromSerialization( 435 EXPECT_TRUE(GetDataFromSerialization(
518 motivation_url, img_subresource_url, recovered_referral_list, 436 motivation_url, img_subresource_url, recovered_referral_list, &rate));
519 &rate, &latency)); 437 EXPECT_EQ(rate, kRateImg / 2);
520 EXPECT_EQ(latency, kLatencyImg / 2);
521 EXPECT_EQ(rate, kRateImg);
522 438
523 predictor->TrimReferrers(); 439 predictor->TrimReferrers();
524 predictor->SerializeReferrers(&recovered_referral_list); 440 predictor->SerializeReferrers(&recovered_referral_list);
525 EXPECT_EQ(2U, recovered_referral_list.GetSize()); 441 EXPECT_EQ(2U, recovered_referral_list.GetSize());
526 EXPECT_TRUE(GetDataFromSerialization( 442 EXPECT_TRUE(GetDataFromSerialization(
527 motivation_url, icon_subresource_url, recovered_referral_list, 443 motivation_url, icon_subresource_url, recovered_referral_list, &rate));
528 &rate, &latency)); 444 EXPECT_EQ(rate, kRateIcon / 4);
529 EXPECT_EQ(latency, kLatencyIcon / 4);
530 EXPECT_EQ(rate, kRateIcon);
531 // Img is down to zero, but we don't delete it yet.
532 EXPECT_TRUE(GetDataFromSerialization( 445 EXPECT_TRUE(GetDataFromSerialization(
533 motivation_url, img_subresource_url, recovered_referral_list, 446 motivation_url, img_subresource_url, recovered_referral_list, &rate));
534 &rate, &latency)); 447 EXPECT_EQ(rate, kRateImg / 4);
535 EXPECT_EQ(kLatencyImg / 4, 0);
536 EXPECT_EQ(latency, kLatencyImg / 4);
537 EXPECT_EQ(rate, kRateImg);
538 448
539 predictor->TrimReferrers(); 449 predictor->TrimReferrers();
540 predictor->SerializeReferrers(&recovered_referral_list); 450 predictor->SerializeReferrers(&recovered_referral_list);
541 EXPECT_EQ(2U, recovered_referral_list.GetSize()); 451 EXPECT_EQ(2U, recovered_referral_list.GetSize());
542 EXPECT_TRUE(GetDataFromSerialization( 452 EXPECT_TRUE(GetDataFromSerialization(
543 motivation_url, icon_subresource_url, recovered_referral_list, 453 motivation_url, icon_subresource_url, recovered_referral_list, &rate));
544 &rate, &latency)); 454 EXPECT_EQ(rate, kRateIcon / 8);
545 EXPECT_EQ(latency, kLatencyIcon / 8);
546 EXPECT_EQ(rate, kRateIcon);
547 455
548 // Img is down to zero, but we don't delete it yet. 456 // Img is below threshold, and so it gets deleted.
549 EXPECT_TRUE(GetDataFromSerialization( 457 EXPECT_FALSE(GetDataFromSerialization(
550 motivation_url, img_subresource_url, recovered_referral_list, 458 motivation_url, img_subresource_url, recovered_referral_list, &rate));
551 &rate, &latency));
552 EXPECT_EQ(kLatencyImg / 8, 0);
553 EXPECT_EQ(latency, kLatencyImg / 8);
554 EXPECT_EQ(rate, kRateImg);
555 459
556 predictor->TrimReferrers(); 460 predictor->TrimReferrers();
557 predictor->SerializeReferrers(&recovered_referral_list); 461 predictor->SerializeReferrers(&recovered_referral_list);
558 // Icon is also trimmed away, so entire set gets discarded. 462 // Icon is also trimmed away, so entire set gets discarded.
559 EXPECT_EQ(1U, recovered_referral_list.GetSize()); 463 EXPECT_EQ(1U, recovered_referral_list.GetSize());
560 EXPECT_FALSE(GetDataFromSerialization( 464 EXPECT_FALSE(GetDataFromSerialization(
561 motivation_url, icon_subresource_url, recovered_referral_list, 465 motivation_url, icon_subresource_url, recovered_referral_list, &rate));
562 &rate, &latency));
563 EXPECT_FALSE(GetDataFromSerialization( 466 EXPECT_FALSE(GetDataFromSerialization(
564 motivation_url, img_subresource_url, recovered_referral_list, 467 motivation_url, img_subresource_url, recovered_referral_list, &rate));
565 &rate, &latency));
566 468
567 predictor->Shutdown(); 469 predictor->Shutdown();
568 } 470 }
569 471
570 472
571 TEST_F(PredictorTest, PriorityQueuePushPopTest) { 473 TEST_F(PredictorTest, PriorityQueuePushPopTest) {
572 Predictor::HostNameQueue queue; 474 Predictor::HostNameQueue queue;
573 475
574 GURL first("http://first:80"), second("http://second:90"); 476 GURL first("http://first:80"), second("http://second:90");
575 477
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 EXPECT_EQ(queue.Pop(), low2); 533 EXPECT_EQ(queue.Pop(), low2);
632 EXPECT_EQ(queue.Pop(), low3); 534 EXPECT_EQ(queue.Pop(), low3);
633 EXPECT_EQ(queue.Pop(), low4); 535 EXPECT_EQ(queue.Pop(), low4);
634 EXPECT_EQ(queue.Pop(), low5); 536 EXPECT_EQ(queue.Pop(), low5);
635 EXPECT_EQ(queue.Pop(), low4); 537 EXPECT_EQ(queue.Pop(), low4);
636 538
637 EXPECT_TRUE(queue.IsEmpty()); 539 EXPECT_TRUE(queue.IsEmpty());
638 } 540 }
639 541
640 } // namespace chrome_browser_net 542 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/predictor_api.cc ('k') | chrome/browser/net/referrer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698