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

Side by Side Diff: chrome/browser/ssl/ssl_error_handler_unittest.cc

Issue 318213002: Add custom interstitial for captive portals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unnecessary change 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ssl/ssl_error_handler.h"
6
7 #include "base/callback.h"
8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h"
11 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
12 #include "content/public/common/content_switches.h"
13 #include "net/base/net_errors.h"
14 #include "net/ssl/ssl_info.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 class TestSSLErrorHandler : public SSLErrorHandler {
18 public:
19 TestSSLErrorHandler(content::WebContents* web_contents,
20 const net::SSLInfo& ssl_info)
21 : SSLErrorHandler(web_contents,
22 net::ERR_CERT_COMMON_NAME_INVALID,
23 ssl_info,
24 GURL(),
25 0,
26 base::TimeDelta(),
27 base::Callback<void(bool)>()) {
28 SSLErrorHandler::DontCreateInterstitials();
mmenke 2014/10/30 19:28:02 Any reason to prefer this over InterstitialPage::D
meacer 2014/11/06 21:21:57 Not needed anymore, removed.
29 }
30
31 ~TestSSLErrorHandler() override {
32 }
33
34 bool TimerRunning() const {
35 return SSLErrorHandler::TimerRunning();
36 }
37
38 bool handled() const {
39 return SSLErrorHandler::handled();
40 }
41
42 int captive_portal_check_count() const {
43 return SSLErrorHandler::captive_portal_check_count();
44 }
45
46 int ssl_interstitial_show_count() const {
47 return SSLErrorHandler::ssl_interstitial_show_count();
48 }
49
50 int captive_portal_interstitial_show_count() const {
51 return SSLErrorHandler::captive_portal_interstitial_show_count();
52 }
Ryan Sleevi 2014/10/29 23:17:32 These aren't virtual methods you're overriding, so
meacer 2014/11/06 21:21:57 They are not overrides anymore since I moved the c
53
54 private:
55
56 DISALLOW_COPY_AND_ASSIGN(TestSSLErrorHandler);
Ryan Sleevi 2014/10/29 23:17:32 no newline
meacer 2014/11/06 21:21:57 Done.
57 };
58
59 class SSLErrorHandlerTest : public ChromeRenderViewHostTestHarness {
60 public:
61 virtual void SetUp() override {
mmenke 2014/10/30 19:28:02 The new coolness is to use override without virtua
meacer 2014/11/06 21:21:57 Done. That change happened long after I wrote this
62 CommandLine& command_line = *CommandLine::ForCurrentProcess();
63 command_line.AppendSwitch(::switches::kTestType);
64 ChromeRenderViewHostTestHarness::SetUp();
65 ssl_info_.reset(new net::SSLInfo);
66 error_handler_.reset(new TestSSLErrorHandler(web_contents(),
67 *ssl_info_.get()));
68 }
69
70 virtual void TearDown() override {
71 EXPECT_FALSE(error_handler().TimerRunning());
72 error_handler_.reset(NULL);
73 ssl_info_.reset(NULL);
74 ChromeRenderViewHostTestHarness::TearDown();
75 }
76
77 TestSSLErrorHandler& error_handler() { return *error_handler_.get(); }
78
79 private:
80 scoped_ptr<net::SSLInfo> ssl_info_;
81 scoped_ptr<TestSSLErrorHandler> error_handler_;
82
83 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandlerTest);
84 };
85
86 #ifdef ENABLE_CAPTIVE_PORTAL_DETECTION
Ryan Sleevi 2014/10/29 23:17:32 #if defined(...)
meacer 2014/11/06 21:21:56 Done.
87
88 TEST_F(SSLErrorHandlerTest,
89 ShouldShowSSLInterstitialOnTimerExpired) {
90 EXPECT_FALSE(error_handler().TimerRunning());
91 error_handler().Handle();
92
93 EXPECT_TRUE(error_handler().TimerRunning());
94 EXPECT_FALSE(error_handler().handled());
95 EXPECT_EQ(1, error_handler().captive_portal_check_count());
96 EXPECT_EQ(0, error_handler().ssl_interstitial_show_count());
97 EXPECT_EQ(0, error_handler().captive_portal_interstitial_show_count());
98
99 base::MessageLoop::current()->RunUntilIdle();
100
101 EXPECT_FALSE(error_handler().TimerRunning());
102 EXPECT_TRUE(error_handler().handled());
103 EXPECT_EQ(1, error_handler().captive_portal_check_count());
104 EXPECT_EQ(1, error_handler().ssl_interstitial_show_count());
105 EXPECT_EQ(0, error_handler().captive_portal_interstitial_show_count());
106
107 // Any captive portal result after the timer expired should be ignored and
108 // counts shouldn't change.
109 error_handler().OnCaptivePortalResult();
110 EXPECT_EQ(1, error_handler().ssl_interstitial_show_count());
111 EXPECT_EQ(0, error_handler().captive_portal_interstitial_show_count());
112 }
113
114 TEST_F(SSLErrorHandlerTest,
115 ShouldShowCustomInterstitialOnCaptivePortalResult) {
116 EXPECT_FALSE(error_handler().TimerRunning());
117 error_handler().Handle();
118
119 EXPECT_TRUE(error_handler().TimerRunning());
120 EXPECT_FALSE(error_handler().handled());
121 EXPECT_EQ(1, error_handler().captive_portal_check_count());
122 EXPECT_EQ(0, error_handler().ssl_interstitial_show_count());
123 EXPECT_EQ(0, error_handler().captive_portal_interstitial_show_count());
124 // Fake a captive portal result.
125 error_handler().OnCaptivePortalResult();
126 base::MessageLoop::current()->RunUntilIdle();
127
128 EXPECT_FALSE(error_handler().TimerRunning());
129 EXPECT_TRUE(error_handler().handled());
130 EXPECT_EQ(1, error_handler().captive_portal_check_count());
131 EXPECT_EQ(0, error_handler().ssl_interstitial_show_count());
132 EXPECT_EQ(1, error_handler().captive_portal_interstitial_show_count());
133
134 // Any captive portal result after the timer expired should be ignored and
135 // counts shouldn't change.
136 error_handler().OnCaptivePortalResult();
137 EXPECT_EQ(0, error_handler().ssl_interstitial_show_count());
138 EXPECT_EQ(1, error_handler().captive_portal_interstitial_show_count());
139 }
140
141 TEST_F(SSLErrorHandlerTest,
142 ShouldShowCaptivePortalInterstitialOnTooEarlyCaptivePortalResult) {
143 EXPECT_FALSE(error_handler().TimerRunning());
144 // A captive portal result arrives before error handler starts.
145 error_handler().OnCaptivePortalResult();
146
147 EXPECT_FALSE(error_handler().TimerRunning());
148 EXPECT_TRUE(error_handler().handled());
149 EXPECT_EQ(0, error_handler().captive_portal_check_count());
150 EXPECT_EQ(0, error_handler().ssl_interstitial_show_count());
151 EXPECT_EQ(1, error_handler().captive_portal_interstitial_show_count());
152
153 error_handler().Handle();
154
155 // Once the captive portal warning is shown, the state shouldn't change later.
156 // The timer shouldn't be fired as we already know captive portal status.
157 EXPECT_FALSE(error_handler().TimerRunning());
158 EXPECT_TRUE(error_handler().handled());
159 EXPECT_EQ(0, error_handler().captive_portal_check_count());
160 EXPECT_EQ(0, error_handler().ssl_interstitial_show_count());
161 EXPECT_EQ(1, error_handler().captive_portal_interstitial_show_count());
162 base::MessageLoop::current()->RunUntilIdle();
163 }
164
165 #else
mmenke 2014/10/30 19:28:02 #else // if !defined(...)
meacer 2014/11/06 21:21:56 Done.
166
167 TEST_F(SSLErrorHandlerTest,
168 ShouldShowSSLInterstitialOnCaptivePortalDetectionDisabled) {
169 EXPECT_FALSE(error_handler().TimerRunning());
170 error_handler().Handle();
171 EXPECT_EQ(0, error_handler().captive_portal_check_count());
172 EXPECT_EQ(1, error_handler().ssl_interstitial_show_count());
173 EXPECT_EQ(0, error_handler().captive_portal_interstitial_show_count());
174 }
175
176 #endif
mmenke 2014/10/30 19:28:02 #endif // defined(ENABLE_CAPTIVE_PORTAL_DETECTION
meacer 2014/11/06 21:21:57 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698