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

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

Issue 11413050: chrome/browser: Update calls from RunAllPending() to RunUntilIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_cloud_policy_store_chromeos.h" 5 #include "chrome/browser/policy/user_cloud_policy_store_chromeos.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 policy_file())); 64 policy_file()));
65 store_->AddObserver(&observer_); 65 store_->AddObserver(&observer_);
66 66
67 policy_.payload().mutable_showhomebutton()->set_showhomebutton(true); 67 policy_.payload().mutable_showhomebutton()->set_showhomebutton(true);
68 policy_.Build(); 68 policy_.Build();
69 } 69 }
70 70
71 virtual void TearDown() OVERRIDE { 71 virtual void TearDown() OVERRIDE {
72 store_->RemoveObserver(&observer_); 72 store_->RemoveObserver(&observer_);
73 store_.reset(); 73 store_.reset();
74 loop_.RunAllPending(); 74 loop_.RunUntilIdle();
75 } 75 }
76 76
77 // Install an expectation on |observer_| for an error code. 77 // Install an expectation on |observer_| for an error code.
78 void ExpectError(CloudPolicyStore::Status error) { 78 void ExpectError(CloudPolicyStore::Status error) {
79 EXPECT_CALL(observer_, 79 EXPECT_CALL(observer_,
80 OnStoreError(AllOf(Eq(store_.get()), 80 OnStoreError(AllOf(Eq(store_.get()),
81 Property(&CloudPolicyStore::status, 81 Property(&CloudPolicyStore::status,
82 Eq(error))))); 82 Eq(error)))));
83 } 83 }
84 84
85 // Triggers a store_->Load() operation, handles the expected call to 85 // Triggers a store_->Load() operation, handles the expected call to
86 // |session_manager_client_| and sends |response|. 86 // |session_manager_client_| and sends |response|.
87 void PerformPolicyLoad(const std::string& response) { 87 void PerformPolicyLoad(const std::string& response) {
88 // Issue a load command. 88 // Issue a load command.
89 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback; 89 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback;
90 EXPECT_CALL(session_manager_client_, RetrieveUserPolicy(_)) 90 EXPECT_CALL(session_manager_client_, RetrieveUserPolicy(_))
91 .WillOnce(SaveArg<0>(&retrieve_callback)); 91 .WillOnce(SaveArg<0>(&retrieve_callback));
92 store_->Load(); 92 store_->Load();
93 loop_.RunAllPending(); 93 loop_.RunUntilIdle();
94 ASSERT_FALSE(retrieve_callback.is_null()); 94 ASSERT_FALSE(retrieve_callback.is_null());
95 95
96 // Run the callback. 96 // Run the callback.
97 retrieve_callback.Run(response); 97 retrieve_callback.Run(response);
98 loop_.RunAllPending(); 98 loop_.RunUntilIdle();
99 } 99 }
100 100
101 // Verifies that store_->policy_map() has the ShowHomeButton entry. 101 // Verifies that store_->policy_map() has the ShowHomeButton entry.
102 void VerifyPolicyMap() { 102 void VerifyPolicyMap() {
103 EXPECT_EQ(1U, store_->policy_map().size()); 103 EXPECT_EQ(1U, store_->policy_map().size());
104 const PolicyMap::Entry* entry = 104 const PolicyMap::Entry* entry =
105 store_->policy_map().Get(key::kShowHomeButton); 105 store_->policy_map().Get(key::kShowHomeButton);
106 ASSERT_TRUE(entry); 106 ASSERT_TRUE(entry);
107 EXPECT_TRUE(base::FundamentalValue(true).Equals(entry->value)); 107 EXPECT_TRUE(base::FundamentalValue(true).Equals(entry->value));
108 } 108 }
(...skipping 20 matching lines...) Expand all
129 129
130 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyStoreChromeOSTest); 130 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyStoreChromeOSTest);
131 }; 131 };
132 132
133 TEST_F(UserCloudPolicyStoreChromeOSTest, Store) { 133 TEST_F(UserCloudPolicyStoreChromeOSTest, Store) {
134 // Store policy. 134 // Store policy.
135 chromeos::SessionManagerClient::StorePolicyCallback store_callback; 135 chromeos::SessionManagerClient::StorePolicyCallback store_callback;
136 EXPECT_CALL(session_manager_client_, StoreUserPolicy(policy_.GetBlob(), _)) 136 EXPECT_CALL(session_manager_client_, StoreUserPolicy(policy_.GetBlob(), _))
137 .WillOnce(SaveArg<1>(&store_callback)); 137 .WillOnce(SaveArg<1>(&store_callback));
138 store_->Store(policy_.policy()); 138 store_->Store(policy_.policy());
139 loop_.RunAllPending(); 139 loop_.RunUntilIdle();
140 140
141 // No policy should be present yet. 141 // No policy should be present yet.
142 EXPECT_FALSE(store_->policy()); 142 EXPECT_FALSE(store_->policy());
143 EXPECT_TRUE(store_->policy_map().empty()); 143 EXPECT_TRUE(store_->policy_map().empty());
144 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); 144 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status());
145 ASSERT_FALSE(store_callback.is_null()); 145 ASSERT_FALSE(store_callback.is_null());
146 146
147 // Let the store operation complete. 147 // Let the store operation complete.
148 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback; 148 chromeos::SessionManagerClient::RetrievePolicyCallback retrieve_callback;
149 EXPECT_CALL(session_manager_client_, RetrieveUserPolicy(_)) 149 EXPECT_CALL(session_manager_client_, RetrieveUserPolicy(_))
150 .WillOnce(SaveArg<0>(&retrieve_callback)); 150 .WillOnce(SaveArg<0>(&retrieve_callback));
151 store_callback.Run(true); 151 store_callback.Run(true);
152 loop_.RunAllPending(); 152 loop_.RunUntilIdle();
153 EXPECT_TRUE(store_->policy_map().empty()); 153 EXPECT_TRUE(store_->policy_map().empty());
154 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); 154 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status());
155 ASSERT_FALSE(retrieve_callback.is_null()); 155 ASSERT_FALSE(retrieve_callback.is_null());
156 156
157 // Finish the retrieve callback. 157 // Finish the retrieve callback.
158 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); 158 EXPECT_CALL(observer_, OnStoreLoaded(store_.get()));
159 retrieve_callback.Run(policy_.GetBlob()); 159 retrieve_callback.Run(policy_.GetBlob());
160 loop_.RunAllPending(); 160 loop_.RunUntilIdle();
161 ASSERT_TRUE(store_->policy()); 161 ASSERT_TRUE(store_->policy());
162 EXPECT_EQ(policy_.policy_data().SerializeAsString(), 162 EXPECT_EQ(policy_.policy_data().SerializeAsString(),
163 store_->policy()->SerializeAsString()); 163 store_->policy()->SerializeAsString());
164 VerifyPolicyMap(); 164 VerifyPolicyMap();
165 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); 165 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status());
166 } 166 }
167 167
168 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreFail) { 168 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreFail) {
169 // Store policy. 169 // Store policy.
170 chromeos::SessionManagerClient::StorePolicyCallback store_callback; 170 chromeos::SessionManagerClient::StorePolicyCallback store_callback;
171 EXPECT_CALL(session_manager_client_, StoreUserPolicy(policy_.GetBlob(), _)) 171 EXPECT_CALL(session_manager_client_, StoreUserPolicy(policy_.GetBlob(), _))
172 .WillOnce(SaveArg<1>(&store_callback)); 172 .WillOnce(SaveArg<1>(&store_callback));
173 store_->Store(policy_.policy()); 173 store_->Store(policy_.policy());
174 loop_.RunAllPending(); 174 loop_.RunUntilIdle();
175 175
176 // Let the store operation complete. 176 // Let the store operation complete.
177 ASSERT_FALSE(store_callback.is_null()); 177 ASSERT_FALSE(store_callback.is_null());
178 ExpectError(CloudPolicyStore::STATUS_STORE_ERROR); 178 ExpectError(CloudPolicyStore::STATUS_STORE_ERROR);
179 store_callback.Run(false); 179 store_callback.Run(false);
180 loop_.RunAllPending(); 180 loop_.RunUntilIdle();
181 EXPECT_FALSE(store_->policy()); 181 EXPECT_FALSE(store_->policy());
182 EXPECT_TRUE(store_->policy_map().empty()); 182 EXPECT_TRUE(store_->policy_map().empty());
183 EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, store_->status()); 183 EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, store_->status());
184 } 184 }
185 185
186 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreValidationError) { 186 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreValidationError) {
187 policy_.policy_data().clear_policy_type(); 187 policy_.policy_data().clear_policy_type();
188 policy_.Build(); 188 policy_.Build();
189 189
190 // Store policy. 190 // Store policy.
191 chromeos::SessionManagerClient::StorePolicyCallback store_callback; 191 chromeos::SessionManagerClient::StorePolicyCallback store_callback;
192 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); 192 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR);
193 EXPECT_CALL(session_manager_client_, StoreUserPolicy(policy_.GetBlob(), _)) 193 EXPECT_CALL(session_manager_client_, StoreUserPolicy(policy_.GetBlob(), _))
194 .Times(0); 194 .Times(0);
195 store_->Store(policy_.policy()); 195 store_->Store(policy_.policy());
196 loop_.RunAllPending(); 196 loop_.RunUntilIdle();
197 } 197 }
198 198
199 TEST_F(UserCloudPolicyStoreChromeOSTest, Load) { 199 TEST_F(UserCloudPolicyStoreChromeOSTest, Load) {
200 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); 200 EXPECT_CALL(observer_, OnStoreLoaded(store_.get()));
201 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob())); 201 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob()));
202 202
203 // Verify that the policy has been loaded. 203 // Verify that the policy has been loaded.
204 ASSERT_TRUE(store_->policy()); 204 ASSERT_TRUE(store_->policy());
205 EXPECT_EQ(policy_.policy_data().SerializeAsString(), 205 EXPECT_EQ(policy_.policy_data().SerializeAsString(),
206 store_->policy()->SerializeAsString()); 206 store_->policy()->SerializeAsString());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 ASSERT_TRUE(store_->policy()); 317 ASSERT_TRUE(store_->policy());
318 EXPECT_EQ(expected_policy_data.SerializeAsString(), 318 EXPECT_EQ(expected_policy_data.SerializeAsString(),
319 store_->policy()->SerializeAsString()); 319 store_->policy()->SerializeAsString());
320 EXPECT_TRUE(store_->policy_map().empty()); 320 EXPECT_TRUE(store_->policy_map().empty());
321 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); 321 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status());
322 }; 322 };
323 323
324 } // namespace 324 } // namespace
325 325
326 } // namespace policy 326 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/url_blacklist_manager_unittest.cc ('k') | chrome/browser/policy/user_policy_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698