summaryrefslogtreecommitdiffstats
path: root/chrome/browser/content_settings
diff options
context:
space:
mode:
authormarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-08 16:35:29 +0000
committermarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-08 16:35:29 +0000
commit7b7ff92a4b17a862df314a24001f4a4c0006eba5 (patch)
tree4156eefbf31ef0e7ba42d8724865911099087213 /chrome/browser/content_settings
parent804cde48896d38246761d0f543fd938657832bfa (diff)
downloadchromium_src-7b7ff92a4b17a862df314a24001f4a4c0006eba5.zip
chromium_src-7b7ff92a4b17a862df314a24001f4a4c0006eba5.tar.gz
chromium_src-7b7ff92a4b17a862df314a24001f4a4c0006eba5.tar.bz2
Add content_settings::MockProvider
BUG=63656 TEST=content_settings_unittest.cc Review URL: http://codereview.chromium.org/6286148 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74123 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/content_settings')
-rw-r--r--chrome/browser/content_settings/content_settings_provider_unittest.cc44
-rw-r--r--chrome/browser/content_settings/mock_content_settings_provider.cc40
-rw-r--r--chrome/browser/content_settings/mock_content_settings_provider.h99
3 files changed, 166 insertions, 17 deletions
diff --git a/chrome/browser/content_settings/content_settings_provider_unittest.cc b/chrome/browser/content_settings/content_settings_provider_unittest.cc
index 4a0b992..71cded4 100644
--- a/chrome/browser/content_settings/content_settings_provider_unittest.cc
+++ b/chrome/browser/content_settings/content_settings_provider_unittest.cc
@@ -5,11 +5,12 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "chrome/browser/content_settings/mock_content_settings_provider.h"
+#include "googleurl/src/gurl.h"
namespace content_settings {
TEST(ContentSettingsProviderTest, Mock) {
- MockContentSettingsProvider provider(CONTENT_SETTINGS_TYPE_COOKIES,
+ MockDefaultProvider provider(CONTENT_SETTINGS_TYPE_COOKIES,
CONTENT_SETTING_ALLOW,
false,
true);
@@ -23,6 +24,47 @@ TEST(ContentSettingsProviderTest, Mock) {
CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
+
+ ContentSettingsPattern pattern("[*.]youtube.com");
+ GURL url("http://www.youtube.com");
+
+ MockProvider mock_provider(
+ pattern,
+ pattern,
+ CONTENT_SETTINGS_TYPE_PLUGINS,
+ "java_plugin",
+ CONTENT_SETTING_BLOCK,
+ false);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, mock_provider.GetContentSetting(
+ url, url, CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin"));
+ EXPECT_EQ(CONTENT_SETTING_DEFAULT, mock_provider.GetContentSetting(
+ url, url, CONTENT_SETTINGS_TYPE_PLUGINS, "flash_plugin"));
+ EXPECT_EQ(CONTENT_SETTING_DEFAULT, mock_provider.GetContentSetting(
+ url, url, CONTENT_SETTINGS_TYPE_GEOLOCATION, ""));
+
+ mock_provider.SetContentSetting(
+ pattern,
+ pattern,
+ CONTENT_SETTINGS_TYPE_PLUGINS,
+ "java_plugin",
+ CONTENT_SETTING_ALLOW);
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, mock_provider.GetContentSetting(
+ url, url, CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin"));
+
+ mock_provider.set_read_only(true);
+ mock_provider.SetContentSetting(
+ pattern,
+ pattern,
+ CONTENT_SETTINGS_TYPE_PLUGINS,
+ "java_plugin",
+ CONTENT_SETTING_BLOCK);
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, mock_provider.GetContentSetting(
+ url, url, CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin"));
+
+ EXPECT_TRUE(mock_provider.read_only());
+ mock_provider.set_setting(CONTENT_SETTING_BLOCK);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, mock_provider.GetContentSetting(
+ url, url, CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin"));
}
} // namespace content_settings
diff --git a/chrome/browser/content_settings/mock_content_settings_provider.cc b/chrome/browser/content_settings/mock_content_settings_provider.cc
index ac5231b..9e888e9 100644
--- a/chrome/browser/content_settings/mock_content_settings_provider.cc
+++ b/chrome/browser/content_settings/mock_content_settings_provider.cc
@@ -6,7 +6,7 @@
namespace content_settings {
-MockContentSettingsProvider::MockContentSettingsProvider(
+MockDefaultProvider::MockDefaultProvider(
ContentSettingsType content_type,
ContentSetting setting,
bool is_managed,
@@ -17,27 +17,55 @@ MockContentSettingsProvider::MockContentSettingsProvider(
can_override_(can_override) {
}
-MockContentSettingsProvider::~MockContentSettingsProvider() {
+MockDefaultProvider::~MockDefaultProvider() {
}
-ContentSetting MockContentSettingsProvider::ProvideDefaultSetting(
+ContentSetting MockDefaultProvider::ProvideDefaultSetting(
ContentSettingsType content_type) const {
return content_type == content_type_ ? setting_ : CONTENT_SETTING_DEFAULT;
}
-void MockContentSettingsProvider::UpdateDefaultSetting(
+void MockDefaultProvider::UpdateDefaultSetting(
ContentSettingsType content_type,
ContentSetting setting) {
if (can_override_ && content_type == content_type_)
setting_ = setting;
}
-bool MockContentSettingsProvider::DefaultSettingIsManaged(
+bool MockDefaultProvider::DefaultSettingIsManaged(
ContentSettingsType content_type) const {
return content_type == content_type_ && is_managed_;
}
-void MockContentSettingsProvider::ResetToDefaults() {
+void MockDefaultProvider::ResetToDefaults() {
+}
+
+ContentSetting MockProvider::GetContentSetting(
+ const GURL& requesting_url,
+ const GURL& embedding_url,
+ ContentSettingsType content_type,
+ const ResourceIdentifier& resource_identifier) const {
+ if (requesting_url_pattern_.Matches(requesting_url) &&
+ content_type_ == content_type &&
+ resource_identifier_ == resource_identifier) {
+ return setting_;
+ }
+ return CONTENT_SETTING_DEFAULT;
+}
+
+void MockProvider::SetContentSetting(
+ const ContentSettingsPattern& requesting_url_pattern,
+ const ContentSettingsPattern& embedding_url_pattern,
+ ContentSettingsType content_type,
+ const ResourceIdentifier& resource_identifier,
+ ContentSetting content_setting) {
+ if (read_only_)
+ return;
+ requesting_url_pattern_ = ContentSettingsPattern(requesting_url_pattern);
+ embedding_url_pattern_ = ContentSettingsPattern(embedding_url_pattern);
+ content_type_ = content_type;
+ resource_identifier_ = resource_identifier;
+ setting_ = content_setting;
}
} // namespace content_settings
diff --git a/chrome/browser/content_settings/mock_content_settings_provider.h b/chrome/browser/content_settings/mock_content_settings_provider.h
index 09f0d21..1446d10 100644
--- a/chrome/browser/content_settings/mock_content_settings_provider.h
+++ b/chrome/browser/content_settings/mock_content_settings_provider.h
@@ -11,15 +11,17 @@
namespace content_settings {
-class MockContentSettingsProvider : public DefaultProviderInterface {
+// The class MockDefaultProvider is a mock for a default content settings
+// provider.
+class MockDefaultProvider : public DefaultProviderInterface {
public:
// Create a content settings provider that provides a given setting for a
// given type.
- MockContentSettingsProvider(ContentSettingsType content_type,
+ MockDefaultProvider(ContentSettingsType content_type,
ContentSetting setting,
bool is_managed,
bool can_override);
- virtual ~MockContentSettingsProvider();
+ virtual ~MockDefaultProvider();
// DefaultProviderInterface implementation.
virtual ContentSetting ProvideDefaultSetting(
@@ -35,29 +37,51 @@ class MockContentSettingsProvider : public DefaultProviderInterface {
bool is_managed_;
bool can_override_;
- DISALLOW_COPY_AND_ASSIGN(MockContentSettingsProvider);
+ DISALLOW_COPY_AND_ASSIGN(MockDefaultProvider);
};
+// The class MockProvider is a mock for a non default content settings provider.
class MockProvider : public ProviderInterface {
public:
- MockProvider();
- virtual ~MockProvider();
+ MockProvider()
+ : requesting_url_pattern_(ContentSettingsPattern()),
+ embedding_url_pattern_(ContentSettingsPattern()),
+ content_type_(CONTENT_SETTINGS_TYPE_COOKIES),
+ resource_identifier_(""),
+ setting_(CONTENT_SETTING_DEFAULT),
+ read_only_(false) {}
+
+ MockProvider(
+ ContentSettingsPattern requesting_url_pattern,
+ ContentSettingsPattern embedding_url_pattern,
+ ContentSettingsType content_type,
+ ResourceIdentifier resource_identifier,
+ ContentSetting setting,
+ bool read_only)
+ : requesting_url_pattern_(requesting_url_pattern),
+ embedding_url_pattern_(embedding_url_pattern),
+ content_type_(content_type),
+ resource_identifier_(resource_identifier),
+ setting_(setting),
+ read_only_(read_only) {}
+
+ virtual ~MockProvider() {}
// ProviderInterface implementation
virtual ContentSetting GetContentSetting(
const GURL& requesting_url,
const GURL& embedding_url,
ContentSettingsType content_type,
- const ResourceIdentifier& resource_identifier) const {
- return CONTENT_SETTING_DEFAULT;
- }
+ const ResourceIdentifier& resource_identifier) const;
+ // The MockProvider is only able to store one content setting. So every time
+ // this method is called the previously set content settings is overwritten.
virtual void SetContentSetting(
const ContentSettingsPattern& requesting_url_pattern,
const ContentSettingsPattern& embedding_url_pattern,
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
- ContentSetting content_setting) {}
+ ContentSetting content_setting);
virtual void GetAllContentSettingsRules(
ContentSettingsType content_type,
@@ -69,7 +93,62 @@ class MockProvider : public ProviderInterface {
virtual void ResetToDefaults() {}
+ // Accessors
+ void set_requesting_url_pattern(ContentSettingsPattern pattern) {
+ requesting_url_pattern_ = pattern;
+ }
+
+ ContentSettingsPattern requesting_url_pattern() {
+ return requesting_url_pattern_;
+ }
+
+ void set_embedding_url_pattern(ContentSettingsPattern pattern) {
+ embedding_url_pattern_ = pattern;
+ }
+
+ ContentSettingsPattern embedding_url_pattern() {
+ return embedding_url_pattern_;
+ }
+
+ void set_content_type(ContentSettingsType content_type) {
+ content_type_ = content_type;
+ }
+
+ ContentSettingsType content_type() {
+ return content_type_;
+ }
+
+ void set_resource_identifier(ResourceIdentifier resource_identifier) {
+ resource_identifier_ = resource_identifier;
+ }
+
+ ResourceIdentifier resource_identifier() {
+ return resource_identifier_;
+ }
+
+ void set_setting(ContentSetting setting) {
+ setting_ = setting;
+ }
+
+ ContentSetting setting() {
+ return setting_;
+ }
+
+ void set_read_only(bool read_only) {
+ read_only_ = read_only;
+ }
+
+ bool read_only() {
+ return read_only_;
+ }
+
private:
+ ContentSettingsPattern requesting_url_pattern_;
+ ContentSettingsPattern embedding_url_pattern_;
+ ContentSettingsType content_type_;
+ ResourceIdentifier resource_identifier_;
+ ContentSetting setting_;
+ bool read_only_;
DISALLOW_COPY_AND_ASSIGN(MockProvider);
};