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/common/chrome_content_settings_client.h" |
5 #include "chrome/common/content_settings.h" | 6 #include "chrome/common/content_settings.h" |
6 #include "chrome/common/render_messages.h" | 7 #include "chrome/common/render_messages.h" |
7 #include "chrome/renderer/content_settings_observer.h" | 8 #include "chrome/renderer/content_settings_observer.h" |
8 #include "chrome/test/base/chrome_render_view_test.h" | 9 #include "chrome/test/base/chrome_render_view_test.h" |
9 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
10 #include "ipc/ipc_message_macros.h" | 11 #include "ipc/ipc_message_macros.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/WebKit/public/web/WebView.h" | 14 #include "third_party/WebKit/public/web/WebView.h" |
14 | 15 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 188 |
188 ContentSettingsObserver* observer = ContentSettingsObserver::Get( | 189 ContentSettingsObserver* observer = ContentSettingsObserver::Get( |
189 view_->GetMainRenderFrame()); | 190 view_->GetMainRenderFrame()); |
190 observer->SetContentSettingRules(&content_setting_rules); | 191 observer->SetContentSettingRules(&content_setting_rules); |
191 EXPECT_CALL(mock_observer, | 192 EXPECT_CALL(mock_observer, |
192 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)); | 193 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)); |
193 EXPECT_FALSE(observer->allowImage(true, mock_observer.image_url_)); | 194 EXPECT_FALSE(observer->allowImage(true, mock_observer.image_url_)); |
194 ::testing::Mock::VerifyAndClearExpectations(&observer); | 195 ::testing::Mock::VerifyAndClearExpectations(&observer); |
195 | 196 |
196 // Create an exception which allows the image. | 197 // Create an exception which allows the image. |
| 198 content_settings::ChromeContentSettingsClient client; |
197 image_setting_rules.insert( | 199 image_setting_rules.insert( |
198 image_setting_rules.begin(), | 200 image_setting_rules.begin(), |
199 ContentSettingPatternSource( | 201 ContentSettingPatternSource( |
200 ContentSettingsPattern::Wildcard(), | 202 ContentSettingsPattern::Wildcard(), |
201 ContentSettingsPattern::FromString(mock_observer.image_origin_), | 203 ContentSettingsPattern::FromString(&client, |
| 204 mock_observer.image_origin_), |
202 CONTENT_SETTING_ALLOW, | 205 CONTENT_SETTING_ALLOW, |
203 std::string(), | 206 std::string(), |
204 false)); | 207 false)); |
205 | 208 |
206 EXPECT_CALL( | 209 EXPECT_CALL( |
207 mock_observer, | 210 mock_observer, |
208 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); | 211 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); |
209 EXPECT_TRUE(observer->allowImage(true, mock_observer.image_url_)); | 212 EXPECT_TRUE(observer->allowImage(true, mock_observer.image_url_)); |
210 ::testing::Mock::VerifyAndClearExpectations(&observer); | 213 ::testing::Mock::VerifyAndClearExpectations(&observer); |
211 } | 214 } |
(...skipping 18 matching lines...) Expand all Loading... |
230 ContentSettingsObserver* observer = | 233 ContentSettingsObserver* observer = |
231 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); | 234 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); |
232 observer->SetContentSettingRules(&content_setting_rules); | 235 observer->SetContentSettingRules(&content_setting_rules); |
233 EXPECT_CALL( | 236 EXPECT_CALL( |
234 mock_observer, | 237 mock_observer, |
235 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); | 238 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); |
236 EXPECT_TRUE(observer->allowImage(true, mock_observer.image_url_)); | 239 EXPECT_TRUE(observer->allowImage(true, mock_observer.image_url_)); |
237 ::testing::Mock::VerifyAndClearExpectations(&observer); | 240 ::testing::Mock::VerifyAndClearExpectations(&observer); |
238 | 241 |
239 // Create an exception which blocks the image. | 242 // Create an exception which blocks the image. |
| 243 content_settings::ChromeContentSettingsClient client; |
240 image_setting_rules.insert( | 244 image_setting_rules.insert( |
241 image_setting_rules.begin(), | 245 image_setting_rules.begin(), |
242 ContentSettingPatternSource( | 246 ContentSettingPatternSource( |
243 ContentSettingsPattern::Wildcard(), | 247 ContentSettingsPattern::Wildcard(), |
244 ContentSettingsPattern::FromString(mock_observer.image_origin_), | 248 ContentSettingsPattern::FromString(&client, |
| 249 mock_observer.image_origin_), |
245 CONTENT_SETTING_BLOCK, | 250 CONTENT_SETTING_BLOCK, |
246 std::string(), | 251 std::string(), |
247 false)); | 252 false)); |
248 EXPECT_CALL(mock_observer, | 253 EXPECT_CALL(mock_observer, |
249 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)); | 254 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)); |
250 EXPECT_FALSE(observer->allowImage(true, mock_observer.image_url_)); | 255 EXPECT_FALSE(observer->allowImage(true, mock_observer.image_url_)); |
251 ::testing::Mock::VerifyAndClearExpectations(&observer); | 256 ::testing::Mock::VerifyAndClearExpectations(&observer); |
252 } | 257 } |
253 | 258 |
254 TEST_F(ChromeRenderViewTest, ContentSettingsBlockScripts) { | 259 TEST_F(ChromeRenderViewTest, ContentSettingsBlockScripts) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 } | 374 } |
370 EXPECT_FALSE(was_blocked); | 375 EXPECT_FALSE(was_blocked); |
371 | 376 |
372 // Verify that images are allowed. | 377 // Verify that images are allowed. |
373 EXPECT_CALL( | 378 EXPECT_CALL( |
374 mock_observer, | 379 mock_observer, |
375 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); | 380 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); |
376 EXPECT_TRUE(observer->allowImage(true, mock_observer.image_url_)); | 381 EXPECT_TRUE(observer->allowImage(true, mock_observer.image_url_)); |
377 ::testing::Mock::VerifyAndClearExpectations(&observer); | 382 ::testing::Mock::VerifyAndClearExpectations(&observer); |
378 } | 383 } |
OLD | NEW |