| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 content::TestBrowserThread ui_thread_; | 121 content::TestBrowserThread ui_thread_; |
| 122 content::TestBrowserThread io_thread_; | 122 content::TestBrowserThread io_thread_; |
| 123 | 123 |
| 124 protected: | 124 protected: |
| 125 scoped_ptr<net::MockCachingHostResolver> host_resolver_; | 125 scoped_ptr<net::MockCachingHostResolver> host_resolver_; |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 //------------------------------------------------------------------------------ | 128 //------------------------------------------------------------------------------ |
| 129 | 129 |
| 130 TEST_F(PredictorTest, StartupShutdownTest) { | 130 TEST_F(PredictorTest, StartupShutdownTest) { |
| 131 Predictor testing_master(true); | 131 Predictor testing_master(true, true); |
| 132 testing_master.Shutdown(); | 132 testing_master.Shutdown(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 | 135 |
| 136 TEST_F(PredictorTest, ShutdownWhenResolutionIsPendingTest) { | 136 TEST_F(PredictorTest, ShutdownWhenResolutionIsPendingTest) { |
| 137 scoped_ptr<net::HostResolver> host_resolver(new net::HangingHostResolver()); | 137 scoped_ptr<net::HostResolver> host_resolver(new net::HangingHostResolver()); |
| 138 | 138 |
| 139 Predictor testing_master(true); | 139 Predictor testing_master(true, true); |
| 140 testing_master.SetHostResolver(host_resolver.get()); | 140 testing_master.SetHostResolver(host_resolver.get()); |
| 141 | 141 |
| 142 GURL localhost("http://localhost:80"); | 142 GURL localhost("http://localhost:80"); |
| 143 UrlList names; | 143 UrlList names; |
| 144 names.push_back(localhost); | 144 names.push_back(localhost); |
| 145 | 145 |
| 146 testing_master.ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); | 146 testing_master.ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); |
| 147 | 147 |
| 148 base::MessageLoop::current()->PostDelayedTask( | 148 base::MessageLoop::current()->PostDelayedTask( |
| 149 FROM_HERE, | 149 FROM_HERE, |
| 150 base::MessageLoop::QuitClosure(), | 150 base::MessageLoop::QuitClosure(), |
| 151 base::TimeDelta::FromMilliseconds(500)); | 151 base::TimeDelta::FromMilliseconds(500)); |
| 152 base::MessageLoop::current()->Run(); | 152 base::MessageLoop::current()->Run(); |
| 153 | 153 |
| 154 EXPECT_FALSE(testing_master.WasFound(localhost)); | 154 EXPECT_FALSE(testing_master.WasFound(localhost)); |
| 155 | 155 |
| 156 testing_master.Shutdown(); | 156 testing_master.Shutdown(); |
| 157 | 157 |
| 158 // Clean up after ourselves. | 158 // Clean up after ourselves. |
| 159 base::MessageLoop::current()->RunUntilIdle(); | 159 base::MessageLoop::current()->RunUntilIdle(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 TEST_F(PredictorTest, SingleLookupTest) { | 162 TEST_F(PredictorTest, SingleLookupTest) { |
| 163 Predictor testing_master(true); | 163 Predictor testing_master(true, true); |
| 164 testing_master.SetHostResolver(host_resolver_.get()); | 164 testing_master.SetHostResolver(host_resolver_.get()); |
| 165 | 165 |
| 166 GURL goog("http://www.google.com:80"); | 166 GURL goog("http://www.google.com:80"); |
| 167 | 167 |
| 168 UrlList names; | 168 UrlList names; |
| 169 names.push_back(goog); | 169 names.push_back(goog); |
| 170 | 170 |
| 171 // Try to flood the predictor with many concurrent requests. | 171 // Try to flood the predictor with many concurrent requests. |
| 172 for (int i = 0; i < 10; i++) | 172 for (int i = 0; i < 10; i++) |
| 173 testing_master.ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); | 173 testing_master.ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); |
| 174 | 174 |
| 175 WaitForResolution(&testing_master, names); | 175 WaitForResolution(&testing_master, names); |
| 176 | 176 |
| 177 EXPECT_TRUE(testing_master.WasFound(goog)); | 177 EXPECT_TRUE(testing_master.WasFound(goog)); |
| 178 | 178 |
| 179 base::MessageLoop::current()->RunUntilIdle(); | 179 base::MessageLoop::current()->RunUntilIdle(); |
| 180 | 180 |
| 181 EXPECT_GT(testing_master.peak_pending_lookups(), names.size() / 2); | 181 EXPECT_GT(testing_master.peak_pending_lookups(), names.size() / 2); |
| 182 EXPECT_LE(testing_master.peak_pending_lookups(), names.size()); | 182 EXPECT_LE(testing_master.peak_pending_lookups(), names.size()); |
| 183 EXPECT_LE(testing_master.peak_pending_lookups(), | 183 EXPECT_LE(testing_master.peak_pending_lookups(), |
| 184 testing_master.max_concurrent_dns_lookups()); | 184 testing_master.max_concurrent_dns_lookups()); |
| 185 | 185 |
| 186 testing_master.Shutdown(); | 186 testing_master.Shutdown(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 TEST_F(PredictorTest, ConcurrentLookupTest) { | 189 TEST_F(PredictorTest, ConcurrentLookupTest) { |
| 190 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); | 190 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); |
| 191 | 191 |
| 192 Predictor testing_master(true); | 192 Predictor testing_master(true, true); |
| 193 testing_master.SetHostResolver(host_resolver_.get()); | 193 testing_master.SetHostResolver(host_resolver_.get()); |
| 194 | 194 |
| 195 GURL goog("http://www.google.com:80"), | 195 GURL goog("http://www.google.com:80"), |
| 196 goog2("http://gmail.google.com.com:80"), | 196 goog2("http://gmail.google.com.com:80"), |
| 197 goog3("http://mail.google.com:80"), | 197 goog3("http://mail.google.com:80"), |
| 198 goog4("http://gmail.com:80"); | 198 goog4("http://gmail.com:80"); |
| 199 GURL bad1("http://bad1.notfound:80"), | 199 GURL bad1("http://bad1.notfound:80"), |
| 200 bad2("http://bad2.notfound:80"); | 200 bad2("http://bad2.notfound:80"); |
| 201 | 201 |
| 202 UrlList names; | 202 UrlList names; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 229 EXPECT_LE(testing_master.peak_pending_lookups(), names.size()); | 229 EXPECT_LE(testing_master.peak_pending_lookups(), names.size()); |
| 230 EXPECT_LE(testing_master.peak_pending_lookups(), | 230 EXPECT_LE(testing_master.peak_pending_lookups(), |
| 231 testing_master.max_concurrent_dns_lookups()); | 231 testing_master.max_concurrent_dns_lookups()); |
| 232 | 232 |
| 233 testing_master.Shutdown(); | 233 testing_master.Shutdown(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 TEST_F(PredictorTest, MassiveConcurrentLookupTest) { | 236 TEST_F(PredictorTest, MassiveConcurrentLookupTest) { |
| 237 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); | 237 host_resolver_->rules()->AddSimulatedFailure("*.notfound"); |
| 238 | 238 |
| 239 Predictor testing_master(true); | 239 Predictor testing_master(true, true); |
| 240 testing_master.SetHostResolver(host_resolver_.get()); | 240 testing_master.SetHostResolver(host_resolver_.get()); |
| 241 | 241 |
| 242 UrlList names; | 242 UrlList names; |
| 243 for (int i = 0; i < 100; i++) | 243 for (int i = 0; i < 100; i++) |
| 244 names.push_back(GURL( | 244 names.push_back(GURL( |
| 245 "http://host" + base::IntToString(i) + ".notfound:80")); | 245 "http://host" + base::IntToString(i) + ".notfound:80")); |
| 246 | 246 |
| 247 // Try to flood the predictor with many concurrent requests. | 247 // Try to flood the predictor with many concurrent requests. |
| 248 for (int i = 0; i < 10; i++) | 248 for (int i = 0; i < 10; i++) |
| 249 testing_master.ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); | 249 testing_master.ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 return true; | 353 return true; |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 return false; | 356 return false; |
| 357 } | 357 } |
| 358 | 358 |
| 359 //------------------------------------------------------------------------------ | 359 //------------------------------------------------------------------------------ |
| 360 | 360 |
| 361 // Make sure nil referral lists really have no entries, and no latency listed. | 361 // Make sure nil referral lists really have no entries, and no latency listed. |
| 362 TEST_F(PredictorTest, ReferrerSerializationNilTest) { | 362 TEST_F(PredictorTest, ReferrerSerializationNilTest) { |
| 363 Predictor predictor(true); | 363 Predictor predictor(true, true); |
| 364 predictor.SetHostResolver(host_resolver_.get()); | 364 predictor.SetHostResolver(host_resolver_.get()); |
| 365 | 365 |
| 366 scoped_ptr<base::ListValue> referral_list(NewEmptySerializationList()); | 366 scoped_ptr<base::ListValue> referral_list(NewEmptySerializationList()); |
| 367 predictor.SerializeReferrers(referral_list.get()); | 367 predictor.SerializeReferrers(referral_list.get()); |
| 368 EXPECT_EQ(1U, referral_list->GetSize()); | 368 EXPECT_EQ(1U, referral_list->GetSize()); |
| 369 EXPECT_FALSE(GetDataFromSerialization( | 369 EXPECT_FALSE(GetDataFromSerialization( |
| 370 GURL("http://a.com:79"), GURL("http://b.com:78"), | 370 GURL("http://a.com:79"), GURL("http://b.com:78"), |
| 371 *referral_list.get(), NULL)); | 371 *referral_list.get(), NULL)); |
| 372 | 372 |
| 373 predictor.Shutdown(); | 373 predictor.Shutdown(); |
| 374 } | 374 } |
| 375 | 375 |
| 376 // Make sure that when a serialization list includes a value, that it can be | 376 // Make sure that when a serialization list includes a value, that it can be |
| 377 // deserialized into the database, and can be extracted back out via | 377 // deserialized into the database, and can be extracted back out via |
| 378 // serialization without being changed. | 378 // serialization without being changed. |
| 379 TEST_F(PredictorTest, ReferrerSerializationSingleReferrerTest) { | 379 TEST_F(PredictorTest, ReferrerSerializationSingleReferrerTest) { |
| 380 Predictor predictor(true); | 380 Predictor predictor(true, true); |
| 381 predictor.SetHostResolver(host_resolver_.get()); | 381 predictor.SetHostResolver(host_resolver_.get()); |
| 382 const GURL motivation_url("http://www.google.com:91"); | 382 const GURL motivation_url("http://www.google.com:91"); |
| 383 const GURL subresource_url("http://icons.google.com:90"); | 383 const GURL subresource_url("http://icons.google.com:90"); |
| 384 const double kUseRate = 23.4; | 384 const double kUseRate = 23.4; |
| 385 scoped_ptr<base::ListValue> referral_list(NewEmptySerializationList()); | 385 scoped_ptr<base::ListValue> referral_list(NewEmptySerializationList()); |
| 386 | 386 |
| 387 AddToSerializedList(motivation_url, subresource_url, | 387 AddToSerializedList(motivation_url, subresource_url, |
| 388 kUseRate, referral_list.get()); | 388 kUseRate, referral_list.get()); |
| 389 | 389 |
| 390 predictor.DeserializeReferrers(*referral_list.get()); | 390 predictor.DeserializeReferrers(*referral_list.get()); |
| 391 | 391 |
| 392 base::ListValue recovered_referral_list; | 392 base::ListValue recovered_referral_list; |
| 393 predictor.SerializeReferrers(&recovered_referral_list); | 393 predictor.SerializeReferrers(&recovered_referral_list); |
| 394 EXPECT_EQ(2U, recovered_referral_list.GetSize()); | 394 EXPECT_EQ(2U, recovered_referral_list.GetSize()); |
| 395 double rate; | 395 double rate; |
| 396 EXPECT_TRUE(GetDataFromSerialization( | 396 EXPECT_TRUE(GetDataFromSerialization( |
| 397 motivation_url, subresource_url, recovered_referral_list, &rate)); | 397 motivation_url, subresource_url, recovered_referral_list, &rate)); |
| 398 EXPECT_EQ(rate, kUseRate); | 398 EXPECT_EQ(rate, kUseRate); |
| 399 | 399 |
| 400 predictor.Shutdown(); | 400 predictor.Shutdown(); |
| 401 } | 401 } |
| 402 | 402 |
| 403 // Check that GetHtmlReferrerLists() doesn't crash when given duplicated | 403 // Check that GetHtmlReferrerLists() doesn't crash when given duplicated |
| 404 // domains for referring URL, and that it sorts the results in the | 404 // domains for referring URL, and that it sorts the results in the |
| 405 // correct order. | 405 // correct order. |
| 406 TEST_F(PredictorTest, GetHtmlReferrerLists) { | 406 TEST_F(PredictorTest, GetHtmlReferrerLists) { |
| 407 Predictor predictor(true); | 407 Predictor predictor(true, true); |
| 408 predictor.SetHostResolver(host_resolver_.get()); | 408 predictor.SetHostResolver(host_resolver_.get()); |
| 409 const double kUseRate = 23.4; | 409 const double kUseRate = 23.4; |
| 410 scoped_ptr<base::ListValue> referral_list(NewEmptySerializationList()); | 410 scoped_ptr<base::ListValue> referral_list(NewEmptySerializationList()); |
| 411 | 411 |
| 412 AddToSerializedList( | 412 AddToSerializedList( |
| 413 GURL("http://d.google.com/x1"), | 413 GURL("http://d.google.com/x1"), |
| 414 GURL("http://foo.com/"), | 414 GURL("http://foo.com/"), |
| 415 kUseRate, referral_list.get()); | 415 kUseRate, referral_list.get()); |
| 416 | 416 |
| 417 // Duplicated hostname (d.google.com). This should not cause any crashes | 417 // Duplicated hostname (d.google.com). This should not cause any crashes |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 double espilon_ratio = 1.01; \ | 482 double espilon_ratio = 1.01; \ |
| 483 if ((a) < 0.) \ | 483 if ((a) < 0.) \ |
| 484 espilon_ratio = 1 / espilon_ratio; \ | 484 espilon_ratio = 1 / espilon_ratio; \ |
| 485 EXPECT_LT(a, espilon_ratio * (b)); \ | 485 EXPECT_LT(a, espilon_ratio * (b)); \ |
| 486 EXPECT_GT((a) * espilon_ratio, b); \ | 486 EXPECT_GT((a) * espilon_ratio, b); \ |
| 487 } while (0) | 487 } while (0) |
| 488 | 488 |
| 489 | 489 |
| 490 // Make sure the Trim() functionality works as expected. | 490 // Make sure the Trim() functionality works as expected. |
| 491 TEST_F(PredictorTest, ReferrerSerializationTrimTest) { | 491 TEST_F(PredictorTest, ReferrerSerializationTrimTest) { |
| 492 Predictor predictor(true); | 492 Predictor predictor(true, true); |
| 493 predictor.SetHostResolver(host_resolver_.get()); | 493 predictor.SetHostResolver(host_resolver_.get()); |
| 494 GURL motivation_url("http://www.google.com:110"); | 494 GURL motivation_url("http://www.google.com:110"); |
| 495 | 495 |
| 496 GURL icon_subresource_url("http://icons.google.com:111"); | 496 GURL icon_subresource_url("http://icons.google.com:111"); |
| 497 const double kRateIcon = 16.0 * Predictor::kDiscardableExpectedValue; | 497 const double kRateIcon = 16.0 * Predictor::kDiscardableExpectedValue; |
| 498 GURL img_subresource_url("http://img.google.com:118"); | 498 GURL img_subresource_url("http://img.google.com:118"); |
| 499 const double kRateImg = 8.0 * Predictor::kDiscardableExpectedValue; | 499 const double kRateImg = 8.0 * Predictor::kDiscardableExpectedValue; |
| 500 | 500 |
| 501 scoped_ptr<base::ListValue> referral_list(NewEmptySerializationList()); | 501 scoped_ptr<base::ListValue> referral_list(NewEmptySerializationList()); |
| 502 AddToSerializedList( | 502 AddToSerializedList( |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 EXPECT_NE(Predictor::CanonicalizeUrl(http), | 671 EXPECT_NE(Predictor::CanonicalizeUrl(http), |
| 672 Predictor::CanonicalizeUrl(https)); | 672 Predictor::CanonicalizeUrl(https)); |
| 673 | 673 |
| 674 // Https works fine. | 674 // Https works fine. |
| 675 GURL long_https("https://host:999/path?query=value"); | 675 GURL long_https("https://host:999/path?query=value"); |
| 676 EXPECT_EQ(Predictor::CanonicalizeUrl(long_https), | 676 EXPECT_EQ(Predictor::CanonicalizeUrl(long_https), |
| 677 long_https.GetWithEmptyPath()); | 677 long_https.GetWithEmptyPath()); |
| 678 } | 678 } |
| 679 | 679 |
| 680 TEST_F(PredictorTest, DiscardPredictorResults) { | 680 TEST_F(PredictorTest, DiscardPredictorResults) { |
| 681 Predictor predictor(true); | 681 Predictor predictor(true, true); |
| 682 predictor.SetHostResolver(host_resolver_.get()); | 682 predictor.SetHostResolver(host_resolver_.get()); |
| 683 base::ListValue referral_list; | 683 base::ListValue referral_list; |
| 684 predictor.SerializeReferrers(&referral_list); | 684 predictor.SerializeReferrers(&referral_list); |
| 685 EXPECT_EQ(1U, referral_list.GetSize()); | 685 EXPECT_EQ(1U, referral_list.GetSize()); |
| 686 | 686 |
| 687 GURL host_1("http://test_1"); | 687 GURL host_1("http://test_1"); |
| 688 GURL host_2("http://test_2"); | 688 GURL host_2("http://test_2"); |
| 689 predictor.LearnFromNavigation(host_1, host_2); | 689 predictor.LearnFromNavigation(host_1, host_2); |
| 690 | 690 |
| 691 predictor.SerializeReferrers(&referral_list); | 691 predictor.SerializeReferrers(&referral_list); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 714 // Tests that preconnects apply the HSTS list. | 714 // Tests that preconnects apply the HSTS list. |
| 715 TEST_F(PredictorTest, HSTSRedirect) { | 715 TEST_F(PredictorTest, HSTSRedirect) { |
| 716 const GURL kHttpUrl("http://example.com"); | 716 const GURL kHttpUrl("http://example.com"); |
| 717 const GURL kHttpsUrl("https://example.com"); | 717 const GURL kHttpsUrl("https://example.com"); |
| 718 | 718 |
| 719 const base::Time expiry = | 719 const base::Time expiry = |
| 720 base::Time::Now() + base::TimeDelta::FromSeconds(1000); | 720 base::Time::Now() + base::TimeDelta::FromSeconds(1000); |
| 721 net::TransportSecurityState state; | 721 net::TransportSecurityState state; |
| 722 state.AddHSTS(kHttpUrl.host(), expiry, false); | 722 state.AddHSTS(kHttpUrl.host(), expiry, false); |
| 723 | 723 |
| 724 Predictor predictor(true); | 724 Predictor predictor(true, true); |
| 725 TestPredictorObserver observer; | 725 TestPredictorObserver observer; |
| 726 predictor.SetObserver(&observer); | 726 predictor.SetObserver(&observer); |
| 727 predictor.SetTransportSecurityState(&state); | 727 predictor.SetTransportSecurityState(&state); |
| 728 | 728 |
| 729 predictor.PreconnectUrl(kHttpUrl, GURL(), UrlInfo::OMNIBOX_MOTIVATED, 2); | 729 predictor.PreconnectUrl(kHttpUrl, GURL(), UrlInfo::OMNIBOX_MOTIVATED, 2); |
| 730 ASSERT_EQ(1u, observer.preconnected_urls_.size()); | 730 ASSERT_EQ(1u, observer.preconnected_urls_.size()); |
| 731 EXPECT_EQ(kHttpsUrl, observer.preconnected_urls_[0]); | 731 EXPECT_EQ(kHttpsUrl, observer.preconnected_urls_[0]); |
| 732 | 732 |
| 733 predictor.Shutdown(); | 733 predictor.Shutdown(); |
| 734 } | 734 } |
| 735 | 735 |
| 736 // Tests that preconnecting a URL on the HSTS list preconnects the subresources | 736 // Tests that preconnecting a URL on the HSTS list preconnects the subresources |
| 737 // for the SSL version. | 737 // for the SSL version. |
| 738 TEST_F(PredictorTest, HSTSRedirectSubresources) { | 738 TEST_F(PredictorTest, HSTSRedirectSubresources) { |
| 739 const GURL kHttpUrl("http://example.com"); | 739 const GURL kHttpUrl("http://example.com"); |
| 740 const GURL kHttpsUrl("https://example.com"); | 740 const GURL kHttpsUrl("https://example.com"); |
| 741 const GURL kSubresourceUrl("https://images.example.com"); | 741 const GURL kSubresourceUrl("https://images.example.com"); |
| 742 const double kUseRate = 23.4; | 742 const double kUseRate = 23.4; |
| 743 | 743 |
| 744 const base::Time expiry = | 744 const base::Time expiry = |
| 745 base::Time::Now() + base::TimeDelta::FromSeconds(1000); | 745 base::Time::Now() + base::TimeDelta::FromSeconds(1000); |
| 746 net::TransportSecurityState state; | 746 net::TransportSecurityState state; |
| 747 state.AddHSTS(kHttpUrl.host(), expiry, false); | 747 state.AddHSTS(kHttpUrl.host(), expiry, false); |
| 748 | 748 |
| 749 Predictor predictor(true); | 749 Predictor predictor(true, true); |
| 750 TestPredictorObserver observer; | 750 TestPredictorObserver observer; |
| 751 predictor.SetObserver(&observer); | 751 predictor.SetObserver(&observer); |
| 752 predictor.SetTransportSecurityState(&state); | 752 predictor.SetTransportSecurityState(&state); |
| 753 | 753 |
| 754 scoped_ptr<base::ListValue> referral_list(NewEmptySerializationList()); | 754 scoped_ptr<base::ListValue> referral_list(NewEmptySerializationList()); |
| 755 AddToSerializedList( | 755 AddToSerializedList( |
| 756 kHttpsUrl, kSubresourceUrl, kUseRate, referral_list.get()); | 756 kHttpsUrl, kSubresourceUrl, kUseRate, referral_list.get()); |
| 757 predictor.DeserializeReferrers(*referral_list.get()); | 757 predictor.DeserializeReferrers(*referral_list.get()); |
| 758 | 758 |
| 759 predictor.PreconnectUrlAndSubresources(kHttpUrl, GURL()); | 759 predictor.PreconnectUrlAndSubresources(kHttpUrl, GURL()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 788 ++would_proxy_count_; | 788 ++would_proxy_count_; |
| 789 return would_proxy_; | 789 return would_proxy_; |
| 790 } | 790 } |
| 791 | 791 |
| 792 bool would_proxy_; | 792 bool would_proxy_; |
| 793 int advise_count_; | 793 int advise_count_; |
| 794 int would_proxy_count_; | 794 int would_proxy_count_; |
| 795 }; | 795 }; |
| 796 | 796 |
| 797 TEST_F(PredictorTest, SingleLookupTestWithDisabledAdvisor) { | 797 TEST_F(PredictorTest, SingleLookupTestWithDisabledAdvisor) { |
| 798 Predictor testing_master(true); | 798 Predictor testing_master(true, true); |
| 799 TestProxyAdvisor* advisor = new TestProxyAdvisor(); | 799 TestProxyAdvisor* advisor = new TestProxyAdvisor(); |
| 800 testing_master.SetHostResolver(host_resolver_.get()); | 800 testing_master.SetHostResolver(host_resolver_.get()); |
| 801 testing_master.proxy_advisor_.reset(advisor); | 801 testing_master.proxy_advisor_.reset(advisor); |
| 802 | 802 |
| 803 GURL goog("http://www.google.com:80"); | 803 GURL goog("http://www.google.com:80"); |
| 804 | 804 |
| 805 advisor->would_proxy_ = false; | 805 advisor->would_proxy_ = false; |
| 806 | 806 |
| 807 UrlList names; | 807 UrlList names; |
| 808 names.push_back(goog); | 808 names.push_back(goog); |
| 809 testing_master.ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); | 809 testing_master.ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); |
| 810 | 810 |
| 811 WaitForResolution(&testing_master, names); | 811 WaitForResolution(&testing_master, names); |
| 812 EXPECT_TRUE(testing_master.WasFound(goog)); | 812 EXPECT_TRUE(testing_master.WasFound(goog)); |
| 813 EXPECT_EQ(advisor->would_proxy_count_, 1); | 813 EXPECT_EQ(advisor->would_proxy_count_, 1); |
| 814 EXPECT_EQ(advisor->advise_count_, 1); | 814 EXPECT_EQ(advisor->advise_count_, 1); |
| 815 | 815 |
| 816 base::MessageLoop::current()->RunUntilIdle(); | 816 base::MessageLoop::current()->RunUntilIdle(); |
| 817 | 817 |
| 818 testing_master.Shutdown(); | 818 testing_master.Shutdown(); |
| 819 } | 819 } |
| 820 | 820 |
| 821 TEST_F(PredictorTest, SingleLookupTestWithEnabledAdvisor) { | 821 TEST_F(PredictorTest, SingleLookupTestWithEnabledAdvisor) { |
| 822 Predictor testing_master(true); | 822 Predictor testing_master(true, true); |
| 823 testing_master.SetHostResolver(host_resolver_.get()); | 823 testing_master.SetHostResolver(host_resolver_.get()); |
| 824 TestProxyAdvisor* advisor = new TestProxyAdvisor(); | 824 TestProxyAdvisor* advisor = new TestProxyAdvisor(); |
| 825 testing_master.proxy_advisor_.reset(advisor); | 825 testing_master.proxy_advisor_.reset(advisor); |
| 826 | 826 |
| 827 GURL goog("http://www.google.com:80"); | 827 GURL goog("http://www.google.com:80"); |
| 828 | 828 |
| 829 advisor->would_proxy_ = true; | 829 advisor->would_proxy_ = true; |
| 830 | 830 |
| 831 UrlList names; | 831 UrlList names; |
| 832 names.push_back(goog); | 832 names.push_back(goog); |
| 833 | 833 |
| 834 testing_master.ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); | 834 testing_master.ResolveList(names, UrlInfo::PAGE_SCAN_MOTIVATED); |
| 835 | 835 |
| 836 // Attempt to resolve a few times. | 836 // Attempt to resolve a few times. |
| 837 WaitForResolutionWithLimit(&testing_master, names, 10); | 837 WaitForResolutionWithLimit(&testing_master, names, 10); |
| 838 | 838 |
| 839 // Because the advisor indicated that the url would be proxied, | 839 // Because the advisor indicated that the url would be proxied, |
| 840 // no resolution should have occurred. | 840 // no resolution should have occurred. |
| 841 EXPECT_FALSE(testing_master.WasFound(goog)); | 841 EXPECT_FALSE(testing_master.WasFound(goog)); |
| 842 EXPECT_EQ(advisor->would_proxy_count_, 1); | 842 EXPECT_EQ(advisor->would_proxy_count_, 1); |
| 843 EXPECT_EQ(advisor->advise_count_, 1); | 843 EXPECT_EQ(advisor->advise_count_, 1); |
| 844 | 844 |
| 845 base::MessageLoop::current()->RunUntilIdle(); | 845 base::MessageLoop::current()->RunUntilIdle(); |
| 846 | 846 |
| 847 testing_master.Shutdown(); | 847 testing_master.Shutdown(); |
| 848 } | 848 } |
| 849 | 849 |
| 850 TEST_F(PredictorTest, TestSimplePreconnectAdvisor) { | 850 TEST_F(PredictorTest, TestSimplePreconnectAdvisor) { |
| 851 Predictor testing_master(true); | 851 Predictor testing_master(true, true); |
| 852 testing_master.SetHostResolver(host_resolver_.get()); | 852 testing_master.SetHostResolver(host_resolver_.get()); |
| 853 TestProxyAdvisor* advisor = new TestProxyAdvisor(); | 853 TestProxyAdvisor* advisor = new TestProxyAdvisor(); |
| 854 testing_master.proxy_advisor_.reset(advisor); | 854 testing_master.proxy_advisor_.reset(advisor); |
| 855 | 855 |
| 856 GURL goog("http://www.google.com:80"); | 856 GURL goog("http://www.google.com:80"); |
| 857 | 857 |
| 858 testing_master.PreconnectUrl(goog, goog, UrlInfo::OMNIBOX_MOTIVATED, 2); | 858 testing_master.PreconnectUrl(goog, goog, UrlInfo::OMNIBOX_MOTIVATED, 2); |
| 859 | 859 |
| 860 EXPECT_EQ(advisor->would_proxy_count_, 0); | 860 EXPECT_EQ(advisor->would_proxy_count_, 0); |
| 861 EXPECT_EQ(advisor->advise_count_, 1); | 861 EXPECT_EQ(advisor->advise_count_, 1); |
| 862 | 862 |
| 863 testing_master.Shutdown(); | 863 testing_master.Shutdown(); |
| 864 } | 864 } |
| 865 | 865 |
| 866 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 866 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
| 867 | 867 |
| 868 } // namespace chrome_browser_net | 868 } // namespace chrome_browser_net |
| OLD | NEW |