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

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

Issue 6840014: Support decoding GenericNamedValue based policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit test broken by patch set 2 Created 9 years, 8 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
« no previous file with comments | « chrome/browser/policy/user_policy_cache.cc ('k') | net/tools/testserver/device_management.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/policy/user_policy_cache_unittest.cc
diff --git a/chrome/browser/policy/user_policy_cache_unittest.cc b/chrome/browser/policy/user_policy_cache_unittest.cc
index 8e7453561be74c0dda36f24d5389407a4864e81c..fdf910247a6472bfff9be20a83b32da14b6be10f 100644
--- a/chrome/browser/policy/user_policy_cache_unittest.cc
+++ b/chrome/browser/policy/user_policy_cache_unittest.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/policy/proto/cloud_policy.pb.h"
#include "chrome/browser/policy/proto/device_management_backend.pb.h"
#include "chrome/browser/policy/proto/device_management_local.pb.h"
+#include "chrome/browser/policy/proto/old_generic_format.pb.h"
#include "content/browser/browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -335,4 +336,41 @@ TEST_F(UserPolicyCacheTest, FreshPolicyOverride) {
EXPECT_TRUE(expected.Equals(mandatory_policy(cache)));
}
+// Test case for the temporary support for GenericNamedValues in the
+// CloudPolicySettings protobuf. Can be removed when this support is no longer
+// required.
+TEST_F(UserPolicyCacheTest, OldStylePolicy) {
+ UserPolicyCache cache(test_file());
+ em::PolicyFetchResponse* policy = new em::PolicyFetchResponse();
+ em::PolicyData signed_response;
+ em::LegacyChromeSettingsProto settings;
+ em::GenericNamedValue* named_value = settings.add_named_value();
+ named_value->set_name("HomepageLocation");
+ em::GenericValue* value_container = named_value->mutable_value();
+ value_container->set_value_type(em::GenericValue::VALUE_TYPE_STRING);
+ value_container->set_string_value("http://www.example.com");
+ EXPECT_TRUE(
+ settings.SerializeToString(signed_response.mutable_policy_value()));
+ base::TimeDelta timestamp =
+ base::Time::NowFromSystemTime() - base::Time::UnixEpoch();
+ signed_response.set_timestamp(timestamp.InMilliseconds());
+ EXPECT_TRUE(
+ signed_response.SerializeToString(policy->mutable_policy_data()));
+
+ SetPolicy(&cache, policy, true);
+ PolicyMap expected;
+ expected.Set(kPolicyHomepageLocation,
+ Value::CreateStringValue("http://www.example.com"));
+ PolicyMap empty;
+ EXPECT_TRUE(expected.Equals(mandatory_policy(cache)));
+ EXPECT_TRUE(empty.Equals(recommended_policy(cache)));
+ // If new-style policy comes in, it should override old-style policy.
+ policy = CreateHomepagePolicy("http://www.example.com",
+ base::Time::NowFromSystemTime(),
+ em::PolicyOptions::RECOMMENDED);
+ SetPolicy(&cache, policy, true);
+ EXPECT_TRUE(expected.Equals(recommended_policy(cache)));
+ EXPECT_TRUE(empty.Equals(mandatory_policy(cache)));
+}
+
} // namespace policy
« no previous file with comments | « chrome/browser/policy/user_policy_cache.cc ('k') | net/tools/testserver/device_management.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698