Chromium Code Reviews| Index: chrome/browser/net/predictor_unittest.cc |
| =================================================================== |
| --- chrome/browser/net/predictor_unittest.cc (revision 96503) |
| +++ chrome/browser/net/predictor_unittest.cc (working copy) |
| @@ -13,7 +13,7 @@ |
| #include "base/string_number_conversions.h" |
| #include "base/timer.h" |
| #include "base/values.h" |
| -#include "chrome/browser/net/predictor_api.h" |
| +#include "chrome/browser/net/predictor.h" |
| #include "chrome/browser/net/url_info.h" |
| #include "chrome/common/net/predictor_common.h" |
| #include "content/browser/browser_thread.h" |
| @@ -62,10 +62,9 @@ |
| class PredictorTest : public testing::Test { |
| public: |
| PredictorTest() |
| - : io_thread_(BrowserThread::IO, &loop_), |
| - host_resolver_(new net::MockCachingHostResolver()), |
| - default_max_queueing_delay_(TimeDelta::FromMilliseconds( |
| - PredictorInit::kMaxSpeculativeResolveQueueDelayMs)) { |
| + : ui_thread_(BrowserThread::UI, &loop_), |
| + io_thread_(BrowserThread::IO, &loop_), |
| + host_resolver_(new net::MockCachingHostResolver()) { |
| } |
| protected: |
| @@ -73,6 +72,10 @@ |
| #if defined(OS_WIN) |
| net::EnsureWinsockInit(); |
| #endif |
| + Predictor::set_max_parallel_resolves( |
| + Predictor::kMaxSpeculativeParallelResolves); |
| + Predictor::set_max_queueing_delay( |
| + Predictor::kMaxSpeculativeResolveQueueDelayMs); |
| // Since we are using a caching HostResolver, the following latencies will |
| // only be incurred by the first request, after which the result will be |
| // cached internally by |host_resolver_|. |
| @@ -91,29 +94,26 @@ |
| MessageLoop::current()->Run(); |
| } |
| + void TearDown() { |
|
willchan no longer on Chromium
2011/08/12 21:51:47
Just delete this
rpetterson
2011/08/13 00:55:17
Done.
|
| + } |
| + |
| private: |
| // IMPORTANT: do not move this below |host_resolver_|; the host resolver |
| // must not outlive the message loop, otherwise bad things can happen |
| // (like posting to a deleted message loop). |
| - MessageLoop loop_; |
| + MessageLoopForUI loop_; |
| + BrowserThread ui_thread_; |
| BrowserThread io_thread_; |
| protected: |
| scoped_ptr<net::MockCachingHostResolver> host_resolver_; |
| - |
| - // Shorthand to access TimeDelta of PredictorInit::kMaxQueueingDelayMs. |
| - // (It would be a static constant... except style rules preclude that :-/ ). |
| - const TimeDelta default_max_queueing_delay_; |
| }; |
| //------------------------------------------------------------------------------ |
| TEST_F(PredictorTest, StartupShutdownTest) { |
| - scoped_refptr<Predictor> testing_master( |
| - new Predictor(host_resolver_.get(), |
| - default_max_queueing_delay_, |
| - PredictorInit::kMaxSpeculativeParallelResolves, |
| - false)); |
| + 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.
|
| + new Predictor()); |
| testing_master->Shutdown(); |
| } |
| @@ -123,11 +123,9 @@ |
| new net::WaitingHostResolverProc(NULL)); |
| host_resolver_->Reset(resolver_proc); |
| - scoped_refptr<Predictor> testing_master( |
| - new Predictor(host_resolver_.get(), |
| - default_max_queueing_delay_, |
| - PredictorInit::kMaxSpeculativeParallelResolves, |
| - false)); |
| + scoped_ptr<Predictor> testing_master( |
| + new Predictor()); |
| + testing_master->SetHostResolver(host_resolver_.get()); |
| GURL localhost("http://localhost:80"); |
| UrlList names; |
| @@ -149,11 +147,9 @@ |
| } |
| TEST_F(PredictorTest, SingleLookupTest) { |
| - scoped_refptr<Predictor> testing_master( |
| - new Predictor(host_resolver_.get(), |
| - default_max_queueing_delay_, |
| - PredictorInit::kMaxSpeculativeParallelResolves, |
| - false)); |
| + scoped_ptr<Predictor> testing_master( |
| + new Predictor()); |
| + testing_master->SetHostResolver(host_resolver_.get()); |
| GURL goog("http://www.google.com:80"); |
| @@ -164,7 +160,7 @@ |
| for (int i = 0; i < 10; i++) |
| testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); |
| - WaitForResolution(testing_master, names); |
| + WaitForResolution(testing_master.get(), names); |
| EXPECT_TRUE(testing_master->WasFound(goog)); |
| @@ -181,11 +177,9 @@ |
| TEST_F(PredictorTest, ConcurrentLookupTest) { |
| host_resolver_->rules()->AddSimulatedFailure("*.notfound"); |
| - scoped_refptr<Predictor> testing_master( |
| - new Predictor(host_resolver_.get(), |
| - default_max_queueing_delay_, |
| - PredictorInit::kMaxSpeculativeParallelResolves, |
| - false)); |
| + scoped_ptr<Predictor> testing_master( |
| + new Predictor()); |
| + testing_master->SetHostResolver(host_resolver_.get()); |
| GURL goog("http://www.google.com:80"), |
| goog2("http://gmail.google.com.com:80"), |
| @@ -207,7 +201,7 @@ |
| for (int i = 0; i < 10; i++) |
| testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); |
| - WaitForResolution(testing_master, names); |
| + WaitForResolution(testing_master.get(), names); |
| EXPECT_TRUE(testing_master->WasFound(goog)); |
| EXPECT_TRUE(testing_master->WasFound(goog3)); |
| @@ -231,11 +225,9 @@ |
| TEST_F(PredictorTest, MassiveConcurrentLookupTest) { |
| host_resolver_->rules()->AddSimulatedFailure("*.notfound"); |
| - scoped_refptr<Predictor> testing_master( |
| - new Predictor(host_resolver_.get(), |
| - default_max_queueing_delay_, |
| - PredictorInit::kMaxSpeculativeParallelResolves, |
| - false)); |
| + scoped_ptr<Predictor> testing_master( |
| + new Predictor()); |
| + testing_master->SetHostResolver(host_resolver_.get()); |
| UrlList names; |
| for (int i = 0; i < 100; i++) |
| @@ -246,7 +238,7 @@ |
| for (int i = 0; i < 10; i++) |
| testing_master->ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); |
| - WaitForResolution(testing_master, names); |
| + WaitForResolution(testing_master.get(), names); |
| MessageLoop::current()->RunAllPending(); |
| @@ -352,11 +344,10 @@ |
| // Make sure nil referral lists really have no entries, and no latency listed. |
| TEST_F(PredictorTest, ReferrerSerializationNilTest) { |
| - scoped_refptr<Predictor> predictor( |
| - new Predictor(host_resolver_.get(), |
| - default_max_queueing_delay_, |
| - PredictorInit::kMaxSpeculativeParallelResolves, |
| - false)); |
| + scoped_ptr<Predictor> predictor( |
| + new Predictor()); |
| + predictor->SetHostResolver(host_resolver_.get()); |
| + |
| scoped_ptr<ListValue> referral_list(NewEmptySerializationList()); |
| predictor->SerializeReferrers(referral_list.get()); |
| EXPECT_EQ(1U, referral_list->GetSize()); |
| @@ -371,11 +362,9 @@ |
| // deserialized into the database, and can be extracted back out via |
| // serialization without being changed. |
| TEST_F(PredictorTest, ReferrerSerializationSingleReferrerTest) { |
| - scoped_refptr<Predictor> predictor( |
| - new Predictor(host_resolver_.get(), |
| - default_max_queueing_delay_, |
| - PredictorInit::kMaxSpeculativeParallelResolves, |
| - false)); |
| + scoped_ptr<Predictor> predictor( |
| + new Predictor()); |
| + predictor->SetHostResolver(host_resolver_.get()); |
| const GURL motivation_url("http://www.google.com:91"); |
| const GURL subresource_url("http://icons.google.com:90"); |
| const double kUseRate = 23.4; |
| @@ -409,11 +398,9 @@ |
| // Make sure the Trim() functionality works as expected. |
| TEST_F(PredictorTest, ReferrerSerializationTrimTest) { |
| - scoped_refptr<Predictor> predictor( |
| - new Predictor(host_resolver_.get(), |
| - default_max_queueing_delay_, |
| - PredictorInit::kMaxSpeculativeParallelResolves, |
| - false)); |
| + scoped_ptr<Predictor> predictor( |
| + new Predictor()); |
| + predictor->SetHostResolver(host_resolver_.get()); |
| GURL motivation_url("http://www.google.com:110"); |
| GURL icon_subresource_url("http://icons.google.com:111"); |
| @@ -601,11 +588,9 @@ |
| } |
| TEST_F(PredictorTest, DiscardPredictorResults) { |
| - scoped_refptr<Predictor> predictor( |
| - new Predictor(host_resolver_.get(), |
| - default_max_queueing_delay_, |
| - PredictorInit::kMaxSpeculativeParallelResolves, |
| - false)); |
| + scoped_ptr<Predictor> predictor( |
| + new Predictor()); |
| + predictor->SetHostResolver(host_resolver_.get()); |
| ListValue referral_list; |
| predictor->SerializeReferrers(&referral_list); |
| EXPECT_EQ(1U, referral_list.GetSize()); |