Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3399)

Unified Diff: chrome/browser/content_settings/host_content_settings_map_unittest.cc

Issue 5574001: Move ContentSettingsDetails and Pattern out of HostContentSettingsMap as separate classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/content_settings
Patch Set: updates Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/content_settings/host_content_settings_map_unittest.cc
diff --git a/chrome/browser/content_settings/host_content_settings_map_unittest.cc b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
index 5f6bf5c6b4ce9077eb00f54cb6f620d3bedce8fe..280799b30d3d2270859224e09b5b54e20f3bd34e 100644
--- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc
+++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
+#include "chrome/browser/content_settings/content_settings_details.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_registrar.h"
@@ -44,8 +45,7 @@ class StubSettingsObserver : public NotificationObserver {
const NotificationDetails& details) {
++counter;
Source<HostContentSettingsMap> content_settings(source);
- Details<HostContentSettingsMap::ContentSettingsDetails>
- settings_details(details);
+ Details<ContentSettingsDetails> settings_details(details);
last_notifier = content_settings.ptr();
last_pattern = settings_details.ptr()->pattern();
last_update_all = settings_details.ptr()->update_all();
@@ -57,7 +57,7 @@ class StubSettingsObserver : public NotificationObserver {
}
HostContentSettingsMap* last_notifier;
- HostContentSettingsMap::Pattern last_pattern;
+ ContentSettingsPattern last_pattern;
bool last_update_all;
bool last_update_all_types;
int counter;
@@ -118,7 +118,7 @@ TEST_F(HostContentSettingsMapTest, DefaultValues) {
// Check returning individual settings.
GURL host("http://example.com/");
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
@@ -163,7 +163,7 @@ TEST_F(HostContentSettingsMapTest, DefaultValues) {
EXPECT_TRUE(SettingsEqual(desired_settings, settings));
// Check returning all hosts for a setting.
- HostContentSettingsMap::Pattern pattern2("[*.]example.org");
+ ContentSettingsPattern pattern2("[*.]example.org");
host_content_settings_map->SetContentSetting(pattern2,
CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK);
host_content_settings_map->SetContentSetting(pattern2,
@@ -186,7 +186,7 @@ TEST_F(HostContentSettingsMapTest, DefaultValues) {
EXPECT_EQ(0U, host_settings.size());
// Check clearing one type.
- HostContentSettingsMap::Pattern pattern3("[*.]example.net");
+ ContentSettingsPattern pattern3("[*.]example.net");
host_content_settings_map->SetContentSetting(pattern,
CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK);
host_content_settings_map->SetContentSetting(pattern2,
@@ -214,8 +214,8 @@ TEST_F(HostContentSettingsMapTest, Patterns) {
GURL host1("http://example.com/");
GURL host2("http://www.example.com/");
GURL host3("http://example.org/");
- HostContentSettingsMap::Pattern pattern1("[*.]example.com");
- HostContentSettingsMap::Pattern pattern2("example.org");
+ ContentSettingsPattern pattern1("[*.]example.com");
+ ContentSettingsPattern pattern2("example.org");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host1, CONTENT_SETTINGS_TYPE_IMAGES, ""));
@@ -237,70 +237,13 @@ TEST_F(HostContentSettingsMapTest, Patterns) {
host3, CONTENT_SETTINGS_TYPE_IMAGES, ""));
}
-TEST_F(HostContentSettingsMapTest, PatternSupport) {
- EXPECT_TRUE(HostContentSettingsMap::Pattern("[*.]example.com").IsValid());
- EXPECT_TRUE(HostContentSettingsMap::Pattern("example.com").IsValid());
- EXPECT_TRUE(HostContentSettingsMap::Pattern("192.168.0.1").IsValid());
- EXPECT_TRUE(HostContentSettingsMap::Pattern("[::1]").IsValid());
- EXPECT_FALSE(HostContentSettingsMap::Pattern("*example.com").IsValid());
- EXPECT_FALSE(HostContentSettingsMap::Pattern("example.*").IsValid());
- EXPECT_FALSE(HostContentSettingsMap::Pattern("http://example.com").IsValid());
-
- EXPECT_TRUE(HostContentSettingsMap::Pattern("[*.]example.com").Matches(
- GURL("http://example.com/")));
- EXPECT_TRUE(HostContentSettingsMap::Pattern("[*.]example.com").Matches(
- GURL("http://www.example.com/")));
- EXPECT_TRUE(HostContentSettingsMap::Pattern("www.example.com").Matches(
- GURL("http://www.example.com/")));
- EXPECT_FALSE(HostContentSettingsMap::Pattern("").Matches(
- GURL("http://www.example.com/")));
- EXPECT_FALSE(HostContentSettingsMap::Pattern("[*.]example.com").Matches(
- GURL("http://example.org/")));
- EXPECT_FALSE(HostContentSettingsMap::Pattern("example.com").Matches(
- GURL("http://example.org/")));
-}
-
-TEST_F(HostContentSettingsMapTest, CanonicalizePattern) {
- // Basic patterns.
- EXPECT_STREQ("[*.]ikea.com", HostContentSettingsMap::Pattern("[*.]ikea.com")
- .CanonicalizePattern().c_str());
- EXPECT_STREQ("example.com", HostContentSettingsMap::Pattern("example.com")
- .CanonicalizePattern().c_str());
- EXPECT_STREQ("192.168.1.1", HostContentSettingsMap::Pattern("192.168.1.1")
- .CanonicalizePattern().c_str());
- EXPECT_STREQ("[::1]", HostContentSettingsMap::Pattern("[::1]")
- .CanonicalizePattern().c_str());
- // IsValid returns false for file:/// patterns.
- EXPECT_STREQ("", HostContentSettingsMap::Pattern(
- "file:///temp/file.html").CanonicalizePattern().c_str());
-
- // UTF-8 patterns.
- EXPECT_STREQ("[*.]xn--ira-ppa.com", HostContentSettingsMap::Pattern(
- "[*.]\xC4\x87ira.com").CanonicalizePattern().c_str());
- EXPECT_STREQ("xn--ira-ppa.com", HostContentSettingsMap::Pattern(
- "\xC4\x87ira.com").CanonicalizePattern().c_str());
- // IsValid returns false for file:/// patterns.
- EXPECT_STREQ("", HostContentSettingsMap::Pattern(
- "file:///\xC4\x87ira.html").CanonicalizePattern().c_str());
-
- // Invalid patterns.
- EXPECT_STREQ("", HostContentSettingsMap::Pattern(
- "*example.com").CanonicalizePattern().c_str());
- EXPECT_STREQ("", HostContentSettingsMap::Pattern(
- "example.*").CanonicalizePattern().c_str());
- EXPECT_STREQ("", HostContentSettingsMap::Pattern(
- "*\xC4\x87ira.com").CanonicalizePattern().c_str());
- EXPECT_STREQ("", HostContentSettingsMap::Pattern(
- "\xC4\x87ira.*").CanonicalizePattern().c_str());
-}
-
TEST_F(HostContentSettingsMapTest, Observer) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
StubSettingsObserver observer;
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
host_content_settings_map->SetContentSetting(pattern,
CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_ALLOW);
EXPECT_EQ(host_content_settings_map, observer.last_notifier);
@@ -377,7 +320,7 @@ TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
scoped_ptr<Value> default_value(prefs->FindPreference(
prefs::kContentSettingsPatterns)->GetValue()->DeepCopy());
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
GURL host("http://example.com");
host_content_settings_map->SetContentSetting(pattern,
@@ -408,7 +351,7 @@ TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
HostContentSettingsMap* host_content_settings_map =
profile.GetHostContentSettingsMap();
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
GURL host_ending_with_dot("http://example.com./");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
@@ -488,9 +431,9 @@ TEST_F(HostContentSettingsMapTest, NestedSettings) {
profile.GetHostContentSettingsMap();
GURL host("http://a.b.example.com/");
- HostContentSettingsMap::Pattern pattern1("[*.]example.com");
- HostContentSettingsMap::Pattern pattern2("[*.]b.example.com");
- HostContentSettingsMap::Pattern pattern3("a.b.example.com");
+ ContentSettingsPattern pattern1("[*.]example.com");
+ ContentSettingsPattern pattern2("[*.]b.example.com");
+ ContentSettingsPattern pattern3("a.b.example.com");
host_content_settings_map->SetContentSetting(pattern1,
CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK);
@@ -543,7 +486,7 @@ TEST_F(HostContentSettingsMapTest, OffTheRecord) {
profile.set_off_the_record(false);
GURL host("http://example.com/");
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
@@ -666,7 +609,7 @@ TEST_F(HostContentSettingsMapTest, NonDefaultSettings) {
profile.GetHostContentSettingsMap();
GURL host("http://example.com/");
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
ContentSettings desired_settings(CONTENT_SETTING_DEFAULT);
ContentSettings settings =
@@ -693,7 +636,7 @@ TEST_F(HostContentSettingsMapTest, ResourceIdentifier) {
profile.GetHostContentSettingsMap();
GURL host("http://example.com/");
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
std::string resource1("someplugin");
std::string resource2("otherplugin");
@@ -724,7 +667,7 @@ TEST_F(HostContentSettingsMapTest, ResourceIdentifierPrefs) {
profile.GetHostContentSettingsMap();
GURL host("http://example.com/");
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
std::string resource1("someplugin");
std::string resource2("otherplugin");
@@ -798,7 +741,7 @@ TEST_F(HostContentSettingsMapTest,
TestingPrefService* prefs = profile.GetTestingPrefService();
// Set pattern for JavaScript setting.
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
host_content_settings_map->SetContentSetting(pattern,
CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_BLOCK);
@@ -833,7 +776,7 @@ TEST_F(HostContentSettingsMapTest,
CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
// Set an exception to allow "[*.]example.com"
- HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ ContentSettingsPattern pattern("[*.]example.com");
host_content_settings_map->SetContentSetting(pattern,
CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_ALLOW);
@@ -905,7 +848,7 @@ TEST_F(HostContentSettingsMapTest, ObserveManagedSettingsChange) {
prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting,
Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
EXPECT_EQ(host_content_settings_map, observer.last_notifier);
- EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern);
+ EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern);
EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
EXPECT_TRUE(observer.last_update_all);
EXPECT_TRUE(observer.last_update_all_types);
@@ -915,7 +858,7 @@ TEST_F(HostContentSettingsMapTest, ObserveManagedSettingsChange) {
prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting);
EXPECT_EQ(host_content_settings_map, observer.last_notifier);
EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
- EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern);
+ EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern);
EXPECT_TRUE(observer.last_update_all);
EXPECT_TRUE(observer.last_update_all_types);
EXPECT_EQ(2, observer.counter);
@@ -941,7 +884,7 @@ TEST_F(HostContentSettingsMapTest, ObserveManagedSettingsNoChange) {
prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting,
Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
EXPECT_EQ(host_content_settings_map, observer.last_notifier);
- EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern);
+ EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern);
EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
EXPECT_TRUE(observer.last_update_all);
EXPECT_TRUE(observer.last_update_all_types);
@@ -951,7 +894,7 @@ TEST_F(HostContentSettingsMapTest, ObserveManagedSettingsNoChange) {
prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting);
EXPECT_EQ(host_content_settings_map, observer.last_notifier);
EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
- EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern);
+ EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern);
EXPECT_TRUE(observer.last_update_all);
EXPECT_TRUE(observer.last_update_all_types);
EXPECT_EQ(2, observer.counter);

Powered by Google App Engine
This is Rietveld 408576698