| 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 5bbed1f469ed84c29499ae8240ffd302fb43ca42..6f38599a76bc1a594187ede535a04610125c5580 100644
|
| --- a/chrome/renderer/content_settings_observer_browsertest.cc
|
| +++ b/chrome/renderer/content_settings_observer_browsertest.cc
|
| @@ -28,15 +28,17 @@ class MockContentSettingsObserver : public ContentSettingsObserver {
|
|
|
| MOCK_METHOD5(OnAllowDOMStorage,
|
| void(int, const GURL&, const GURL&, bool, IPC::Message*));
|
| - GURL image_url_;
|
| - std::string image_origin_;
|
| + GURL image_url_, media_url_;
|
| + std::string image_origin_, media_origin_;
|
| };
|
|
|
| MockContentSettingsObserver::MockContentSettingsObserver(
|
| content::RenderFrame* render_frame)
|
| : ContentSettingsObserver(render_frame, NULL),
|
| image_url_("http://www.foo.com/image.jpg"),
|
| - image_origin_("http://www.foo.com") {
|
| + media_url_("http://www.bar.com/video.webm"),
|
| + image_origin_("http://www.foo.com"),
|
| + media_origin_("http://www.bar.com") {
|
| }
|
|
|
| bool MockContentSettingsObserver::Send(IPC::Message* message) {
|
| @@ -251,6 +253,90 @@ TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) {
|
| ::testing::Mock::VerifyAndClearExpectations(&observer);
|
| }
|
|
|
| +TEST_F(ChromeRenderViewTest, MediaBlockedByDefault) {
|
| + MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame());
|
| +
|
| + // Load some HTML.
|
| + LoadHTML("<html>Foo</html>");
|
| +
|
| + // Set the default media blocking setting.
|
| + RendererContentSettingRules content_setting_rules;
|
| + ContentSettingsForOneType& media_setting_rules =
|
| + content_setting_rules.media_rules;
|
| + media_setting_rules.push_back(
|
| + ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
|
| + ContentSettingsPattern::Wildcard(),
|
| + CONTENT_SETTING_BLOCK,
|
| + std::string(),
|
| + false));
|
| +
|
| + ContentSettingsObserver* observer =
|
| + ContentSettingsObserver::Get(view_->GetMainRenderFrame());
|
| + observer->SetContentSettingRules(&content_setting_rules);
|
| + EXPECT_CALL(mock_observer,
|
| + OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIA));
|
| + EXPECT_FALSE(observer->allowMedia(mock_observer.media_url_));
|
| + ::testing::Mock::VerifyAndClearExpectations(&observer);
|
| +
|
| + // Create an exception which allows the video.
|
| + media_setting_rules.insert(
|
| + media_setting_rules.begin(),
|
| + ContentSettingPatternSource(
|
| + ContentSettingsPattern::Wildcard(),
|
| + ContentSettingsPattern::FromString(mock_observer.media_origin_),
|
| + CONTENT_SETTING_ALLOW,
|
| + std::string(),
|
| + false));
|
| +
|
| + EXPECT_CALL(
|
| + mock_observer,
|
| + OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIA)).Times(0);
|
| + EXPECT_TRUE(observer->allowMedia(mock_observer.media_url_));
|
| + ::testing::Mock::VerifyAndClearExpectations(&observer);
|
| +}
|
| +
|
| +TEST_F(ChromeRenderViewTest, MediaAllowedByDefault) {
|
| + MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame());
|
| +
|
| + // Load some HTML.
|
| + LoadHTML("<html>Foo</html>");
|
| +
|
| + // Set the default media blocking setting.
|
| + RendererContentSettingRules content_setting_rules;
|
| + ContentSettingsForOneType& media_setting_rules =
|
| + content_setting_rules.media_rules;
|
| + media_setting_rules.push_back(
|
| + ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
|
| + ContentSettingsPattern::Wildcard(),
|
| + CONTENT_SETTING_ALLOW,
|
| + std::string(),
|
| + false));
|
| +
|
| + ContentSettingsObserver* observer =
|
| + ContentSettingsObserver::Get(view_->GetMainRenderFrame());
|
| + observer->SetContentSettingRules(&content_setting_rules);
|
| + EXPECT_CALL(
|
| + mock_observer,
|
| + OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIA)).Times(0);
|
| + EXPECT_TRUE(observer->allowMedia(mock_observer.media_url_));
|
| + ::testing::Mock::VerifyAndClearExpectations(&observer);
|
| +
|
| + // Create an exception which blocks the video.
|
| + media_setting_rules.insert(
|
| + media_setting_rules.begin(),
|
| + ContentSettingPatternSource(
|
| + ContentSettingsPattern::Wildcard(),
|
| + ContentSettingsPattern::FromString(mock_observer.media_origin_),
|
| + CONTENT_SETTING_BLOCK,
|
| + std::string(),
|
| + false));
|
| + EXPECT_CALL(mock_observer,
|
| + OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIA));
|
| + EXPECT_FALSE(observer->allowMedia(mock_observer.media_url_));
|
| + ::testing::Mock::VerifyAndClearExpectations(&observer);
|
| +}
|
| +
|
| +
|
| TEST_F(ChromeRenderViewTest, ContentSettingsBlockScripts) {
|
| // Set the content settings for scripts.
|
| RendererContentSettingRules content_setting_rules;
|
| @@ -345,6 +431,16 @@ TEST_F(ChromeRenderViewTest, ContentSettingsInterstitialPages) {
|
| std::string(),
|
| false));
|
|
|
| + // Block media.
|
| + ContentSettingsForOneType& media_setting_rules =
|
| + content_setting_rules.media_rules;
|
| + media_setting_rules.push_back(
|
| + ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
|
| + ContentSettingsPattern::Wildcard(),
|
| + CONTENT_SETTING_BLOCK,
|
| + std::string(),
|
| + false));
|
| +
|
| ContentSettingsObserver* observer =
|
| ContentSettingsObserver::Get(view_->GetMainRenderFrame());
|
| observer->SetContentSettingRules(&content_setting_rules);
|
| @@ -369,10 +465,16 @@ TEST_F(ChromeRenderViewTest, ContentSettingsInterstitialPages) {
|
| }
|
| EXPECT_FALSE(was_blocked);
|
|
|
| - // Verify that images are allowed.
|
| + // Verify that images and media are allowed.
|
| EXPECT_CALL(
|
| mock_observer,
|
| OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0);
|
| + EXPECT_CALL(
|
| + mock_observer,
|
| + OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIA)).Times(0);
|
| EXPECT_TRUE(observer->allowImage(true, mock_observer.image_url_));
|
| + EXPECT_TRUE(observer->allowMedia(mock_observer.media_url_));
|
| +
|
| +
|
| ::testing::Mock::VerifyAndClearExpectations(&observer);
|
| }
|
|
|