Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / website_settings / website_settings_unittest.cc
blob5eaba491ce31ac944c31461d0fd2cdbbd49fb6a7
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/website_settings/website_settings.h"
7 #include "base/at_exit.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/ui/website_settings/website_settings_ui.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "chrome/test/base/testing_profile.h"
16 #include "components/content_settings/core/browser/host_content_settings_map.h"
17 #include "components/content_settings/core/common/content_settings.h"
18 #include "components/content_settings/core/common/content_settings_types.h"
19 #include "components/infobars/core/infobar.h"
20 #include "content/public/browser/cert_store.h"
21 #include "content/public/common/ssl_status.h"
22 #include "grit/theme_resources.h"
23 #include "net/cert/cert_status_flags.h"
24 #include "net/cert/x509_certificate.h"
25 #include "net/ssl/ssl_connection_status_flags.h"
26 #include "net/test/test_certificate_data.h"
27 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h"
30 using content::SSLStatus;
31 using testing::_;
32 using testing::AnyNumber;
33 using testing::Return;
34 using testing::SetArgPointee;
36 namespace {
38 // SSL cipher suite like specified in RFC5246 Appendix A.5. "The Cipher Suite".
39 // Without the CR_ prefix, this clashes with the OS X 10.8 headers.
40 int CR_TLS_RSA_WITH_AES_256_CBC_SHA256 = 0x3D;
42 int SetSSLVersion(int connection_status, int version) {
43 // Clear SSL version bits (Bits 20, 21 and 22).
44 connection_status &=
45 ~(net::SSL_CONNECTION_VERSION_MASK << net::SSL_CONNECTION_VERSION_SHIFT);
46 int bitmask = version << net::SSL_CONNECTION_VERSION_SHIFT;
47 return bitmask | connection_status;
50 int SetSSLCipherSuite(int connection_status, int cipher_suite) {
51 // Clear cipher suite bits (the 16 lowest bits).
52 connection_status &= ~net::SSL_CONNECTION_CIPHERSUITE_MASK;
53 return cipher_suite | connection_status;
56 class MockCertStore : public content::CertStore {
57 public:
58 virtual ~MockCertStore() {}
59 MOCK_METHOD2(StoreCert, int(net::X509Certificate*, int));
60 MOCK_METHOD2(RetrieveCert, bool(int, scoped_refptr<net::X509Certificate>*));
63 class MockWebsiteSettingsUI : public WebsiteSettingsUI {
64 public:
65 virtual ~MockWebsiteSettingsUI() {}
66 MOCK_METHOD1(SetCookieInfo, void(const CookieInfoList& cookie_info_list));
67 MOCK_METHOD1(SetPermissionInfo,
68 void(const PermissionInfoList& permission_info_list));
69 MOCK_METHOD1(SetIdentityInfo, void(const IdentityInfo& identity_info));
70 MOCK_METHOD1(SetSelectedTab, void(TabId tab_id));
73 class WebsiteSettingsTest : public ChromeRenderViewHostTestHarness {
74 public:
75 WebsiteSettingsTest() : cert_id_(0), url_("http://www.example.com") {}
77 ~WebsiteSettingsTest() override {}
79 void SetUp() override {
80 ChromeRenderViewHostTestHarness::SetUp();
81 // Setup stub SSLStatus.
82 security_info_.security_level = SecurityStateModel::NONE;
84 // Create the certificate.
85 cert_id_ = 1;
86 base::Time start_date = base::Time::Now();
87 base::Time expiration_date = base::Time::FromInternalValue(
88 start_date.ToInternalValue() + base::Time::kMicrosecondsPerWeek);
89 cert_ = new net::X509Certificate("subject",
90 "issuer",
91 start_date,
92 expiration_date);
94 TabSpecificContentSettings::CreateForWebContents(web_contents());
95 InfoBarService::CreateForWebContents(web_contents());
97 // Setup the mock cert store.
98 EXPECT_CALL(cert_store_, RetrieveCert(cert_id_, _) )
99 .Times(AnyNumber())
100 .WillRepeatedly(DoAll(SetArgPointee<1>(cert_), Return(true)));
102 // Setup mock ui.
103 mock_ui_.reset(new MockWebsiteSettingsUI());
106 void TearDown() override {
107 ASSERT_TRUE(website_settings_.get())
108 << "No WebsiteSettings instance created.";
109 RenderViewHostTestHarness::TearDown();
110 website_settings_.reset();
113 void SetDefaultUIExpectations(MockWebsiteSettingsUI* mock_ui) {
114 // During creation |WebsiteSettings| makes the following calls to the ui.
115 EXPECT_CALL(*mock_ui, SetPermissionInfo(_));
116 EXPECT_CALL(*mock_ui, SetIdentityInfo(_));
117 EXPECT_CALL(*mock_ui, SetCookieInfo(_));
120 void SetURL(std::string url) { url_ = GURL(url); }
122 const GURL& url() const { return url_; }
123 MockCertStore* cert_store() { return &cert_store_; }
124 int cert_id() { return cert_id_; }
125 MockWebsiteSettingsUI* mock_ui() { return mock_ui_.get(); }
126 const SecurityStateModel::SecurityInfo& security_info() {
127 return security_info_;
129 TabSpecificContentSettings* tab_specific_content_settings() {
130 return TabSpecificContentSettings::FromWebContents(web_contents());
132 InfoBarService* infobar_service() {
133 return InfoBarService::FromWebContents(web_contents());
136 WebsiteSettings* website_settings() {
137 if (!website_settings_.get()) {
138 website_settings_.reset(new WebsiteSettings(
139 mock_ui(), profile(), tab_specific_content_settings(), web_contents(),
140 url(), security_info(), cert_store()));
142 return website_settings_.get();
145 SecurityStateModel::SecurityInfo security_info_;
147 private:
148 scoped_ptr<WebsiteSettings> website_settings_;
149 scoped_ptr<MockWebsiteSettingsUI> mock_ui_;
150 int cert_id_;
151 scoped_refptr<net::X509Certificate> cert_;
152 MockCertStore cert_store_;
153 GURL url_;
156 } // namespace
158 TEST_F(WebsiteSettingsTest, OnPermissionsChanged) {
159 // Setup site permissions.
160 HostContentSettingsMap* content_settings =
161 HostContentSettingsMapFactory::GetForProfile(profile());
162 ContentSetting setting = content_settings->GetContentSetting(
163 url(), url(), CONTENT_SETTINGS_TYPE_POPUPS, std::string());
164 EXPECT_EQ(setting, CONTENT_SETTING_BLOCK);
165 #if defined(ENABLE_PLUGINS)
166 setting = content_settings->GetContentSetting(
167 url(), url(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
168 EXPECT_EQ(setting, CONTENT_SETTING_ALLOW);
169 #endif
170 setting = content_settings->GetContentSetting(
171 url(), url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string());
172 EXPECT_EQ(setting, CONTENT_SETTING_ASK);
173 setting = content_settings->GetContentSetting(
174 url(), url(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string());
175 EXPECT_EQ(setting, CONTENT_SETTING_ASK);
176 setting = content_settings->GetContentSetting(
177 url(), url(), CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string());
178 EXPECT_EQ(setting, CONTENT_SETTING_ASK);
179 setting = content_settings->GetContentSetting(
180 url(), url(), CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string());
181 EXPECT_EQ(setting, CONTENT_SETTING_ASK);
183 EXPECT_CALL(*mock_ui(), SetIdentityInfo(_));
184 EXPECT_CALL(*mock_ui(), SetCookieInfo(_));
186 // SetPermissionInfo() is called once initially, and then again every time
187 // OnSitePermissionChanged() is called.
188 EXPECT_CALL(*mock_ui(), SetPermissionInfo(_)).Times(7);
189 EXPECT_CALL(*mock_ui(), SetSelectedTab(
190 WebsiteSettingsUI::TAB_ID_PERMISSIONS));
192 // Execute code under tests.
193 website_settings()->OnSitePermissionChanged(CONTENT_SETTINGS_TYPE_POPUPS,
194 CONTENT_SETTING_ALLOW);
195 website_settings()->OnSitePermissionChanged(CONTENT_SETTINGS_TYPE_PLUGINS,
196 CONTENT_SETTING_BLOCK);
197 website_settings()->OnSitePermissionChanged(CONTENT_SETTINGS_TYPE_GEOLOCATION,
198 CONTENT_SETTING_ALLOW);
199 website_settings()->OnSitePermissionChanged(
200 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
201 website_settings()->OnSitePermissionChanged(
202 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, CONTENT_SETTING_ALLOW);
203 website_settings()->OnSitePermissionChanged(
204 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, CONTENT_SETTING_ALLOW);
206 // Verify that the site permissions were changed correctly.
207 setting = content_settings->GetContentSetting(
208 url(), url(), CONTENT_SETTINGS_TYPE_POPUPS, std::string());
209 EXPECT_EQ(setting, CONTENT_SETTING_ALLOW);
210 setting = content_settings->GetContentSetting(
211 url(), url(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
212 EXPECT_EQ(setting, CONTENT_SETTING_BLOCK);
213 setting = content_settings->GetContentSetting(
214 url(), url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string());
215 EXPECT_EQ(setting, CONTENT_SETTING_ALLOW);
216 setting = content_settings->GetContentSetting(
217 url(), url(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string());
218 EXPECT_EQ(setting, CONTENT_SETTING_ALLOW);
219 setting = content_settings->GetContentSetting(
220 url(), url(), CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string());
221 EXPECT_EQ(setting, CONTENT_SETTING_ALLOW);
222 setting = content_settings->GetContentSetting(
223 url(), url(), CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string());
224 EXPECT_EQ(setting, CONTENT_SETTING_ALLOW);
227 TEST_F(WebsiteSettingsTest, OnPermissionsChanged_Fullscreen) {
228 // Setup site permissions.
229 HostContentSettingsMap* content_settings =
230 HostContentSettingsMapFactory::GetForProfile(profile());
231 ContentSetting setting = content_settings->GetContentSetting(
232 url(), url(), CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string());
233 EXPECT_EQ(setting, CONTENT_SETTING_ASK);
235 EXPECT_CALL(*mock_ui(), SetIdentityInfo(_));
236 EXPECT_CALL(*mock_ui(), SetCookieInfo(_));
237 EXPECT_CALL(*mock_ui(), SetSelectedTab(
238 WebsiteSettingsUI::TAB_ID_PERMISSIONS));
240 // SetPermissionInfo() is called once initially, and then again every time
241 // OnSitePermissionChanged() is called.
242 EXPECT_CALL(*mock_ui(), SetPermissionInfo(_)).Times(3);
244 // Execute code under tests.
245 website_settings()->OnSitePermissionChanged(CONTENT_SETTINGS_TYPE_FULLSCREEN,
246 CONTENT_SETTING_ALLOW);
248 // Verify that the site permissions were changed correctly.
249 setting = content_settings->GetContentSetting(
250 url(), url(), CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string());
251 EXPECT_EQ(setting, CONTENT_SETTING_ALLOW);
253 // ... and that the primary pattern must match the secondary one.
254 setting = content_settings->GetContentSetting(
255 url(), GURL("https://test.com"),
256 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string());
257 EXPECT_EQ(setting, CONTENT_SETTING_ASK);
260 // Resetting the setting should move the permission back to ASK.
261 website_settings()->OnSitePermissionChanged(CONTENT_SETTINGS_TYPE_FULLSCREEN,
262 CONTENT_SETTING_ASK);
264 setting = content_settings->GetContentSetting(
265 url(), url(), CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string());
266 EXPECT_EQ(setting, CONTENT_SETTING_ASK);
269 TEST_F(WebsiteSettingsTest, OnSiteDataAccessed) {
270 EXPECT_CALL(*mock_ui(), SetPermissionInfo(_));
271 EXPECT_CALL(*mock_ui(), SetIdentityInfo(_));
272 EXPECT_CALL(*mock_ui(), SetCookieInfo(_)).Times(2);
273 EXPECT_CALL(*mock_ui(), SetSelectedTab(
274 WebsiteSettingsUI::TAB_ID_PERMISSIONS));
276 website_settings()->OnSiteDataAccessed();
279 TEST_F(WebsiteSettingsTest, HTTPConnection) {
280 SetDefaultUIExpectations(mock_ui());
281 EXPECT_CALL(*mock_ui(), SetSelectedTab(
282 WebsiteSettingsUI::TAB_ID_PERMISSIONS));
283 EXPECT_EQ(WebsiteSettings::SITE_CONNECTION_STATUS_UNENCRYPTED,
284 website_settings()->site_connection_status());
285 EXPECT_EQ(WebsiteSettings::SITE_IDENTITY_STATUS_NO_CERT,
286 website_settings()->site_identity_status());
287 EXPECT_EQ(base::string16(), website_settings()->organization_name());
290 TEST_F(WebsiteSettingsTest, HTTPSConnection) {
291 security_info_.security_level = SecurityStateModel::SECURE;
292 security_info_.scheme_is_cryptographic = true;
293 security_info_.cert_id = cert_id();
294 security_info_.cert_status = 0;
295 security_info_.security_bits = 81; // No error if > 80.
296 int status = 0;
297 status = SetSSLVersion(status, net::SSL_CONNECTION_VERSION_TLS1);
298 status = SetSSLCipherSuite(status, CR_TLS_RSA_WITH_AES_256_CBC_SHA256);
299 security_info_.connection_status = status;
301 SetDefaultUIExpectations(mock_ui());
302 EXPECT_CALL(*mock_ui(), SetSelectedTab(
303 WebsiteSettingsUI::TAB_ID_PERMISSIONS));
305 EXPECT_EQ(WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED,
306 website_settings()->site_connection_status());
307 EXPECT_EQ(WebsiteSettings::SITE_IDENTITY_STATUS_CERT,
308 website_settings()->site_identity_status());
309 EXPECT_EQ(base::string16(), website_settings()->organization_name());
312 TEST_F(WebsiteSettingsTest, HTTPSPassiveMixedContent) {
313 security_info_.security_level = SecurityStateModel::NONE;
314 security_info_.scheme_is_cryptographic = true;
315 security_info_.cert_id = cert_id();
316 security_info_.cert_status = 0;
317 security_info_.security_bits = 81; // No error if > 80.
318 security_info_.mixed_content_status =
319 SecurityStateModel::DISPLAYED_MIXED_CONTENT;
320 int status = 0;
321 status = SetSSLVersion(status, net::SSL_CONNECTION_VERSION_TLS1);
322 status = SetSSLCipherSuite(status, CR_TLS_RSA_WITH_AES_256_CBC_SHA256);
323 security_info_.connection_status = status;
325 SetDefaultUIExpectations(mock_ui());
326 EXPECT_CALL(*mock_ui(), SetSelectedTab(WebsiteSettingsUI::TAB_ID_CONNECTION));
328 EXPECT_EQ(WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_CONTENT,
329 website_settings()->site_connection_status());
330 EXPECT_EQ(WebsiteSettings::SITE_IDENTITY_STATUS_CERT,
331 website_settings()->site_identity_status());
332 EXPECT_EQ(IDR_PAGEINFO_WARNING_MINOR,
333 WebsiteSettingsUI::GetConnectionIconID(
334 website_settings()->site_connection_status()));
335 EXPECT_EQ(base::string16(), website_settings()->organization_name());
338 TEST_F(WebsiteSettingsTest, HTTPSActiveMixedContent) {
339 security_info_.security_level = SecurityStateModel::SECURITY_ERROR;
340 security_info_.scheme_is_cryptographic = true;
341 security_info_.cert_id = cert_id();
342 security_info_.cert_status = 0;
343 security_info_.security_bits = 81; // No error if > 80.
344 security_info_.mixed_content_status =
345 SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT;
346 int status = 0;
347 status = SetSSLVersion(status, net::SSL_CONNECTION_VERSION_TLS1);
348 status = SetSSLCipherSuite(status, CR_TLS_RSA_WITH_AES_256_CBC_SHA256);
349 security_info_.connection_status = status;
351 SetDefaultUIExpectations(mock_ui());
352 EXPECT_CALL(*mock_ui(), SetSelectedTab(WebsiteSettingsUI::TAB_ID_CONNECTION));
354 EXPECT_EQ(WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_SCRIPT,
355 website_settings()->site_connection_status());
356 EXPECT_EQ(WebsiteSettings::SITE_IDENTITY_STATUS_CERT,
357 website_settings()->site_identity_status());
358 EXPECT_EQ(IDR_PAGEINFO_BAD,
359 WebsiteSettingsUI::GetConnectionIconID(
360 website_settings()->site_connection_status()));
361 EXPECT_EQ(base::string16(), website_settings()->organization_name());
364 TEST_F(WebsiteSettingsTest, HTTPSEVCert) {
365 scoped_refptr<net::X509Certificate> ev_cert =
366 net::X509Certificate::CreateFromBytes(
367 reinterpret_cast<const char*>(google_der),
368 sizeof(google_der));
369 int ev_cert_id = 1;
370 EXPECT_CALL(*cert_store(), RetrieveCert(ev_cert_id, _)).WillRepeatedly(
371 DoAll(SetArgPointee<1>(ev_cert), Return(true)));
373 security_info_.security_level = SecurityStateModel::NONE;
374 security_info_.scheme_is_cryptographic = true;
375 security_info_.cert_id = ev_cert_id;
376 security_info_.cert_status = net::CERT_STATUS_IS_EV;
377 security_info_.security_bits = 81; // No error if > 80.
378 security_info_.mixed_content_status =
379 SecurityStateModel::DISPLAYED_MIXED_CONTENT;
380 int status = 0;
381 status = SetSSLVersion(status, net::SSL_CONNECTION_VERSION_TLS1);
382 status = SetSSLCipherSuite(status, CR_TLS_RSA_WITH_AES_256_CBC_SHA256);
383 security_info_.connection_status = status;
385 SetDefaultUIExpectations(mock_ui());
386 EXPECT_CALL(*mock_ui(), SetSelectedTab(WebsiteSettingsUI::TAB_ID_CONNECTION));
388 EXPECT_EQ(WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_CONTENT,
389 website_settings()->site_connection_status());
390 EXPECT_EQ(WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT,
391 website_settings()->site_identity_status());
392 EXPECT_EQ(base::UTF8ToUTF16("Google Inc"),
393 website_settings()->organization_name());
396 TEST_F(WebsiteSettingsTest, HTTPSRevocationError) {
397 security_info_.security_level = SecurityStateModel::SECURE;
398 security_info_.scheme_is_cryptographic = true;
399 security_info_.cert_id = cert_id();
400 security_info_.cert_status = net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION;
401 security_info_.security_bits = 81; // No error if > 80.
402 int status = 0;
403 status = SetSSLVersion(status, net::SSL_CONNECTION_VERSION_TLS1);
404 status = SetSSLCipherSuite(status, CR_TLS_RSA_WITH_AES_256_CBC_SHA256);
405 security_info_.connection_status = status;
407 SetDefaultUIExpectations(mock_ui());
408 EXPECT_CALL(*mock_ui(), SetSelectedTab(WebsiteSettingsUI::TAB_ID_CONNECTION));
410 EXPECT_EQ(WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED,
411 website_settings()->site_connection_status());
412 EXPECT_EQ(WebsiteSettings::SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN,
413 website_settings()->site_identity_status());
414 EXPECT_EQ(base::string16(), website_settings()->organization_name());
417 TEST_F(WebsiteSettingsTest, HTTPSConnectionError) {
418 security_info_.security_level = SecurityStateModel::SECURE;
419 security_info_.scheme_is_cryptographic = true;
420 security_info_.cert_id = cert_id();
421 security_info_.cert_status = 0;
422 security_info_.security_bits = -1;
423 int status = 0;
424 status = SetSSLVersion(status, net::SSL_CONNECTION_VERSION_TLS1);
425 status = SetSSLCipherSuite(status, CR_TLS_RSA_WITH_AES_256_CBC_SHA256);
426 security_info_.connection_status = status;
428 SetDefaultUIExpectations(mock_ui());
429 EXPECT_CALL(*mock_ui(), SetSelectedTab(WebsiteSettingsUI::TAB_ID_CONNECTION));
431 EXPECT_EQ(WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR,
432 website_settings()->site_connection_status());
433 EXPECT_EQ(WebsiteSettings::SITE_IDENTITY_STATUS_CERT,
434 website_settings()->site_identity_status());
435 EXPECT_EQ(base::string16(), website_settings()->organization_name());
438 TEST_F(WebsiteSettingsTest, HTTPSPolicyCertConnection) {
439 security_info_.security_level = SecurityStateModel::SECURITY_POLICY_WARNING;
440 security_info_.scheme_is_cryptographic = true;
441 security_info_.cert_id = cert_id();
442 security_info_.cert_status = 0;
443 security_info_.security_bits = 81; // No error if > 80.
444 int status = 0;
445 status = SetSSLVersion(status, net::SSL_CONNECTION_VERSION_TLS1);
446 status = SetSSLCipherSuite(status, CR_TLS_RSA_WITH_AES_256_CBC_SHA256);
447 security_info_.connection_status = status;
449 SetDefaultUIExpectations(mock_ui());
450 EXPECT_CALL(*mock_ui(), SetSelectedTab(WebsiteSettingsUI::TAB_ID_CONNECTION));
452 EXPECT_EQ(WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED,
453 website_settings()->site_connection_status());
454 EXPECT_EQ(WebsiteSettings::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT,
455 website_settings()->site_identity_status());
456 EXPECT_EQ(base::string16(), website_settings()->organization_name());
459 TEST_F(WebsiteSettingsTest, HTTPSSHA1Connection) {
460 security_info_.security_level = SecurityStateModel::NONE;
461 security_info_.scheme_is_cryptographic = true;
462 security_info_.cert_id = cert_id();
463 security_info_.cert_status = 0;
464 security_info_.security_bits = 81; // No error if > 80.
465 int status = 0;
466 status = SetSSLVersion(status, net::SSL_CONNECTION_VERSION_TLS1);
467 status = SetSSLCipherSuite(status, CR_TLS_RSA_WITH_AES_256_CBC_SHA256);
468 security_info_.connection_status = status;
469 security_info_.sha1_deprecation_status =
470 SecurityStateModel::DEPRECATED_SHA1_WARNING;
472 SetDefaultUIExpectations(mock_ui());
473 EXPECT_CALL(*mock_ui(), SetSelectedTab(WebsiteSettingsUI::TAB_ID_CONNECTION));
475 EXPECT_EQ(WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED,
476 website_settings()->site_connection_status());
477 EXPECT_EQ(
478 WebsiteSettings::SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM,
479 website_settings()->site_identity_status());
480 EXPECT_EQ(base::string16(), website_settings()->organization_name());
483 #if !defined(OS_ANDROID)
484 TEST_F(WebsiteSettingsTest, NoInfoBar) {
485 SetDefaultUIExpectations(mock_ui());
486 EXPECT_CALL(*mock_ui(), SetSelectedTab(
487 WebsiteSettingsUI::TAB_ID_PERMISSIONS));
488 EXPECT_EQ(0u, infobar_service()->infobar_count());
489 website_settings()->OnUIClosing();
490 EXPECT_EQ(0u, infobar_service()->infobar_count());
493 TEST_F(WebsiteSettingsTest, ShowInfoBar) {
494 EXPECT_CALL(*mock_ui(), SetIdentityInfo(_));
495 EXPECT_CALL(*mock_ui(), SetCookieInfo(_));
497 EXPECT_CALL(*mock_ui(), SetPermissionInfo(_)).Times(2);
499 EXPECT_CALL(*mock_ui(), SetSelectedTab(
500 WebsiteSettingsUI::TAB_ID_PERMISSIONS));
501 EXPECT_EQ(0u, infobar_service()->infobar_count());
502 website_settings()->OnSitePermissionChanged(
503 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW);
504 website_settings()->OnUIClosing();
505 ASSERT_EQ(1u, infobar_service()->infobar_count());
507 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0));
509 #endif
511 TEST_F(WebsiteSettingsTest, AboutBlankPage) {
512 SetURL("about:blank");
513 SetDefaultUIExpectations(mock_ui());
514 EXPECT_EQ(WebsiteSettings::SITE_CONNECTION_STATUS_INTERNAL_PAGE,
515 website_settings()->site_connection_status());
516 EXPECT_EQ(WebsiteSettings::SITE_IDENTITY_STATUS_INTERNAL_PAGE,
517 website_settings()->site_identity_status());
518 EXPECT_EQ(base::string16(), website_settings()->organization_name());
521 TEST_F(WebsiteSettingsTest, InternalPage) {
522 SetURL("chrome://bookmarks");
523 SetDefaultUIExpectations(mock_ui());
524 EXPECT_EQ(WebsiteSettings::SITE_CONNECTION_STATUS_INTERNAL_PAGE,
525 website_settings()->site_connection_status());
526 EXPECT_EQ(WebsiteSettings::SITE_IDENTITY_STATUS_INTERNAL_PAGE,
527 website_settings()->site_identity_status());
528 EXPECT_EQ(base::string16(), website_settings()->organization_name());