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

Unified Diff: chrome/browser/policy/configuration_policy_pref_store_unittest.cc

Issue 5915004: Introduce incognito preference settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Whitespaces + fixes for trybot 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/policy/configuration_policy_pref_store_unittest.cc
diff --git a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
index 80c69e451355ed36f9ae9ab6a97bc34ac5813d86..55225dbbfaaf3b8dce9127e36f0ed54f445af7c4 100644
--- a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
@@ -5,6 +5,7 @@
#include <gtest/gtest.h>
#include "base/file_path.h"
+#include "base/ref_counted.h"
#include "chrome/browser/policy/configuration_policy_pref_store.h"
#include "chrome/browser/policy/mock_configuration_policy_provider.h"
#include "chrome/common/pref_names.h"
@@ -32,10 +33,10 @@ class ConfigurationPolicyPrefStoreTestBase : public TESTBASE {
protected:
ConfigurationPolicyPrefStoreTestBase()
: provider_(),
- store_(&provider_) {}
+ store_(new ConfigurationPolicyPrefStore(&provider_)) {}
MockConfigurationPolicyProvider provider_;
- ConfigurationPolicyPrefStore store_;
+ scoped_refptr<ConfigurationPolicyPrefStore> store_;
};
// Test cases for list-valued policy settings.
@@ -46,16 +47,16 @@ class ConfigurationPolicyPrefStoreListTest
TEST_P(ConfigurationPolicyPrefStoreListTest, GetDefault) {
ListValue* list = NULL;
- EXPECT_FALSE(store_.prefs()->GetList(GetParam().pref_name(), &list));
+ EXPECT_FALSE(store_->prefs()->GetList(GetParam().pref_name(), &list));
}
TEST_P(ConfigurationPolicyPrefStoreListTest, SetValue) {
ListValue* in_value = new ListValue();
in_value->Append(Value::CreateStringValue("test1"));
in_value->Append(Value::CreateStringValue("test2,"));
- store_.Apply(GetParam().type(), in_value);
+ store_->Apply(GetParam().type(), in_value);
ListValue* list = NULL;
- EXPECT_TRUE(store_.prefs()->GetList(GetParam().pref_name(), &list));
+ EXPECT_TRUE(store_->prefs()->GetList(GetParam().pref_name(), &list));
ListValue::const_iterator current(list->begin());
const ListValue::const_iterator end(list->end());
ASSERT_TRUE(current != end);
@@ -91,14 +92,14 @@ class ConfigurationPolicyPrefStoreStringTest
TEST_P(ConfigurationPolicyPrefStoreStringTest, GetDefault) {
std::string result;
- EXPECT_FALSE(store_.prefs()->GetString(GetParam().pref_name(), &result));
+ EXPECT_FALSE(store_->prefs()->GetString(GetParam().pref_name(), &result));
}
TEST_P(ConfigurationPolicyPrefStoreStringTest, SetValue) {
- store_.Apply(GetParam().type(),
- Value::CreateStringValue("http://chromium.org"));
+ store_->Apply(GetParam().type(),
+ Value::CreateStringValue("http://chromium.org"));
std::string result;
- EXPECT_TRUE(store_.prefs()->GetString(GetParam().pref_name(), &result));
+ EXPECT_TRUE(store_->prefs()->GetString(GetParam().pref_name(), &result));
EXPECT_EQ(result, "http://chromium.org");
}
@@ -135,18 +136,18 @@ class ConfigurationPolicyPrefStoreBooleanTest
TEST_P(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) {
bool result = false;
- EXPECT_FALSE(store_.prefs()->GetBoolean(GetParam().pref_name(), &result));
+ EXPECT_FALSE(store_->prefs()->GetBoolean(GetParam().pref_name(), &result));
}
TEST_P(ConfigurationPolicyPrefStoreBooleanTest, SetValue) {
- store_.Apply(GetParam().type(), Value::CreateBooleanValue(false));
+ store_->Apply(GetParam().type(), Value::CreateBooleanValue(false));
bool result = true;
- EXPECT_TRUE(store_.prefs()->GetBoolean(GetParam().pref_name(), &result));
+ EXPECT_TRUE(store_->prefs()->GetBoolean(GetParam().pref_name(), &result));
EXPECT_FALSE(result);
- store_.Apply(GetParam().type(), Value::CreateBooleanValue(true));
+ store_->Apply(GetParam().type(), Value::CreateBooleanValue(true));
result = false;
- EXPECT_TRUE(store_.prefs()->GetBoolean(GetParam().pref_name(), &result));
+ EXPECT_TRUE(store_->prefs()->GetBoolean(GetParam().pref_name(), &result));
EXPECT_TRUE(result);
}
@@ -204,13 +205,13 @@ class ConfigurationPolicyPrefStoreIntegerTest
TEST_P(ConfigurationPolicyPrefStoreIntegerTest, GetDefault) {
int result = 0;
- EXPECT_FALSE(store_.prefs()->GetInteger(GetParam().pref_name(), &result));
+ EXPECT_FALSE(store_->prefs()->GetInteger(GetParam().pref_name(), &result));
}
TEST_P(ConfigurationPolicyPrefStoreIntegerTest, SetValue) {
- store_.Apply(GetParam().type(), Value::CreateIntegerValue(2));
+ store_->Apply(GetParam().type(), Value::CreateIntegerValue(2));
int result = 0;
- EXPECT_TRUE(store_.prefs()->GetInteger(GetParam().pref_name(), &result));
+ EXPECT_TRUE(store_->prefs()->GetInteger(GetParam().pref_name(), &result));
EXPECT_EQ(result, 2);
}
@@ -238,20 +239,22 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) {
Value::CreateIntegerValue(
kPolicyManuallyConfiguredProxyMode));
- ConfigurationPolicyPrefStore store(provider.get());
+ scoped_refptr<ConfigurationPolicyPrefStore> store(
+ new ConfigurationPolicyPrefStore(provider.get()));
std::string string_result;
- EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList,
- &string_result));
+ EXPECT_TRUE(store->prefs()->GetString(prefs::kProxyBypassList,
+ &string_result));
EXPECT_EQ("http://chromium.org/override", string_result);
- EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
+ EXPECT_TRUE(store->prefs()->GetString(prefs::kProxyPacUrl, &string_result));
EXPECT_EQ("http://short.org/proxy.pac", string_result);
- EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
+ EXPECT_TRUE(store->prefs()->GetString(prefs::kProxyServer, &string_result));
EXPECT_EQ("chromium.org", string_result);
bool bool_result;
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
+ EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
EXPECT_FALSE(bool_result);
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
+ EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kProxyAutoDetect,
+ &bool_result));
EXPECT_FALSE(bool_result);
}
@@ -264,17 +267,19 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxy) {
Value::CreateIntegerValue(
kPolicyNoProxyServerMode));
- ConfigurationPolicyPrefStore store(provider.get());
+ scoped_refptr<ConfigurationPolicyPrefStore> store(
+ new ConfigurationPolicyPrefStore(provider.get()));
std::string string_result;
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
- &string_result));
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyBypassList,
+ &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyPacUrl, &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyServer, &string_result));
bool bool_result;
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
+ EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
EXPECT_TRUE(bool_result);
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
+ EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kProxyAutoDetect,
+ &bool_result));
EXPECT_FALSE(bool_result);
}
@@ -287,17 +292,19 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxyReversedApplyOrder) {
provider->AddPolicy(kPolicyProxyBypassList,
Value::CreateStringValue("http://chromium.org/override"));
- ConfigurationPolicyPrefStore store(provider.get());
+ scoped_refptr<ConfigurationPolicyPrefStore> store(
+ new ConfigurationPolicyPrefStore(provider.get()));
std::string string_result;
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
- &string_result));
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyBypassList,
+ &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyPacUrl, &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyServer, &string_result));
bool bool_result;
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
+ EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
EXPECT_TRUE(bool_result);
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
+ EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kProxyAutoDetect,
+ &bool_result));
EXPECT_FALSE(bool_result);
}
@@ -308,17 +315,19 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetect) {
Value::CreateIntegerValue(
kPolicyAutoDetectProxyMode));
- ConfigurationPolicyPrefStore store(provider.get());
+ scoped_refptr<ConfigurationPolicyPrefStore> store(
+ new ConfigurationPolicyPrefStore(provider.get()));
std::string string_result;
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
- &string_result));
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyBypassList,
+ &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyPacUrl, &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyServer, &string_result));
bool bool_result;
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
+ EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
EXPECT_FALSE(bool_result);
- EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
+ EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kProxyAutoDetect,
+ &bool_result));
EXPECT_TRUE(bool_result);
}
@@ -331,17 +340,18 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystem) {
Value::CreateIntegerValue(
kPolicyUseSystemProxyMode));
- ConfigurationPolicyPrefStore store(provider.get());
+ scoped_refptr<ConfigurationPolicyPrefStore> store(
+ new ConfigurationPolicyPrefStore(provider.get()));
std::string string_result;
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
- &string_result));
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyBypassList,
+ &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyPacUrl, &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyServer, &string_result));
bool bool_result;
- EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
- EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect,
- &bool_result));
+ EXPECT_FALSE(store->prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
+ EXPECT_FALSE(store->prefs()->GetBoolean(prefs::kProxyAutoDetect,
+ &bool_result));
}
TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystemReversedApplyOrder) {
@@ -353,17 +363,18 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystemReversedApplyOrder) {
provider->AddPolicy(kPolicyProxyBypassList,
Value::CreateStringValue("http://chromium.org/override"));
- ConfigurationPolicyPrefStore store(provider.get());
+ scoped_refptr<ConfigurationPolicyPrefStore> store(
+ new ConfigurationPolicyPrefStore(provider.get()));
std::string string_result;
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
- &string_result));
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
- EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyBypassList,
+ &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyPacUrl, &string_result));
+ EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyServer, &string_result));
bool bool_result;
- EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
- EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect,
- &bool_result));
+ EXPECT_FALSE(store->prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
+ EXPECT_FALSE(store->prefs()->GetBoolean(prefs::kProxyAutoDetect,
+ &bool_result));
}
class ConfigurationPolicyPrefStoreDefaultSearchTest : public testing::Test {
@@ -382,8 +393,9 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) {
kPolicyDefaultSearchProviderSearchURL,
Value::CreateStringValue(search_url));
- ConfigurationPolicyPrefStore store(provider.get());
- const DictionaryValue* prefs = store.prefs();
+ scoped_refptr<ConfigurationPolicyPrefStore> store(
+ new ConfigurationPolicyPrefStore(provider.get()));
+ const DictionaryValue* prefs = store->prefs();
std::string string_result;
EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL,
@@ -444,8 +456,9 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, FullyDefined) {
kPolicyDefaultSearchProviderEncodings,
Value::CreateStringValue(encodings));
- ConfigurationPolicyPrefStore store(provider.get());
- const DictionaryValue* prefs = store.prefs();
+ scoped_refptr<ConfigurationPolicyPrefStore> store(
+ new ConfigurationPolicyPrefStore(provider.get()));
+ const DictionaryValue* prefs = store->prefs();
std::string result_search_url;
EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL,
@@ -507,8 +520,9 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MissingUrl) {
kPolicyDefaultSearchProviderEncodings,
Value::CreateStringValue(encodings));
- ConfigurationPolicyPrefStore store(provider.get());
- const DictionaryValue* prefs = store.prefs();
+ scoped_refptr<ConfigurationPolicyPrefStore> store(
+ new ConfigurationPolicyPrefStore(provider.get()));
+ const DictionaryValue* prefs = store->prefs();
std::string string_result;
EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL,
@@ -558,8 +572,9 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Invalid) {
kPolicyDefaultSearchProviderEncodings,
Value::CreateStringValue(encodings));
- ConfigurationPolicyPrefStore store(provider.get());
- const DictionaryValue* const prefs = store.prefs();
+ scoped_refptr<ConfigurationPolicyPrefStore> store(
+ new ConfigurationPolicyPrefStore(provider.get()));
+ const DictionaryValue* const prefs = store->prefs();
std::string string_result;
EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEnabled,
@@ -585,21 +600,21 @@ class ConfigurationPolicyPrefStoreSyncTest
TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) {
bool result = false;
- EXPECT_FALSE(store_.prefs()->GetBoolean(prefs::kSyncManaged, &result));
+ EXPECT_FALSE(store_->prefs()->GetBoolean(prefs::kSyncManaged, &result));
}
TEST_F(ConfigurationPolicyPrefStoreSyncTest, Enabled) {
- store_.Apply(kPolicySyncDisabled, Value::CreateBooleanValue(false));
+ store_->Apply(kPolicySyncDisabled, Value::CreateBooleanValue(false));
// Enabling Sync should not set the pref.
bool result = false;
- EXPECT_FALSE(store_.prefs()->GetBoolean(prefs::kSyncManaged, &result));
+ EXPECT_FALSE(store_->prefs()->GetBoolean(prefs::kSyncManaged, &result));
}
TEST_F(ConfigurationPolicyPrefStoreSyncTest, Disabled) {
- store_.Apply(kPolicySyncDisabled, Value::CreateBooleanValue(true));
+ store_->Apply(kPolicySyncDisabled, Value::CreateBooleanValue(true));
// Sync should be flagged as managed.
bool result = false;
- EXPECT_TRUE(store_.prefs()->GetBoolean(prefs::kSyncManaged, &result));
+ EXPECT_TRUE(store_->prefs()->GetBoolean(prefs::kSyncManaged, &result));
EXPECT_TRUE(result);
}
@@ -610,21 +625,21 @@ class ConfigurationPolicyPrefStoreAutoFillTest
TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Default) {
bool result = false;
- EXPECT_FALSE(store_.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result));
+ EXPECT_FALSE(store_->prefs()->GetBoolean(prefs::kAutoFillEnabled, &result));
}
TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Enabled) {
- store_.Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(true));
+ store_->Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(true));
// Enabling AutoFill should not set the pref.
bool result = false;
- EXPECT_FALSE(store_.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result));
+ EXPECT_FALSE(store_->prefs()->GetBoolean(prefs::kAutoFillEnabled, &result));
}
TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Disabled) {
- store_.Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(false));
+ store_->Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(false));
// Disabling AutoFill should switch the pref to managed.
bool result = true;
- EXPECT_TRUE(store_.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result));
+ EXPECT_TRUE(store_->prefs()->GetBoolean(prefs::kAutoFillEnabled, &result));
EXPECT_FALSE(result);
}

Powered by Google App Engine
This is Rietveld 408576698