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

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: Fix build Created 6 years, 6 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 (c) 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/message_loop/message_loop.h"
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
10 #include "net/ssl/ssl_info.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14
15 class TestSSLErrorHandler : public SSLErrorHandler {
16 public:
17 TestSSLErrorHandler(content::WebContents* web_contents,
18 const net::SSLInfo& ssl_info,
19 bool overridable)
20 : SSLErrorHandler(web_contents,
21 -1,
22 ssl_info,
23 GURL(),
24 overridable,
25 false,
26 base::Callback<void(bool)>()) {
27 }
28
29 virtual ~TestSSLErrorHandler() {
30 }
31
32 void set_ssl_interstitial_display_delay(base::TimeDelta delay) {
33 EXPECT_FALSE(TimerRunning());
34 SSLErrorHandler::set_ssl_interstitial_display_delay(delay);
35 }
36
37 bool TimerRunning() {
38 return timer_.IsRunning();
39 }
40
41 MOCK_METHOD0(CheckForCaptivePortal, void());
42 MOCK_METHOD0(ShowCaptivePortalInterstitial, void());
43 MOCK_METHOD0(ShowSSLInterstitial, void());
44 private:
45 DISALLOW_COPY_AND_ASSIGN(TestSSLErrorHandler);
46 };
47
48 class SSLErrorHandlerTest : public ChromeRenderViewHostTestHarness {
49 public:
50 // testing::Test:
51 virtual void SetUp() OVERRIDE {
52 ChromeRenderViewHostTestHarness::SetUp();
53 ssl_info_.reset(new net::SSLInfo);
54 error_handler_.reset(
55 new testing::StrictMock<TestSSLErrorHandler>(web_contents(),
56 *ssl_info_.get(),
57 false));
58 error_handler_->set_ssl_interstitial_display_delay(base::TimeDelta());
59 }
60
61 virtual void TearDown() OVERRIDE {
62 EXPECT_FALSE(error_handler().TimerRunning());
63 error_handler_.reset(NULL);
64 ssl_info_.reset(NULL);
65 ChromeRenderViewHostTestHarness::TearDown();
66 }
67
68 TestSSLErrorHandler& error_handler() { return *error_handler_.get(); }
69
70 private:
71 scoped_ptr<net::SSLInfo> ssl_info_;
72 scoped_ptr<TestSSLErrorHandler> error_handler_;
73 };
74
75 TEST_F(SSLErrorHandlerTest,
76 ShouldShowSSLInterstitialOnTimerExpired) {
77 EXPECT_FALSE(error_handler().TimerRunning());
78 EXPECT_CALL(error_handler(), CheckForCaptivePortal()).Times(1);
79 error_handler().Handle();
80
81 EXPECT_TRUE(error_handler().TimerRunning());
82 EXPECT_FALSE(error_handler().handled());
83 EXPECT_CALL(error_handler(), ShowSSLInterstitial()).Times(1);
84 EXPECT_CALL(error_handler(), ShowCaptivePortalInterstitial()).Times(0);
85 base::MessageLoop::current()->RunUntilIdle();
86
87 EXPECT_FALSE(error_handler().TimerRunning());
88 EXPECT_TRUE(error_handler().handled());
89
90 // Any captive portal result after the timer expired should be ignored.
91 error_handler().OnCaptivePortalResult();
92 EXPECT_CALL(error_handler(), ShowSSLInterstitial()).Times(0);
93 EXPECT_CALL(error_handler(), ShowCaptivePortalInterstitial()).Times(0);
94 }
95
96 TEST_F(SSLErrorHandlerTest,
97 ShouldShowCustomInterstitialOnCaptivePortalResult) {
98 EXPECT_FALSE(error_handler().TimerRunning());
99 EXPECT_CALL(error_handler(), CheckForCaptivePortal()).Times(1);
100 error_handler().Handle();
101
102 EXPECT_TRUE(error_handler().TimerRunning());
103 EXPECT_FALSE(error_handler().handled());
104 EXPECT_CALL(error_handler(), ShowSSLInterstitial()).Times(0);
105 EXPECT_CALL(error_handler(), ShowCaptivePortalInterstitial()).Times(1);
106 // Fake a captive portal result.
107 error_handler().OnCaptivePortalResult();
108 base::MessageLoop::current()->RunUntilIdle();
109
110 EXPECT_FALSE(error_handler().TimerRunning());
111 EXPECT_TRUE(error_handler().handled());
112
113 // Any captive portal result after the timer expired should be ignored.
114 error_handler().OnCaptivePortalResult();
115 EXPECT_CALL(error_handler(), ShowSSLInterstitial()).Times(0);
116 EXPECT_CALL(error_handler(), ShowCaptivePortalInterstitial()).Times(0);
117 }
118
119 TEST_F(SSLErrorHandlerTest,
120 ShouldShowSSLInterstitialOnTooEarlyCaptivePortalResult) {
121 EXPECT_FALSE(error_handler().TimerRunning());
122 EXPECT_CALL(error_handler(), CheckForCaptivePortal()).Times(1);
123
124 EXPECT_CALL(error_handler(), ShowSSLInterstitial()).Times(0);
125 EXPECT_CALL(error_handler(), ShowCaptivePortalInterstitial()).Times(0);
126 // A captive portal result arrives before error handler starts.
127 error_handler().OnCaptivePortalResult();
128
129 EXPECT_FALSE(error_handler().handled());
130 EXPECT_FALSE(error_handler().TimerRunning());
131
132 error_handler().Handle();
133
134 EXPECT_TRUE(error_handler().TimerRunning());
135 EXPECT_FALSE(error_handler().handled());
136 EXPECT_CALL(error_handler(), ShowSSLInterstitial()).Times(1);
137 EXPECT_CALL(error_handler(), ShowCaptivePortalInterstitial()).Times(0);
138 base::MessageLoop::current()->RunUntilIdle();
139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698