OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ssl/ssl_error_handler.h" | 5 #include "chrome/browser/ssl/ssl_error_handler.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/metrics/field_trial.h" |
9 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
11 #include "chrome/browser/captive_portal/captive_portal_service.h" | 12 #include "chrome/browser/captive_portal/captive_portal_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
14 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
15 #include "components/captive_portal/captive_portal_testing_utils.h" | 16 #include "components/captive_portal/captive_portal_testing_utils.h" |
16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
18 #include "net/ssl/ssl_info.h" | 19 #include "net/ssl/ssl_info.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 Profile* profile_; | 90 Profile* profile_; |
90 bool captive_portal_checked_; | 91 bool captive_portal_checked_; |
91 bool ssl_interstitial_shown_; | 92 bool ssl_interstitial_shown_; |
92 bool captive_portal_interstitial_shown_; | 93 bool captive_portal_interstitial_shown_; |
93 | 94 |
94 DISALLOW_COPY_AND_ASSIGN(TestSSLErrorHandler); | 95 DISALLOW_COPY_AND_ASSIGN(TestSSLErrorHandler); |
95 }; | 96 }; |
96 | 97 |
97 class SSLErrorHandlerTest : public ChromeRenderViewHostTestHarness { | 98 class SSLErrorHandlerTest : public ChromeRenderViewHostTestHarness { |
98 public: | 99 public: |
| 100 SSLErrorHandlerTest() |
| 101 : field_trial_list_(NULL) { |
| 102 } |
| 103 |
99 void SetUp() override { | 104 void SetUp() override { |
100 ChromeRenderViewHostTestHarness::SetUp(); | 105 ChromeRenderViewHostTestHarness::SetUp(); |
101 SSLErrorHandler::SetInterstitialDelayTypeForTest(SSLErrorHandler::NONE); | 106 SSLErrorHandler::SetInterstitialDelayTypeForTest(SSLErrorHandler::NONE); |
102 error_handler_.reset(new TestSSLErrorHandler(profile(), | 107 error_handler_.reset(new TestSSLErrorHandler(profile(), |
103 web_contents(), | 108 web_contents(), |
104 ssl_info_)); | 109 ssl_info_)); |
105 } | 110 // Enable finch experiment for captive portal interstitials. |
| 111 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 112 "CaptivePortalInterstitial", "Enabled")); |
| 113 } |
106 | 114 |
107 void TearDown() override { | 115 void TearDown() override { |
108 EXPECT_FALSE(error_handler()->IsTimerRunning()); | 116 EXPECT_FALSE(error_handler()->IsTimerRunning()); |
109 error_handler_.reset(NULL); | 117 error_handler_.reset(NULL); |
110 ChromeRenderViewHostTestHarness::TearDown(); | 118 ChromeRenderViewHostTestHarness::TearDown(); |
111 } | 119 } |
112 | 120 |
113 TestSSLErrorHandler* error_handler() { return error_handler_.get(); } | 121 TestSSLErrorHandler* error_handler() { return error_handler_.get(); } |
114 | 122 |
115 private: | 123 private: |
116 net::SSLInfo ssl_info_; | 124 net::SSLInfo ssl_info_; |
117 scoped_ptr<TestSSLErrorHandler> error_handler_; | 125 scoped_ptr<TestSSLErrorHandler> error_handler_; |
| 126 base::FieldTrialList field_trial_list_; |
118 }; | 127 }; |
119 | 128 |
120 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 129 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
121 | 130 |
122 TEST_F(SSLErrorHandlerTest, | 131 TEST_F(SSLErrorHandlerTest, |
123 ShouldShowSSLInterstitialOnTimerExpired) { | 132 ShouldShowSSLInterstitialOnTimerExpired) { |
124 EXPECT_FALSE(error_handler()->IsTimerRunning()); | 133 EXPECT_FALSE(error_handler()->IsTimerRunning()); |
125 error_handler()->StartHandlingError(); | 134 error_handler()->StartHandlingError(); |
126 | 135 |
127 EXPECT_TRUE(error_handler()->IsTimerRunning()); | 136 EXPECT_TRUE(error_handler()->IsTimerRunning()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 ShouldShowSSLInterstitialOnCaptivePortalDetectionDisabled) { | 197 ShouldShowSSLInterstitialOnCaptivePortalDetectionDisabled) { |
189 EXPECT_FALSE(error_handler()->IsTimerRunning()); | 198 EXPECT_FALSE(error_handler()->IsTimerRunning()); |
190 error_handler()->StartHandlingError(); | 199 error_handler()->StartHandlingError(); |
191 EXPECT_FALSE(error_handler()->IsTimerRunning()); | 200 EXPECT_FALSE(error_handler()->IsTimerRunning()); |
192 EXPECT_FALSE(error_handler()->captive_portal_checked()); | 201 EXPECT_FALSE(error_handler()->captive_portal_checked()); |
193 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); | 202 EXPECT_TRUE(error_handler()->ssl_interstitial_shown()); |
194 EXPECT_FALSE(error_handler()->captive_portal_interstitial_shown()); | 203 EXPECT_FALSE(error_handler()->captive_portal_interstitial_shown()); |
195 } | 204 } |
196 | 205 |
197 #endif // defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 206 #endif // defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
OLD | NEW |