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

Side by Side Diff: chrome/browser/captive_portal/captive_portal_browsertest.cc

Issue 648653003: Standardize usage of virtual/override/final in chrome/browser/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // captive portal. 109 // captive portal.
110 const char* const kInternetConnectedTitle = "Title Of Awesomeness"; 110 const char* const kInternetConnectedTitle = "Title Of Awesomeness";
111 111
112 // A URL request job that hangs until FailJobs() is called. Started jobs 112 // A URL request job that hangs until FailJobs() is called. Started jobs
113 // are stored in a static class variable containing a linked list so that 113 // are stored in a static class variable containing a linked list so that
114 // FailJobs() can locate them. 114 // FailJobs() can locate them.
115 class URLRequestTimeoutOnDemandJob : public net::URLRequestJob, 115 class URLRequestTimeoutOnDemandJob : public net::URLRequestJob,
116 public base::NonThreadSafe { 116 public base::NonThreadSafe {
117 public: 117 public:
118 // net::URLRequestJob: 118 // net::URLRequestJob:
119 virtual void Start() override; 119 void Start() override;
120 120
121 // All the public static methods below can be called on any thread. 121 // All the public static methods below can be called on any thread.
122 122
123 // Waits for exactly |num_jobs|. 123 // Waits for exactly |num_jobs|.
124 static void WaitForJobs(int num_jobs); 124 static void WaitForJobs(int num_jobs);
125 125
126 // Fails all active URLRequestTimeoutOnDemandJobs with connection timeouts. 126 // Fails all active URLRequestTimeoutOnDemandJobs with connection timeouts.
127 // There are expected to be exactly |expected_num_jobs| waiting for 127 // There are expected to be exactly |expected_num_jobs| waiting for
128 // failure. The only way to gaurantee this is with an earlier call to 128 // failure. The only way to gaurantee this is with an earlier call to
129 // WaitForJobs, so makes sure there has been a matching WaitForJobs call. 129 // WaitForJobs, so makes sure there has been a matching WaitForJobs call.
130 static void FailJobs(int expected_num_jobs); 130 static void FailJobs(int expected_num_jobs);
131 131
132 // Abandon all active URLRequestTimeoutOnDemandJobs. |expected_num_jobs| 132 // Abandon all active URLRequestTimeoutOnDemandJobs. |expected_num_jobs|
133 // behaves just as in FailJobs. 133 // behaves just as in FailJobs.
134 static void AbandonJobs(int expected_num_jobs); 134 static void AbandonJobs(int expected_num_jobs);
135 135
136 private: 136 private:
137 friend class URLRequestMockCaptivePortalJobFactory; 137 friend class URLRequestMockCaptivePortalJobFactory;
138 138
139 // Operation to perform on jobs when removing them from |job_list_|. 139 // Operation to perform on jobs when removing them from |job_list_|.
140 enum EndJobOperation { 140 enum EndJobOperation {
141 FAIL_JOBS, 141 FAIL_JOBS,
142 ABANDON_JOBS, 142 ABANDON_JOBS,
143 }; 143 };
144 144
145 URLRequestTimeoutOnDemandJob(net::URLRequest* request, 145 URLRequestTimeoutOnDemandJob(net::URLRequest* request,
146 net::NetworkDelegate* network_delegate); 146 net::NetworkDelegate* network_delegate);
147 virtual ~URLRequestTimeoutOnDemandJob(); 147 ~URLRequestTimeoutOnDemandJob() override;
148 148
149 // Attempts to removes |this| from |jobs_|. Returns true if it was removed 149 // Attempts to removes |this| from |jobs_|. Returns true if it was removed
150 // from the list. 150 // from the list.
151 bool RemoveFromList(); 151 bool RemoveFromList();
152 152
153 static void WaitForJobsOnIOThread(int num_jobs); 153 static void WaitForJobsOnIOThread(int num_jobs);
154 static void FailOrAbandonJobsOnIOThread( 154 static void FailOrAbandonJobsOnIOThread(
155 int expected_num_jobs, 155 int expected_num_jobs,
156 EndJobOperation end_job_operation); 156 EndJobOperation end_job_operation);
157 157
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 bool IsLoginTab(WebContents* web_contents) { 496 bool IsLoginTab(WebContents* web_contents) {
497 return CaptivePortalTabHelper::FromWebContents(web_contents)->IsLoginTab(); 497 return CaptivePortalTabHelper::FromWebContents(web_contents)->IsLoginTab();
498 } 498 }
499 499
500 // Tracks how many times each tab has been navigated since the Observer was 500 // Tracks how many times each tab has been navigated since the Observer was
501 // created. The standard TestNavigationObserver can only watch specific 501 // created. The standard TestNavigationObserver can only watch specific
502 // pre-existing tabs or loads in serial for all tabs. 502 // pre-existing tabs or loads in serial for all tabs.
503 class MultiNavigationObserver : public content::NotificationObserver { 503 class MultiNavigationObserver : public content::NotificationObserver {
504 public: 504 public:
505 MultiNavigationObserver(); 505 MultiNavigationObserver();
506 virtual ~MultiNavigationObserver(); 506 ~MultiNavigationObserver() override;
507 507
508 // Waits for exactly |num_navigations_to_wait_for| LOAD_STOP 508 // Waits for exactly |num_navigations_to_wait_for| LOAD_STOP
509 // notifications to have occurred since the construction of |this|. More 509 // notifications to have occurred since the construction of |this|. More
510 // navigations than expected occuring will trigger a expect failure. 510 // navigations than expected occuring will trigger a expect failure.
511 void WaitForNavigations(int num_navigations_to_wait_for); 511 void WaitForNavigations(int num_navigations_to_wait_for);
512 512
513 // Returns the number of LOAD_STOP events that have occurred for 513 // Returns the number of LOAD_STOP events that have occurred for
514 // |web_contents| since this was constructed. 514 // |web_contents| since this was constructed.
515 int NumNavigationsForTab(WebContents* web_contents) const; 515 int NumNavigationsForTab(WebContents* web_contents) const;
516 516
517 // The number of LOAD_STOP events since |this| was created. 517 // The number of LOAD_STOP events since |this| was created.
518 int num_navigations() const { return num_navigations_; } 518 int num_navigations() const { return num_navigations_; }
519 519
520 private: 520 private:
521 typedef std::map<const WebContents*, int> TabNavigationMap; 521 typedef std::map<const WebContents*, int> TabNavigationMap;
522 522
523 // content::NotificationObserver: 523 // content::NotificationObserver:
524 virtual void Observe(int type, const content::NotificationSource& source, 524 void Observe(int type,
525 const content::NotificationDetails& details) override; 525 const content::NotificationSource& source,
526 const content::NotificationDetails& details) override;
526 527
527 int num_navigations_; 528 int num_navigations_;
528 529
529 // Map of how many times each tab has navigated since |this| was created. 530 // Map of how many times each tab has navigated since |this| was created.
530 TabNavigationMap tab_navigation_map_; 531 TabNavigationMap tab_navigation_map_;
531 532
532 // Total number of navigations to wait for. Value only matters when 533 // Total number of navigations to wait for. Value only matters when
533 // |waiting_for_navigation_| is true. 534 // |waiting_for_navigation_| is true.
534 int num_navigations_to_wait_for_; 535 int num_navigations_to_wait_for_;
535 536
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 // to stop loading and have the kInternetConnectedTitle. 597 // to stop loading and have the kInternetConnectedTitle.
597 // 598 //
598 // This is for the specific purpose of observing tabs time out after logging in 599 // This is for the specific purpose of observing tabs time out after logging in
599 // to a captive portal, which will then cause them to reload. 600 // to a captive portal, which will then cause them to reload.
600 // MultiNavigationObserver is insufficient for this because there may or may not 601 // MultiNavigationObserver is insufficient for this because there may or may not
601 // be a LOAD_STOP event between the timeout and the reload. 602 // be a LOAD_STOP event between the timeout and the reload.
602 // See bug http://crbug.com/133227 603 // See bug http://crbug.com/133227
603 class FailLoadsAfterLoginObserver : public content::NotificationObserver { 604 class FailLoadsAfterLoginObserver : public content::NotificationObserver {
604 public: 605 public:
605 FailLoadsAfterLoginObserver(); 606 FailLoadsAfterLoginObserver();
606 virtual ~FailLoadsAfterLoginObserver(); 607 ~FailLoadsAfterLoginObserver() override;
607 608
608 void WaitForNavigations(); 609 void WaitForNavigations();
609 610
610 private: 611 private:
611 typedef std::set<const WebContents*> TabSet; 612 typedef std::set<const WebContents*> TabSet;
612 613
613 // content::NotificationObserver: 614 // content::NotificationObserver:
614 virtual void Observe(int type, const content::NotificationSource& source, 615 void Observe(int type,
615 const content::NotificationDetails& details) override; 616 const content::NotificationSource& source,
617 const content::NotificationDetails& details) override;
616 618
617 // The set of tabs that need to be navigated. This is the set of loading 619 // The set of tabs that need to be navigated. This is the set of loading
618 // tabs when the observer is created. 620 // tabs when the observer is created.
619 TabSet tabs_needing_navigation_; 621 TabSet tabs_needing_navigation_;
620 622
621 // Number of tabs that have stopped navigating with the expected title. These 623 // Number of tabs that have stopped navigating with the expected title. These
622 // are expected not to be navigated again. 624 // are expected not to be navigated again.
623 TabSet tabs_navigated_to_final_destination_; 625 TabSet tabs_navigated_to_final_destination_;
624 626
625 // True if WaitForNavigations has been called, until 627 // True if WaitForNavigations has been called, until
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 void WaitForResults(int num_results_to_wait_for); 695 void WaitForResults(int num_results_to_wait_for);
694 696
695 int num_results_received() const { return num_results_received_; } 697 int num_results_received() const { return num_results_received_; }
696 698
697 CaptivePortalResult captive_portal_result() const { 699 CaptivePortalResult captive_portal_result() const {
698 return captive_portal_result_; 700 return captive_portal_result_;
699 } 701 }
700 702
701 private: 703 private:
702 // Records results and exits the message loop, if needed. 704 // Records results and exits the message loop, if needed.
703 virtual void Observe(int type, 705 void Observe(int type,
704 const content::NotificationSource& source, 706 const content::NotificationSource& source,
705 const content::NotificationDetails& details) override; 707 const content::NotificationDetails& details) override;
706 708
707 // Number of times OnPortalResult has been called since construction. 709 // Number of times OnPortalResult has been called since construction.
708 int num_results_received_; 710 int num_results_received_;
709 711
710 // If WaitForResults was called, the total number of updates for which to 712 // If WaitForResults was called, the total number of updates for which to
711 // wait. Value doesn't matter when |waiting_for_result_| is false. 713 // wait. Value doesn't matter when |waiting_for_result_| is false.
712 int num_results_to_wait_for_; 714 int num_results_to_wait_for_;
713 715
714 bool waiting_for_result_; 716 bool waiting_for_result_;
715 717
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 transport_security_state->AddHSTS(host, expiry, include_subdomains); 794 transport_security_state->AddHSTS(host, expiry, include_subdomains);
793 } 795 }
794 796
795 } // namespace 797 } // namespace
796 798
797 class CaptivePortalBrowserTest : public InProcessBrowserTest { 799 class CaptivePortalBrowserTest : public InProcessBrowserTest {
798 public: 800 public:
799 CaptivePortalBrowserTest(); 801 CaptivePortalBrowserTest();
800 802
801 // InProcessBrowserTest: 803 // InProcessBrowserTest:
802 virtual void SetUpOnMainThread() override; 804 void SetUpOnMainThread() override;
803 virtual void TearDownOnMainThread() override; 805 void TearDownOnMainThread() override;
804 806
805 // Sets the captive portal checking preference. Does not affect the command 807 // Sets the captive portal checking preference. Does not affect the command
806 // line flag, which is set in SetUpCommandLine. 808 // line flag, which is set in SetUpCommandLine.
807 void EnableCaptivePortalDetection(Profile* profile, bool enabled); 809 void EnableCaptivePortalDetection(Profile* profile, bool enabled);
808 810
809 // Sets up the captive portal service for the given profile so that 811 // Sets up the captive portal service for the given profile so that
810 // all checks go to |test_url|. Also disables all timers. 812 // all checks go to |test_url|. Also disables all timers.
811 void SetUpCaptivePortalService(Profile* profile, const GURL& test_url); 813 void SetUpCaptivePortalService(Profile* profile, const GURL& test_url);
812 814
813 // Returns true if |browser|'s profile is currently running a captive portal 815 // Returns true if |browser|'s profile is currently running a captive portal
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after
2204 content::BrowserThread::PostTask( 2206 content::BrowserThread::PostTask(
2205 content::BrowserThread::IO, FROM_HERE, 2207 content::BrowserThread::IO, FROM_HERE,
2206 base::Bind(&AddHstsHost, 2208 base::Bind(&AddHstsHost,
2207 make_scoped_refptr(browser()->profile()->GetRequestContext()), 2209 make_scoped_refptr(browser()->profile()->GetRequestContext()),
2208 http_timeout_url.host())); 2210 http_timeout_url.host()));
2209 2211
2210 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1); 2212 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1);
2211 Login(browser(), 1, 0); 2213 Login(browser(), 1, 0);
2212 FailLoadsAfterLogin(browser(), 1); 2214 FailLoadsAfterLogin(browser(), 1);
2213 } 2215 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_process_platform_part_mac.h ('k') | chrome/browser/captive_portal/captive_portal_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698