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