| 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 "chrome/browser/net/predictor.h" | 5 #include "chrome/browser/net/predictor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 predictor.DeserializeReferrers(*referral_list.get()); | 544 predictor.DeserializeReferrers(*referral_list.get()); |
| 545 | 545 |
| 546 predictor.PreconnectUrlAndSubresources(kHttpUrl, GURL()); | 546 predictor.PreconnectUrlAndSubresources(kHttpUrl, GURL()); |
| 547 ASSERT_EQ(2u, observer.preconnected_urls_.size()); | 547 ASSERT_EQ(2u, observer.preconnected_urls_.size()); |
| 548 EXPECT_EQ(kHttpsUrl, observer.preconnected_urls_[0]); | 548 EXPECT_EQ(kHttpsUrl, observer.preconnected_urls_[0]); |
| 549 EXPECT_EQ(kSubresourceUrl, observer.preconnected_urls_[1]); | 549 EXPECT_EQ(kSubresourceUrl, observer.preconnected_urls_[1]); |
| 550 | 550 |
| 551 predictor.Shutdown(); | 551 predictor.Shutdown(); |
| 552 } | 552 } |
| 553 | 553 |
| 554 TEST_F(PredictorTest, HSTSRedirectLearnedSubresource) { |
| 555 const GURL kHttpUrl("http://example.com"); |
| 556 const GURL kHttpsUrl("https://example.com"); |
| 557 const GURL kSubresourceUrl("https://images.example.com"); |
| 558 |
| 559 const base::Time expiry = |
| 560 base::Time::Now() + base::TimeDelta::FromSeconds(1000); |
| 561 net::TransportSecurityState state; |
| 562 state.AddHSTS(kHttpUrl.host(), expiry, false); |
| 563 |
| 564 SimplePredictor predictor(true, true); |
| 565 TestPredictorObserver observer; |
| 566 predictor.SetObserver(&observer); |
| 567 predictor.SetTransportSecurityState(&state); |
| 568 |
| 569 // Note that the predictor would also learn the HSTS redirect from kHttpUrl to |
| 570 // kHttpsUrl during the navigation. |
| 571 predictor.LearnFromNavigation(kHttpUrl, kSubresourceUrl); |
| 572 |
| 573 predictor.PreconnectUrlAndSubresources(kHttpUrl, GURL()); |
| 574 ASSERT_EQ(2u, observer.preconnected_urls_.size()); |
| 575 EXPECT_EQ(kHttpsUrl, observer.preconnected_urls_[0]); |
| 576 EXPECT_EQ(kSubresourceUrl, observer.preconnected_urls_[1]); |
| 577 |
| 578 predictor.Shutdown(); |
| 579 } |
| 580 |
| 554 TEST_F(PredictorTest, NoProxyService) { | 581 TEST_F(PredictorTest, NoProxyService) { |
| 555 // Don't actually try to resolve names. | 582 // Don't actually try to resolve names. |
| 556 Predictor::set_max_parallel_resolves(0); | 583 Predictor::set_max_parallel_resolves(0); |
| 557 | 584 |
| 558 Predictor testing_master(true, true); | 585 Predictor testing_master(true, true); |
| 559 | 586 |
| 560 GURL goog("http://www.google.com:80"); | 587 GURL goog("http://www.google.com:80"); |
| 561 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED); | 588 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED); |
| 562 EXPECT_FALSE(testing_master.work_queue_.IsEmpty()); | 589 EXPECT_FALSE(testing_master.work_queue_.IsEmpty()); |
| 563 | 590 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED); | 646 testing_master.Resolve(goog, UrlInfo::OMNIBOX_MOTIVATED); |
| 620 | 647 |
| 621 // Proxy may not be in use (the PAC script has not yet been evaluated), so the | 648 // Proxy may not be in use (the PAC script has not yet been evaluated), so the |
| 622 // name has been registered for pre-resolve. | 649 // name has been registered for pre-resolve. |
| 623 EXPECT_FALSE(testing_master.work_queue_.IsEmpty()); | 650 EXPECT_FALSE(testing_master.work_queue_.IsEmpty()); |
| 624 | 651 |
| 625 testing_master.Shutdown(); | 652 testing_master.Shutdown(); |
| 626 } | 653 } |
| 627 | 654 |
| 628 } // namespace chrome_browser_net | 655 } // namespace chrome_browser_net |
| OLD | NEW |