| 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 bc11b17609a2235d5379ece7d565984112020c19..244088aa3059f8fba146a0dff6e3df515f5a400b 100644
|
| --- a/chrome/renderer/content_settings_observer_browsertest.cc
|
| +++ b/chrome/renderer/content_settings_observer_browsertest.cc
|
| @@ -2,6 +2,8 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include <vector>
|
| +
|
| #include "chrome/common/content_settings.h"
|
| #include "chrome/common/render_messages.h"
|
| #include "chrome/renderer/content_settings_observer.h"
|
| @@ -19,7 +21,9 @@ namespace {
|
|
|
| class MockContentSettingsObserver : public ContentSettingsObserver {
|
| public:
|
| - explicit MockContentSettingsObserver(content::RenderView* render_view);
|
| + explicit MockContentSettingsObserver(
|
| + content::RenderView* render_view,
|
| + const ContentSettingsForOneType* image_setting_rules_);
|
|
|
| virtual bool Send(IPC::Message* message);
|
|
|
| @@ -28,11 +32,16 @@ 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) {
|
| + content::RenderView* render_view,
|
| + const ContentSettingsForOneType* image_setting_rules)
|
| + : ContentSettingsObserver(render_view, image_setting_rules),
|
| + image_url_("http://www.foo.com/image.jpg"),
|
| + image_origin_("http://www.foo.com") {
|
| }
|
|
|
| bool MockContentSettingsObserver::Send(IPC::Message* message) {
|
| @@ -50,7 +59,7 @@ bool MockContentSettingsObserver::Send(IPC::Message* message) {
|
| } // namespace
|
|
|
| TEST_F(ChromeRenderViewTest, DidBlockContentType) {
|
| - MockContentSettingsObserver observer(view_);
|
| + MockContentSettingsObserver observer(view_, NULL);
|
| EXPECT_CALL(observer,
|
| OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
|
| observer.DidBlockContentType(CONTENT_SETTINGS_TYPE_COOKIES, std::string());
|
| @@ -74,7 +83,7 @@ TEST_F(ChromeRenderViewTest, DidBlockContentType) {
|
| TEST_F(ChromeRenderViewTest, AllowDOMStorage) {
|
| // Load some HTML, so we have a valid security origin.
|
| LoadHTML("<html></html>");
|
| - MockContentSettingsObserver observer(view_);
|
| + MockContentSettingsObserver observer(view_, NULL);
|
| ON_CALL(observer,
|
| OnAllowDOMStorage(_, _, _, _, _)).WillByDefault(DeleteArg<4>());
|
| EXPECT_CALL(observer,
|
| @@ -166,3 +175,80 @@ TEST_F(ChromeRenderViewTest, PluginsTemporarilyAllowed) {
|
| EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| observer->GetContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS));
|
| }
|
| +
|
| +TEST_F(ChromeRenderViewTest, ImagesBlockedByDefault) {
|
| + MockContentSettingsObserver mock_observer(view_, &image_setting_rules_);
|
| +
|
| + // Load some HTML.
|
| + LoadHTML("<html>Foo</html>");
|
| +
|
| + // Set the default image blocking setting.
|
| + image_setting_rules_.push_back(
|
| + ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
|
| + ContentSettingsPattern::Wildcard(),
|
| + CONTENT_SETTING_BLOCK,
|
| + "",
|
| + false));
|
| +
|
| + ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_);
|
| + 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_, &image_setting_rules_);
|
| +
|
| + // Load some HTML.
|
| + LoadHTML("<html>Foo</html>");
|
| +
|
| + // Set the default image blocking setting.
|
| + image_setting_rules_.push_back(
|
| + ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
|
| + ContentSettingsPattern::Wildcard(),
|
| + CONTENT_SETTING_ALLOW,
|
| + "",
|
| + false));
|
| +
|
| + ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_);
|
| + 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);
|
| +}
|
|
|