Commit b6907448 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Clean up ContentSettingsObserver.

Change-Id: Ie24494686e8a054aed8280320f27090e2703b974
Reviewed-on: https://chromium-review.googlesource.com/746150
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513006}
parent 1a36d501
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/renderer/content_settings_observer.h" #include "chrome/renderer/content_settings_observer.h"
#include <vector>
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "chrome/common/client_hints.mojom.h" #include "chrome/common/client_hints.mojom.h"
...@@ -75,7 +77,6 @@ ContentSetting GetContentSettingFromRules( ...@@ -75,7 +77,6 @@ ContentSetting GetContentSettingFromRules(
const ContentSettingsForOneType& rules, const ContentSettingsForOneType& rules,
const WebFrame* frame, const WebFrame* frame,
const URL& secondary_url) { const URL& secondary_url) {
ContentSettingsForOneType::const_iterator it;
// If there is only one rule, it's the default rule and we don't need to match // If there is only one rule, it's the default rule and we don't need to match
// the patterns. // the patterns.
if (rules.size() == 1) { if (rules.size() == 1) {
...@@ -85,10 +86,10 @@ ContentSetting GetContentSettingFromRules( ...@@ -85,10 +86,10 @@ ContentSetting GetContentSettingFromRules(
} }
const GURL& primary_url = GetOriginOrURL(frame); const GURL& primary_url = GetOriginOrURL(frame);
const GURL& secondary_gurl = secondary_url; const GURL& secondary_gurl = secondary_url;
for (it = rules.begin(); it != rules.end(); ++it) { for (const auto& rule : rules) {
if (it->primary_pattern.Matches(primary_url) && if (rule.primary_pattern.Matches(primary_url) &&
it->secondary_pattern.Matches(secondary_gurl)) { rule.secondary_pattern.Matches(secondary_gurl)) {
return it->GetContentSetting(); return rule.GetContentSetting();
} }
} }
NOTREACHED(); NOTREACHED();
...@@ -99,6 +100,11 @@ bool IsScriptDisabledForPreview(const content::RenderFrame* render_frame) { ...@@ -99,6 +100,11 @@ bool IsScriptDisabledForPreview(const content::RenderFrame* render_frame) {
return render_frame->GetPreviewsState() & content::NOSCRIPT_ON; return render_frame->GetPreviewsState() & content::NOSCRIPT_ON;
} }
bool IsUniqueFrame(WebFrame* frame) {
return frame->GetSecurityOrigin().IsUnique() ||
frame->Top()->GetSecurityOrigin().IsUnique();
}
} // namespace } // namespace
ContentSettingsObserver::ContentSettingsObserver( ContentSettingsObserver::ContentSettingsObserver(
...@@ -113,7 +119,7 @@ ContentSettingsObserver::ContentSettingsObserver( ...@@ -113,7 +119,7 @@ ContentSettingsObserver::ContentSettingsObserver(
extension_dispatcher_(extension_dispatcher), extension_dispatcher_(extension_dispatcher),
#endif #endif
allow_running_insecure_content_(false), allow_running_insecure_content_(false),
content_setting_rules_(NULL), content_setting_rules_(nullptr),
is_interstitial_page_(false), is_interstitial_page_(false),
current_request_id_(0), current_request_id_(0),
should_whitelist_(should_whitelist) { should_whitelist_(should_whitelist) {
...@@ -153,10 +159,8 @@ bool ContentSettingsObserver::IsPluginTemporarilyAllowed( ...@@ -153,10 +159,8 @@ bool ContentSettingsObserver::IsPluginTemporarilyAllowed(
const std::string& identifier) { const std::string& identifier) {
// If the empty string is in here, it means all plugins are allowed. // If the empty string is in here, it means all plugins are allowed.
// TODO(bauerb): Remove this once we only pass in explicit identifiers. // TODO(bauerb): Remove this once we only pass in explicit identifiers.
return (temporarily_allowed_plugins_.find(identifier) != return base::ContainsKey(temporarily_allowed_plugins_, identifier) ||
temporarily_allowed_plugins_.end()) || base::ContainsKey(temporarily_allowed_plugins_, std::string());
(temporarily_allowed_plugins_.find(std::string()) !=
temporarily_allowed_plugins_.end());
} }
void ContentSettingsObserver::DidBlockContentType( void ContentSettingsObserver::DidBlockContentType(
...@@ -242,8 +246,7 @@ bool ContentSettingsObserver::AllowDatabase(const WebString& name, ...@@ -242,8 +246,7 @@ bool ContentSettingsObserver::AllowDatabase(const WebString& name,
const WebString& display_name, const WebString& display_name,
unsigned estimated_size) { unsigned estimated_size) {
WebFrame* frame = render_frame()->GetWebFrame(); WebFrame* frame = render_frame()->GetWebFrame();
if (frame->GetSecurityOrigin().IsUnique() || if (IsUniqueFrame(frame))
frame->Top()->GetSecurityOrigin().IsUnique())
return false; return false;
bool result = false; bool result = false;
...@@ -257,19 +260,18 @@ bool ContentSettingsObserver::AllowDatabase(const WebString& name, ...@@ -257,19 +260,18 @@ bool ContentSettingsObserver::AllowDatabase(const WebString& name,
void ContentSettingsObserver::RequestFileSystemAccessAsync( void ContentSettingsObserver::RequestFileSystemAccessAsync(
const WebContentSettingCallbacks& callbacks) { const WebContentSettingCallbacks& callbacks) {
WebFrame* frame = render_frame()->GetWebFrame(); WebFrame* frame = render_frame()->GetWebFrame();
if (frame->GetSecurityOrigin().IsUnique() || if (IsUniqueFrame(frame)) {
frame->Top()->GetSecurityOrigin().IsUnique()) {
WebContentSettingCallbacks permissionCallbacks(callbacks); WebContentSettingCallbacks permissionCallbacks(callbacks);
permissionCallbacks.DoDeny(); permissionCallbacks.DoDeny();
return; return;
} }
++current_request_id_; ++current_request_id_;
std::pair<PermissionRequestMap::iterator, bool> insert_result = bool inserted = permission_requests_
permission_requests_.insert( .insert(std::make_pair(current_request_id_, callbacks))
std::make_pair(current_request_id_, callbacks)); .second;
// Verify there are no duplicate insertions. // Verify there are no duplicate insertions.
DCHECK(insert_result.second); DCHECK(inserted);
Send(new ChromeViewHostMsg_RequestFileSystemAccessAsync( Send(new ChromeViewHostMsg_RequestFileSystemAccessAsync(
routing_id(), current_request_id_, routing_id(), current_request_id_,
...@@ -301,8 +303,7 @@ bool ContentSettingsObserver::AllowImage(bool enabled_per_settings, ...@@ -301,8 +303,7 @@ bool ContentSettingsObserver::AllowImage(bool enabled_per_settings,
bool ContentSettingsObserver::AllowIndexedDB(const WebString& name, bool ContentSettingsObserver::AllowIndexedDB(const WebString& name,
const WebSecurityOrigin& origin) { const WebSecurityOrigin& origin) {
WebFrame* frame = render_frame()->GetWebFrame(); WebFrame* frame = render_frame()->GetWebFrame();
if (frame->GetSecurityOrigin().IsUnique() || if (IsUniqueFrame(frame))
frame->Top()->GetSecurityOrigin().IsUnique())
return false; return false;
bool result = false; bool result = false;
...@@ -327,7 +328,7 @@ bool ContentSettingsObserver::AllowScript(bool enabled_per_settings) { ...@@ -327,7 +328,7 @@ bool ContentSettingsObserver::AllowScript(bool enabled_per_settings) {
return it->second; return it->second;
// Evaluate the content setting rules before // Evaluate the content setting rules before
// |IsWhitelistedForContentSettings|; if there is only the default rule // IsWhitelistedForContentSettings(); if there is only the default rule
// allowing all scripts, it's quicker this way. // allowing all scripts, it's quicker this way.
bool allow = true; bool allow = true;
if (content_setting_rules_) { if (content_setting_rules_) {
...@@ -364,8 +365,7 @@ bool ContentSettingsObserver::AllowScriptFromSource( ...@@ -364,8 +365,7 @@ bool ContentSettingsObserver::AllowScriptFromSource(
bool ContentSettingsObserver::AllowStorage(bool local) { bool ContentSettingsObserver::AllowStorage(bool local) {
blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
if (frame->GetSecurityOrigin().IsUnique() || if (IsUniqueFrame(frame))
frame->Top()->GetSecurityOrigin().IsUnique())
return false; return false;
StoragePermissionsKey key( StoragePermissionsKey key(
...@@ -471,16 +471,17 @@ void ContentSettingsObserver::PersistClientHints( ...@@ -471,16 +471,17 @@ void ContentSettingsObserver::PersistClientHints(
// browser side or the renderer. If the value needs to be overridden, // browser side or the renderer. If the value needs to be overridden,
// this method should not return early if |update_count| is 0. // this method should not return early if |update_count| is 0.
std::vector<::blink::mojom::WebClientHintsType> client_hints; std::vector<::blink::mojom::WebClientHintsType> client_hints;
static constexpr size_t kWebClientHintsCount =
static_cast<size_t>(blink::mojom::WebClientHintsType::kLast) + 1;
client_hints.reserve(kWebClientHintsCount);
size_t update_count = 0; for (size_t i = 0; i < kWebClientHintsCount; ++i) {
for (size_t i = 0;
i < static_cast<int>(blink::mojom::WebClientHintsType::kLast) + 1; ++i) {
if (enabled_client_hints.IsEnabled( if (enabled_client_hints.IsEnabled(
static_cast<blink::mojom::WebClientHintsType>(i))) { static_cast<blink::mojom::WebClientHintsType>(i))) {
client_hints.push_back(static_cast<blink::mojom::WebClientHintsType>(i)); client_hints.push_back(static_cast<blink::mojom::WebClientHintsType>(i));
update_count++;
} }
} }
size_t update_count = client_hints.size();
if (update_count == 0) if (update_count == 0)
return; return;
...@@ -565,16 +566,17 @@ bool ContentSettingsObserver::IsPlatformApp() { ...@@ -565,16 +566,17 @@ bool ContentSettingsObserver::IsPlatformApp() {
const extensions::Extension* ContentSettingsObserver::GetExtension( const extensions::Extension* ContentSettingsObserver::GetExtension(
const WebSecurityOrigin& origin) const { const WebSecurityOrigin& origin) const {
if (origin.Protocol().Ascii() != extensions::kExtensionScheme) if (origin.Protocol().Ascii() != extensions::kExtensionScheme)
return NULL; return nullptr;
const std::string extension_id = origin.Host().Utf8().data(); const std::string extension_id = origin.Host().Utf8().data();
if (!extension_dispatcher_->IsExtensionActive(extension_id)) if (!extension_dispatcher_->IsExtensionActive(extension_id))
return NULL; return nullptr;
return extensions::RendererExtensionRegistry::Get()->GetByID(extension_id); return extensions::RendererExtensionRegistry::Get()->GetByID(extension_id);
} }
#endif #endif
// static
bool ContentSettingsObserver::IsWhitelistedForContentSettings() const { bool ContentSettingsObserver::IsWhitelistedForContentSettings() const {
if (should_whitelist_) if (should_whitelist_)
return true; return true;
......
...@@ -67,7 +67,7 @@ class ContentSettingsObserver ...@@ -67,7 +67,7 @@ class ContentSettingsObserver
void DidBlockContentType(ContentSettingsType settings_type, void DidBlockContentType(ContentSettingsType settings_type,
const base::string16& details); const base::string16& details);
// blink::WebContentSettingsClient implementation. // blink::WebContentSettingsClient:
bool AllowDatabase(const blink::WebString& name, bool AllowDatabase(const blink::WebString& name,
const blink::WebString& display_name, const blink::WebString& display_name,
unsigned estimated_size) override; unsigned estimated_size) override;
...@@ -143,6 +143,8 @@ class ContentSettingsObserver ...@@ -143,6 +143,8 @@ class ContentSettingsObserver
// True if |render_frame()| contains content that is white-listed for content // True if |render_frame()| contains content that is white-listed for content
// settings. // settings.
bool IsWhitelistedForContentSettings() const; bool IsWhitelistedForContentSettings() const;
// Exposed for unit tests.
static bool IsWhitelistedForContentSettings( static bool IsWhitelistedForContentSettings(
const blink::WebSecurityOrigin& origin, const blink::WebSecurityOrigin& origin,
const blink::WebURL& document_url); const blink::WebURL& document_url);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "components/content_settings/core/common/content_settings_utils.h" #include "components/content_settings/core/common/content_settings_utils.h"
#include "content/public/renderer/render_view.h" #include "content/public/renderer/render_view.h"
#include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_macros.h"
#include "ipc/ipc_test_sink.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/web/WebFrameContentDumper.h" #include "third_party/WebKit/public/web/WebFrameContentDumper.h"
...@@ -26,20 +27,37 @@ using testing::DeleteArg; ...@@ -26,20 +27,37 @@ using testing::DeleteArg;
namespace { namespace {
constexpr char kScriptHtml[] =
"<html>"
"<head>"
"<script src='data:foo'></script>"
"</head>"
"<body>"
"</body>"
"</html>";
class MockContentSettingsObserver : public ContentSettingsObserver { class MockContentSettingsObserver : public ContentSettingsObserver {
public: public:
MockContentSettingsObserver(content::RenderFrame* render_frame, MockContentSettingsObserver(content::RenderFrame* render_frame,
service_manager::BinderRegistry* registry); service_manager::BinderRegistry* registry);
~MockContentSettingsObserver() override {}
virtual bool Send(IPC::Message* message); bool Send(IPC::Message* message) override;
MOCK_METHOD2(OnContentBlocked, MOCK_METHOD2(OnContentBlocked,
void(ContentSettingsType, const base::string16&)); void(ContentSettingsType, const base::string16&));
MOCK_METHOD5(OnAllowDOMStorage, MOCK_METHOD5(OnAllowDOMStorage,
void(int, const GURL&, const GURL&, bool, IPC::Message*)); void(int, const GURL&, const GURL&, bool, IPC::Message*));
GURL image_url_;
std::string image_origin_; const GURL& image_url() const { return image_url_; }
const std::string& image_origin() const { return image_origin_; }
private:
const GURL image_url_;
const std::string image_origin_;
DISALLOW_COPY_AND_ASSIGN(MockContentSettingsObserver);
}; };
MockContentSettingsObserver::MockContentSettingsObserver( MockContentSettingsObserver::MockContentSettingsObserver(
...@@ -84,8 +102,8 @@ class CommitTimeConditionChecker : public content::RenderFrameObserver { ...@@ -84,8 +102,8 @@ class CommitTimeConditionChecker : public content::RenderFrameObserver {
} }
private: private:
Predicate predicate_; const Predicate predicate_;
bool expectation_; const bool expectation_;
DISALLOW_COPY_AND_ASSIGN(CommitTimeConditionChecker); DISALLOW_COPY_AND_ASSIGN(CommitTimeConditionChecker);
}; };
...@@ -229,7 +247,7 @@ TEST_F(ChromeRenderViewTest, ImagesBlockedByDefault) { ...@@ -229,7 +247,7 @@ TEST_F(ChromeRenderViewTest, ImagesBlockedByDefault) {
observer->SetContentSettingRules(&content_setting_rules); observer->SetContentSettingRules(&content_setting_rules);
EXPECT_CALL(mock_observer, EXPECT_CALL(mock_observer,
OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, base::string16())); OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, base::string16()));
EXPECT_FALSE(observer->AllowImage(true, mock_observer.image_url_)); EXPECT_FALSE(observer->AllowImage(true, mock_observer.image_url()));
::testing::Mock::VerifyAndClearExpectations(&observer); ::testing::Mock::VerifyAndClearExpectations(&observer);
// Create an exception which allows the image. // Create an exception which allows the image.
...@@ -237,13 +255,13 @@ TEST_F(ChromeRenderViewTest, ImagesBlockedByDefault) { ...@@ -237,13 +255,13 @@ TEST_F(ChromeRenderViewTest, ImagesBlockedByDefault) {
image_setting_rules.begin(), image_setting_rules.begin(),
ContentSettingPatternSource( ContentSettingPatternSource(
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
ContentSettingsPattern::FromString(mock_observer.image_origin_), ContentSettingsPattern::FromString(mock_observer.image_origin()),
content_settings::ContentSettingToValue(CONTENT_SETTING_ALLOW), content_settings::ContentSettingToValue(CONTENT_SETTING_ALLOW),
std::string(), false)); std::string(), false));
EXPECT_CALL(mock_observer, OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, EXPECT_CALL(mock_observer, OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES,
base::string16())).Times(0); base::string16())).Times(0);
EXPECT_TRUE(observer->AllowImage(true, mock_observer.image_url_)); EXPECT_TRUE(observer->AllowImage(true, mock_observer.image_url()));
::testing::Mock::VerifyAndClearExpectations(&observer); ::testing::Mock::VerifyAndClearExpectations(&observer);
} }
...@@ -268,7 +286,7 @@ TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) { ...@@ -268,7 +286,7 @@ TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) {
observer->SetContentSettingRules(&content_setting_rules); observer->SetContentSettingRules(&content_setting_rules);
EXPECT_CALL(mock_observer, OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, EXPECT_CALL(mock_observer, OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES,
base::string16())).Times(0); base::string16())).Times(0);
EXPECT_TRUE(observer->AllowImage(true, mock_observer.image_url_)); EXPECT_TRUE(observer->AllowImage(true, mock_observer.image_url()));
::testing::Mock::VerifyAndClearExpectations(&observer); ::testing::Mock::VerifyAndClearExpectations(&observer);
// Create an exception which blocks the image. // Create an exception which blocks the image.
...@@ -276,12 +294,12 @@ TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) { ...@@ -276,12 +294,12 @@ TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) {
image_setting_rules.begin(), image_setting_rules.begin(),
ContentSettingPatternSource( ContentSettingPatternSource(
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
ContentSettingsPattern::FromString(mock_observer.image_origin_), ContentSettingsPattern::FromString(mock_observer.image_origin()),
content_settings::ContentSettingToValue(CONTENT_SETTING_BLOCK), content_settings::ContentSettingToValue(CONTENT_SETTING_BLOCK),
std::string(), false)); std::string(), false));
EXPECT_CALL(mock_observer, EXPECT_CALL(mock_observer,
OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, base::string16())); OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, base::string16()));
EXPECT_FALSE(observer->AllowImage(true, mock_observer.image_url_)); EXPECT_FALSE(observer->AllowImage(true, mock_observer.image_url()));
::testing::Mock::VerifyAndClearExpectations(&observer); ::testing::Mock::VerifyAndClearExpectations(&observer);
} }
...@@ -300,24 +318,11 @@ TEST_F(ChromeRenderViewTest, ContentSettingsBlockScripts) { ...@@ -300,24 +318,11 @@ TEST_F(ChromeRenderViewTest, ContentSettingsBlockScripts) {
observer->SetContentSettingRules(&content_setting_rules); observer->SetContentSettingRules(&content_setting_rules);
// Load a page which contains a script. // Load a page which contains a script.
const char kHtml[] = LoadHTML(kScriptHtml);
"<html>"
"<head>"
"<script src='data:foo'></script>"
"</head>"
"<body>"
"</body>"
"</html>";
LoadHTML(kHtml);
// Verify that the script was blocked. // Verify that the script was blocked.
bool was_blocked = false; EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) { ChromeViewHostMsg_ContentBlocked::ID));
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) { TEST_F(ChromeRenderViewTest, ContentSettingsAllowScripts) {
...@@ -335,24 +340,11 @@ TEST_F(ChromeRenderViewTest, ContentSettingsAllowScripts) { ...@@ -335,24 +340,11 @@ TEST_F(ChromeRenderViewTest, ContentSettingsAllowScripts) {
observer->SetContentSettingRules(&content_setting_rules); observer->SetContentSettingRules(&content_setting_rules);
// Load a page which contains a script. // Load a page which contains a script.
const char kHtml[] = LoadHTML(kScriptHtml);
"<html>"
"<head>"
"<script src='data:foo'></script>"
"</head>"
"<body>"
"</body>"
"</html>";
LoadHTML(kHtml);
// Verify that the script was not blocked. // Verify that the script was not blocked.
bool was_blocked = false; EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) { ChromeViewHostMsg_ContentBlocked::ID));
const IPC::Message* msg = render_thread_->sink().GetMessageAt(i);
if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID)
was_blocked = true;
}
EXPECT_FALSE(was_blocked);
} }
// Regression test for crbug.com/232410: Load a page with JS blocked. Then, // Regression test for crbug.com/232410: Load a page with JS blocked. Then,
...@@ -426,24 +418,11 @@ TEST_F(ChromeRenderViewTest, ContentSettingsSameDocumentNavigation) { ...@@ -426,24 +418,11 @@ TEST_F(ChromeRenderViewTest, ContentSettingsSameDocumentNavigation) {
MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame(), MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame(),
registry_.get()); registry_.get());
// Load a page which contains a script. // Load a page which contains a script.
const char kHtml[] = LoadHTML(kScriptHtml);
"<html>"
"<head>"
"<script src='data:foo'></script>"
"</head>"
"<body>"
"</body>"
"</html>";
LoadHTML(kHtml);
// Verify that the script was not blocked. // Verify that the script was not blocked.
bool was_blocked = false; EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) { ChromeViewHostMsg_ContentBlocked::ID));
const IPC::Message* msg = render_thread_->sink().GetMessageAt(i);
if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID)
was_blocked = true;
}
EXPECT_FALSE(was_blocked);
// Block JavaScript. // Block JavaScript.
RendererContentSettingRules content_setting_rules; RendererContentSettingRules content_setting_rules;
...@@ -489,29 +468,16 @@ TEST_F(ChromeRenderViewTest, ContentSettingsInterstitialPages) { ...@@ -489,29 +468,16 @@ TEST_F(ChromeRenderViewTest, ContentSettingsInterstitialPages) {
observer->OnSetAsInterstitial(); observer->OnSetAsInterstitial();
// Load a page which contains a script. // Load a page which contains a script.
const char kHtml[] = LoadHTML(kScriptHtml);
"<html>"
"<head>"
"<script src='data:foo'></script>"
"</head>"
"<body>"
"</body>"
"</html>";
LoadHTML(kHtml);
// Verify that the script was allowed. // Verify that the script was allowed.
bool was_blocked = false; EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) { ChromeViewHostMsg_ContentBlocked::ID));
const IPC::Message* msg = render_thread_->sink().GetMessageAt(i);
if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID)
was_blocked = true;
}
EXPECT_FALSE(was_blocked);
// Verify that images are allowed. // Verify that images are allowed.
EXPECT_CALL(mock_observer, OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, EXPECT_CALL(mock_observer, OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES,
base::string16())).Times(0); base::string16())).Times(0);
EXPECT_TRUE(observer->AllowImage(true, mock_observer.image_url_)); EXPECT_TRUE(observer->AllowImage(true, mock_observer.image_url()));
::testing::Mock::VerifyAndClearExpectations(&observer); ::testing::Mock::VerifyAndClearExpectations(&observer);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment