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

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

Issue 1989363007: Move predictor dns unit tests to browser tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Hopefully fixed 469120 Created 4 years, 7 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
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 10
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 size_t num_accepted_connections_needed_; 242 size_t num_accepted_connections_needed_;
243 base::RunLoop* num_accepted_connections_loop_; 243 base::RunLoop* num_accepted_connections_loop_;
244 244
245 DISALLOW_COPY_AND_ASSIGN(ConnectionListener); 245 DISALLOW_COPY_AND_ASSIGN(ConnectionListener);
246 }; 246 };
247 247
248 // Records a history of all hostnames for which resolving has been requested, 248 // Records a history of all hostnames for which resolving has been requested,
249 // and immediately fails the resolution requests themselves. 249 // and immediately fails the resolution requests themselves.
250 class HostResolutionRequestRecorder : public net::HostResolverProc { 250 class HostResolutionRequestRecorder : public net::HostResolverProc {
251 public: 251 public:
252 HostResolutionRequestRecorder() 252 explicit HostResolutionRequestRecorder(net::HostResolverProc* previous)
253 : HostResolverProc(NULL), 253 : HostResolverProc(previous), run_loop_(nullptr) {}
254 is_waiting_for_hostname_(false) {
255 }
256 254
257 int Resolve(const std::string& host, 255 int Resolve(const std::string& host,
258 net::AddressFamily address_family, 256 net::AddressFamily address_family,
259 net::HostResolverFlags host_resolver_flags, 257 net::HostResolverFlags host_resolver_flags,
260 net::AddressList* addrlist, 258 net::AddressList* addrlist,
261 int* os_error) override { 259 int* os_error) override {
260 // Note the rule based proc sleep synchronously.
Randy Smith (Not in Mondays) 2016/05/23 19:55:18 Sorry, I'm getting past the lexing phase, but fail
Charlie Harrison 2016/05/24 16:57:06 Hahaha yeah that's extremely confusing. I meant th
261 int result = ResolveUsingPrevious(host, address_family, host_resolver_flags,
262 addrlist, os_error);
262 BrowserThread::PostTask( 263 BrowserThread::PostTask(
263 BrowserThread::UI, 264 BrowserThread::IO, FROM_HERE,
264 FROM_HERE,
265 base::Bind(&HostResolutionRequestRecorder::AddToHistory, 265 base::Bind(&HostResolutionRequestRecorder::AddToHistory,
266 base::Unretained(this), 266 base::Unretained(this), host));
267 host)); 267 return result;
268 return net::ERR_NAME_NOT_RESOLVED;
269 } 268 }
270 269
271 int RequestedHostnameCount() const { 270 int RequestedHostnameCount() const {
271 base::AutoLock lock(lock_);
272 return requested_hostnames_.size(); 272 return requested_hostnames_.size();
273 } 273 }
274 274
275 bool HasHostBeenRequested(const std::string& hostname) const { 275 bool HasHostBeenRequested(const std::string& hostname) const {
276 base::AutoLock lock(lock_);
277 return HasHostBeenRequestedLocked(hostname);
278 }
279
280 bool HasHostBeenRequestedLocked(const std::string& hostname) const {
281 lock_.AssertAcquired();
276 DCHECK_CURRENTLY_ON(BrowserThread::UI); 282 DCHECK_CURRENTLY_ON(BrowserThread::UI);
277 return std::find(requested_hostnames_.begin(), 283 return std::find(requested_hostnames_.begin(),
278 requested_hostnames_.end(), 284 requested_hostnames_.end(),
279 hostname) != requested_hostnames_.end(); 285 hostname) != requested_hostnames_.end();
280 } 286 }
281 287
288 void WaitUntilHostNamesHaveBeenRequested(
289 const network_hints::UrlList& names) {
290 for (const auto& name : names) {
291 WaitUntilHostHasBeenRequested(name.host());
292 }
293 }
294
282 void WaitUntilHostHasBeenRequested(const std::string& hostname) { 295 void WaitUntilHostHasBeenRequested(const std::string& hostname) {
283 DCHECK_CURRENTLY_ON(BrowserThread::UI); 296 DCHECK_CURRENTLY_ON(BrowserThread::UI);
284 DCHECK(!is_waiting_for_hostname_); 297 base::RunLoop run_loop;
285 if (HasHostBeenRequested(hostname)) 298 {
286 return; 299 base::AutoLock lock(lock_);
287 waiting_for_hostname_ = hostname; 300 if (HasHostBeenRequestedLocked(hostname))
288 is_waiting_for_hostname_ = true; 301 return;
289 content::RunMessageLoop(); 302 waiting_for_hostname_ = hostname;
303 DCHECK(!run_loop_);
304 run_loop_ = &run_loop;
305 }
306 run_loop_->Run();
307 }
308
309 void set_task_runner(
310 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
311 task_runner_.swap(task_runner);
290 } 312 }
291 313
292 private: 314 private:
293 ~HostResolutionRequestRecorder() override {} 315 ~HostResolutionRequestRecorder() override {}
294 316
295 void AddToHistory(const std::string& hostname) { 317 void AddToHistory(const std::string& hostname) {
296 DCHECK_CURRENTLY_ON(BrowserThread::UI); 318 DCHECK_CURRENTLY_ON(BrowserThread::IO);
319 base::AutoLock lock(lock_);
297 requested_hostnames_.push_back(hostname); 320 requested_hostnames_.push_back(hostname);
298 if (is_waiting_for_hostname_ && waiting_for_hostname_ == hostname) { 321 if (run_loop_ && waiting_for_hostname_ == hostname) {
299 is_waiting_for_hostname_ = false;
300 waiting_for_hostname_.clear(); 322 waiting_for_hostname_.clear();
301 base::MessageLoop::current()->QuitWhenIdle(); 323 task_runner_->PostTask(FROM_HERE, run_loop_->QuitClosure());
324 run_loop_ = nullptr;
302 } 325 }
303 } 326 }
304 327
305 // The hostname which WaitUntilHostHasBeenRequested is currently waiting for 328 // The hostname which WaitUntilHostHasBeenRequested is currently waiting for
306 // to be requested. 329 // to be requested.
307 std::string waiting_for_hostname_; 330 std::string waiting_for_hostname_;
308 331
309 // Whether WaitUntilHostHasBeenRequested is waiting for a hostname to be
310 // requested and thus is running a nested message loop.
311 bool is_waiting_for_hostname_;
312
313 // A list of hostnames for which resolution has already been requested. Only 332 // A list of hostnames for which resolution has already been requested. Only
314 // to be accessed from the UI thread. 333 // to be accessed from the UI thread.
315 std::vector<std::string> requested_hostnames_; 334 std::vector<std::string> requested_hostnames_;
316 335
336 base::RunLoop* run_loop_;
337
338 // Protects |waiting_for_hostname_| and |requested_hostnames_|.
339 mutable base::Lock lock_;
340
341 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
342
317 DISALLOW_COPY_AND_ASSIGN(HostResolutionRequestRecorder); 343 DISALLOW_COPY_AND_ASSIGN(HostResolutionRequestRecorder);
318 }; 344 };
319 345
320 // This class intercepts URLRequests and responds with the URLRequestJob* 346 // This class intercepts URLRequests and responds with the URLRequestJob*
321 // callback provided by the constructor. Note that the port of the URL must 347 // callback provided by the constructor. Note that the port of the URL must
322 // match the port given in the constructor. 348 // match the port given in the constructor.
323 class MatchingPortRequestInterceptor : public net::URLRequestInterceptor { 349 class MatchingPortRequestInterceptor : public net::URLRequestInterceptor {
324 public: 350 public:
325 typedef base::Callback<net::URLRequestJob*(net::URLRequest*, 351 typedef base::Callback<net::URLRequestJob*(net::URLRequest*,
326 net::NetworkDelegate*)> 352 net::NetworkDelegate*)>
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 } // namespace 468 } // namespace
443 469
444 namespace chrome_browser_net { 470 namespace chrome_browser_net {
445 471
446 class PredictorBrowserTest : public InProcessBrowserTest { 472 class PredictorBrowserTest : public InProcessBrowserTest {
447 public: 473 public:
448 PredictorBrowserTest() 474 PredictorBrowserTest()
449 : startup_url_("http://host1:1"), 475 : startup_url_("http://host1:1"),
450 referring_url_("http://host2:1"), 476 referring_url_("http://host2:1"),
451 target_url_("http://host3:1"), 477 target_url_("http://host3:1"),
452 host_resolution_request_recorder_(new HostResolutionRequestRecorder), 478 rule_based_resolver_proc_(new net::RuleBasedHostResolverProc(nullptr)),
453 cross_site_test_server_(new net::EmbeddedTestServer()) {} 479 host_resolution_request_recorder_(
480 new HostResolutionRequestRecorder(rule_based_resolver_proc_.get())),
481 cross_site_test_server_(new net::EmbeddedTestServer()) {
482 rule_based_resolver_proc_->AddRuleWithLatency("www.example.test",
483 "127.0.0.1", 50);
484 rule_based_resolver_proc_->AddRuleWithLatency("gmail.google.com",
485 "127.0.0.1", 70);
486 rule_based_resolver_proc_->AddRuleWithLatency("mail.google.com",
487 "127.0.0.1", 44);
488 rule_based_resolver_proc_->AddRuleWithLatency("gmail.com", "127.0.0.1", 63);
489 rule_based_resolver_proc_->AddSimulatedFailure("*.notfound");
490 rule_based_resolver_proc_->AddRuleWithLatency("delay.google.com",
491 "127.0.0.1", 1000 * 60);
492 }
454 493
455 protected: 494 protected:
456 void SetUpInProcessBrowserTestFixture() override { 495 void SetUpInProcessBrowserTestFixture() override {
457 scoped_host_resolver_proc_.reset(new net::ScopedDefaultHostResolverProc( 496 scoped_host_resolver_proc_.reset(new net::ScopedDefaultHostResolverProc(
458 host_resolution_request_recorder_.get())); 497 host_resolution_request_recorder_.get()));
459 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); 498 InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
460 } 499 }
461 500
462 void SetUpCommandLine(base::CommandLine* command_line) override { 501 void SetUpCommandLine(base::CommandLine* command_line) override {
463 command_line->AppendSwitch( 502 command_line->AppendSwitch(
464 switches::kEnableExperimentalWebPlatformFeatures); 503 switches::kEnableExperimentalWebPlatformFeatures);
465 command_line->AppendSwitchASCII( 504 command_line->AppendSwitchASCII(
466 switches::kEnableBlinkFeatures, kBlinkPreconnectFeature); 505 switches::kEnableBlinkFeatures, kBlinkPreconnectFeature);
467 command_line->AppendSwitchASCII(switches::kEnableFeatures, 506 command_line->AppendSwitchASCII(switches::kEnableFeatures,
468 "PreconnectMore"); 507 "PreconnectMore");
508 command_line->AppendSwitchASCII(switches::kEnableFeatures,
509 "UsePredictorDNSQueue");
469 } 510 }
470 511
471 void SetUpOnMainThread() override { 512 void SetUpOnMainThread() override {
472 DCHECK_CURRENTLY_ON(BrowserThread::UI); 513 DCHECK_CURRENTLY_ON(BrowserThread::UI);
473 task_runner_ = base::ThreadTaskRunnerHandle::Get(); 514 task_runner_ = base::ThreadTaskRunnerHandle::Get();
515 host_resolution_request_recorder_->set_task_runner(task_runner_);
474 cross_site_test_server_->ServeFilesFromSourceDirectory("chrome/test/data/"); 516 cross_site_test_server_->ServeFilesFromSourceDirectory("chrome/test/data/");
475 517
476 connection_listener_.reset(new ConnectionListener()); 518 connection_listener_.reset(new ConnectionListener());
477 cross_site_connection_listener_.reset(new ConnectionListener()); 519 cross_site_connection_listener_.reset(new ConnectionListener());
478 embedded_test_server()->SetConnectionListener(connection_listener_.get()); 520 embedded_test_server()->SetConnectionListener(connection_listener_.get());
479 cross_site_test_server_->SetConnectionListener( 521 cross_site_test_server_->SetConnectionListener(
480 cross_site_connection_listener_.get()); 522 cross_site_connection_listener_.get());
481 ASSERT_TRUE(embedded_test_server()->Start()); 523 ASSERT_TRUE(embedded_test_server()->Start());
482 ASSERT_TRUE(cross_site_test_server_->Start()); 524 ASSERT_TRUE(cross_site_test_server_->Start());
483 525
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 } 616 }
575 617
576 bool HasHostBeenRequested(const std::string& hostname) const { 618 bool HasHostBeenRequested(const std::string& hostname) const {
577 return host_resolution_request_recorder_->HasHostBeenRequested(hostname); 619 return host_resolution_request_recorder_->HasHostBeenRequested(hostname);
578 } 620 }
579 621
580 void WaitUntilHostHasBeenRequested(const std::string& hostname) { 622 void WaitUntilHostHasBeenRequested(const std::string& hostname) {
581 host_resolution_request_recorder_->WaitUntilHostHasBeenRequested(hostname); 623 host_resolution_request_recorder_->WaitUntilHostHasBeenRequested(hostname);
582 } 624 }
583 625
626 void WaitUntilHostNamesHaveBeenRequested(
627 const network_hints::UrlList& names) {
628 host_resolution_request_recorder_->WaitUntilHostNamesHaveBeenRequested(
629 names);
630 }
631
584 int RequestedHostnameCount() const { 632 int RequestedHostnameCount() const {
585 return host_resolution_request_recorder_->RequestedHostnameCount(); 633 return host_resolution_request_recorder_->RequestedHostnameCount();
586 } 634 }
587 635
636 void FloodResolveRequestsOnUIThread(const network_hints::UrlList& names) {
637 DCHECK_CURRENTLY_ON(BrowserThread::UI);
638 BrowserThread::PostTask(
639 BrowserThread::IO, FROM_HERE,
640 base::Bind(&PredictorBrowserTest::FloodResolveRequests, this, names));
641 }
642
643 void FloodResolveRequests(const network_hints::UrlList& names) {
644 DCHECK_CURRENTLY_ON(BrowserThread::IO);
645 for (int i = 0; i < 10; i++) {
646 predictor()->DnsPrefetchMotivatedList(names,
647 UrlInfo::PAGE_SCAN_MOTIVATED);
648 }
649 }
650
588 net::EmbeddedTestServer* cross_site_test_server() { 651 net::EmbeddedTestServer* cross_site_test_server() {
589 return cross_site_test_server_.get(); 652 return cross_site_test_server_.get();
590 } 653 }
591 654
592 Predictor* predictor() { return browser()->profile()->GetNetworkPredictor(); } 655 Predictor* predictor() { return browser()->profile()->GetNetworkPredictor(); }
593 656
594 void InstallPredictorObserver(const GURL& source_host, 657 void InstallPredictorObserver(const GURL& source_host,
595 const GURL& cross_site_host) { 658 const GURL& cross_site_host) {
596 DCHECK_CURRENTLY_ON(BrowserThread::UI); 659 DCHECK_CURRENTLY_ON(BrowserThread::UI);
597 observer_.reset( 660 observer_.reset(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 base::Unretained(this)), 695 base::Unretained(this)),
633 run_loop.QuitClosure()); 696 run_loop.QuitClosure());
634 run_loop.Run(); 697 run_loop.Run();
635 } 698 }
636 699
637 void FlushServerSocketsOnUIThread(net::EmbeddedTestServer* test_server) { 700 void FlushServerSocketsOnUIThread(net::EmbeddedTestServer* test_server) {
638 DCHECK_CURRENTLY_ON(BrowserThread::UI); 701 DCHECK_CURRENTLY_ON(BrowserThread::UI);
639 EXPECT_TRUE(test_server->FlushAllSocketsAndConnectionsOnUIThread()); 702 EXPECT_TRUE(test_server->FlushAllSocketsAndConnectionsOnUIThread());
640 } 703 }
641 704
705 void ExpectFoundUrlsOnUIThread(
706 const network_hints::UrlList& found_names,
707 const network_hints::UrlList& not_found_names) {
708 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
709 base::Bind(&PredictorBrowserTest::ExpectFoundUrls,
710 this, found_names, not_found_names));
711 }
712 void ExpectFoundUrls(const network_hints::UrlList& found_names,
713 const network_hints::UrlList& not_found_names) {
714 for (const auto& name : found_names) {
715 EXPECT_TRUE(predictor()->WasFound(name)) << "Expected to have found "
716 << name.spec();
717 }
718 for (const auto& name : not_found_names) {
719 EXPECT_FALSE(predictor()->WasFound(name)) << "Did not expect to find "
720 << name.spec();
721 }
722 }
723
724 void DiscardAllResultsOnUIThread() {
725 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
726 base::Bind(&Predictor::DiscardAllResults,
727 base::Unretained(predictor())));
728 }
729
642 CrossSitePredictorObserver* observer() { return observer_.get(); } 730 CrossSitePredictorObserver* observer() { return observer_.get(); }
643 731
644 // Navigate to an html file on embedded_test_server and tell it to request 732 // Navigate to an html file on embedded_test_server and tell it to request
645 // |num_cors| resources from the cross_site_test_server. It then waits for 733 // |num_cors| resources from the cross_site_test_server. It then waits for
646 // those requests to complete. Note that "cors" here means using cors-mode in 734 // those requests to complete. Note that "cors" here means using cors-mode in
647 // correspondence with the fetch spec. 735 // correspondence with the fetch spec.
648 void NavigateToCrossSiteHtmlUrl(int num_cors, const char* file_suffix) { 736 void NavigateToCrossSiteHtmlUrl(int num_cors, const char* file_suffix) {
649 DCHECK_CURRENTLY_ON(BrowserThread::UI); 737 DCHECK_CURRENTLY_ON(BrowserThread::UI);
650 const GURL& base_url = cross_site_test_server()->base_url(); 738 const GURL& base_url = cross_site_test_server()->base_url();
651 std::string path = base::StringPrintf( 739 std::string path = base::StringPrintf(
(...skipping 10 matching lines...) Expand all
662 EXPECT_TRUE(result); 750 EXPECT_TRUE(result);
663 } 751 }
664 752
665 const GURL startup_url_; 753 const GURL startup_url_;
666 const GURL referring_url_; 754 const GURL referring_url_;
667 const GURL target_url_; 755 const GURL target_url_;
668 std::unique_ptr<ConnectionListener> connection_listener_; 756 std::unique_ptr<ConnectionListener> connection_listener_;
669 std::unique_ptr<ConnectionListener> cross_site_connection_listener_; 757 std::unique_ptr<ConnectionListener> cross_site_connection_listener_;
670 758
671 private: 759 private:
760 scoped_refptr<net::RuleBasedHostResolverProc> rule_based_resolver_proc_;
672 scoped_refptr<HostResolutionRequestRecorder> 761 scoped_refptr<HostResolutionRequestRecorder>
673 host_resolution_request_recorder_; 762 host_resolution_request_recorder_;
674 std::unique_ptr<net::ScopedDefaultHostResolverProc> 763 std::unique_ptr<net::ScopedDefaultHostResolverProc>
675 scoped_host_resolver_proc_; 764 scoped_host_resolver_proc_;
676 std::unique_ptr<net::EmbeddedTestServer> cross_site_test_server_; 765 std::unique_ptr<net::EmbeddedTestServer> cross_site_test_server_;
677 std::unique_ptr<CrossSitePredictorObserver> observer_; 766 std::unique_ptr<CrossSitePredictorObserver> observer_;
678 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 767 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
679 }; 768 };
680 769
770 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, SingleLookupTest) {
771 DiscardAllResultsOnUIThread();
772
773 GURL goog("http://www.example.test:80");
774
775 network_hints::UrlList names{goog};
776
777 // Try to flood the predictor with many concurrent requests.
778 FloodResolveRequestsOnUIThread(names);
779 WaitUntilHostNamesHaveBeenRequested(names);
780 base::MessageLoop::current()->RunUntilIdle();
781 ExpectFoundUrlsOnUIThread(names, network_hints::UrlList());
782
783 EXPECT_GT(predictor()->peak_pending_lookups(), names.size() / 2);
784 EXPECT_LE(predictor()->peak_pending_lookups(), names.size());
785 EXPECT_LE(predictor()->peak_pending_lookups(),
786 predictor()->max_concurrent_dns_lookups());
787 }
788
789 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, ConcurrentLookupTest) {
790 DiscardAllResultsOnUIThread();
791
792 GURL goog("http://www.example.test:80"), goog2("http://gmail.google.com:80"),
793 goog3("http://mail.google.com:80"), goog4("http://gmail.com:80");
794 GURL bad1("http://bad1.notfound:80"), bad2("http://bad2.notfound:80");
795
796 UrlList found_names{goog, goog3, goog2, goog4, goog};
797 UrlList not_found_names{bad1, bad2};
798
799 FloodResolveRequestsOnUIThread(found_names);
800 FloodResolveRequestsOnUIThread(not_found_names);
801 WaitUntilHostNamesHaveBeenRequested(found_names);
802 WaitUntilHostNamesHaveBeenRequested(not_found_names);
803 base::MessageLoop::current()->RunUntilIdle();
804
805 ExpectFoundUrlsOnUIThread(found_names, not_found_names);
806
807 EXPECT_LE(predictor()->peak_pending_lookups(),
808 found_names.size() + not_found_names.size());
809 EXPECT_LE(predictor()->peak_pending_lookups(),
810 predictor()->max_concurrent_dns_lookups());
811 }
812
813 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, MassiveConcurrentLookupTest) {
814 DiscardAllResultsOnUIThread();
815 UrlList not_found_names;
816 for (int i = 0; i < 100; i++) {
817 not_found_names.push_back(
818 GURL(base::StringPrintf("http://host%d.notfound:80", i)));
819 }
820 FloodResolveRequestsOnUIThread(not_found_names);
821 WaitUntilHostNamesHaveBeenRequested(not_found_names);
822 base::MessageLoop::current()->RunUntilIdle();
823
824 ExpectFoundUrlsOnUIThread(network_hints::UrlList(), not_found_names);
825
826 EXPECT_LE(predictor()->peak_pending_lookups(), not_found_names.size());
827
828 EXPECT_LE(predictor()->peak_pending_lookups(),
829 predictor()->max_concurrent_dns_lookups());
830 }
831
832 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest,
833 ShutdownWhenResolutionIsPendingTest) {
834 GURL localhost("http://delay.google.com:80");
835 UrlList names;
836 names.push_back(localhost);
837
838 // Flood with delayed requests.
839 FloodResolveRequestsOnUIThread(names);
840 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
841 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
842 base::TimeDelta::FromMilliseconds(500));
843 base::MessageLoop::current()->Run();
844
845 EXPECT_FALSE(predictor()->WasFound(localhost));
846 }
847
681 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, SimplePreconnectOne) { 848 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, SimplePreconnectOne) {
682 predictor()->PreconnectUrl( 849 predictor()->PreconnectUrl(
683 embedded_test_server()->base_url(), GURL(), 850 embedded_test_server()->base_url(), GURL(),
684 UrlInfo::ResolutionMotivation::EARLY_LOAD_MOTIVATED, 851 UrlInfo::ResolutionMotivation::EARLY_LOAD_MOTIVATED,
685 false /* allow credentials */, 1); 852 false /* allow credentials */, 1);
686 connection_listener_->WaitForAcceptedConnectionsOnUI(1u); 853 connection_listener_->WaitForAcceptedConnectionsOnUI(1u);
687 } 854 }
688 855
689 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, SimplePreconnectTwo) { 856 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, SimplePreconnectTwo) {
690 predictor()->PreconnectUrl( 857 predictor()->PreconnectUrl(
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 EXPECT_THAT(cleared_referral_list, Not(HasSubstr(referring_url_.host()))); 1292 EXPECT_THAT(cleared_referral_list, Not(HasSubstr(referring_url_.host())));
1126 EXPECT_THAT(cleared_referral_list, Not(HasSubstr(target_url_.host()))); 1293 EXPECT_THAT(cleared_referral_list, Not(HasSubstr(target_url_.host())));
1127 1294
1128 // But also make sure this data has been first loaded into the Predictor, by 1295 // But also make sure this data has been first loaded into the Predictor, by
1129 // inspecting that the Predictor starts making the expected hostname requests. 1296 // inspecting that the Predictor starts making the expected hostname requests.
1130 PrepareFrameSubresources(referring_url_); 1297 PrepareFrameSubresources(referring_url_);
1131 WaitUntilHostHasBeenRequested(startup_url_.host()); 1298 WaitUntilHostHasBeenRequested(startup_url_.host());
1132 WaitUntilHostHasBeenRequested(target_url_.host()); 1299 WaitUntilHostHasBeenRequested(target_url_.host());
1133 } 1300 }
1134 1301
1135 // Flaky on Windows: http://crbug.com/469120 1302 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, DnsPrefetch) {
1136 #if defined(OS_WIN) 1303 // Navigate once to make sure all initial hostnames are requested.
1137 #define MAYBE_DnsPrefetch DISABLED_DnsPrefetch 1304 ui_test_utils::NavigateToURL(browser(),
1138 #else 1305 embedded_test_server()->GetURL("/title1.html"));
1139 #define MAYBE_DnsPrefetch DnsPrefetch 1306
1140 #endif
1141 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, MAYBE_DnsPrefetch) {
1142 int hostnames_requested_before_load = RequestedHostnameCount(); 1307 int hostnames_requested_before_load = RequestedHostnameCount();
1143 ui_test_utils::NavigateToURL( 1308 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL(
1144 browser(), 1309 "/predictor/dns_prefetch.html"));
1145 GURL(embedded_test_server()->GetURL("/predictor/dns_prefetch.html")));
1146 WaitUntilHostHasBeenRequested(kChromiumHostname); 1310 WaitUntilHostHasBeenRequested(kChromiumHostname);
1147 ASSERT_FALSE(HasHostBeenRequested(kInvalidLongHostname)); 1311 ASSERT_FALSE(HasHostBeenRequested(kInvalidLongHostname));
1148 ASSERT_EQ(hostnames_requested_before_load + 1, RequestedHostnameCount()); 1312 ASSERT_EQ(hostnames_requested_before_load + 1, RequestedHostnameCount());
1149 } 1313 }
1150 1314
1151 // Tests that preconnect warms up a socket connection to a test server. 1315 // Tests that preconnect warms up a socket connection to a test server.
1152 // Note: This test uses a data URI to serve the preconnect hint, to make sure 1316 // Note: This test uses a data URI to serve the preconnect hint, to make sure
1153 // that the network stack doesn't just re-use its connection to the test server. 1317 // that the network stack doesn't just re-use its connection to the test server.
1154 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, PreconnectNonCORS) { 1318 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, PreconnectNonCORS) {
1155 GURL preconnect_url = embedded_test_server()->base_url(); 1319 GURL preconnect_url = embedded_test_server()->base_url();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 // Second navigation to content with an img. 1413 // Second navigation to content with an img.
1250 std::string img_content = 1414 std::string img_content =
1251 "<img src=\"" + preconnect_url.spec() + "test.gif\">"; 1415 "<img src=\"" + preconnect_url.spec() + "test.gif\">";
1252 NavigateToDataURLWithContent(img_content); 1416 NavigateToDataURLWithContent(img_content);
1253 connection_listener_->WaitUntilFirstConnectionRead(); 1417 connection_listener_->WaitUntilFirstConnectionRead();
1254 EXPECT_EQ(2u, connection_listener_->GetAcceptedSocketCount()); 1418 EXPECT_EQ(2u, connection_listener_->GetAcceptedSocketCount());
1255 EXPECT_EQ(1u, connection_listener_->GetReadSocketCount()); 1419 EXPECT_EQ(1u, connection_listener_->GetReadSocketCount());
1256 } 1420 }
1257 1421
1258 } // namespace chrome_browser_net 1422 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698