Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3595)

Unified Diff: chrome/renderer/content_settings_observer_browsertest.cc

Issue 7831075: Delegating the "are images allowed" decision to renderer. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Updated contentSettings.html. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/content_settings_observer_browsertest.cc
diff --git a/chrome/renderer/content_settings_observer_browsertest.cc b/chrome/renderer/content_settings_observer_browsertest.cc
index ceaaee1f19868bd091fef9fe82e06c1550a3fb47..932640772ee1e008d638a9f840d6bd03c8520bac 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);
+}
« chrome/renderer/content_settings_observer.cc ('K') | « chrome/renderer/content_settings_observer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698