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

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

Issue 4192012: Convert implicit scoped_refptr constructor calls to explicit ones, part 1 (Closed) Base URL: http://git.chromium.org/git/chromium.git
Patch Set: fix presubmit Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 scoped_ptr<net::MockCachingHostResolver> host_resolver_; 102 scoped_ptr<net::MockCachingHostResolver> host_resolver_;
103 103
104 // Shorthand to access TimeDelta of PredictorInit::kMaxQueueingDelayMs. 104 // Shorthand to access TimeDelta of PredictorInit::kMaxQueueingDelayMs.
105 // (It would be a static constant... except style rules preclude that :-/ ). 105 // (It would be a static constant... except style rules preclude that :-/ ).
106 const TimeDelta default_max_queueing_delay_; 106 const TimeDelta default_max_queueing_delay_;
107 }; 107 };
108 108
109 //------------------------------------------------------------------------------ 109 //------------------------------------------------------------------------------
110 110
111 TEST_F(PredictorTest, StartupShutdownTest) { 111 TEST_F(PredictorTest, StartupShutdownTest) {
112 scoped_refptr<Predictor> testing_master = 112 scoped_refptr<Predictor> testing_master(
113 new Predictor(host_resolver_.get(), 113 new Predictor(host_resolver_.get(),
114 default_max_queueing_delay_, 114 default_max_queueing_delay_,
115 PredictorInit::kMaxSpeculativeParallelResolves, 115 PredictorInit::kMaxSpeculativeParallelResolves,
116 false); 116 false));
117 testing_master->Shutdown(); 117 testing_master->Shutdown();
118 } 118 }
119 119
120 120
121 TEST_F(PredictorTest, ShutdownWhenResolutionIsPendingTest) { 121 TEST_F(PredictorTest, ShutdownWhenResolutionIsPendingTest) {
122 scoped_refptr<net::WaitingHostResolverProc> resolver_proc = 122 scoped_refptr<net::WaitingHostResolverProc> resolver_proc(
123 new net::WaitingHostResolverProc(NULL); 123 new net::WaitingHostResolverProc(NULL));
124 host_resolver_->Reset(resolver_proc); 124 host_resolver_->Reset(resolver_proc);
125 125
126 scoped_refptr<Predictor> testing_master = 126 scoped_refptr<Predictor> testing_master(
127 new Predictor(host_resolver_.get(), 127 new Predictor(host_resolver_.get(),
128 default_max_queueing_delay_, 128 default_max_queueing_delay_,
129 PredictorInit::kMaxSpeculativeParallelResolves, 129 PredictorInit::kMaxSpeculativeParallelResolves,
130 false); 130 false));
131 131
132 GURL localhost("http://localhost:80"); 132 GURL localhost("http://localhost:80");
133 UrlList names; 133 UrlList names;
134 names.push_back(localhost); 134 names.push_back(localhost);
135 135
136 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); 136 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED);
137 137
138 MessageLoop::current()->PostDelayedTask(FROM_HERE, 138 MessageLoop::current()->PostDelayedTask(FROM_HERE,
139 new MessageLoop::QuitTask(), 500); 139 new MessageLoop::QuitTask(), 500);
140 MessageLoop::current()->Run(); 140 MessageLoop::current()->Run();
141 141
142 EXPECT_FALSE(testing_master->WasFound(localhost)); 142 EXPECT_FALSE(testing_master->WasFound(localhost));
143 143
144 testing_master->Shutdown(); 144 testing_master->Shutdown();
145 145
146 // Clean up after ourselves. 146 // Clean up after ourselves.
147 resolver_proc->Signal(); 147 resolver_proc->Signal();
148 MessageLoop::current()->RunAllPending(); 148 MessageLoop::current()->RunAllPending();
149 } 149 }
150 150
151 TEST_F(PredictorTest, SingleLookupTest) { 151 TEST_F(PredictorTest, SingleLookupTest) {
152 scoped_refptr<Predictor> testing_master = 152 scoped_refptr<Predictor> testing_master(
153 new Predictor(host_resolver_.get(), 153 new Predictor(host_resolver_.get(),
154 default_max_queueing_delay_, 154 default_max_queueing_delay_,
155 PredictorInit::kMaxSpeculativeParallelResolves, 155 PredictorInit::kMaxSpeculativeParallelResolves,
156 false); 156 false));
157 157
158 GURL goog("http://www.google.com:80"); 158 GURL goog("http://www.google.com:80");
159 159
160 UrlList names; 160 UrlList names;
161 names.push_back(goog); 161 names.push_back(goog);
162 162
163 // Try to flood the predictor with many concurrent requests. 163 // Try to flood the predictor with many concurrent requests.
164 for (int i = 0; i < 10; i++) 164 for (int i = 0; i < 10; i++)
165 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); 165 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED);
166 166
167 WaitForResolution(testing_master, names); 167 WaitForResolution(testing_master, names);
168 168
169 EXPECT_TRUE(testing_master->WasFound(goog)); 169 EXPECT_TRUE(testing_master->WasFound(goog));
170 170
171 MessageLoop::current()->RunAllPending(); 171 MessageLoop::current()->RunAllPending();
172 172
173 EXPECT_GT(testing_master->peak_pending_lookups(), names.size() / 2); 173 EXPECT_GT(testing_master->peak_pending_lookups(), names.size() / 2);
174 EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); 174 EXPECT_LE(testing_master->peak_pending_lookups(), names.size());
175 EXPECT_LE(testing_master->peak_pending_lookups(), 175 EXPECT_LE(testing_master->peak_pending_lookups(),
176 testing_master->max_concurrent_dns_lookups()); 176 testing_master->max_concurrent_dns_lookups());
177 177
178 testing_master->Shutdown(); 178 testing_master->Shutdown();
179 } 179 }
180 180
181 TEST_F(PredictorTest, ConcurrentLookupTest) { 181 TEST_F(PredictorTest, ConcurrentLookupTest) {
182 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); 182 host_resolver_->rules()->AddSimulatedFailure("*.notfound");
183 183
184 scoped_refptr<Predictor> testing_master = 184 scoped_refptr<Predictor> testing_master(
185 new Predictor(host_resolver_.get(), 185 new Predictor(host_resolver_.get(),
186 default_max_queueing_delay_, 186 default_max_queueing_delay_,
187 PredictorInit::kMaxSpeculativeParallelResolves, 187 PredictorInit::kMaxSpeculativeParallelResolves,
188 false); 188 false));
189 189
190 GURL goog("http://www.google.com:80"), 190 GURL goog("http://www.google.com:80"),
191 goog2("http://gmail.google.com.com:80"), 191 goog2("http://gmail.google.com.com:80"),
192 goog3("http://mail.google.com:80"), 192 goog3("http://mail.google.com:80"),
193 goog4("http://gmail.com:80"); 193 goog4("http://gmail.com:80");
194 GURL bad1("http://bad1.notfound:80"), 194 GURL bad1("http://bad1.notfound:80"),
195 bad2("http://bad2.notfound:80"); 195 bad2("http://bad2.notfound:80");
196 196
197 UrlList names; 197 UrlList names;
198 names.push_back(goog); 198 names.push_back(goog);
(...skipping 25 matching lines...) Expand all
224 EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); 224 EXPECT_LE(testing_master->peak_pending_lookups(), names.size());
225 EXPECT_LE(testing_master->peak_pending_lookups(), 225 EXPECT_LE(testing_master->peak_pending_lookups(),
226 testing_master->max_concurrent_dns_lookups()); 226 testing_master->max_concurrent_dns_lookups());
227 227
228 testing_master->Shutdown(); 228 testing_master->Shutdown();
229 } 229 }
230 230
231 TEST_F(PredictorTest, MassiveConcurrentLookupTest) { 231 TEST_F(PredictorTest, MassiveConcurrentLookupTest) {
232 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); 232 host_resolver_->rules()->AddSimulatedFailure("*.notfound");
233 233
234 scoped_refptr<Predictor> testing_master = 234 scoped_refptr<Predictor> testing_master(
235 new Predictor(host_resolver_.get(), 235 new Predictor(host_resolver_.get(),
236 default_max_queueing_delay_, 236 default_max_queueing_delay_,
237 PredictorInit::kMaxSpeculativeParallelResolves, 237 PredictorInit::kMaxSpeculativeParallelResolves,
238 false); 238 false));
239 239
240 UrlList names; 240 UrlList names;
241 for (int i = 0; i < 100; i++) 241 for (int i = 0; i < 100; i++)
242 names.push_back(GURL( 242 names.push_back(GURL(
243 "http://host" + base::IntToString(i) + ".notfound:80")); 243 "http://host" + base::IntToString(i) + ".notfound:80"));
244 244
245 // Try to flood the predictor with many concurrent requests. 245 // Try to flood the predictor with many concurrent requests.
246 for (int i = 0; i < 10; i++) 246 for (int i = 0; i < 10; i++)
247 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); 247 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED);
248 248
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 return true; 344 return true;
345 } 345 }
346 } 346 }
347 return false; 347 return false;
348 } 348 }
349 349
350 //------------------------------------------------------------------------------ 350 //------------------------------------------------------------------------------
351 351
352 // Make sure nil referral lists really have no entries, and no latency listed. 352 // Make sure nil referral lists really have no entries, and no latency listed.
353 TEST_F(PredictorTest, ReferrerSerializationNilTest) { 353 TEST_F(PredictorTest, ReferrerSerializationNilTest) {
354 scoped_refptr<Predictor> predictor = 354 scoped_refptr<Predictor> predictor(
355 new Predictor(host_resolver_.get(), 355 new Predictor(host_resolver_.get(),
356 default_max_queueing_delay_, 356 default_max_queueing_delay_,
357 PredictorInit::kMaxSpeculativeParallelResolves, 357 PredictorInit::kMaxSpeculativeParallelResolves,
358 false); 358 false));
359 scoped_ptr<ListValue> referral_list(NewEmptySerializationList()); 359 scoped_ptr<ListValue> referral_list(NewEmptySerializationList());
360 predictor->SerializeReferrers(referral_list.get()); 360 predictor->SerializeReferrers(referral_list.get());
361 EXPECT_EQ(1U, referral_list->GetSize()); 361 EXPECT_EQ(1U, referral_list->GetSize());
362 EXPECT_FALSE(GetDataFromSerialization( 362 EXPECT_FALSE(GetDataFromSerialization(
363 GURL("http://a.com:79"), GURL("http://b.com:78"), 363 GURL("http://a.com:79"), GURL("http://b.com:78"),
364 *referral_list.get(), NULL)); 364 *referral_list.get(), NULL));
365 365
366 predictor->Shutdown(); 366 predictor->Shutdown();
367 } 367 }
368 368
369 // Make sure that when a serialization list includes a value, that it can be 369 // Make sure that when a serialization list includes a value, that it can be
370 // deserialized into the database, and can be extracted back out via 370 // deserialized into the database, and can be extracted back out via
371 // serialization without being changed. 371 // serialization without being changed.
372 TEST_F(PredictorTest, ReferrerSerializationSingleReferrerTest) { 372 TEST_F(PredictorTest, ReferrerSerializationSingleReferrerTest) {
373 scoped_refptr<Predictor> predictor = 373 scoped_refptr<Predictor> predictor(
374 new Predictor(host_resolver_.get(), 374 new Predictor(host_resolver_.get(),
375 default_max_queueing_delay_, 375 default_max_queueing_delay_,
376 PredictorInit::kMaxSpeculativeParallelResolves, 376 PredictorInit::kMaxSpeculativeParallelResolves,
377 false); 377 false));
378 const GURL motivation_url("http://www.google.com:91"); 378 const GURL motivation_url("http://www.google.com:91");
379 const GURL subresource_url("http://icons.google.com:90"); 379 const GURL subresource_url("http://icons.google.com:90");
380 const double kUseRate = 23.4; 380 const double kUseRate = 23.4;
381 scoped_ptr<ListValue> referral_list(NewEmptySerializationList()); 381 scoped_ptr<ListValue> referral_list(NewEmptySerializationList());
382 382
383 AddToSerializedList(motivation_url, subresource_url, 383 AddToSerializedList(motivation_url, subresource_url,
384 kUseRate, referral_list.get()); 384 kUseRate, referral_list.get());
385 385
386 predictor->DeserializeReferrers(*referral_list.get()); 386 predictor->DeserializeReferrers(*referral_list.get());
387 387
388 ListValue recovered_referral_list; 388 ListValue recovered_referral_list;
389 predictor->SerializeReferrers(&recovered_referral_list); 389 predictor->SerializeReferrers(&recovered_referral_list);
390 EXPECT_EQ(2U, recovered_referral_list.GetSize()); 390 EXPECT_EQ(2U, recovered_referral_list.GetSize());
391 double rate; 391 double rate;
392 EXPECT_TRUE(GetDataFromSerialization( 392 EXPECT_TRUE(GetDataFromSerialization(
393 motivation_url, subresource_url, recovered_referral_list, &rate)); 393 motivation_url, subresource_url, recovered_referral_list, &rate));
394 EXPECT_EQ(rate, kUseRate); 394 EXPECT_EQ(rate, kUseRate);
395 395
396 predictor->Shutdown(); 396 predictor->Shutdown();
397 } 397 }
398 398
399 // Make sure the Trim() functionality works as expected. 399 // Make sure the Trim() functionality works as expected.
400 TEST_F(PredictorTest, ReferrerSerializationTrimTest) { 400 TEST_F(PredictorTest, ReferrerSerializationTrimTest) {
401 scoped_refptr<Predictor> predictor = 401 scoped_refptr<Predictor> predictor(
402 new Predictor(host_resolver_.get(), 402 new Predictor(host_resolver_.get(),
403 default_max_queueing_delay_, 403 default_max_queueing_delay_,
404 PredictorInit::kMaxSpeculativeParallelResolves, 404 PredictorInit::kMaxSpeculativeParallelResolves,
405 false); 405 false));
406 GURL motivation_url("http://www.google.com:110"); 406 GURL motivation_url("http://www.google.com:110");
407 407
408 GURL icon_subresource_url("http://icons.google.com:111"); 408 GURL icon_subresource_url("http://icons.google.com:111");
409 const double kRateIcon = 16.0 * Predictor::kPersistWorthyExpectedValue; 409 const double kRateIcon = 16.0 * Predictor::kPersistWorthyExpectedValue;
410 GURL img_subresource_url("http://img.google.com:118"); 410 GURL img_subresource_url("http://img.google.com:118");
411 const double kRateImg = 8.0 * Predictor::kPersistWorthyExpectedValue; 411 const double kRateImg = 8.0 * Predictor::kPersistWorthyExpectedValue;
412 412
413 scoped_ptr<ListValue> referral_list(NewEmptySerializationList()); 413 scoped_ptr<ListValue> referral_list(NewEmptySerializationList());
414 AddToSerializedList( 414 AddToSerializedList(
415 motivation_url, icon_subresource_url, kRateIcon, referral_list.get()); 415 motivation_url, icon_subresource_url, kRateIcon, referral_list.get());
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 EXPECT_NE(Predictor::CanonicalizeUrl(http), 579 EXPECT_NE(Predictor::CanonicalizeUrl(http),
580 Predictor::CanonicalizeUrl(https)); 580 Predictor::CanonicalizeUrl(https));
581 581
582 // Https works fine. 582 // Https works fine.
583 GURL long_https("https://host:999/path?query=value"); 583 GURL long_https("https://host:999/path?query=value");
584 EXPECT_EQ(Predictor::CanonicalizeUrl(long_https), 584 EXPECT_EQ(Predictor::CanonicalizeUrl(long_https),
585 long_https.GetWithEmptyPath()); 585 long_https.GetWithEmptyPath());
586 } 586 }
587 587
588 } // namespace chrome_browser_net 588 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698