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

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

Issue 2038463004: Remove references to network_hints::UrlList and network_hints::NameList (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « chrome/browser/net/predictor.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 } 617 }
618 618
619 void GetListFromPrefsAsString(const char* list_path, 619 void GetListFromPrefsAsString(const char* list_path,
620 std::string* value_as_string) const { 620 std::string* value_as_string) const {
621 PrefService* prefs = browser()->profile()->GetPrefs(); 621 PrefService* prefs = browser()->profile()->GetPrefs();
622 const base::ListValue* list_value = prefs->GetList(list_path); 622 const base::ListValue* list_value = prefs->GetList(list_path);
623 JSONStringValueSerializer serializer(value_as_string); 623 JSONStringValueSerializer serializer(value_as_string);
624 serializer.Serialize(*list_value); 624 serializer.Serialize(*list_value);
625 } 625 }
626 626
627 void WaitUntilHostsLookedUp(const network_hints::UrlList& names) { 627 void WaitUntilHostsLookedUp(const std::vector<GURL>& names) {
628 for (const GURL& url : names) 628 for (const GURL& url : names)
629 observer()->WaitUntilHostLookedUp(url); 629 observer()->WaitUntilHostLookedUp(url);
630 } 630 }
631 631
632 void FloodResolveRequestsOnUIThread(const network_hints::UrlList& names) { 632 void FloodResolveRequestsOnUIThread(const std::vector<GURL>& names) {
633 DCHECK_CURRENTLY_ON(BrowserThread::UI); 633 DCHECK_CURRENTLY_ON(BrowserThread::UI);
634 BrowserThread::PostTask( 634 BrowserThread::PostTask(
635 BrowserThread::IO, FROM_HERE, 635 BrowserThread::IO, FROM_HERE,
636 base::Bind(&PredictorBrowserTest::FloodResolveRequests, this, names)); 636 base::Bind(&PredictorBrowserTest::FloodResolveRequests, this, names));
637 } 637 }
638 638
639 void FloodResolveRequests(const network_hints::UrlList& names) { 639 void FloodResolveRequests(const std::vector<GURL>& names) {
640 DCHECK_CURRENTLY_ON(BrowserThread::IO); 640 DCHECK_CURRENTLY_ON(BrowserThread::IO);
641 for (int i = 0; i < 10; i++) { 641 for (int i = 0; i < 10; i++) {
642 predictor()->DnsPrefetchMotivatedList(names, 642 predictor()->DnsPrefetchMotivatedList(names,
643 UrlInfo::PAGE_SCAN_MOTIVATED); 643 UrlInfo::PAGE_SCAN_MOTIVATED);
644 } 644 }
645 } 645 }
646 646
647 net::EmbeddedTestServer* cross_site_test_server() { 647 net::EmbeddedTestServer* cross_site_test_server() {
648 return cross_site_test_server_.get(); 648 return cross_site_test_server_.get();
649 } 649 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 run_loop.Run(); 693 run_loop.Run();
694 } 694 }
695 695
696 void FlushServerSocketsOnUIThread(net::EmbeddedTestServer* test_server) { 696 void FlushServerSocketsOnUIThread(net::EmbeddedTestServer* test_server) {
697 DCHECK_CURRENTLY_ON(BrowserThread::UI); 697 DCHECK_CURRENTLY_ON(BrowserThread::UI);
698 EXPECT_TRUE(test_server->FlushAllSocketsAndConnectionsOnUIThread()); 698 EXPECT_TRUE(test_server->FlushAllSocketsAndConnectionsOnUIThread());
699 } 699 }
700 700
701 // Note this method also expects that all the urls (found or not) were looked 701 // Note this method also expects that all the urls (found or not) were looked
702 // up. 702 // up.
703 void ExpectFoundUrls( 703 void ExpectFoundUrls(const std::vector<GURL>& found_names,
704 const network_hints::UrlList& found_names, 704 const std::vector<GURL>& not_found_names) {
705 const network_hints::UrlList& not_found_names) {
706 for (const auto& name : found_names) { 705 for (const auto& name : found_names) {
707 EXPECT_TRUE(observer()->HostFound(name)) << "Expected to have found " 706 EXPECT_TRUE(observer()->HostFound(name)) << "Expected to have found "
708 << name.spec(); 707 << name.spec();
709 } 708 }
710 for (const auto& name : not_found_names) { 709 for (const auto& name : not_found_names) {
711 EXPECT_FALSE(observer()->HostFound(name)) << "Did not expect to find " 710 EXPECT_FALSE(observer()->HostFound(name)) << "Did not expect to find "
712 << name.spec(); 711 << name.spec();
713 } 712 }
714 } 713 }
715 714
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 std::unique_ptr<net::EmbeddedTestServer> cross_site_test_server_; 783 std::unique_ptr<net::EmbeddedTestServer> cross_site_test_server_;
785 std::unique_ptr<CrossSitePredictorObserver> observer_; 784 std::unique_ptr<CrossSitePredictorObserver> observer_;
786 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 785 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
787 }; 786 };
788 787
789 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, SingleLookupTest) { 788 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, SingleLookupTest) {
790 DiscardAllResultsOnUIThread(); 789 DiscardAllResultsOnUIThread();
791 GURL url("http://www.example.test/"); 790 GURL url("http://www.example.test/");
792 791
793 // Try to flood the predictor with many concurrent requests. 792 // Try to flood the predictor with many concurrent requests.
794 network_hints::UrlList names{url}; 793 std::vector<GURL> names{url};
795 FloodResolveRequestsOnUIThread(names); 794 FloodResolveRequestsOnUIThread(names);
796 observer()->WaitUntilHostLookedUp(url); 795 observer()->WaitUntilHostLookedUp(url);
797 EXPECT_TRUE(observer()->HostFound(url)); 796 EXPECT_TRUE(observer()->HostFound(url));
798 ExpectValidPeakPendingLookupsOnUI(1u); 797 ExpectValidPeakPendingLookupsOnUI(1u);
799 } 798 }
800 799
801 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, ConcurrentLookupTest) { 800 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, ConcurrentLookupTest) {
802 DiscardAllResultsOnUIThread(); 801 DiscardAllResultsOnUIThread();
803 GURL url("http://www.example.test"), goog2("http://gmail.google.com"), 802 GURL url("http://www.example.test"), goog2("http://gmail.google.com"),
804 goog3("http://mail.google.com"), goog4("http://gmail.com"); 803 goog3("http://mail.google.com"), goog4("http://gmail.com");
805 GURL bad1("http://bad1.notfound"), bad2("http://bad2.notfound"); 804 GURL bad1("http://bad1.notfound"), bad2("http://bad2.notfound");
806 805
807 UrlList found_names{url, goog3, goog2, goog4}; 806 std::vector<GURL> found_names{url, goog3, goog2, goog4};
808 UrlList not_found_names{bad1, bad2}; 807 std::vector<GURL> not_found_names{bad1, bad2};
809 FloodResolveRequestsOnUIThread(found_names); 808 FloodResolveRequestsOnUIThread(found_names);
810 FloodResolveRequestsOnUIThread(not_found_names); 809 FloodResolveRequestsOnUIThread(not_found_names);
811 810
812 WaitUntilHostsLookedUp(found_names); 811 WaitUntilHostsLookedUp(found_names);
813 WaitUntilHostsLookedUp(not_found_names); 812 WaitUntilHostsLookedUp(not_found_names);
814 ExpectFoundUrls(found_names, not_found_names); 813 ExpectFoundUrls(found_names, not_found_names);
815 ExpectValidPeakPendingLookupsOnUI(found_names.size() + 814 ExpectValidPeakPendingLookupsOnUI(found_names.size() +
816 not_found_names.size()); 815 not_found_names.size());
817 } 816 }
818 817
819 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, MassiveConcurrentLookupTest) { 818 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, MassiveConcurrentLookupTest) {
820 DiscardAllResultsOnUIThread(); 819 DiscardAllResultsOnUIThread();
821 UrlList not_found_names; 820 std::vector<GURL> not_found_names;
822 for (int i = 0; i < 100; i++) { 821 for (int i = 0; i < 100; i++) {
823 not_found_names.push_back( 822 not_found_names.push_back(
824 GURL(base::StringPrintf("http://host%d.notfound:80", i))); 823 GURL(base::StringPrintf("http://host%d.notfound:80", i)));
825 } 824 }
826 FloodResolveRequestsOnUIThread(not_found_names); 825 FloodResolveRequestsOnUIThread(not_found_names);
827 826
828 WaitUntilHostsLookedUp(not_found_names); 827 WaitUntilHostsLookedUp(not_found_names);
829 ExpectFoundUrls(network_hints::UrlList(), not_found_names); 828 ExpectFoundUrls(std::vector<GURL>(), not_found_names);
830 ExpectValidPeakPendingLookupsOnUI(not_found_names.size()); 829 ExpectValidPeakPendingLookupsOnUI(not_found_names.size());
831 } 830 }
832 831
833 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, 832 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest,
834 ShutdownWhenResolutionIsPendingTest) { 833 ShutdownWhenResolutionIsPendingTest) {
835 GURL delayed_url("http://delay.google.com:80"); 834 GURL delayed_url("http://delay.google.com:80");
836 UrlList names{delayed_url}; 835 std::vector<GURL> names{delayed_url};
837 836
838 // Flood with delayed requests, then wait. 837 // Flood with delayed requests, then wait.
839 FloodResolveRequestsOnUIThread(names); 838 FloodResolveRequestsOnUIThread(names);
840 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 839 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
841 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 840 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
842 base::TimeDelta::FromMilliseconds(500)); 841 base::TimeDelta::FromMilliseconds(500));
843 base::MessageLoop::current()->Run(); 842 base::MessageLoop::current()->Run();
844 843
845 ExpectUrlRequestedFromPredictor(delayed_url); 844 ExpectUrlRequestedFromPredictor(delayed_url);
846 EXPECT_FALSE(observer()->HasHostBeenLookedUp(delayed_url)); 845 EXPECT_FALSE(observer()->HasHostBeenLookedUp(delayed_url));
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 // Second navigation to content with an img. 1502 // Second navigation to content with an img.
1504 std::string img_content = 1503 std::string img_content =
1505 "<img src=\"" + preconnect_url.spec() + "test.gif\">"; 1504 "<img src=\"" + preconnect_url.spec() + "test.gif\">";
1506 NavigateToDataURLWithContent(img_content); 1505 NavigateToDataURLWithContent(img_content);
1507 connection_listener_->WaitUntilFirstConnectionRead(); 1506 connection_listener_->WaitUntilFirstConnectionRead();
1508 EXPECT_EQ(2u, connection_listener_->GetAcceptedSocketCount()); 1507 EXPECT_EQ(2u, connection_listener_->GetAcceptedSocketCount());
1509 EXPECT_EQ(1u, connection_listener_->GetReadSocketCount()); 1508 EXPECT_EQ(1u, connection_listener_->GetReadSocketCount());
1510 } 1509 }
1511 1510
1512 } // namespace chrome_browser_net 1511 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/predictor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698