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

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

Issue 11667006: Create a list of policy changes before notifying observers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix lint error/merge to ToT Created 8 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/policy_service_impl_unittest.cc
diff --git a/chrome/browser/policy/policy_service_impl_unittest.cc b/chrome/browser/policy/policy_service_impl_unittest.cc
index 4ee3a677677c7279a941e6d154cf1f7e67e458bb..49a9fc2d2115590c7e81b1705aacd907634ec9b1 100644
--- a/chrome/browser/policy/policy_service_impl_unittest.cc
+++ b/chrome/browser/policy/policy_service_impl_unittest.cc
@@ -66,6 +66,27 @@ void AddTestPolicies(PolicyBundle* bundle,
base::Value::CreateStringValue(value));
}
+// Observer class that changes the policy in the passed provider when the
+// callback is invoked.
+class ChangePolicyObserver : public PolicyService::Observer {
Joao da Silva 2012/12/22 21:42:00 Suggestion: the MockPolicyServiceObserver class ab
Andrew T Wilson (Slow) 2013/01/04 15:54:48 Apparently we're trying to get rid of ACTION_P: ht
+ public:
+ explicit ChangePolicyObserver(MockConfigurationPolicyProvider* provider)
+ : provider_(provider) {}
+
+ virtual void OnPolicyUpdated(PolicyDomain domain,
+ const std::string& ns,
+ const PolicyMap& previous,
+ const PolicyMap& current) {
Joao da Silva 2012/12/22 21:42:00 OVERRIDE
Andrew T Wilson (Slow) 2013/01/04 15:54:48 Done.
+ PolicyMap new_policy;
+ new_policy.Set("foo", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateIntegerValue(14));
+ provider_->UpdateChromePolicy(new_policy);
+ }
+
+ private:
+ MockConfigurationPolicyProvider* provider_;
+};
+
} // namespace
class PolicyServiceTest : public testing::Test {
@@ -275,6 +296,18 @@ TEST_F(PolicyServiceTest, NotifyObserversInMultipleNamespaces) {
&extension_observer);
}
+TEST_F(PolicyServiceTest, ObserverChangesPolicy) {
+ ChangePolicyObserver observer(&provider0_);
+ policy_service_->AddObserver(POLICY_DOMAIN_CHROME, &observer);
+ policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateIntegerValue(123));
+ policy0_.Set("bbb", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ base::Value::CreateIntegerValue(1234));
+ // Should not crash.
+ provider0_.UpdateChromePolicy(policy0_);
+ policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, &observer);
+}
+
TEST_F(PolicyServiceTest, Priorities) {
PolicyMap expected;
expected.Set("pre", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
« chrome/browser/policy/policy_service_impl.cc ('K') | « chrome/browser/policy/policy_service_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698