diff options
author | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-09 10:02:45 +0000 |
---|---|---|
committer | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-09 10:02:45 +0000 |
commit | fa775cf16c88fbf3176df7724b2009d62869c361 (patch) | |
tree | 2b553465d8b32a1d231bda70d55bdc0317196612 /chrome/renderer/content_settings_observer_browsertest.cc | |
parent | 4db9f28275062950f16dcce294aee6a66f84c6f3 (diff) | |
download | chromium_src-fa775cf16c88fbf3176df7724b2009d62869c361.zip chromium_src-fa775cf16c88fbf3176df7724b2009d62869c361.tar.gz chromium_src-fa775cf16c88fbf3176df7724b2009d62869c361.tar.bz2 |
Take script URLs into account when applying script content settings.
Transmit script content settings to the renderer. Use the script URL as the secondary URL
for the content setting rules.
BUG=90840
TEST=ChromeRenderViewTest.ContentSettings(Allow|Block)Scripts
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=109005
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=109036
Review URL: http://codereview.chromium.org/8409006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109213 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/content_settings_observer_browsertest.cc')
-rw-r--r-- | chrome/renderer/content_settings_observer_browsertest.cc | 101 |
1 files changed, 91 insertions, 10 deletions
diff --git a/chrome/renderer/content_settings_observer_browsertest.cc b/chrome/renderer/content_settings_observer_browsertest.cc index 8bde493..78c7d21 100644 --- a/chrome/renderer/content_settings_observer_browsertest.cc +++ b/chrome/renderer/content_settings_observer_browsertest.cc @@ -105,13 +105,18 @@ TEST_F(ChromeRenderViewTest, JSBlockSentAfterPageLoad) { LoadHTML(html.c_str()); // 2. Block JavaScript. - ContentSettings settings; - for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) - settings.settings[i] = CONTENT_SETTING_ALLOW; - settings.settings[CONTENT_SETTINGS_TYPE_JAVASCRIPT] = CONTENT_SETTING_BLOCK; + RendererContentSettingRules content_setting_rules; + ContentSettingsForOneType& script_setting_rules = + content_setting_rules.script_rules; + script_setting_rules.push_back( + ContentSettingPatternSource( + ContentSettingsPattern::Wildcard(), + ContentSettingsPattern::Wildcard(), + CONTENT_SETTING_BLOCK, + "", + false)); ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); - observer->SetContentSettings(settings); - observer->SetDefaultContentSettings(&settings); + observer->SetContentSettingRules(&content_setting_rules); // Make sure no pending messages are in the queue. ProcessPendingMessages(); @@ -174,7 +179,9 @@ TEST_F(ChromeRenderViewTest, ImagesBlockedByDefault) { LoadHTML("<html>Foo</html>"); // Set the default image blocking setting. - ContentSettingsForOneType image_setting_rules; + RendererContentSettingRules content_setting_rules; + ContentSettingsForOneType& image_setting_rules = + content_setting_rules.image_rules; image_setting_rules.push_back( ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), @@ -183,7 +190,7 @@ TEST_F(ChromeRenderViewTest, ImagesBlockedByDefault) { false)); ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); - observer->SetImageSettingRules(&image_setting_rules); + observer->SetContentSettingRules(&content_setting_rules); EXPECT_CALL(mock_observer, OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string())); EXPECT_FALSE(observer->AllowImage(GetMainFrame(), @@ -215,7 +222,9 @@ TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) { LoadHTML("<html>Foo</html>"); // Set the default image blocking setting. - ContentSettingsForOneType image_setting_rules; + RendererContentSettingRules content_setting_rules; + ContentSettingsForOneType& image_setting_rules = + content_setting_rules.image_rules; image_setting_rules.push_back( ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), @@ -224,7 +233,7 @@ TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) { false)); ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); - observer->SetImageSettingRules(&image_setting_rules); + observer->SetContentSettingRules(&content_setting_rules); EXPECT_CALL( mock_observer, OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string())).Times(0); @@ -247,3 +256,75 @@ TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) { true, mock_observer.image_url_)); ::testing::Mock::VerifyAndClearExpectations(&observer); } + +TEST_F(ChromeRenderViewTest, ContentSettingsBlockScripts) { + // Set the content settings for scripts. + RendererContentSettingRules content_setting_rules; + ContentSettingsForOneType& script_setting_rules = + content_setting_rules.script_rules; + script_setting_rules.push_back( + ContentSettingPatternSource( + ContentSettingsPattern::Wildcard(), + ContentSettingsPattern::Wildcard(), + CONTENT_SETTING_BLOCK, + "", + false)); + + ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); + observer->SetContentSettingRules(&content_setting_rules); + + // Load a page which contains a script. + std::string html = "<html>" + "<head>" + "<script src='data:foo'></script>" + "</head>" + "<body>" + "</body>" + "</html>"; + LoadHTML(html.c_str()); + + // Verify that the script was blocked. + bool was_blocked = false; + for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) { + const IPC::Message* msg = render_thread_->sink().GetMessageAt(i); + if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID) + was_blocked = true; + } + EXPECT_TRUE(was_blocked); +} + +TEST_F(ChromeRenderViewTest, ContentSettingsAllowScripts) { + // Set the content settings for scripts. + RendererContentSettingRules content_setting_rules; + ContentSettingsForOneType& script_setting_rules = + content_setting_rules.script_rules; + script_setting_rules.push_back( + ContentSettingPatternSource( + ContentSettingsPattern::Wildcard(), + ContentSettingsPattern::Wildcard(), + CONTENT_SETTING_ALLOW, + "", + false)); + + ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); + observer->SetContentSettingRules(&content_setting_rules); + + // Load a page which contains a script. + std::string html = "<html>" + "<head>" + "<script src='data:foo'></script>" + "</head>" + "<body>" + "</body>" + "</html>"; + LoadHTML(html.c_str()); + + // Verify that the script was not blocked. + bool was_blocked = false; + for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) { + const IPC::Message* msg = render_thread_->sink().GetMessageAt(i); + if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID) + was_blocked = true; + } + EXPECT_FALSE(was_blocked); +} |