summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/content_settings_observer_browsertest.cc
diff options
context:
space:
mode:
authormarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-27 13:43:42 +0000
committermarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-27 13:43:42 +0000
commitc144060968bce7873e4079bd2293272fe03b520f (patch)
tree6d1f7cc551e53d2626ff522ec46adb18da6c991c /chrome/renderer/content_settings_observer_browsertest.cc
parent78d4939cf2732a79ff823a0b00938e6aef77cf97 (diff)
downloadchromium_src-c144060968bce7873e4079bd2293272fe03b520f.zip
chromium_src-c144060968bce7873e4079bd2293272fe03b520f.tar.gz
chromium_src-c144060968bce7873e4079bd2293272fe03b520f.tar.bz2
Delegating the "are images allowed" decision to renderer.
This enables making the decision based on both image url and the page url. E.g., blocking third-party images. BUG=81179 TEST=RenderViewTest.ImagesBlockedByDefault, RenderViewTest.ImagesAllowedByDefault Review URL: http://codereview.chromium.org/7831075 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107562 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/content_settings_observer_browsertest.cc')
-rw-r--r--chrome/renderer/content_settings_observer_browsertest.cc87
1 files changed, 86 insertions, 1 deletions
diff --git a/chrome/renderer/content_settings_observer_browsertest.cc b/chrome/renderer/content_settings_observer_browsertest.cc
index ceaaee1..9326407 100644
--- a/chrome/renderer/content_settings_observer_browsertest.cc
+++ b/chrome/renderer/content_settings_observer_browsertest.cc
@@ -28,11 +28,15 @@ class MockContentSettingsObserver : public ContentSettingsObserver {
MOCK_METHOD5(OnAllowDOMStorage,
void(int, const GURL&, const GURL&, bool, IPC::Message*));
+ GURL image_url_;
+ std::string image_origin_;
};
MockContentSettingsObserver::MockContentSettingsObserver(
content::RenderView* render_view)
- : ContentSettingsObserver(render_view) {
+ : ContentSettingsObserver(render_view),
+ image_url_("http://www.foo.com/image.jpg"),
+ image_origin_("http://www.foo.com") {
}
bool MockContentSettingsObserver::Send(IPC::Message* message) {
@@ -162,3 +166,84 @@ TEST_F(ChromeRenderViewTest, PluginsTemporarilyAllowed) {
LoadHTML("<html>Bar</html>");
EXPECT_FALSE(observer->plugins_temporarily_allowed());
}
+
+TEST_F(ChromeRenderViewTest, ImagesBlockedByDefault) {
+ MockContentSettingsObserver mock_observer(view_);
+
+ // Load some HTML.
+ LoadHTML("<html>Foo</html>");
+
+ // Set the default image blocking setting.
+ ContentSettingsForOneType image_setting_rules;
+ image_setting_rules.push_back(
+ ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTING_BLOCK,
+ "",
+ false));
+
+ ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_);
+ observer->SetImageSettingRules(&image_setting_rules);
+ EXPECT_CALL(mock_observer,
+ OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
+ EXPECT_FALSE(observer->AllowImage(GetMainFrame(),
+ true, mock_observer.image_url_));
+ ::testing::Mock::VerifyAndClearExpectations(&observer);
+
+ // Create an exception which allows the image.
+ image_setting_rules.insert(
+ image_setting_rules.begin(),
+ ContentSettingPatternSource(
+ ContentSettingsPattern::Wildcard(),
+ ContentSettingsPattern::FromString(mock_observer.image_origin_),
+ CONTENT_SETTING_ALLOW,
+ "",
+ false));
+
+ EXPECT_CALL(
+ mock_observer,
+ OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string())).Times(0);
+ EXPECT_TRUE(observer->AllowImage(GetMainFrame(), true,
+ mock_observer.image_url_));
+ ::testing::Mock::VerifyAndClearExpectations(&observer);
+}
+
+TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) {
+ MockContentSettingsObserver mock_observer(view_);
+
+ // Load some HTML.
+ LoadHTML("<html>Foo</html>");
+
+ // Set the default image blocking setting.
+ ContentSettingsForOneType image_setting_rules;
+ image_setting_rules.push_back(
+ ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTING_ALLOW,
+ "",
+ false));
+
+ ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_);
+ observer->SetImageSettingRules(&image_setting_rules);
+ EXPECT_CALL(
+ mock_observer,
+ OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string())).Times(0);
+ EXPECT_TRUE(observer->AllowImage(GetMainFrame(), true,
+ mock_observer.image_url_));
+ ::testing::Mock::VerifyAndClearExpectations(&observer);
+
+ // Create an exception which blocks the image.
+ image_setting_rules.insert(
+ image_setting_rules.begin(),
+ ContentSettingPatternSource(
+ ContentSettingsPattern::Wildcard(),
+ ContentSettingsPattern::FromString(mock_observer.image_origin_),
+ CONTENT_SETTING_BLOCK,
+ "",
+ false));
+ EXPECT_CALL(mock_observer,
+ OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
+ EXPECT_FALSE(observer->AllowImage(GetMainFrame(),
+ true, mock_observer.image_url_));
+ ::testing::Mock::VerifyAndClearExpectations(&observer);
+}