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

Side by Side Diff: chrome/browser/policy/user_policy_cache_unittest.cc

Issue 8586030: Added ConfigurationPolicyProvider::RefreshPolicies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 9 years, 1 month 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
« no previous file with comments | « chrome/browser/policy/user_policy_cache.cc ('k') | chrome/browser/ui/webui/policy_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 em::CachedCloudPolicyResponse cached_policy; 96 em::CachedCloudPolicyResponse cached_policy;
97 cached_policy.mutable_cloud_policy()->CopyFrom(policy); 97 cached_policy.mutable_cloud_policy()->CopyFrom(policy);
98 EXPECT_TRUE(cached_policy.SerializeToString(&data)); 98 EXPECT_TRUE(cached_policy.SerializeToString(&data));
99 int size = static_cast<int>(data.size()); 99 int size = static_cast<int>(data.size());
100 EXPECT_EQ(size, file_util::WriteFile(test_file(), data.c_str(), size)); 100 EXPECT_EQ(size, file_util::WriteFile(test_file(), data.c_str(), size));
101 } 101 }
102 102
103 // Takes ownership of |policy_response|. 103 // Takes ownership of |policy_response|.
104 void SetPolicy(UserPolicyCache* cache, 104 void SetPolicy(UserPolicyCache* cache,
105 em::PolicyFetchResponse* policy_response) { 105 em::PolicyFetchResponse* policy_response) {
106 EXPECT_CALL(observer_, OnCacheUpdate(_)).Times(1);
107 cache->AddObserver(&observer_);
108
106 scoped_ptr<em::PolicyFetchResponse> policy(policy_response); 109 scoped_ptr<em::PolicyFetchResponse> policy(policy_response);
110 cache->SetPolicy(*policy);
107 cache->SetReady(); 111 cache->SetReady();
108 cache->AddObserver(&observer); 112 testing::Mock::VerifyAndClearExpectations(&observer_);
109 113
110 EXPECT_CALL(observer, OnCacheUpdate(_)).Times(1); 114 cache->RemoveObserver(&observer_);
111
112 cache->SetPolicy(*policy);
113 testing::Mock::VerifyAndClearExpectations(&observer);
114
115 cache->RemoveObserver(&observer);
116 } 115 }
117 116
118 void SetReady(UserPolicyCache* cache) { 117 void SetReady(UserPolicyCache* cache) {
119 cache->SetReady(); 118 cache->SetReady();
120 } 119 }
121 120
122 FilePath test_file() { 121 FilePath test_file() {
123 return temp_dir_.path().AppendASCII("UserPolicyCacheTest"); 122 return temp_dir_.path().AppendASCII("UserPolicyCacheTest");
124 } 123 }
125 124
126 const PolicyMap& mandatory_policy(const UserPolicyCache& cache) { 125 const PolicyMap& mandatory_policy(const UserPolicyCache& cache) {
127 return cache.mandatory_policy_; 126 return cache.mandatory_policy_;
128 } 127 }
129 128
130 const PolicyMap& recommended_policy(const UserPolicyCache& cache) { 129 const PolicyMap& recommended_policy(const UserPolicyCache& cache) {
131 return cache.recommended_policy_; 130 return cache.recommended_policy_;
132 } 131 }
133 132
134 MessageLoop loop_; 133 MessageLoop loop_;
135 MockCloudPolicyCacheBaseObserver observer; 134 MockCloudPolicyCacheBaseObserver observer_;
136 135
137 private: 136 private:
138 ScopedTempDir temp_dir_; 137 ScopedTempDir temp_dir_;
139 content::TestBrowserThread ui_thread_; 138 content::TestBrowserThread ui_thread_;
140 content::TestBrowserThread file_thread_; 139 content::TestBrowserThread file_thread_;
141 }; 140 };
142 141
143 TEST_F(UserPolicyCacheTest, DecodePolicy) { 142 TEST_F(UserPolicyCacheTest, DecodePolicy) {
144 em::CloudPolicySettings settings; 143 em::CloudPolicySettings settings;
145 settings.mutable_homepagelocation()->set_homepagelocation("chromium.org"); 144 settings.mutable_homepagelocation()->set_homepagelocation("chromium.org");
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 cache.Load(); 351 cache.Load();
353 loop_.RunAllPending(); 352 loop_.RunAllPending();
354 PolicyMap expected; 353 PolicyMap expected;
355 expected.Set(kPolicyHomepageLocation, 354 expected.Set(kPolicyHomepageLocation,
356 Value::CreateStringValue("http://www.chromium.org")); 355 Value::CreateStringValue("http://www.chromium.org"));
357 EXPECT_TRUE(expected.Equals(mandatory_policy(cache))); 356 EXPECT_TRUE(expected.Equals(mandatory_policy(cache)));
358 } 357 }
359 358
360 TEST_F(UserPolicyCacheTest, SetReady) { 359 TEST_F(UserPolicyCacheTest, SetReady) {
361 UserPolicyCache cache(test_file(), false /* wait_for_policy_fetch */); 360 UserPolicyCache cache(test_file(), false /* wait_for_policy_fetch */);
362 cache.AddObserver(&observer); 361 cache.AddObserver(&observer_);
363 scoped_ptr<em::PolicyFetchResponse> policy( 362 scoped_ptr<em::PolicyFetchResponse> policy(
364 CreateHomepagePolicy("http://www.example.com", 363 CreateHomepagePolicy("http://www.example.com",
365 base::Time::NowFromSystemTime(), 364 base::Time::NowFromSystemTime(),
366 em::PolicyOptions::MANDATORY)); 365 em::PolicyOptions::MANDATORY));
367 EXPECT_CALL(observer, OnCacheUpdate(_)).Times(0); 366 EXPECT_CALL(observer_, OnCacheUpdate(_)).Times(0);
368 cache.SetPolicy(*policy); 367 cache.SetPolicy(*policy);
369 testing::Mock::VerifyAndClearExpectations(&observer); 368 testing::Mock::VerifyAndClearExpectations(&observer_);
370 369
371 // Switching the cache to ready should send a notification. 370 // Switching the cache to ready should send a notification.
372 EXPECT_CALL(observer, OnCacheUpdate(_)).Times(1); 371 EXPECT_CALL(observer_, OnCacheUpdate(_)).Times(1);
373 SetReady(&cache); 372 SetReady(&cache);
374 cache.RemoveObserver(&observer); 373 cache.RemoveObserver(&observer_);
375 } 374 }
376 375
377 // Test case for the temporary support for GenericNamedValues in the 376 // Test case for the temporary support for GenericNamedValues in the
378 // CloudPolicySettings protobuf. Can be removed when this support is no longer 377 // CloudPolicySettings protobuf. Can be removed when this support is no longer
379 // required. 378 // required.
380 TEST_F(UserPolicyCacheTest, OldStylePolicy) { 379 TEST_F(UserPolicyCacheTest, OldStylePolicy) {
381 UserPolicyCache cache(test_file(), false /* wait_for_policy_fetch */); 380 UserPolicyCache cache(test_file(), false /* wait_for_policy_fetch */);
382 em::PolicyFetchResponse* policy = new em::PolicyFetchResponse(); 381 em::PolicyFetchResponse* policy = new em::PolicyFetchResponse();
383 em::PolicyData signed_response; 382 em::PolicyData signed_response;
384 em::LegacyChromeSettingsProto settings; 383 em::LegacyChromeSettingsProto settings;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 UserPolicyCache cache(test_file(), true /* wait_for_policy_fetch */); 432 UserPolicyCache cache(test_file(), true /* wait_for_policy_fetch */);
434 EXPECT_FALSE(cache.IsReady()); 433 EXPECT_FALSE(cache.IsReady());
435 cache.SetFetchingDone(); 434 cache.SetFetchingDone();
436 EXPECT_FALSE(cache.IsReady()); 435 EXPECT_FALSE(cache.IsReady());
437 cache.Load(); 436 cache.Load();
438 loop_.RunAllPending(); 437 loop_.RunAllPending();
439 EXPECT_TRUE(cache.IsReady()); 438 EXPECT_TRUE(cache.IsReady());
440 } 439 }
441 440
442 } // namespace policy 441 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/user_policy_cache.cc ('k') | chrome/browser/ui/webui/policy_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698