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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/policy/user_policy_cache.h" 5 #include "chrome/browser/policy/user_policy_cache.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 em::PolicyOptions::MANDATORY); 328 em::PolicyOptions::MANDATORY);
329 SetPolicy(&cache, updated_policy, true); 329 SetPolicy(&cache, updated_policy, true);
330 330
331 cache.Load(); 331 cache.Load();
332 PolicyMap expected; 332 PolicyMap expected;
333 expected.Set(kPolicyHomepageLocation, 333 expected.Set(kPolicyHomepageLocation,
334 Value::CreateStringValue("http://www.chromium.org")); 334 Value::CreateStringValue("http://www.chromium.org"));
335 EXPECT_TRUE(expected.Equals(mandatory_policy(cache))); 335 EXPECT_TRUE(expected.Equals(mandatory_policy(cache)));
336 } 336 }
337 337
338 // Test case for the temporary support for GenericNamedValues in the
339 // CloudPolicySettings protobuf. Can be removed when this support is no longer
340 // required.
341 TEST_F(UserPolicyCacheTest, OldStylePolicy) {
342 UserPolicyCache cache(test_file());
343 em::PolicyFetchResponse* policy = new em::PolicyFetchResponse();
344 em::PolicyData signed_response;
345 em::CloudPolicySettings settings;
346 em::GenericNamedValue* named_value = settings.add_named_value();
347 named_value->set_name("HomepageLocation");
348 em::GenericValue* value_container = named_value->mutable_value();
349 value_container->set_value_type(em::GenericValue::VALUE_TYPE_STRING);
350 value_container->set_string_value("http://www.example.com");
351 EXPECT_TRUE(
352 settings.SerializeToString(signed_response.mutable_policy_value()));
353 base::TimeDelta timestamp =
354 base::Time::NowFromSystemTime() - base::Time::UnixEpoch();
355 signed_response.set_timestamp(timestamp.InMilliseconds());
356 EXPECT_TRUE(
357 signed_response.SerializeToString(policy->mutable_policy_data()));
358
359 SetPolicy(&cache, policy, true);
360 PolicyMap expected;
361 expected.Set(kPolicyHomepageLocation,
362 Value::CreateStringValue("http://www.example.com"));
363 PolicyMap empty;
364 EXPECT_TRUE(expected.Equals(mandatory_policy(cache)));
365 EXPECT_TRUE(empty.Equals(recommended_policy(cache)));
366 // If new-style policy comes in, it should override old-style policy.
367 policy = CreateHomepagePolicy("http://www.example.com",
368 base::Time::NowFromSystemTime(),
369 em::PolicyOptions::RECOMMENDED);
370 SetPolicy(&cache, policy, true);
371 EXPECT_TRUE(expected.Equals(recommended_policy(cache)));
372 EXPECT_TRUE(empty.Equals(mandatory_policy(cache)));
373 }
374
338 } // namespace policy 375 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698