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

Unified Diff: components/policy/core/common/configuration_policy_provider_test.cc

Issue 2414663002: Fix log spew for "_comment..." policies. (Closed)
Patch Set: Rename EraseGeneric() to FilterErase(). Created 4 years, 2 months 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: components/policy/core/common/configuration_policy_provider_test.cc
diff --git a/components/policy/core/common/configuration_policy_provider_test.cc b/components/policy/core/common/configuration_policy_provider_test.cc
index b8e5356558c959eec624c7b72ded30247e589f27..492ab02532929132fe8edd9cd14eff53c1def62b 100644
--- a/components/policy/core/common/configuration_policy_provider_test.cc
+++ b/components/policy/core/common/configuration_policy_provider_test.cc
@@ -17,14 +17,13 @@
#include "components/policy/core/common/policy_bundle.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_namespace.h"
-#include "components/policy/core/common/policy_test_utils.h"
#include "components/policy/core/common/policy_types.h"
#include "testing/gmock/include/gmock/gmock.h"
using ::testing::Mock;
using ::testing::_;
-namespace {
+namespace policy {
const char kTestChromeSchema[] =
"{"
@@ -116,15 +115,8 @@ const char kTestChromeSchema[] =
" }"
"}";
-} // anonymous namespace
-
-namespace policy {
-
namespace test_keys {
-// These are the defaults for PolicyProviderTestHarness but they are generally
-// available for use in other tests. Subclasses of PolicyProviderTestHarness
-// may use different values.
const char kKeyString[] = "StringPolicy";
const char kKeyBoolean[] = "BooleanPolicy";
const char kKeyInteger[] = "IntegerPolicy";
@@ -166,19 +158,22 @@ bool PolicyTestBase::RegisterSchema(const PolicyNamespace& ns,
PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level,
PolicyScope scope,
PolicySource source)
- : key_string_(test_keys::kKeyString),
- key_boolean_(test_keys::kKeyBoolean),
- key_integer_(test_keys::kKeyInteger),
- key_stringlist_(test_keys::kKeyStringList),
- key_dictionary_(test_keys::kKeyDictionary),
- test_schema_(kTestChromeSchema),
- level_(level),
- scope_(scope),
- source_(source) {
-}
+ : level_(level), scope_(scope), source_(source) {}
PolicyProviderTestHarness::~PolicyProviderTestHarness() {}
+PolicyLevel PolicyProviderTestHarness::policy_level() const {
+ return level_;
+}
+
+PolicyScope PolicyProviderTestHarness::policy_scope() const {
+ return scope_;
+}
+
+PolicySource PolicyProviderTestHarness::policy_source() const {
+ return source_;
+}
+
void PolicyProviderTestHarness::Install3rdPartyPolicy(
const base::DictionaryValue* policies) {
FAIL();
@@ -189,15 +184,15 @@ ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {}
ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {}
void ConfigurationPolicyProviderTest::SetUp() {
- harness_.reset((*GetParam())());
- harness_->SetUp();
+ PolicyTestBase::SetUp();
- const PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, "");
- ASSERT_TRUE(RegisterSchema(chrome_ns, harness_->test_schema()));
+ test_harness_.reset((*GetParam())());
+ test_harness_->SetUp();
+ const PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, "");
Schema chrome_schema = *schema_registry_.schema_map()->GetSchema(chrome_ns);
Schema extension_schema =
- chrome_schema.GetKnownProperty(harness_->key_dictionary());
+ chrome_schema.GetKnownProperty(test_keys::kKeyDictionary);
ASSERT_TRUE(extension_schema.valid());
schema_registry_.RegisterComponent(
PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
@@ -213,7 +208,7 @@ void ConfigurationPolicyProviderTest::SetUp() {
extension_schema);
provider_.reset(
- harness_->CreateProvider(&schema_registry_, loop_.task_runner()));
+ test_harness_->CreateProvider(&schema_registry_, loop_.task_runner()));
provider_->Init(&schema_registry_);
// Some providers do a reload on init. Make sure any notifications generated
// are fired now.
@@ -225,10 +220,8 @@ void ConfigurationPolicyProviderTest::SetUp() {
void ConfigurationPolicyProviderTest::TearDown() {
// Give providers the chance to clean up after themselves on the file thread.
- if (provider_) {
- provider_->Shutdown();
- provider_.reset();
- }
+ provider_->Shutdown();
+ provider_.reset();
PolicyTestBase::TearDown();
}
@@ -243,14 +236,10 @@ void ConfigurationPolicyProviderTest::CheckValue(
base::RunLoop().RunUntilIdle();
PolicyBundle expected_bundle;
expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
- .Set(policy_name, harness_->policy_level(), harness_->policy_scope(),
- harness_->policy_source(), expected_value.CreateDeepCopy(), nullptr);
- bool match = provider_->policies().Equals(expected_bundle);
- if (!match) {
- LOG(ERROR) << "EXPECTED: " << expected_bundle;
- LOG(ERROR) << "ACTUAL: " << provider_->policies();
- }
- EXPECT_TRUE(match);
+ .Set(policy_name, test_harness_->policy_level(),
+ test_harness_->policy_scope(), test_harness_->policy_source(),
+ expected_value.CreateDeepCopy(), nullptr);
+ EXPECT_TRUE(provider_->policies().Equals(expected_bundle));
// TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too,
// and extend the |expected_bundle|, once all providers are ready.
}
@@ -265,31 +254,31 @@ TEST_P(ConfigurationPolicyProviderTest, Empty) {
TEST_P(ConfigurationPolicyProviderTest, StringValue) {
const char kTestString[] = "string_value";
base::StringValue expected_value(kTestString);
- CheckValue(harness_->key_string(),
+ CheckValue(test_keys::kKeyString,
expected_value,
base::Bind(&PolicyProviderTestHarness::InstallStringPolicy,
- base::Unretained(harness_.get()),
- harness_->key_string(),
+ base::Unretained(test_harness_.get()),
+ test_keys::kKeyString,
kTestString));
}
TEST_P(ConfigurationPolicyProviderTest, BooleanValue) {
base::FundamentalValue expected_value(true);
- CheckValue(harness_->key_boolean(),
+ CheckValue(test_keys::kKeyBoolean,
expected_value,
base::Bind(&PolicyProviderTestHarness::InstallBooleanPolicy,
- base::Unretained(harness_.get()),
- harness_->key_boolean(),
+ base::Unretained(test_harness_.get()),
+ test_keys::kKeyBoolean,
true));
}
TEST_P(ConfigurationPolicyProviderTest, IntegerValue) {
base::FundamentalValue expected_value(42);
- CheckValue(harness_->key_integer(),
+ CheckValue(test_keys::kKeyInteger,
expected_value,
base::Bind(&PolicyProviderTestHarness::InstallIntegerPolicy,
- base::Unretained(harness_.get()),
- harness_->key_integer(),
+ base::Unretained(test_harness_.get()),
+ test_keys::kKeyInteger,
42));
}
@@ -297,11 +286,11 @@ TEST_P(ConfigurationPolicyProviderTest, StringListValue) {
base::ListValue expected_value;
expected_value.Set(0U, new base::StringValue("first"));
expected_value.Set(1U, new base::StringValue("second"));
- CheckValue(harness_->key_stringlist(),
+ CheckValue(test_keys::kKeyStringList,
expected_value,
base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy,
- base::Unretained(harness_.get()),
- harness_->key_stringlist(),
+ base::Unretained(test_harness_.get()),
+ test_keys::kKeyStringList,
&expected_value));
}
@@ -331,11 +320,11 @@ TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) {
dict->Set("sublist", list);
expected_value.Set("dictionary", dict);
- CheckValue(harness_->key_dictionary(),
+ CheckValue(test_keys::kKeyDictionary,
expected_value,
base::Bind(&PolicyProviderTestHarness::InstallDictionaryPolicy,
- base::Unretained(harness_.get()),
- harness_->key_dictionary(),
+ base::Unretained(test_harness_.get()),
+ test_keys::kKeyDictionary,
&expected_value));
}
@@ -354,15 +343,15 @@ TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) {
EXPECT_TRUE(provider_->policies().Equals(bundle));
// OnUpdatePolicy is called when there are changes.
- harness_->InstallStringPolicy(harness_->key_string(), "value");
+ test_harness_->InstallStringPolicy(test_keys::kKeyString, "value");
EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1);
provider_->RefreshPolicies();
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(&observer);
bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
- .Set(harness_->key_string(), harness_->policy_level(),
- harness_->policy_scope(), harness_->policy_source(),
+ .Set(test_keys::kKeyString, test_harness_->policy_level(),
+ test_harness_->policy_scope(), test_harness_->policy_source(),
base::MakeUnique<base::StringValue>("value"), nullptr);
EXPECT_TRUE(provider_->policies().Equals(bundle));
provider_->RemoveObserver(&observer);
@@ -392,7 +381,8 @@ TEST_P(Configuration3rdPartyPolicyProviderTest, Load3rdParty) {
policy_dict.Set("dict", policy_dict.DeepCopy());
// Install these policies as a Chrome policy.
- harness_->InstallDictionaryPolicy(harness_->key_dictionary(), &policy_dict);
+ test_harness_->InstallDictionaryPolicy(test_keys::kKeyDictionary,
+ &policy_dict);
// Install them as 3rd party policies too.
base::DictionaryValue policy_3rdparty;
policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
@@ -404,23 +394,24 @@ TEST_P(Configuration3rdPartyPolicyProviderTest, Load3rdParty) {
policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy());
policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc",
new base::StringValue("invalid-value"));
- harness_->Install3rdPartyPolicy(&policy_3rdparty);
+ test_harness_->Install3rdPartyPolicy(&policy_3rdparty);
provider_->RefreshPolicies();
base::RunLoop().RunUntilIdle();
PolicyMap expected_policy;
- expected_policy.Set(harness_->key_dictionary(), harness_->policy_level(),
- harness_->policy_scope(), harness_->policy_source(),
+ expected_policy.Set(test_keys::kKeyDictionary, test_harness_->policy_level(),
+ test_harness_->policy_scope(),
+ test_harness_->policy_source(),
policy_dict.CreateDeepCopy(), nullptr);
PolicyBundle expected_bundle;
expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
.CopyFrom(expected_policy);
expected_policy.Clear();
expected_policy.LoadFrom(&policy_dict,
- harness_->policy_level(),
- harness_->policy_scope(),
- harness_->policy_source());
+ test_harness_->policy_level(),
+ test_harness_->policy_scope(),
+ test_harness_->policy_source());
expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
.CopyFrom(expected_policy);

Powered by Google App Engine
This is Rietveld 408576698