OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/website_settings/website_settings.h" | 5 #include "chrome/browser/ui/website_settings/website_settings.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/content_settings/host_content_settings_map.h" | 11 #include "chrome/browser/content_settings/host_content_settings_map.h" |
12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 13 #include "chrome/browser/infobars/infobar_tab_helper.h" |
13 #include "chrome/browser/ui/website_settings/website_settings_ui.h" | 14 #include "chrome/browser/ui/website_settings/website_settings_ui.h" |
14 #include "chrome/common/content_settings.h" | 15 #include "chrome/common/content_settings.h" |
15 #include "chrome/common/content_settings_types.h" | 16 #include "chrome/common/content_settings_types.h" |
16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
17 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
18 #include "content/public/browser/cert_store.h" | 19 #include "content/public/browser/cert_store.h" |
19 #include "content/public/common/ssl_status.h" | 20 #include "content/public/common/ssl_status.h" |
20 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
21 #include "net/base/cert_status_flags.h" | 22 #include "net/base/cert_status_flags.h" |
22 #include "net/base/ssl_connection_status_flags.h" | 23 #include "net/base/ssl_connection_status_flags.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 }; | 66 }; |
66 | 67 |
67 class WebsiteSettingsTest : public ChromeRenderViewHostTestHarness { | 68 class WebsiteSettingsTest : public ChromeRenderViewHostTestHarness { |
68 public: | 69 public: |
69 WebsiteSettingsTest() | 70 WebsiteSettingsTest() |
70 : website_settings_(NULL), | 71 : website_settings_(NULL), |
71 mock_ui_(NULL), | 72 mock_ui_(NULL), |
72 cert_id_(0), | 73 cert_id_(0), |
73 browser_thread_(content::BrowserThread::UI, &message_loop_), | 74 browser_thread_(content::BrowserThread::UI, &message_loop_), |
74 tab_specific_content_settings_(NULL), | 75 tab_specific_content_settings_(NULL), |
| 76 infobar_tab_helper_(NULL), |
75 url_("http://www.example.com") { | 77 url_("http://www.example.com") { |
76 } | 78 } |
77 | 79 |
78 virtual ~WebsiteSettingsTest() { | 80 virtual ~WebsiteSettingsTest() { |
79 } | 81 } |
80 | 82 |
81 virtual void SetUp() { | 83 virtual void SetUp() { |
82 ChromeRenderViewHostTestHarness::SetUp(); | 84 ChromeRenderViewHostTestHarness::SetUp(); |
83 // Setup stub SSLStatus. | 85 // Setup stub SSLStatus. |
84 ssl_.security_style = content::SECURITY_STYLE_UNAUTHENTICATED; | 86 ssl_.security_style = content::SECURITY_STYLE_UNAUTHENTICATED; |
85 | 87 |
86 // Create the certificate. | 88 // Create the certificate. |
87 cert_id_ = 1; | 89 cert_id_ = 1; |
88 base::Time start_date = base::Time::Now(); | 90 base::Time start_date = base::Time::Now(); |
89 base::Time expiration_date = base::Time::FromInternalValue( | 91 base::Time expiration_date = base::Time::FromInternalValue( |
90 start_date.ToInternalValue() + base::Time::kMicrosecondsPerWeek); | 92 start_date.ToInternalValue() + base::Time::kMicrosecondsPerWeek); |
91 cert_ = new net::X509Certificate("subject", | 93 cert_ = new net::X509Certificate("subject", |
92 "issuer", | 94 "issuer", |
93 start_date, | 95 start_date, |
94 expiration_date); | 96 expiration_date); |
95 | 97 |
96 tab_specific_content_settings_.reset( | 98 tab_specific_content_settings_.reset( |
97 new TabSpecificContentSettings(contents())); | 99 new TabSpecificContentSettings(contents())); |
| 100 infobar_tab_helper_.reset(new InfoBarTabHelper(contents())); |
98 | 101 |
99 // Setup the mock cert store. | 102 // Setup the mock cert store. |
100 EXPECT_CALL(cert_store_, RetrieveCert(cert_id_, _) ) | 103 EXPECT_CALL(cert_store_, RetrieveCert(cert_id_, _) ) |
101 .Times(AnyNumber()) | 104 .Times(AnyNumber()) |
102 .WillRepeatedly(DoAll(SetArgPointee<1>(cert_), Return(true))); | 105 .WillRepeatedly(DoAll(SetArgPointee<1>(cert_), Return(true))); |
103 | 106 |
104 // Setup mock ui. | 107 // Setup mock ui. |
105 mock_ui_.reset(new MockWebsiteSettingsUI()); | 108 mock_ui_.reset(new MockWebsiteSettingsUI()); |
106 } | 109 } |
107 | 110 |
(...skipping 13 matching lines...) Expand all Loading... |
121 } | 124 } |
122 | 125 |
123 const GURL& url() const { return url_; } | 126 const GURL& url() const { return url_; } |
124 MockCertStore* cert_store() { return &cert_store_; } | 127 MockCertStore* cert_store() { return &cert_store_; } |
125 int cert_id() { return cert_id_; } | 128 int cert_id() { return cert_id_; } |
126 MockWebsiteSettingsUI* mock_ui() { return mock_ui_.get(); } | 129 MockWebsiteSettingsUI* mock_ui() { return mock_ui_.get(); } |
127 const SSLStatus& ssl() { return ssl_; } | 130 const SSLStatus& ssl() { return ssl_; } |
128 TabSpecificContentSettings* tab_specific_content_settings() { | 131 TabSpecificContentSettings* tab_specific_content_settings() { |
129 return tab_specific_content_settings_.get(); | 132 return tab_specific_content_settings_.get(); |
130 } | 133 } |
| 134 InfoBarTabHelper* infobar_tab_helper() { return infobar_tab_helper_.get(); } |
131 | 135 |
132 WebsiteSettings* website_settings() { | 136 WebsiteSettings* website_settings() { |
133 if (!website_settings_.get()) { | 137 if (!website_settings_.get()) { |
134 website_settings_.reset(new WebsiteSettings( | 138 website_settings_.reset(new WebsiteSettings( |
135 mock_ui(), profile(), tab_specific_content_settings_.get(), url(), | 139 mock_ui(), profile(), tab_specific_content_settings_.get(), |
136 ssl(), cert_store())); | 140 infobar_tab_helper_.get(), url(), ssl(), cert_store())); |
137 } | 141 } |
138 return website_settings_.get(); | 142 return website_settings_.get(); |
139 } | 143 } |
140 | 144 |
141 SSLStatus ssl_; | 145 SSLStatus ssl_; |
142 | 146 |
143 private: | 147 private: |
144 scoped_ptr<WebsiteSettings> website_settings_; | 148 scoped_ptr<WebsiteSettings> website_settings_; |
145 scoped_ptr<MockWebsiteSettingsUI> mock_ui_; | 149 scoped_ptr<MockWebsiteSettingsUI> mock_ui_; |
146 int cert_id_; | 150 int cert_id_; |
147 scoped_refptr<net::X509Certificate> cert_; | 151 scoped_refptr<net::X509Certificate> cert_; |
148 content::TestBrowserThread browser_thread_; | 152 content::TestBrowserThread browser_thread_; |
149 scoped_ptr<TabSpecificContentSettings> tab_specific_content_settings_; | 153 scoped_ptr<TabSpecificContentSettings> tab_specific_content_settings_; |
| 154 scoped_ptr<InfoBarTabHelper> infobar_tab_helper_; |
150 MockCertStore cert_store_; | 155 MockCertStore cert_store_; |
151 GURL url_; | 156 GURL url_; |
152 }; | 157 }; |
153 | 158 |
154 } // namespace | 159 } // namespace |
155 | 160 |
156 TEST_F(WebsiteSettingsTest, OnPermissionsChanged) { | 161 TEST_F(WebsiteSettingsTest, OnPermissionsChanged) { |
157 // Setup site permissions. | 162 // Setup site permissions. |
158 HostContentSettingsMap* content_settings = | 163 HostContentSettingsMap* content_settings = |
159 profile()->GetHostContentSettingsMap(); | 164 profile()->GetHostContentSettingsMap(); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 ssl_.connection_status = status; | 317 ssl_.connection_status = status; |
313 | 318 |
314 SetDefaultUIExpectations(mock_ui()); | 319 SetDefaultUIExpectations(mock_ui()); |
315 | 320 |
316 EXPECT_EQ(WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR, | 321 EXPECT_EQ(WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR, |
317 website_settings()->site_connection_status()); | 322 website_settings()->site_connection_status()); |
318 EXPECT_EQ(WebsiteSettings::SITE_IDENTITY_STATUS_CERT, | 323 EXPECT_EQ(WebsiteSettings::SITE_IDENTITY_STATUS_CERT, |
319 website_settings()->site_identity_status()); | 324 website_settings()->site_identity_status()); |
320 EXPECT_EQ(string16(), website_settings()->organization_name()); | 325 EXPECT_EQ(string16(), website_settings()->organization_name()); |
321 } | 326 } |
| 327 |
| 328 TEST_F(WebsiteSettingsTest, NoInfoBar) { |
| 329 SetDefaultUIExpectations(mock_ui()); |
| 330 EXPECT_EQ(0u, infobar_tab_helper()->infobar_count()); |
| 331 website_settings()->OnUIClosing(); |
| 332 EXPECT_EQ(0u, infobar_tab_helper()->infobar_count()); |
| 333 } |
| 334 |
| 335 TEST_F(WebsiteSettingsTest, ShowInfoBar) { |
| 336 SetDefaultUIExpectations(mock_ui()); |
| 337 EXPECT_EQ(0u, infobar_tab_helper()->infobar_count()); |
| 338 website_settings()->OnSitePermissionChanged( |
| 339 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW); |
| 340 website_settings()->OnUIClosing(); |
| 341 EXPECT_EQ(1u, infobar_tab_helper()->infobar_count()); |
| 342 |
| 343 infobar_tab_helper()->RemoveInfoBar( |
| 344 infobar_tab_helper()->GetInfoBarDelegateAt(0)); |
| 345 } |
OLD | NEW |