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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/test/simple_test_clock.h" | 9 #include "base/test/simple_test_clock.h" |
10 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 10 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
11 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 11 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
12 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 12 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" | 14 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
15 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" | |
16 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
20 #include "content/public/browser/ssl_host_state_delegate.h" | 19 #include "content/public/browser/ssl_host_state_delegate.h" |
21 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
22 #include "content/public/test/browser_test_utils.h" | 21 #include "content/public/test/browser_test_utils.h" |
23 #include "net/base/test_data_directory.h" | 22 #include "net/base/test_data_directory.h" |
24 #include "net/test/cert_test_util.h" | 23 #include "net/test/cert_test_util.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 125 EXPECT_EQ(net::CertPolicy::UNKNOWN, |
127 state->QueryPolicy( | 126 state->QueryPolicy( |
128 kGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID)); | 127 kGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID)); |
129 EXPECT_EQ( | 128 EXPECT_EQ( |
130 net::CertPolicy::DENIED, | 129 net::CertPolicy::DENIED, |
131 state->QueryPolicy( | 130 state->QueryPolicy( |
132 kExampleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID)); | 131 kExampleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID)); |
133 } | 132 } |
134 | 133 |
135 // HasPolicyAndRevoke unit tests the expected behavior of calling | 134 // HasPolicyAndRevoke unit tests the expected behavior of calling |
136 // HasUserDecision before and after calling RevokeUserDecisions on the | 135 // HasAllowedOrDeniedCert before and after calling RevokeAllowAndDenyPreferences |
137 // SSLHostStateDelegate class. | 136 // on the SSLHostStateDelegate class. |
138 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, HasPolicyAndRevoke) { | 137 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, HasPolicyAndRevoke) { |
139 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); | 138 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); |
140 content::WebContents* tab = | 139 content::WebContents* tab = |
141 browser()->tab_strip_model()->GetActiveWebContents(); | 140 browser()->tab_strip_model()->GetActiveWebContents(); |
142 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 141 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
143 ChromeSSLHostStateDelegate* state = | 142 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); |
144 ChromeSSLHostStateDelegateFactory::GetForProfile(profile); | |
145 | 143 |
146 // Simulate a user decision to allow an invalid certificate exception for | 144 // Simulate a user decision to allow an invalid certificate exception for |
147 // kWWWGoogleHost and for kExampleHost. | 145 // kWWWGoogleHost and for kExampleHost. |
148 state->AllowCert( | 146 state->AllowCert( |
149 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 147 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
150 state->AllowCert( | 148 state->AllowCert( |
151 kExampleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 149 kExampleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
152 | 150 |
153 // Verify that HasUserDecision correctly acknowledges that a user decision has | 151 // Verify that HasAllowedOrDeniedCert correctly acknowledges that a user |
154 // been made about kWWWGoogleHost. Then verify that HasUserDecision correctly | 152 // decision has been made about kWWWGoogleHost. Then verify that |
155 // identifies that the decision has been revoked. | 153 // HasAllowedOrDeniedCert correctly identifies that the decision has been |
156 EXPECT_TRUE(state->HasUserDecision(kWWWGoogleHost)); | 154 // revoked. |
157 state->RevokeUserDecisions(kWWWGoogleHost); | 155 EXPECT_TRUE(state->HasAllowedOrDeniedCert(kWWWGoogleHost)); |
158 EXPECT_FALSE(state->HasUserDecision(kWWWGoogleHost)); | 156 state->RevokeAllowAndDenyPreferences(kWWWGoogleHost); |
| 157 EXPECT_FALSE(state->HasAllowedOrDeniedCert(kWWWGoogleHost)); |
159 EXPECT_EQ( | 158 EXPECT_EQ( |
160 net::CertPolicy::UNKNOWN, | 159 net::CertPolicy::UNKNOWN, |
161 state->QueryPolicy( | 160 state->QueryPolicy( |
162 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID)); | 161 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID)); |
163 | 162 |
164 // Verify that the revocation of the kWWWGoogleHost decision does not affect | 163 // Verify that the revocation of the kWWWGoogleHost decision does not affect |
165 // the Allow for kExampleHost. | 164 // the Allow for kExampleHost. |
166 EXPECT_TRUE(state->HasUserDecision(kExampleHost)); | 165 EXPECT_TRUE(state->HasAllowedOrDeniedCert(kExampleHost)); |
167 | 166 |
168 // Verify the revocation of the kWWWGoogleHost decision does not affect the | 167 // Verify the revocation of the kWWWGoogleHost decision does not affect the |
169 // non-decision for kGoogleHost. Then verify that a revocation of a URL with | 168 // non-decision for kGoogleHost. Then verify that a revocation of a URL with |
170 // no decision has no effect. | 169 // no decision has no effect. |
171 EXPECT_FALSE(state->HasUserDecision(kGoogleHost)); | 170 EXPECT_FALSE(state->HasAllowedOrDeniedCert(kGoogleHost)); |
172 state->RevokeUserDecisions(kGoogleHost); | 171 state->RevokeAllowAndDenyPreferences(kGoogleHost); |
173 EXPECT_FALSE(state->HasUserDecision(kGoogleHost)); | 172 EXPECT_FALSE(state->HasAllowedOrDeniedCert(kGoogleHost)); |
174 } | 173 } |
175 | 174 |
176 // Clear unit tests the expected behavior of calling Clear to forget all cert | 175 // Clear unit tests the expected behavior of calling Clear to forget all cert |
177 // decision state on the SSLHostStateDelegate class. | 176 // decision state on the SSLHostStateDelegate class. |
178 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, Clear) { | 177 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, Clear) { |
179 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); | 178 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); |
180 content::WebContents* tab = | 179 content::WebContents* tab = |
181 browser()->tab_strip_model()->GetActiveWebContents(); | 180 browser()->tab_strip_model()->GetActiveWebContents(); |
182 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 181 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
183 ChromeSSLHostStateDelegate* state = | 182 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); |
184 ChromeSSLHostStateDelegateFactory::GetForProfile(profile); | |
185 | 183 |
186 // Simulate a user decision to allow an invalid certificate exception for | 184 // Simulate a user decision to allow an invalid certificate exception for |
187 // kWWWGoogleHost and for kExampleHost. | 185 // kWWWGoogleHost and for kExampleHost. |
188 state->AllowCert( | 186 state->AllowCert( |
189 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 187 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
190 | 188 |
191 // Do a full clear, then make sure that both kWWWGoogleHost, which had a | 189 // Do a full clear, then make sure that both kWWWGoogleHost, which had a |
192 // decision made, and kExampleHost, which was untouched, are now in a | 190 // decision made, and kExampleHost, which was untouched, are now in a |
193 // non-decision state. | 191 // non-decision state. |
194 state->Clear(); | 192 state->Clear(); |
195 EXPECT_FALSE(state->HasUserDecision(kWWWGoogleHost)); | 193 EXPECT_FALSE(state->HasAllowedOrDeniedCert(kWWWGoogleHost)); |
196 EXPECT_EQ( | 194 EXPECT_EQ( |
197 net::CertPolicy::UNKNOWN, | 195 net::CertPolicy::UNKNOWN, |
198 state->QueryPolicy( | 196 state->QueryPolicy( |
199 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID)); | 197 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID)); |
200 EXPECT_FALSE(state->HasUserDecision(kExampleHost)); | 198 EXPECT_FALSE(state->HasAllowedOrDeniedCert(kExampleHost)); |
201 EXPECT_EQ( | 199 EXPECT_EQ( |
202 net::CertPolicy::UNKNOWN, | 200 net::CertPolicy::UNKNOWN, |
203 state->QueryPolicy( | 201 state->QueryPolicy( |
204 kExampleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID)); | 202 kExampleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID)); |
205 } | 203 } |
206 | 204 |
207 // DidHostRunInsecureContent unit tests the expected behavior of calling | |
208 // DidHostRunInsecureContent as well as HostRanInsecureContent to check if | |
209 // insecure content has been run and to mark it as such. | |
210 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, | |
211 DidHostRunInsecureContent) { | |
212 content::WebContents* tab = | |
213 browser()->tab_strip_model()->GetActiveWebContents(); | |
214 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | |
215 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); | |
216 | |
217 EXPECT_FALSE(state->DidHostRunInsecureContent("www.google.com", 42)); | |
218 EXPECT_FALSE(state->DidHostRunInsecureContent("www.google.com", 191)); | |
219 EXPECT_FALSE(state->DidHostRunInsecureContent("example.com", 42)); | |
220 | |
221 state->HostRanInsecureContent("www.google.com", 42); | |
222 | |
223 EXPECT_TRUE(state->DidHostRunInsecureContent("www.google.com", 42)); | |
224 EXPECT_FALSE(state->DidHostRunInsecureContent("www.google.com", 191)); | |
225 EXPECT_FALSE(state->DidHostRunInsecureContent("example.com", 42)); | |
226 | |
227 state->HostRanInsecureContent("example.com", 42); | |
228 | |
229 EXPECT_TRUE(state->DidHostRunInsecureContent("www.google.com", 42)); | |
230 EXPECT_FALSE(state->DidHostRunInsecureContent("www.google.com", 191)); | |
231 EXPECT_TRUE(state->DidHostRunInsecureContent("example.com", 42)); | |
232 } | |
233 | |
234 // Tests the basic behavior of cert memory in incognito. | 205 // Tests the basic behavior of cert memory in incognito. |
235 class IncognitoSSLHostStateDelegateTest | 206 class IncognitoSSLHostStateDelegateTest |
236 : public ChromeSSLHostStateDelegateTest { | 207 : public ChromeSSLHostStateDelegateTest { |
237 protected: | 208 protected: |
238 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 209 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
239 ChromeSSLHostStateDelegateTest::SetUpCommandLine(command_line); | 210 ChromeSSLHostStateDelegateTest::SetUpCommandLine(command_line); |
240 command_line->AppendSwitchASCII(switches::kRememberCertErrorDecisions, | 211 command_line->AppendSwitchASCII(switches::kRememberCertErrorDecisions, |
241 kDeltaSecondsString); | 212 kDeltaSecondsString); |
242 } | 213 } |
243 }; | 214 }; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 | 441 |
471 // Add an exception for an invalid certificate. Then remove the last hour's | 442 // Add an exception for an invalid certificate. Then remove the last hour's |
472 // worth of browsing history and verify that the exception has been deleted. | 443 // worth of browsing history and verify that the exception has been deleted. |
473 state->AllowCert( | 444 state->AllowCert( |
474 kGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 445 kGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
475 RemoveAndWait(profile); | 446 RemoveAndWait(profile); |
476 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 447 EXPECT_EQ(net::CertPolicy::UNKNOWN, |
477 state->QueryPolicy( | 448 state->QueryPolicy( |
478 kGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID)); | 449 kGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID)); |
479 } | 450 } |
OLD | NEW |