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

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

Issue 7467012: Modifying prefetch to account for multi-profile. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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
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 <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
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/timer.h" 14 #include "base/timer.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/net/predictor_api.h" 16 #include "chrome/browser/net/predictor.h"
17 #include "chrome/browser/net/url_info.h" 17 #include "chrome/browser/net/url_info.h"
18 #include "chrome/common/net/predictor_common.h" 18 #include "chrome/common/net/predictor_common.h"
19 #include "content/browser/browser_thread.h" 19 #include "content/browser/browser_thread.h"
20 #include "net/base/address_list.h" 20 #include "net/base/address_list.h"
21 #include "net/base/mock_host_resolver.h" 21 #include "net/base/mock_host_resolver.h"
22 #include "net/base/winsock_init.h" 22 #include "net/base/winsock_init.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 using base::Time; 25 using base::Time;
26 using base::TimeDelta; 26 using base::TimeDelta;
(...skipping 28 matching lines...) Expand all
55 55
56 private: 56 private:
57 Predictor* predictor_; 57 Predictor* predictor_;
58 const UrlList hosts_; 58 const UrlList hosts_;
59 HelperTimer* timer_; 59 HelperTimer* timer_;
60 }; 60 };
61 61
62 class PredictorTest : public testing::Test { 62 class PredictorTest : public testing::Test {
63 public: 63 public:
64 PredictorTest() 64 PredictorTest()
65 : io_thread_(BrowserThread::IO, &loop_), 65 : ui_thread_(BrowserThread::UI, &loop_),
66 host_resolver_(new net::MockCachingHostResolver()), 66 io_thread_(BrowserThread::IO, &loop_),
67 default_max_queueing_delay_(TimeDelta::FromMilliseconds( 67 host_resolver_(new net::MockCachingHostResolver()) {
68 PredictorInit::kMaxSpeculativeResolveQueueDelayMs)) {
69 } 68 }
70 69
71 protected: 70 protected:
72 virtual void SetUp() { 71 virtual void SetUp() {
73 #if defined(OS_WIN) 72 #if defined(OS_WIN)
74 net::EnsureWinsockInit(); 73 net::EnsureWinsockInit();
75 #endif 74 #endif
75 Predictor::set_max_parallel_resolves(
76 Predictor::kMaxSpeculativeParallelResolves);
77 Predictor::set_max_queueing_delay(
78 Predictor::kMaxSpeculativeResolveQueueDelayMs);
76 // Since we are using a caching HostResolver, the following latencies will 79 // Since we are using a caching HostResolver, the following latencies will
77 // only be incurred by the first request, after which the result will be 80 // only be incurred by the first request, after which the result will be
78 // cached internally by |host_resolver_|. 81 // cached internally by |host_resolver_|.
79 net::RuleBasedHostResolverProc* rules = host_resolver_->rules(); 82 net::RuleBasedHostResolverProc* rules = host_resolver_->rules();
80 rules->AddRuleWithLatency("www.google.com", "127.0.0.1", 50); 83 rules->AddRuleWithLatency("www.google.com", "127.0.0.1", 50);
81 rules->AddRuleWithLatency("gmail.google.com.com", "127.0.0.1", 70); 84 rules->AddRuleWithLatency("gmail.google.com.com", "127.0.0.1", 70);
82 rules->AddRuleWithLatency("mail.google.com", "127.0.0.1", 44); 85 rules->AddRuleWithLatency("mail.google.com", "127.0.0.1", 44);
83 rules->AddRuleWithLatency("gmail.com", "127.0.0.1", 63); 86 rules->AddRuleWithLatency("gmail.com", "127.0.0.1", 63);
84 } 87 }
85 88
86 void WaitForResolution(Predictor* predictor, const UrlList& hosts) { 89 void WaitForResolution(Predictor* predictor, const UrlList& hosts) {
87 HelperTimer* timer = new HelperTimer(); 90 HelperTimer* timer = new HelperTimer();
88 timer->Start(TimeDelta::FromMilliseconds(100), 91 timer->Start(TimeDelta::FromMilliseconds(100),
89 new WaitForResolutionHelper(predictor, hosts, timer), 92 new WaitForResolutionHelper(predictor, hosts, timer),
90 &WaitForResolutionHelper::Run); 93 &WaitForResolutionHelper::Run);
91 MessageLoop::current()->Run(); 94 MessageLoop::current()->Run();
92 } 95 }
93 96
97 void TearDown() {
willchan no longer on Chromium 2011/08/12 21:51:47 Just delete this
rpetterson 2011/08/13 00:55:17 Done.
98 }
99
94 private: 100 private:
95 // IMPORTANT: do not move this below |host_resolver_|; the host resolver 101 // IMPORTANT: do not move this below |host_resolver_|; the host resolver
96 // must not outlive the message loop, otherwise bad things can happen 102 // must not outlive the message loop, otherwise bad things can happen
97 // (like posting to a deleted message loop). 103 // (like posting to a deleted message loop).
98 MessageLoop loop_; 104 MessageLoopForUI loop_;
105 BrowserThread ui_thread_;
99 BrowserThread io_thread_; 106 BrowserThread io_thread_;
100 107
101 protected: 108 protected:
102 scoped_ptr<net::MockCachingHostResolver> host_resolver_; 109 scoped_ptr<net::MockCachingHostResolver> host_resolver_;
103
104 // Shorthand to access TimeDelta of PredictorInit::kMaxQueueingDelayMs.
105 // (It would be a static constant... except style rules preclude that :-/ ).
106 const TimeDelta default_max_queueing_delay_;
107 }; 110 };
108 111
109 //------------------------------------------------------------------------------ 112 //------------------------------------------------------------------------------
110 113
111 TEST_F(PredictorTest, StartupShutdownTest) { 114 TEST_F(PredictorTest, StartupShutdownTest) {
112 scoped_refptr<Predictor> testing_master( 115 scoped_ptr<Predictor> testing_master(
willchan no longer on Chromium 2011/08/12 21:51:47 Just do Predictor testing_master; Same elsewhere.
rpetterson 2011/08/13 00:55:17 Done.
113 new Predictor(host_resolver_.get(), 116 new Predictor());
114 default_max_queueing_delay_,
115 PredictorInit::kMaxSpeculativeParallelResolves,
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_ptr<Predictor> testing_master(
127 new Predictor(host_resolver_.get(), 127 new Predictor());
128 default_max_queueing_delay_, 128 testing_master->SetHostResolver(host_resolver_.get());
129 PredictorInit::kMaxSpeculativeParallelResolves,
130 false));
131 129
132 GURL localhost("http://localhost:80"); 130 GURL localhost("http://localhost:80");
133 UrlList names; 131 UrlList names;
134 names.push_back(localhost); 132 names.push_back(localhost);
135 133
136 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); 134 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED);
137 135
138 MessageLoop::current()->PostDelayedTask(FROM_HERE, 136 MessageLoop::current()->PostDelayedTask(FROM_HERE,
139 new MessageLoop::QuitTask(), 500); 137 new MessageLoop::QuitTask(), 500);
140 MessageLoop::current()->Run(); 138 MessageLoop::current()->Run();
141 139
142 EXPECT_FALSE(testing_master->WasFound(localhost)); 140 EXPECT_FALSE(testing_master->WasFound(localhost));
143 141
144 testing_master->Shutdown(); 142 testing_master->Shutdown();
145 143
146 // Clean up after ourselves. 144 // Clean up after ourselves.
147 resolver_proc->Signal(); 145 resolver_proc->Signal();
148 MessageLoop::current()->RunAllPending(); 146 MessageLoop::current()->RunAllPending();
149 } 147 }
150 148
151 TEST_F(PredictorTest, SingleLookupTest) { 149 TEST_F(PredictorTest, SingleLookupTest) {
152 scoped_refptr<Predictor> testing_master( 150 scoped_ptr<Predictor> testing_master(
153 new Predictor(host_resolver_.get(), 151 new Predictor());
154 default_max_queueing_delay_, 152 testing_master->SetHostResolver(host_resolver_.get());
155 PredictorInit::kMaxSpeculativeParallelResolves,
156 false));
157 153
158 GURL goog("http://www.google.com:80"); 154 GURL goog("http://www.google.com:80");
159 155
160 UrlList names; 156 UrlList names;
161 names.push_back(goog); 157 names.push_back(goog);
162 158
163 // Try to flood the predictor with many concurrent requests. 159 // Try to flood the predictor with many concurrent requests.
164 for (int i = 0; i < 10; i++) 160 for (int i = 0; i < 10; i++)
165 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); 161 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED);
166 162
167 WaitForResolution(testing_master, names); 163 WaitForResolution(testing_master.get(), names);
168 164
169 EXPECT_TRUE(testing_master->WasFound(goog)); 165 EXPECT_TRUE(testing_master->WasFound(goog));
170 166
171 MessageLoop::current()->RunAllPending(); 167 MessageLoop::current()->RunAllPending();
172 168
173 EXPECT_GT(testing_master->peak_pending_lookups(), names.size() / 2); 169 EXPECT_GT(testing_master->peak_pending_lookups(), names.size() / 2);
174 EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); 170 EXPECT_LE(testing_master->peak_pending_lookups(), names.size());
175 EXPECT_LE(testing_master->peak_pending_lookups(), 171 EXPECT_LE(testing_master->peak_pending_lookups(),
176 testing_master->max_concurrent_dns_lookups()); 172 testing_master->max_concurrent_dns_lookups());
177 173
178 testing_master->Shutdown(); 174 testing_master->Shutdown();
179 } 175 }
180 176
181 TEST_F(PredictorTest, ConcurrentLookupTest) { 177 TEST_F(PredictorTest, ConcurrentLookupTest) {
182 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); 178 host_resolver_->rules()->AddSimulatedFailure("*.notfound");
183 179
184 scoped_refptr<Predictor> testing_master( 180 scoped_ptr<Predictor> testing_master(
185 new Predictor(host_resolver_.get(), 181 new Predictor());
186 default_max_queueing_delay_, 182 testing_master->SetHostResolver(host_resolver_.get());
187 PredictorInit::kMaxSpeculativeParallelResolves,
188 false));
189 183
190 GURL goog("http://www.google.com:80"), 184 GURL goog("http://www.google.com:80"),
191 goog2("http://gmail.google.com.com:80"), 185 goog2("http://gmail.google.com.com:80"),
192 goog3("http://mail.google.com:80"), 186 goog3("http://mail.google.com:80"),
193 goog4("http://gmail.com:80"); 187 goog4("http://gmail.com:80");
194 GURL bad1("http://bad1.notfound:80"), 188 GURL bad1("http://bad1.notfound:80"),
195 bad2("http://bad2.notfound:80"); 189 bad2("http://bad2.notfound:80");
196 190
197 UrlList names; 191 UrlList names;
198 names.push_back(goog); 192 names.push_back(goog);
199 names.push_back(goog3); 193 names.push_back(goog3);
200 names.push_back(bad1); 194 names.push_back(bad1);
201 names.push_back(goog2); 195 names.push_back(goog2);
202 names.push_back(bad2); 196 names.push_back(bad2);
203 names.push_back(goog4); 197 names.push_back(goog4);
204 names.push_back(goog); 198 names.push_back(goog);
205 199
206 // Try to flood the predictor with many concurrent requests. 200 // Try to flood the predictor with many concurrent requests.
207 for (int i = 0; i < 10; i++) 201 for (int i = 0; i < 10; i++)
208 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); 202 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED);
209 203
210 WaitForResolution(testing_master, names); 204 WaitForResolution(testing_master.get(), names);
211 205
212 EXPECT_TRUE(testing_master->WasFound(goog)); 206 EXPECT_TRUE(testing_master->WasFound(goog));
213 EXPECT_TRUE(testing_master->WasFound(goog3)); 207 EXPECT_TRUE(testing_master->WasFound(goog3));
214 EXPECT_TRUE(testing_master->WasFound(goog2)); 208 EXPECT_TRUE(testing_master->WasFound(goog2));
215 EXPECT_TRUE(testing_master->WasFound(goog4)); 209 EXPECT_TRUE(testing_master->WasFound(goog4));
216 EXPECT_FALSE(testing_master->WasFound(bad1)); 210 EXPECT_FALSE(testing_master->WasFound(bad1));
217 EXPECT_FALSE(testing_master->WasFound(bad2)); 211 EXPECT_FALSE(testing_master->WasFound(bad2));
218 212
219 MessageLoop::current()->RunAllPending(); 213 MessageLoop::current()->RunAllPending();
220 214
221 EXPECT_FALSE(testing_master->WasFound(bad1)); 215 EXPECT_FALSE(testing_master->WasFound(bad1));
222 EXPECT_FALSE(testing_master->WasFound(bad2)); 216 EXPECT_FALSE(testing_master->WasFound(bad2));
223 217
224 EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); 218 EXPECT_LE(testing_master->peak_pending_lookups(), names.size());
225 EXPECT_LE(testing_master->peak_pending_lookups(), 219 EXPECT_LE(testing_master->peak_pending_lookups(),
226 testing_master->max_concurrent_dns_lookups()); 220 testing_master->max_concurrent_dns_lookups());
227 221
228 testing_master->Shutdown(); 222 testing_master->Shutdown();
229 } 223 }
230 224
231 TEST_F(PredictorTest, MassiveConcurrentLookupTest) { 225 TEST_F(PredictorTest, MassiveConcurrentLookupTest) {
232 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); 226 host_resolver_->rules()->AddSimulatedFailure("*.notfound");
233 227
234 scoped_refptr<Predictor> testing_master( 228 scoped_ptr<Predictor> testing_master(
235 new Predictor(host_resolver_.get(), 229 new Predictor());
236 default_max_queueing_delay_, 230 testing_master->SetHostResolver(host_resolver_.get());
237 PredictorInit::kMaxSpeculativeParallelResolves,
238 false));
239 231
240 UrlList names; 232 UrlList names;
241 for (int i = 0; i < 100; i++) 233 for (int i = 0; i < 100; i++)
242 names.push_back(GURL( 234 names.push_back(GURL(
243 "http://host" + base::IntToString(i) + ".notfound:80")); 235 "http://host" + base::IntToString(i) + ".notfound:80"));
244 236
245 // Try to flood the predictor with many concurrent requests. 237 // Try to flood the predictor with many concurrent requests.
246 for (int i = 0; i < 10; i++) 238 for (int i = 0; i < 10; i++)
247 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); 239 testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED);
248 240
249 WaitForResolution(testing_master, names); 241 WaitForResolution(testing_master.get(), names);
250 242
251 MessageLoop::current()->RunAllPending(); 243 MessageLoop::current()->RunAllPending();
252 244
253 EXPECT_LE(testing_master->peak_pending_lookups(), names.size()); 245 EXPECT_LE(testing_master->peak_pending_lookups(), names.size());
254 EXPECT_LE(testing_master->peak_pending_lookups(), 246 EXPECT_LE(testing_master->peak_pending_lookups(),
255 testing_master->max_concurrent_dns_lookups()); 247 testing_master->max_concurrent_dns_lookups());
256 248
257 testing_master->Shutdown(); 249 testing_master->Shutdown();
258 } 250 }
259 251
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 return true; 337 return true;
346 } 338 }
347 } 339 }
348 return false; 340 return false;
349 } 341 }
350 342
351 //------------------------------------------------------------------------------ 343 //------------------------------------------------------------------------------
352 344
353 // Make sure nil referral lists really have no entries, and no latency listed. 345 // Make sure nil referral lists really have no entries, and no latency listed.
354 TEST_F(PredictorTest, ReferrerSerializationNilTest) { 346 TEST_F(PredictorTest, ReferrerSerializationNilTest) {
355 scoped_refptr<Predictor> predictor( 347 scoped_ptr<Predictor> predictor(
356 new Predictor(host_resolver_.get(), 348 new Predictor());
357 default_max_queueing_delay_, 349 predictor->SetHostResolver(host_resolver_.get());
358 PredictorInit::kMaxSpeculativeParallelResolves, 350
359 false));
360 scoped_ptr<ListValue> referral_list(NewEmptySerializationList()); 351 scoped_ptr<ListValue> referral_list(NewEmptySerializationList());
361 predictor->SerializeReferrers(referral_list.get()); 352 predictor->SerializeReferrers(referral_list.get());
362 EXPECT_EQ(1U, referral_list->GetSize()); 353 EXPECT_EQ(1U, referral_list->GetSize());
363 EXPECT_FALSE(GetDataFromSerialization( 354 EXPECT_FALSE(GetDataFromSerialization(
364 GURL("http://a.com:79"), GURL("http://b.com:78"), 355 GURL("http://a.com:79"), GURL("http://b.com:78"),
365 *referral_list.get(), NULL)); 356 *referral_list.get(), NULL));
366 357
367 predictor->Shutdown(); 358 predictor->Shutdown();
368 } 359 }
369 360
370 // Make sure that when a serialization list includes a value, that it can be 361 // Make sure that when a serialization list includes a value, that it can be
371 // deserialized into the database, and can be extracted back out via 362 // deserialized into the database, and can be extracted back out via
372 // serialization without being changed. 363 // serialization without being changed.
373 TEST_F(PredictorTest, ReferrerSerializationSingleReferrerTest) { 364 TEST_F(PredictorTest, ReferrerSerializationSingleReferrerTest) {
374 scoped_refptr<Predictor> predictor( 365 scoped_ptr<Predictor> predictor(
375 new Predictor(host_resolver_.get(), 366 new Predictor());
376 default_max_queueing_delay_, 367 predictor->SetHostResolver(host_resolver_.get());
377 PredictorInit::kMaxSpeculativeParallelResolves,
378 false));
379 const GURL motivation_url("http://www.google.com:91"); 368 const GURL motivation_url("http://www.google.com:91");
380 const GURL subresource_url("http://icons.google.com:90"); 369 const GURL subresource_url("http://icons.google.com:90");
381 const double kUseRate = 23.4; 370 const double kUseRate = 23.4;
382 scoped_ptr<ListValue> referral_list(NewEmptySerializationList()); 371 scoped_ptr<ListValue> referral_list(NewEmptySerializationList());
383 372
384 AddToSerializedList(motivation_url, subresource_url, 373 AddToSerializedList(motivation_url, subresource_url,
385 kUseRate, referral_list.get()); 374 kUseRate, referral_list.get());
386 375
387 predictor->DeserializeReferrers(*referral_list.get()); 376 predictor->DeserializeReferrers(*referral_list.get());
388 377
(...skipping 13 matching lines...) Expand all
402 double espilon_ratio = 1.01; \ 391 double espilon_ratio = 1.01; \
403 if ((a) < 0.) \ 392 if ((a) < 0.) \
404 espilon_ratio = 1 / espilon_ratio; \ 393 espilon_ratio = 1 / espilon_ratio; \
405 EXPECT_LT(a, espilon_ratio * (b)); \ 394 EXPECT_LT(a, espilon_ratio * (b)); \
406 EXPECT_GT((a) * espilon_ratio, b); \ 395 EXPECT_GT((a) * espilon_ratio, b); \
407 } while (0) 396 } while (0)
408 397
409 398
410 // Make sure the Trim() functionality works as expected. 399 // Make sure the Trim() functionality works as expected.
411 TEST_F(PredictorTest, ReferrerSerializationTrimTest) { 400 TEST_F(PredictorTest, ReferrerSerializationTrimTest) {
412 scoped_refptr<Predictor> predictor( 401 scoped_ptr<Predictor> predictor(
413 new Predictor(host_resolver_.get(), 402 new Predictor());
414 default_max_queueing_delay_, 403 predictor->SetHostResolver(host_resolver_.get());
415 PredictorInit::kMaxSpeculativeParallelResolves,
416 false));
417 GURL motivation_url("http://www.google.com:110"); 404 GURL motivation_url("http://www.google.com:110");
418 405
419 GURL icon_subresource_url("http://icons.google.com:111"); 406 GURL icon_subresource_url("http://icons.google.com:111");
420 const double kRateIcon = 16.0 * Predictor::kDiscardableExpectedValue; 407 const double kRateIcon = 16.0 * Predictor::kDiscardableExpectedValue;
421 GURL img_subresource_url("http://img.google.com:118"); 408 GURL img_subresource_url("http://img.google.com:118");
422 const double kRateImg = 8.0 * Predictor::kDiscardableExpectedValue; 409 const double kRateImg = 8.0 * Predictor::kDiscardableExpectedValue;
423 410
424 scoped_ptr<ListValue> referral_list(NewEmptySerializationList()); 411 scoped_ptr<ListValue> referral_list(NewEmptySerializationList());
425 AddToSerializedList( 412 AddToSerializedList(
426 motivation_url, icon_subresource_url, kRateIcon, referral_list.get()); 413 motivation_url, icon_subresource_url, kRateIcon, referral_list.get());
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 EXPECT_NE(Predictor::CanonicalizeUrl(http), 581 EXPECT_NE(Predictor::CanonicalizeUrl(http),
595 Predictor::CanonicalizeUrl(https)); 582 Predictor::CanonicalizeUrl(https));
596 583
597 // Https works fine. 584 // Https works fine.
598 GURL long_https("https://host:999/path?query=value"); 585 GURL long_https("https://host:999/path?query=value");
599 EXPECT_EQ(Predictor::CanonicalizeUrl(long_https), 586 EXPECT_EQ(Predictor::CanonicalizeUrl(long_https),
600 long_https.GetWithEmptyPath()); 587 long_https.GetWithEmptyPath());
601 } 588 }
602 589
603 TEST_F(PredictorTest, DiscardPredictorResults) { 590 TEST_F(PredictorTest, DiscardPredictorResults) {
604 scoped_refptr<Predictor> predictor( 591 scoped_ptr<Predictor> predictor(
605 new Predictor(host_resolver_.get(), 592 new Predictor());
606 default_max_queueing_delay_, 593 predictor->SetHostResolver(host_resolver_.get());
607 PredictorInit::kMaxSpeculativeParallelResolves,
608 false));
609 ListValue referral_list; 594 ListValue referral_list;
610 predictor->SerializeReferrers(&referral_list); 595 predictor->SerializeReferrers(&referral_list);
611 EXPECT_EQ(1U, referral_list.GetSize()); 596 EXPECT_EQ(1U, referral_list.GetSize());
612 597
613 GURL host_1("http://test_1"); 598 GURL host_1("http://test_1");
614 GURL host_2("http://test_2"); 599 GURL host_2("http://test_2");
615 predictor->LearnFromNavigation(host_1, host_2); 600 predictor->LearnFromNavigation(host_1, host_2);
616 601
617 predictor->SerializeReferrers(&referral_list); 602 predictor->SerializeReferrers(&referral_list);
618 EXPECT_EQ(2U, referral_list.GetSize()); 603 EXPECT_EQ(2U, referral_list.GetSize());
619 604
620 predictor->DiscardAllResults(); 605 predictor->DiscardAllResults();
621 predictor->SerializeReferrers(&referral_list); 606 predictor->SerializeReferrers(&referral_list);
622 EXPECT_EQ(1U, referral_list.GetSize()); 607 EXPECT_EQ(1U, referral_list.GetSize());
623 608
624 predictor->Shutdown(); 609 predictor->Shutdown();
625 } 610 }
626 611
627 } // namespace chrome_browser_net 612 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698