| 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 <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 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 transport_security_state->EnableHost(host, state); | 754 transport_security_state->EnableHost(host, state); |
| 755 } | 755 } |
| 756 | 756 |
| 757 } // namespace | 757 } // namespace |
| 758 | 758 |
| 759 class CaptivePortalBrowserTest : public InProcessBrowserTest { | 759 class CaptivePortalBrowserTest : public InProcessBrowserTest { |
| 760 public: | 760 public: |
| 761 CaptivePortalBrowserTest(); | 761 CaptivePortalBrowserTest(); |
| 762 | 762 |
| 763 // InProcessBrowserTest: | 763 // InProcessBrowserTest: |
| 764 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; | |
| 765 virtual void SetUpOnMainThread() OVERRIDE; | 764 virtual void SetUpOnMainThread() OVERRIDE; |
| 766 virtual void CleanUpOnMainThread() OVERRIDE; | 765 virtual void CleanUpOnMainThread() OVERRIDE; |
| 767 | 766 |
| 768 // Sets the captive portal checking preference. Does not affect the command | 767 // Sets the captive portal checking preference. Does not affect the command |
| 769 // line flag, which is set in SetUpCommandLine. | 768 // line flag, which is set in SetUpCommandLine. |
| 770 void EnableCaptivePortalDetection(Profile* profile, bool enabled); | 769 void EnableCaptivePortalDetection(Profile* profile, bool enabled); |
| 771 | 770 |
| 772 // Sets up the captive portal service for the given profile so that | 771 // Sets up the captive portal service for the given profile so that |
| 773 // all checks go to |test_url|. Also disables all timers. | 772 // all checks go to |test_url|. Also disables all timers. |
| 774 void SetUpCaptivePortalService(Profile* profile, const GURL& test_url); | 773 void SetUpCaptivePortalService(Profile* profile, const GURL& test_url); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 CaptivePortalBrowserTest::CaptivePortalBrowserTest() { | 890 CaptivePortalBrowserTest::CaptivePortalBrowserTest() { |
| 892 } | 891 } |
| 893 | 892 |
| 894 void CaptivePortalBrowserTest::SetUpOnMainThread() { | 893 void CaptivePortalBrowserTest::SetUpOnMainThread() { |
| 895 // Enable mock requests. | 894 // Enable mock requests. |
| 896 content::BrowserThread::PostTask( | 895 content::BrowserThread::PostTask( |
| 897 content::BrowserThread::IO, FROM_HERE, | 896 content::BrowserThread::IO, FROM_HERE, |
| 898 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 897 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
| 899 URLRequestMockCaptivePortalJobFactory::AddUrlHandlers(); | 898 URLRequestMockCaptivePortalJobFactory::AddUrlHandlers(); |
| 900 | 899 |
| 900 // Double-check that the captive portal service isn't enabled by default for |
| 901 // browser tests. |
| 902 EXPECT_TRUE(CaptivePortalService::is_disabled_for_tests()); |
| 903 |
| 904 CaptivePortalService::set_is_disabled_for_tests(false); |
| 901 EnableCaptivePortalDetection(browser()->profile(), true); | 905 EnableCaptivePortalDetection(browser()->profile(), true); |
| 902 | 906 |
| 903 // Set the captive portal service to use URLRequestMockCaptivePortalJob's | 907 // Set the captive portal service to use URLRequestMockCaptivePortalJob's |
| 904 // mock URL, by default. | 908 // mock URL, by default. |
| 905 SetUpCaptivePortalService(browser()->profile(), | 909 SetUpCaptivePortalService(browser()->profile(), |
| 906 GURL(kMockCaptivePortalTestUrl)); | 910 GURL(kMockCaptivePortalTestUrl)); |
| 907 } | 911 } |
| 908 | 912 |
| 909 void CaptivePortalBrowserTest::CleanUpOnMainThread() { | 913 void CaptivePortalBrowserTest::CleanUpOnMainThread() { |
| 910 // No test should have a captive portal check pending on quit. | 914 // No test should have a captive portal check pending on quit. |
| 911 EXPECT_FALSE(CheckPending(browser())); | 915 EXPECT_FALSE(CheckPending(browser())); |
| 912 } | 916 } |
| 913 | 917 |
| 914 void CaptivePortalBrowserTest::SetUpCommandLine( | |
| 915 CommandLine* command_line) { | |
| 916 command_line->AppendSwitch(switches::kCaptivePortalDetection); | |
| 917 } | |
| 918 | |
| 919 void CaptivePortalBrowserTest::EnableCaptivePortalDetection( | 918 void CaptivePortalBrowserTest::EnableCaptivePortalDetection( |
| 920 Profile* profile, bool enabled) { | 919 Profile* profile, bool enabled) { |
| 921 profile->GetPrefs()->SetBoolean(prefs::kAlternateErrorPagesEnabled, enabled); | 920 profile->GetPrefs()->SetBoolean(prefs::kAlternateErrorPagesEnabled, enabled); |
| 922 } | 921 } |
| 923 | 922 |
| 924 void CaptivePortalBrowserTest::SetUpCaptivePortalService(Profile* profile, | 923 void CaptivePortalBrowserTest::SetUpCaptivePortalService(Profile* profile, |
| 925 const GURL& test_url) { | 924 const GURL& test_url) { |
| 926 CaptivePortalService* captive_portal_service = | 925 CaptivePortalService* captive_portal_service = |
| 927 CaptivePortalServiceFactory::GetForProfile(profile); | 926 CaptivePortalServiceFactory::GetForProfile(profile); |
| 928 captive_portal_service->set_test_url(test_url); | 927 captive_portal_service->set_test_url(test_url); |
| (...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1997 base::Bind(&AddHstsHost, | 1996 base::Bind(&AddHstsHost, |
| 1998 make_scoped_refptr(browser()->profile()->GetRequestContext()), | 1997 make_scoped_refptr(browser()->profile()->GetRequestContext()), |
| 1999 http_timeout_url.host())); | 1998 http_timeout_url.host())); |
| 2000 | 1999 |
| 2001 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url); | 2000 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url); |
| 2002 Login(browser(), 1, 0); | 2001 Login(browser(), 1, 0); |
| 2003 FailLoadsAfterLogin(browser(), 1); | 2002 FailLoadsAfterLogin(browser(), 1); |
| 2004 } | 2003 } |
| 2005 | 2004 |
| 2006 } // namespace captive_portal | 2005 } // namespace captive_portal |
| OLD | NEW |