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/content_settings.h" | 5 #include "chrome/common/content_settings.h" |
6 #include "chrome/common/render_messages.h" | 6 #include "chrome/common/render_messages.h" |
7 #include "chrome/renderer/content_settings_observer.h" | 7 #include "chrome/renderer/content_settings_observer.h" |
8 #include "chrome/test/base/chrome_render_view_test.h" | 8 #include "chrome/test/base/chrome_render_view_test.h" |
9 #include "content/public/renderer/render_view.h" | 9 #include "content/public/renderer/render_view.h" |
| 10 #include "extensions/common/constants.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 |
15 using testing::_; | 16 using testing::_; |
16 using testing::DeleteArg; | 17 using testing::DeleteArg; |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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. |
197 image_setting_rules.insert( | 198 image_setting_rules.insert( |
198 image_setting_rules.begin(), | 199 image_setting_rules.begin(), |
199 ContentSettingPatternSource( | 200 ContentSettingPatternSource( |
200 ContentSettingsPattern::Wildcard(), | 201 ContentSettingsPattern::Wildcard(), |
201 ContentSettingsPattern::FromString(mock_observer.image_origin_), | 202 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 203 mock_observer.image_origin_), |
202 CONTENT_SETTING_ALLOW, | 204 CONTENT_SETTING_ALLOW, |
203 std::string(), | 205 std::string(), |
204 false)); | 206 false)); |
205 | 207 |
206 EXPECT_CALL( | 208 EXPECT_CALL( |
207 mock_observer, | 209 mock_observer, |
208 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); | 210 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); |
209 EXPECT_TRUE(observer->allowImage(true, mock_observer.image_url_)); | 211 EXPECT_TRUE(observer->allowImage(true, mock_observer.image_url_)); |
210 ::testing::Mock::VerifyAndClearExpectations(&observer); | 212 ::testing::Mock::VerifyAndClearExpectations(&observer); |
211 } | 213 } |
(...skipping 22 matching lines...) Expand all Loading... |
234 mock_observer, | 236 mock_observer, |
235 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); | 237 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); |
236 EXPECT_TRUE(observer->allowImage(true, mock_observer.image_url_)); | 238 EXPECT_TRUE(observer->allowImage(true, mock_observer.image_url_)); |
237 ::testing::Mock::VerifyAndClearExpectations(&observer); | 239 ::testing::Mock::VerifyAndClearExpectations(&observer); |
238 | 240 |
239 // Create an exception which blocks the image. | 241 // Create an exception which blocks the image. |
240 image_setting_rules.insert( | 242 image_setting_rules.insert( |
241 image_setting_rules.begin(), | 243 image_setting_rules.begin(), |
242 ContentSettingPatternSource( | 244 ContentSettingPatternSource( |
243 ContentSettingsPattern::Wildcard(), | 245 ContentSettingsPattern::Wildcard(), |
244 ContentSettingsPattern::FromString(mock_observer.image_origin_), | 246 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 247 mock_observer.image_origin_), |
245 CONTENT_SETTING_BLOCK, | 248 CONTENT_SETTING_BLOCK, |
246 std::string(), | 249 std::string(), |
247 false)); | 250 false)); |
248 EXPECT_CALL(mock_observer, | 251 EXPECT_CALL(mock_observer, |
249 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)); | 252 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)); |
250 EXPECT_FALSE(observer->allowImage(true, mock_observer.image_url_)); | 253 EXPECT_FALSE(observer->allowImage(true, mock_observer.image_url_)); |
251 ::testing::Mock::VerifyAndClearExpectations(&observer); | 254 ::testing::Mock::VerifyAndClearExpectations(&observer); |
252 } | 255 } |
253 | 256 |
254 TEST_F(ChromeRenderViewTest, ContentSettingsBlockScripts) { | 257 TEST_F(ChromeRenderViewTest, ContentSettingsBlockScripts) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 } | 372 } |
370 EXPECT_FALSE(was_blocked); | 373 EXPECT_FALSE(was_blocked); |
371 | 374 |
372 // Verify that images are allowed. | 375 // Verify that images are allowed. |
373 EXPECT_CALL( | 376 EXPECT_CALL( |
374 mock_observer, | 377 mock_observer, |
375 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); | 378 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); |
376 EXPECT_TRUE(observer->allowImage(true, mock_observer.image_url_)); | 379 EXPECT_TRUE(observer->allowImage(true, mock_observer.image_url_)); |
377 ::testing::Mock::VerifyAndClearExpectations(&observer); | 380 ::testing::Mock::VerifyAndClearExpectations(&observer); |
378 } | 381 } |
OLD | NEW |