| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/policy/cloud_external_data_manager_base.h" | 5 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base.h" | 
| 6 | 6 | 
| 7 #include <map> | 7 #include <map> | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
| 10 #include "base/bind.h" | 10 #include "base/bind.h" | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 95     net::URLFetcher::RequestType request_type, | 95     net::URLFetcher::RequestType request_type, | 
| 96     net::URLFetcherDelegate* delegate) { | 96     net::URLFetcherDelegate* delegate) { | 
| 97   net::URLFetcher* fetcher = net::FakeURLFetcherFactory::CreateURLFetcher( | 97   net::URLFetcher* fetcher = net::FakeURLFetcherFactory::CreateURLFetcher( | 
| 98       id, url, request_type, delegate); | 98       id, url, request_type, delegate); | 
| 99   EXPECT_TRUE(fetcher); | 99   EXPECT_TRUE(fetcher); | 
| 100   return fetcher; | 100   return fetcher; | 
| 101 } | 101 } | 
| 102 | 102 | 
| 103 }  // namespace | 103 }  // namespace | 
| 104 | 104 | 
| 105 class CouldExternalDataManagerBaseTest : public testing::Test { | 105 class CloudExternalDataManagerBaseTest : public testing::Test { | 
| 106  protected: | 106  protected: | 
| 107   CouldExternalDataManagerBaseTest(); | 107   CloudExternalDataManagerBaseTest(); | 
| 108 | 108 | 
| 109   virtual void SetUp() OVERRIDE; | 109   virtual void SetUp() OVERRIDE; | 
| 110   virtual void TearDown() OVERRIDE; | 110   virtual void TearDown() OVERRIDE; | 
| 111 | 111 | 
| 112   void SetUpExternalDataManager(); | 112   void SetUpExternalDataManager(); | 
| 113 | 113 | 
| 114   scoped_ptr<base::DictionaryValue> ConstructMetadata(const std::string& url, | 114   scoped_ptr<base::DictionaryValue> ConstructMetadata(const std::string& url, | 
| 115                                                       const std::string& hash); | 115                                                       const std::string& hash); | 
| 116   void SetExternalDataReference(const std::string& policy, | 116   void SetExternalDataReference(const std::string& policy, | 
| 117                                 scoped_ptr<base::DictionaryValue> metadata); | 117                                 scoped_ptr<base::DictionaryValue> metadata); | 
| 118 | 118 | 
| 119   ExternalDataFetcher::FetchCallback ConstructFetchCallback(int id); | 119   ExternalDataFetcher::FetchCallback ConstructFetchCallback(int id); | 
| 120   void ResetCallbackData(); | 120   void ResetCallbackData(); | 
| 121 | 121 | 
| 122   void OnFetchDone(int id, scoped_ptr<std::string> data); | 122   void OnFetchDone(int id, scoped_ptr<std::string> data); | 
| 123 | 123 | 
| 124   void FetchAll(); | 124   void FetchAll(); | 
| 125 | 125 | 
|  | 126   void SetFakeResponse(const std::string& url, | 
|  | 127                        const std::string& repsonse_data, | 
|  | 128                        bool success); | 
|  | 129 | 
| 126   base::MessageLoop message_loop_; | 130   base::MessageLoop message_loop_; | 
| 127   base::ScopedTempDir temp_dir_; | 131   base::ScopedTempDir temp_dir_; | 
| 128   scoped_ptr<ResourceCache> resource_cache_; | 132   scoped_ptr<ResourceCache> resource_cache_; | 
| 129   MockCloudPolicyStore cloud_policy_store_; | 133   MockCloudPolicyStore cloud_policy_store_; | 
| 130   scoped_refptr<net::TestURLRequestContextGetter> request_content_getter_; | 134   scoped_refptr<net::TestURLRequestContextGetter> request_content_getter_; | 
| 131   FakeURLFetcherFactory fetcher_factory_; | 135   FakeURLFetcherFactory fetcher_factory_; | 
| 132 | 136 | 
| 133   scoped_ptr<CloudExternalDataManagerBase> external_data_manager_; | 137   scoped_ptr<CloudExternalDataManagerBase> external_data_manager_; | 
| 134 | 138 | 
| 135   std::map<int, std::string*> callback_data_; | 139   std::map<int, std::string*> callback_data_; | 
| 136 | 140 | 
| 137   DISALLOW_COPY_AND_ASSIGN(CouldExternalDataManagerBaseTest); | 141   DISALLOW_COPY_AND_ASSIGN(CloudExternalDataManagerBaseTest); | 
| 138 }; | 142 }; | 
| 139 | 143 | 
| 140 CouldExternalDataManagerBaseTest::CouldExternalDataManagerBaseTest() { | 144 CloudExternalDataManagerBaseTest::CloudExternalDataManagerBaseTest() { | 
| 141 } | 145 } | 
| 142 | 146 | 
| 143 void CouldExternalDataManagerBaseTest::SetUp() { | 147 void CloudExternalDataManagerBaseTest::SetUp() { | 
| 144   ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 148   ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 
| 145   resource_cache_.reset(new ResourceCache(temp_dir_.path(), | 149   resource_cache_.reset(new ResourceCache(temp_dir_.path(), | 
| 146                                           message_loop_.message_loop_proxy())); | 150                                           message_loop_.message_loop_proxy())); | 
| 147   SetUpExternalDataManager(); | 151   SetUpExternalDataManager(); | 
| 148 | 152 | 
| 149   // Set |kStringPolicy| to a string value. | 153   // Set |kStringPolicy| to a string value. | 
| 150   cloud_policy_store_.policy_map_.Set(kStringPolicy, | 154   cloud_policy_store_.policy_map_.Set(kStringPolicy, | 
| 151                                       POLICY_LEVEL_MANDATORY, | 155                                       POLICY_LEVEL_MANDATORY, | 
| 152                                       POLICY_SCOPE_USER, | 156                                       POLICY_SCOPE_USER, | 
| 153                                       new base::StringValue(std::string()), | 157                                       new base::StringValue(std::string()), | 
| 154                                       NULL); | 158                                       NULL); | 
| 155   // Make |k10BytePolicy| reference 10 bytes of external data. | 159   // Make |k10BytePolicy| reference 10 bytes of external data. | 
| 156   SetExternalDataReference( | 160   SetExternalDataReference( | 
| 157       k10BytePolicy, | 161       k10BytePolicy, | 
| 158       ConstructMetadata(k10BytePolicyURL, base::SHA1HashString(k10ByteData))); | 162       ConstructMetadata(k10BytePolicyURL, base::SHA1HashString(k10ByteData))); | 
| 159   // Make |k20BytePolicy| reference 20 bytes of external data. | 163   // Make |k20BytePolicy| reference 20 bytes of external data. | 
| 160   SetExternalDataReference( | 164   SetExternalDataReference( | 
| 161       k20BytePolicy, | 165       k20BytePolicy, | 
| 162       ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k20ByteData))); | 166       ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k20ByteData))); | 
| 163   cloud_policy_store_.NotifyStoreLoaded(); | 167   cloud_policy_store_.NotifyStoreLoaded(); | 
| 164 | 168 | 
| 165   request_content_getter_ = new net::TestURLRequestContextGetter( | 169   request_content_getter_ = new net::TestURLRequestContextGetter( | 
| 166       base::MessageLoopProxy::current()); | 170       base::MessageLoopProxy::current()); | 
| 167 } | 171 } | 
| 168 | 172 | 
| 169 void CouldExternalDataManagerBaseTest::TearDown() { | 173 void CloudExternalDataManagerBaseTest::TearDown() { | 
| 170   external_data_manager_.reset(); | 174   external_data_manager_.reset(); | 
| 171   base::RunLoop().RunUntilIdle(); | 175   base::RunLoop().RunUntilIdle(); | 
| 172   ResetCallbackData(); | 176   ResetCallbackData(); | 
| 173 } | 177 } | 
| 174 | 178 | 
| 175 void CouldExternalDataManagerBaseTest::SetUpExternalDataManager() { | 179 void CloudExternalDataManagerBaseTest::SetUpExternalDataManager() { | 
| 176   external_data_manager_.reset(new CloudExternalDataManagerBase( | 180   external_data_manager_.reset(new CloudExternalDataManagerBase( | 
| 177       &kPolicyDefinitionList, | 181       &kPolicyDefinitionList, | 
| 178       message_loop_.message_loop_proxy(), | 182       message_loop_.message_loop_proxy(), | 
| 179       message_loop_.message_loop_proxy())); | 183       message_loop_.message_loop_proxy())); | 
| 180   external_data_manager_->SetExternalDataStore(make_scoped_ptr( | 184   external_data_manager_->SetExternalDataStore(make_scoped_ptr( | 
| 181       new CloudExternalDataStore(kCacheKey, | 185       new CloudExternalDataStore(kCacheKey, | 
| 182                                  message_loop_.message_loop_proxy(), | 186                                  message_loop_.message_loop_proxy(), | 
| 183                                  resource_cache_.get()))); | 187                                  resource_cache_.get()))); | 
| 184   external_data_manager_->SetPolicyStore(&cloud_policy_store_); | 188   external_data_manager_->SetPolicyStore(&cloud_policy_store_); | 
| 185 } | 189 } | 
| 186 | 190 | 
| 187 scoped_ptr<base::DictionaryValue> | 191 scoped_ptr<base::DictionaryValue> | 
| 188     CouldExternalDataManagerBaseTest::ConstructMetadata( | 192     CloudExternalDataManagerBaseTest::ConstructMetadata( | 
| 189         const std::string& url, | 193         const std::string& url, | 
| 190         const std::string& hash) { | 194         const std::string& hash) { | 
| 191   scoped_ptr<base::DictionaryValue> metadata(new base::DictionaryValue); | 195   scoped_ptr<base::DictionaryValue> metadata(new base::DictionaryValue); | 
| 192   metadata->SetStringWithoutPathExpansion("url", url); | 196   metadata->SetStringWithoutPathExpansion("url", url); | 
| 193   metadata->SetStringWithoutPathExpansion("hash", base::HexEncode(hash.c_str(), | 197   metadata->SetStringWithoutPathExpansion("hash", base::HexEncode(hash.c_str(), | 
| 194                                                                   hash.size())); | 198                                                                   hash.size())); | 
| 195   return metadata.Pass(); | 199   return metadata.Pass(); | 
| 196 } | 200 } | 
| 197 | 201 | 
| 198 void CouldExternalDataManagerBaseTest::SetExternalDataReference( | 202 void CloudExternalDataManagerBaseTest::SetExternalDataReference( | 
| 199     const std::string& policy, | 203     const std::string& policy, | 
| 200     scoped_ptr<base::DictionaryValue> metadata) { | 204     scoped_ptr<base::DictionaryValue> metadata) { | 
| 201   cloud_policy_store_.policy_map_.Set( | 205   cloud_policy_store_.policy_map_.Set( | 
| 202       policy, | 206       policy, | 
| 203       POLICY_LEVEL_MANDATORY, | 207       POLICY_LEVEL_MANDATORY, | 
| 204       POLICY_SCOPE_USER, | 208       POLICY_SCOPE_USER, | 
| 205       metadata.release(), | 209       metadata.release(), | 
| 206       new ExternalDataFetcher( | 210       new ExternalDataFetcher( | 
| 207           external_data_manager_->weak_factory_.GetWeakPtr(), policy)); | 211           external_data_manager_->weak_factory_.GetWeakPtr(), policy)); | 
| 208 } | 212 } | 
| 209 | 213 | 
| 210 ExternalDataFetcher::FetchCallback | 214 ExternalDataFetcher::FetchCallback | 
| 211 CouldExternalDataManagerBaseTest::ConstructFetchCallback(int id) { | 215 CloudExternalDataManagerBaseTest::ConstructFetchCallback(int id) { | 
| 212   return base::Bind(&CouldExternalDataManagerBaseTest::OnFetchDone, | 216   return base::Bind(&CloudExternalDataManagerBaseTest::OnFetchDone, | 
| 213                     base::Unretained(this), | 217                     base::Unretained(this), | 
| 214                     id); | 218                     id); | 
| 215 } | 219 } | 
| 216 | 220 | 
| 217 void CouldExternalDataManagerBaseTest::ResetCallbackData() { | 221 void CloudExternalDataManagerBaseTest::ResetCallbackData() { | 
| 218   STLDeleteValues(&callback_data_); | 222   STLDeleteValues(&callback_data_); | 
| 219 } | 223 } | 
| 220 | 224 | 
| 221 void CouldExternalDataManagerBaseTest::OnFetchDone( | 225 void CloudExternalDataManagerBaseTest::OnFetchDone( | 
| 222     int id, | 226     int id, | 
| 223     scoped_ptr<std::string> data) { | 227     scoped_ptr<std::string> data) { | 
| 224   delete callback_data_[id]; | 228   delete callback_data_[id]; | 
| 225   callback_data_[id] = data.release(); | 229   callback_data_[id] = data.release(); | 
| 226 } | 230 } | 
| 227 | 231 | 
| 228 void CouldExternalDataManagerBaseTest::FetchAll() { | 232 void CloudExternalDataManagerBaseTest::FetchAll() { | 
| 229   external_data_manager_->FetchAll(); | 233   external_data_manager_->FetchAll(); | 
| 230 } | 234 } | 
| 231 | 235 | 
|  | 236 void CloudExternalDataManagerBaseTest::SetFakeResponse( | 
|  | 237     const std::string& url, | 
|  | 238     const std::string& response_data, | 
|  | 239     bool success) { | 
|  | 240   fetcher_factory_.SetFakeResponse(GURL(url), response_data, success); | 
|  | 241 } | 
|  | 242 | 
| 232 // Verifies that when no valid external data reference has been set for a | 243 // Verifies that when no valid external data reference has been set for a | 
| 233 // policy, the attempt to retrieve the external data fails immediately. | 244 // policy, the attempt to retrieve the external data fails immediately. | 
| 234 TEST_F(CouldExternalDataManagerBaseTest, FailToFetchInvalid) { | 245 TEST_F(CloudExternalDataManagerBaseTest, FailToFetchInvalid) { | 
| 235   external_data_manager_->Connect(request_content_getter_); | 246   external_data_manager_->Connect(request_content_getter_); | 
| 236 | 247 | 
| 237   // Attempt to retrieve external data for |kStringPolicy|, which is a string | 248   // Attempt to retrieve external data for |kStringPolicy|, which is a string | 
| 238   // policy that does not reference any external data. | 249   // policy that does not reference any external data. | 
| 239   external_data_manager_->Fetch(kStringPolicy, ConstructFetchCallback(0)); | 250   external_data_manager_->Fetch(kStringPolicy, ConstructFetchCallback(0)); | 
| 240   base::RunLoop().RunUntilIdle(); | 251   base::RunLoop().RunUntilIdle(); | 
| 241   EXPECT_EQ(1u, callback_data_.size()); | 252   EXPECT_EQ(1u, callback_data_.size()); | 
| 242   EXPECT_TRUE(callback_data_.find(0) != callback_data_.end()); | 253   EXPECT_TRUE(callback_data_.find(0) != callback_data_.end()); | 
| 243   EXPECT_FALSE(callback_data_[0]); | 254   EXPECT_FALSE(callback_data_[0]); | 
| 244   ResetCallbackData(); | 255   ResetCallbackData(); | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 263   base::RunLoop().RunUntilIdle(); | 274   base::RunLoop().RunUntilIdle(); | 
| 264   EXPECT_EQ(1u, callback_data_.size()); | 275   EXPECT_EQ(1u, callback_data_.size()); | 
| 265   EXPECT_TRUE(callback_data_.find(2) != callback_data_.end()); | 276   EXPECT_TRUE(callback_data_.find(2) != callback_data_.end()); | 
| 266   EXPECT_FALSE(callback_data_[2]); | 277   EXPECT_FALSE(callback_data_[2]); | 
| 267   ResetCallbackData(); | 278   ResetCallbackData(); | 
| 268 } | 279 } | 
| 269 | 280 | 
| 270 // Verifies that external data referenced by a policy is downloaded and cached | 281 // Verifies that external data referenced by a policy is downloaded and cached | 
| 271 // when first requested. Subsequent requests are served from the cache without | 282 // when first requested. Subsequent requests are served from the cache without | 
| 272 // further download attempts. | 283 // further download attempts. | 
| 273 TEST_F(CouldExternalDataManagerBaseTest, DownloadAndCache) { | 284 TEST_F(CloudExternalDataManagerBaseTest, DownloadAndCache) { | 
| 274   // Serve valid external data for |k10BytePolicy|. | 285   // Serve valid external data for |k10BytePolicy|. | 
| 275   fetcher_factory_.SetFakeResponse(k10BytePolicyURL, k10ByteData, true); | 286   SetFakeResponse(k10BytePolicyURL, k10ByteData, true); | 
| 276   external_data_manager_->Connect(request_content_getter_); | 287   external_data_manager_->Connect(request_content_getter_); | 
| 277 | 288 | 
| 278   // Retrieve external data for |k10BytePolicy|. Verify that a download happens | 289   // Retrieve external data for |k10BytePolicy|. Verify that a download happens | 
| 279   // and the callback is invoked with the downloaded data. | 290   // and the callback is invoked with the downloaded data. | 
| 280   external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 291   external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 
| 281   base::RunLoop().RunUntilIdle(); | 292   base::RunLoop().RunUntilIdle(); | 
| 282   EXPECT_EQ(1u, callback_data_.size()); | 293   EXPECT_EQ(1u, callback_data_.size()); | 
| 283   ASSERT_TRUE(callback_data_[0]); | 294   ASSERT_TRUE(callback_data_[0]); | 
| 284   EXPECT_EQ(k10ByteData, *callback_data_[0]); | 295   EXPECT_EQ(k10ByteData, *callback_data_[0]); | 
| 285   ResetCallbackData(); | 296   ResetCallbackData(); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 318   EXPECT_TRUE(CloudExternalDataStore(kCacheKey, | 329   EXPECT_TRUE(CloudExternalDataStore(kCacheKey, | 
| 319                                      message_loop_.message_loop_proxy(), | 330                                      message_loop_.message_loop_proxy(), | 
| 320                                      resource_cache_.get()).Load( | 331                                      resource_cache_.get()).Load( | 
| 321       k10BytePolicy, base::SHA1HashString(k10ByteData), 10, &data)); | 332       k10BytePolicy, base::SHA1HashString(k10ByteData), 10, &data)); | 
| 322   EXPECT_EQ(k10ByteData, data); | 333   EXPECT_EQ(k10ByteData, data); | 
| 323 } | 334 } | 
| 324 | 335 | 
| 325 // Verifies that a request to download and cache all external data referenced by | 336 // Verifies that a request to download and cache all external data referenced by | 
| 326 // policies is carried out correctly. Subsequent requests for the data are | 337 // policies is carried out correctly. Subsequent requests for the data are | 
| 327 // served from the cache without further download attempts. | 338 // served from the cache without further download attempts. | 
| 328 TEST_F(CouldExternalDataManagerBaseTest, DownloadAndCacheAll) { | 339 TEST_F(CloudExternalDataManagerBaseTest, DownloadAndCacheAll) { | 
| 329   // Serve valid external data for |k10BytePolicy| and |k20BytePolicy|. | 340   // Serve valid external data for |k10BytePolicy| and |k20BytePolicy|. | 
| 330   fetcher_factory_.SetFakeResponse(k10BytePolicyURL, k10ByteData, true); | 341   SetFakeResponse(k10BytePolicyURL, k10ByteData, true); | 
| 331   fetcher_factory_.SetFakeResponse(k20BytePolicyURL, k20ByteData, true); | 342   SetFakeResponse(k20BytePolicyURL, k20ByteData, true); | 
| 332   external_data_manager_->Connect(request_content_getter_); | 343   external_data_manager_->Connect(request_content_getter_); | 
| 333 | 344 | 
| 334   // Request that external data referenced by all policies be downloaded. | 345   // Request that external data referenced by all policies be downloaded. | 
| 335   FetchAll(); | 346   FetchAll(); | 
| 336   base::RunLoop().RunUntilIdle(); | 347   base::RunLoop().RunUntilIdle(); | 
| 337 | 348 | 
| 338   // Stop serving external data for |k10BytePolicy| and |k20BytePolicy|. | 349   // Stop serving external data for |k10BytePolicy| and |k20BytePolicy|. | 
| 339   fetcher_factory_.ClearFakeResponses(); | 350   fetcher_factory_.ClearFakeResponses(); | 
| 340 | 351 | 
| 341   // Retrieve external data for |k10BytePolicy| and |k20BytePolicy|. Verify that | 352   // Retrieve external data for |k10BytePolicy| and |k20BytePolicy|. Verify that | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 379                          &data)); | 390                          &data)); | 
| 380   EXPECT_EQ(k10ByteData, data); | 391   EXPECT_EQ(k10ByteData, data); | 
| 381   EXPECT_TRUE(cache.Load(k20BytePolicy, base::SHA1HashString(k20ByteData), 20, | 392   EXPECT_TRUE(cache.Load(k20BytePolicy, base::SHA1HashString(k20ByteData), 20, | 
| 382                          &data)); | 393                          &data)); | 
| 383   EXPECT_EQ(k20ByteData, data); | 394   EXPECT_EQ(k20ByteData, data); | 
| 384 } | 395 } | 
| 385 | 396 | 
| 386 // Verifies that when the external data referenced by a policy is not present in | 397 // Verifies that when the external data referenced by a policy is not present in | 
| 387 // the cache and downloads are not allowed, a request to retrieve the data is | 398 // the cache and downloads are not allowed, a request to retrieve the data is | 
| 388 // enqueued and carried out when downloads become possible. | 399 // enqueued and carried out when downloads become possible. | 
| 389 TEST_F(CouldExternalDataManagerBaseTest, DownloadAfterConnect) { | 400 TEST_F(CloudExternalDataManagerBaseTest, DownloadAfterConnect) { | 
| 390   // Attempt to retrieve external data for |k10BytePolicy|. Verify that the | 401   // Attempt to retrieve external data for |k10BytePolicy|. Verify that the | 
| 391   // callback is not invoked as the request remains pending. | 402   // callback is not invoked as the request remains pending. | 
| 392   external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 403   external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 
| 393   base::RunLoop().RunUntilIdle(); | 404   base::RunLoop().RunUntilIdle(); | 
| 394   EXPECT_TRUE(callback_data_.empty()); | 405   EXPECT_TRUE(callback_data_.empty()); | 
| 395   ResetCallbackData(); | 406   ResetCallbackData(); | 
| 396 | 407 | 
| 397   // Serve valid external data for |k10BytePolicy| and allow the | 408   // Serve valid external data for |k10BytePolicy| and allow the | 
| 398   // external_data_manager_ to perform downloads. | 409   // external_data_manager_ to perform downloads. | 
| 399   fetcher_factory_.SetFakeResponse(k10BytePolicyURL, k10ByteData, true); | 410   SetFakeResponse(k10BytePolicyURL, k10ByteData, true); | 
| 400   external_data_manager_->Connect(request_content_getter_); | 411   external_data_manager_->Connect(request_content_getter_); | 
| 401 | 412 | 
| 402   // Verify that a download happens and the callback is invoked with the | 413   // Verify that a download happens and the callback is invoked with the | 
| 403   // downloaded data. | 414   // downloaded data. | 
| 404   base::RunLoop().RunUntilIdle(); | 415   base::RunLoop().RunUntilIdle(); | 
| 405   EXPECT_EQ(1u, callback_data_.size()); | 416   EXPECT_EQ(1u, callback_data_.size()); | 
| 406   ASSERT_TRUE(callback_data_[0]); | 417   ASSERT_TRUE(callback_data_[0]); | 
| 407   EXPECT_EQ(k10ByteData, *callback_data_[0]); | 418   EXPECT_EQ(k10ByteData, *callback_data_[0]); | 
| 408   ResetCallbackData(); | 419   ResetCallbackData(); | 
| 409 } | 420 } | 
| 410 | 421 | 
| 411 // Verifies that when the external data referenced by a policy is not present in | 422 // Verifies that when the external data referenced by a policy is not present in | 
| 412 // the cache and cannot be downloaded at this time, a request to retrieve the | 423 // the cache and cannot be downloaded at this time, a request to retrieve the | 
| 413 // data is enqueued to be retried later. | 424 // data is enqueued to be retried later. | 
| 414 TEST_F(CouldExternalDataManagerBaseTest, DownloadError) { | 425 TEST_F(CloudExternalDataManagerBaseTest, DownloadError) { | 
| 415   // Make attempts to download the external data for |k20BytePolicy| fail with | 426   // Make attempts to download the external data for |k20BytePolicy| fail with | 
| 416   // an error. | 427   // an error. | 
| 417   fetcher_factory_.SetFakeResponse(k20BytePolicyURL, std::string(), false); | 428   SetFakeResponse(k20BytePolicyURL, std::string(), false); | 
| 418   external_data_manager_->Connect(request_content_getter_); | 429   external_data_manager_->Connect(request_content_getter_); | 
| 419 | 430 | 
| 420   // Attempt to retrieve external data for |k20BytePolicy|. Verify that the | 431   // Attempt to retrieve external data for |k20BytePolicy|. Verify that the | 
| 421   // callback is not invoked as the download attempt fails and the request | 432   // callback is not invoked as the download attempt fails and the request | 
| 422   // remains pending. | 433   // remains pending. | 
| 423   external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(0)); | 434   external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(0)); | 
| 424   base::RunLoop().RunUntilIdle(); | 435   base::RunLoop().RunUntilIdle(); | 
| 425   EXPECT_TRUE(callback_data_.empty()); | 436   EXPECT_TRUE(callback_data_.empty()); | 
| 426   ResetCallbackData(); | 437   ResetCallbackData(); | 
| 427 | 438 | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 442 | 453 | 
| 443   // Modify the external data reference for |k20BytePolicy|, allowing the | 454   // Modify the external data reference for |k20BytePolicy|, allowing the | 
| 444   // download to be retried immediately. | 455   // download to be retried immediately. | 
| 445   SetExternalDataReference( | 456   SetExternalDataReference( | 
| 446       k20BytePolicy, | 457       k20BytePolicy, | 
| 447       ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k20ByteData))); | 458       ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k20ByteData))); | 
| 448   cloud_policy_store_.NotifyStoreLoaded(); | 459   cloud_policy_store_.NotifyStoreLoaded(); | 
| 449 | 460 | 
| 450   // Serve external data for |k20BytePolicy| that does not match the hash | 461   // Serve external data for |k20BytePolicy| that does not match the hash | 
| 451   // specified in its current external data reference. | 462   // specified in its current external data reference. | 
| 452   fetcher_factory_.SetFakeResponse(k20BytePolicyURL, k10ByteData, true); | 463   SetFakeResponse(k20BytePolicyURL, k10ByteData, true); | 
| 453 | 464 | 
| 454   // Attempt to retrieve external data for |k20BytePolicy| again. Verify that | 465   // Attempt to retrieve external data for |k20BytePolicy| again. Verify that | 
| 455   // no callback is invoked still as the downloaded succeeds but returns data | 466   // no callback is invoked still as the downloaded succeeds but returns data | 
| 456   // that does not match the external data reference. | 467   // that does not match the external data reference. | 
| 457   external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(2)); | 468   external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(2)); | 
| 458   base::RunLoop().RunUntilIdle(); | 469   base::RunLoop().RunUntilIdle(); | 
| 459   EXPECT_TRUE(callback_data_.empty()); | 470   EXPECT_TRUE(callback_data_.empty()); | 
| 460   ResetCallbackData(); | 471   ResetCallbackData(); | 
| 461 | 472 | 
| 462   // Modify the external data reference for |k20BytePolicy|, allowing the | 473   // Modify the external data reference for |k20BytePolicy|, allowing the | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 480   ASSERT_TRUE(callback_data_[2]); | 491   ASSERT_TRUE(callback_data_[2]); | 
| 481   EXPECT_EQ(k10ByteData, *callback_data_[2]); | 492   EXPECT_EQ(k10ByteData, *callback_data_[2]); | 
| 482   ASSERT_TRUE(callback_data_[3]); | 493   ASSERT_TRUE(callback_data_[3]); | 
| 483   EXPECT_EQ(k10ByteData, *callback_data_[3]); | 494   EXPECT_EQ(k10ByteData, *callback_data_[3]); | 
| 484   ResetCallbackData(); | 495   ResetCallbackData(); | 
| 485 } | 496 } | 
| 486 | 497 | 
| 487 // Verifies that when the external data referenced by a policy is present in the | 498 // Verifies that when the external data referenced by a policy is present in the | 
| 488 // cache, a request to retrieve it is served from the cache without any download | 499 // cache, a request to retrieve it is served from the cache without any download | 
| 489 // attempts. | 500 // attempts. | 
| 490 TEST_F(CouldExternalDataManagerBaseTest, LoadFromCache) { | 501 TEST_F(CloudExternalDataManagerBaseTest, LoadFromCache) { | 
| 491   // Store valid external data for |k10BytePolicy| in the cache. | 502   // Store valid external data for |k10BytePolicy| in the cache. | 
| 492   external_data_manager_.reset(); | 503   external_data_manager_.reset(); | 
| 493   base::RunLoop().RunUntilIdle(); | 504   base::RunLoop().RunUntilIdle(); | 
| 494   EXPECT_TRUE(CloudExternalDataStore(kCacheKey, | 505   EXPECT_TRUE(CloudExternalDataStore(kCacheKey, | 
| 495                                      message_loop_.message_loop_proxy(), | 506                                      message_loop_.message_loop_proxy(), | 
| 496                                      resource_cache_.get()).Store( | 507                                      resource_cache_.get()).Store( | 
| 497       k10BytePolicy, base::SHA1HashString(k10ByteData), k10ByteData)); | 508       k10BytePolicy, base::SHA1HashString(k10ByteData), k10ByteData)); | 
| 498 | 509 | 
| 499   // Instantiate an external_data_manager_ that uses the primed cache. | 510   // Instantiate an external_data_manager_ that uses the primed cache. | 
| 500   SetUpExternalDataManager(); | 511   SetUpExternalDataManager(); | 
| 501   external_data_manager_->Connect(request_content_getter_); | 512   external_data_manager_->Connect(request_content_getter_); | 
| 502 | 513 | 
| 503   // Retrieve external data for |k10BytePolicy|. Verify that no download is | 514   // Retrieve external data for |k10BytePolicy|. Verify that no download is | 
| 504   // attempted but the callback is still invoked with the expected data, served | 515   // attempted but the callback is still invoked with the expected data, served | 
| 505   // from the cache. | 516   // from the cache. | 
| 506   external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 517   external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 
| 507   base::RunLoop().RunUntilIdle(); | 518   base::RunLoop().RunUntilIdle(); | 
| 508   EXPECT_EQ(1u, callback_data_.size()); | 519   EXPECT_EQ(1u, callback_data_.size()); | 
| 509   ASSERT_TRUE(callback_data_[0]); | 520   ASSERT_TRUE(callback_data_[0]); | 
| 510   EXPECT_EQ(k10ByteData, *callback_data_[0]); | 521   EXPECT_EQ(k10ByteData, *callback_data_[0]); | 
| 511   ResetCallbackData(); | 522   ResetCallbackData(); | 
| 512 } | 523 } | 
| 513 | 524 | 
| 514 // Verifies that cache entries which do not correspond to the external data | 525 // Verifies that cache entries which do not correspond to the external data | 
| 515 // referenced by any policy are pruned on startup. | 526 // referenced by any policy are pruned on startup. | 
| 516 TEST_F(CouldExternalDataManagerBaseTest, PruneCacheOnStartup) { | 527 TEST_F(CloudExternalDataManagerBaseTest, PruneCacheOnStartup) { | 
| 517   external_data_manager_.reset(); | 528   external_data_manager_.reset(); | 
| 518   base::RunLoop().RunUntilIdle(); | 529   base::RunLoop().RunUntilIdle(); | 
| 519   scoped_ptr<CloudExternalDataStore> | 530   scoped_ptr<CloudExternalDataStore> | 
| 520       cache(new CloudExternalDataStore(kCacheKey, | 531       cache(new CloudExternalDataStore(kCacheKey, | 
| 521                                        message_loop_.message_loop_proxy(), | 532                                        message_loop_.message_loop_proxy(), | 
| 522                                        resource_cache_.get())); | 533                                        resource_cache_.get())); | 
| 523   // Store valid external data for |k10BytePolicy| in the cache. | 534   // Store valid external data for |k10BytePolicy| in the cache. | 
| 524   EXPECT_TRUE(cache->Store(k10BytePolicy, | 535   EXPECT_TRUE(cache->Store(k10BytePolicy, | 
| 525                            base::SHA1HashString(k10ByteData), | 536                            base::SHA1HashString(k10ByteData), | 
| 526                            k10ByteData)); | 537                            k10ByteData)); | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 553   // Verify that the external data for |k20BytePolicy| and |kUnknownPolicy| has | 564   // Verify that the external data for |k20BytePolicy| and |kUnknownPolicy| has | 
| 554   // been pruned from the cache. | 565   // been pruned from the cache. | 
| 555   EXPECT_FALSE(cache->Load(k20BytePolicy, base::SHA1HashString(k10ByteData), | 566   EXPECT_FALSE(cache->Load(k20BytePolicy, base::SHA1HashString(k10ByteData), | 
| 556                            20, &data)); | 567                            20, &data)); | 
| 557   EXPECT_FALSE(cache->Load(kUnknownPolicy, base::SHA1HashString(k10ByteData), | 568   EXPECT_FALSE(cache->Load(kUnknownPolicy, base::SHA1HashString(k10ByteData), | 
| 558                            20, &data)); | 569                            20, &data)); | 
| 559 } | 570 } | 
| 560 | 571 | 
| 561 // Verifies that when the external data referenced by a policy is present in the | 572 // Verifies that when the external data referenced by a policy is present in the | 
| 562 // cache and the reference changes, the old data is pruned from the cache. | 573 // cache and the reference changes, the old data is pruned from the cache. | 
| 563 TEST_F(CouldExternalDataManagerBaseTest, PruneCacheOnChange) { | 574 TEST_F(CloudExternalDataManagerBaseTest, PruneCacheOnChange) { | 
| 564   // Store valid external data for |k20BytePolicy| in the cache. | 575   // Store valid external data for |k20BytePolicy| in the cache. | 
| 565   external_data_manager_.reset(); | 576   external_data_manager_.reset(); | 
| 566   base::RunLoop().RunUntilIdle(); | 577   base::RunLoop().RunUntilIdle(); | 
| 567   scoped_ptr<CloudExternalDataStore> | 578   scoped_ptr<CloudExternalDataStore> | 
| 568       cache(new CloudExternalDataStore(kCacheKey, | 579       cache(new CloudExternalDataStore(kCacheKey, | 
| 569                                        message_loop_.message_loop_proxy(), | 580                                        message_loop_.message_loop_proxy(), | 
| 570                                        resource_cache_.get())); | 581                                        resource_cache_.get())); | 
| 571   EXPECT_TRUE(cache->Store(k20BytePolicy, | 582   EXPECT_TRUE(cache->Store(k20BytePolicy, | 
| 572                            base::SHA1HashString(k20ByteData), | 583                            base::SHA1HashString(k20ByteData), | 
| 573                            k20ByteData)); | 584                            k20ByteData)); | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 589   base::RunLoop().RunUntilIdle(); | 600   base::RunLoop().RunUntilIdle(); | 
| 590   cache.reset(new CloudExternalDataStore(kCacheKey, | 601   cache.reset(new CloudExternalDataStore(kCacheKey, | 
| 591                                          message_loop_.message_loop_proxy(), | 602                                          message_loop_.message_loop_proxy(), | 
| 592                                          resource_cache_.get())); | 603                                          resource_cache_.get())); | 
| 593   std::string data; | 604   std::string data; | 
| 594   EXPECT_FALSE(cache->Load(k20BytePolicy, base::SHA1HashString(k20ByteData), 20, | 605   EXPECT_FALSE(cache->Load(k20BytePolicy, base::SHA1HashString(k20ByteData), 20, | 
| 595                            &data)); | 606                            &data)); | 
| 596 } | 607 } | 
| 597 | 608 | 
| 598 // Verifies that corrupt cache entries are detected and deleted when accessed. | 609 // Verifies that corrupt cache entries are detected and deleted when accessed. | 
| 599 TEST_F(CouldExternalDataManagerBaseTest, CacheCorruption) { | 610 TEST_F(CloudExternalDataManagerBaseTest, CacheCorruption) { | 
| 600   external_data_manager_.reset(); | 611   external_data_manager_.reset(); | 
| 601   base::RunLoop().RunUntilIdle(); | 612   base::RunLoop().RunUntilIdle(); | 
| 602   scoped_ptr<CloudExternalDataStore> | 613   scoped_ptr<CloudExternalDataStore> | 
| 603       cache(new CloudExternalDataStore(kCacheKey, | 614       cache(new CloudExternalDataStore(kCacheKey, | 
| 604                                        message_loop_.message_loop_proxy(), | 615                                        message_loop_.message_loop_proxy(), | 
| 605                                        resource_cache_.get())); | 616                                        resource_cache_.get())); | 
| 606   // Store external data for |k10BytePolicy| that exceeds the maximal external | 617   // Store external data for |k10BytePolicy| that exceeds the maximal external | 
| 607   // data size allowed for that policy. | 618   // data size allowed for that policy. | 
| 608   EXPECT_TRUE(cache->Store(k10BytePolicy, | 619   EXPECT_TRUE(cache->Store(k10BytePolicy, | 
| 609                            base::SHA1HashString(k20ByteData), | 620                            base::SHA1HashString(k20ByteData), | 
| 610                            k20ByteData)); | 621                            k20ByteData)); | 
| 611   // Store external data for |k20BytePolicy| that is corrupted and does not | 622   // Store external data for |k20BytePolicy| that is corrupted and does not | 
| 612   // match the expected hash. | 623   // match the expected hash. | 
| 613   EXPECT_TRUE(cache->Store(k20BytePolicy, | 624   EXPECT_TRUE(cache->Store(k20BytePolicy, | 
| 614                            base::SHA1HashString(k20ByteData), | 625                            base::SHA1HashString(k20ByteData), | 
| 615                            k10ByteData)); | 626                            k10ByteData)); | 
| 616   cache.reset(); | 627   cache.reset(); | 
| 617 | 628 | 
| 618   SetUpExternalDataManager(); | 629   SetUpExternalDataManager(); | 
| 619   // Serve external data for |k10BytePolicy| that exceeds the maximal external | 630   // Serve external data for |k10BytePolicy| that exceeds the maximal external | 
| 620   // data size allowed for that policy. | 631   // data size allowed for that policy. | 
| 621   fetcher_factory_.SetFakeResponse(k10BytePolicyURL, k20ByteData, true); | 632   SetFakeResponse(k10BytePolicyURL, k20ByteData, true); | 
| 622   external_data_manager_->Connect(request_content_getter_); | 633   external_data_manager_->Connect(request_content_getter_); | 
| 623 | 634 | 
| 624   // Modify the external data reference for |k10BytePolicy| to match the | 635   // Modify the external data reference for |k10BytePolicy| to match the | 
| 625   // external data being served. | 636   // external data being served. | 
| 626   SetExternalDataReference( | 637   SetExternalDataReference( | 
| 627       k10BytePolicy, | 638       k10BytePolicy, | 
| 628       ConstructMetadata(k10BytePolicyURL, base::SHA1HashString(k20ByteData))); | 639       ConstructMetadata(k10BytePolicyURL, base::SHA1HashString(k20ByteData))); | 
| 629   cloud_policy_store_.NotifyStoreLoaded(); | 640   cloud_policy_store_.NotifyStoreLoaded(); | 
| 630 | 641 | 
| 631   // Retrieve external data for |k10BytePolicy|. Verify that the callback is | 642   // Retrieve external data for |k10BytePolicy|. Verify that the callback is | 
| 632   // not invoked as the cached and downloaded external data exceed the maximal | 643   // not invoked as the cached and downloaded external data exceed the maximal | 
| 633   // size allowed for this policy and the request remains pending. | 644   // size allowed for this policy and the request remains pending. | 
| 634   external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 645   external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 
| 635   base::RunLoop().RunUntilIdle(); | 646   base::RunLoop().RunUntilIdle(); | 
| 636   EXPECT_TRUE(callback_data_.empty()); | 647   EXPECT_TRUE(callback_data_.empty()); | 
| 637   ResetCallbackData(); | 648   ResetCallbackData(); | 
| 638 | 649 | 
| 639   // Serve valid external data for |k20BytePolicy|. | 650   // Serve valid external data for |k20BytePolicy|. | 
| 640   fetcher_factory_.SetFakeResponse(k20BytePolicyURL, k20ByteData, true); | 651   SetFakeResponse(k20BytePolicyURL, k20ByteData, true); | 
| 641 | 652 | 
| 642   // Retrieve external data for |k20BytePolicy|. Verify that the callback is | 653   // Retrieve external data for |k20BytePolicy|. Verify that the callback is | 
| 643   // invoked with the valid downloaded data, not the invalid data in the cache. | 654   // invoked with the valid downloaded data, not the invalid data in the cache. | 
| 644   external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(1)); | 655   external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(1)); | 
| 645   base::RunLoop().RunUntilIdle(); | 656   base::RunLoop().RunUntilIdle(); | 
| 646   EXPECT_EQ(1u, callback_data_.size()); | 657   EXPECT_EQ(1u, callback_data_.size()); | 
| 647   ASSERT_TRUE(callback_data_[1]); | 658   ASSERT_TRUE(callback_data_[1]); | 
| 648   EXPECT_EQ(k20ByteData, *callback_data_[1]); | 659   EXPECT_EQ(k20ByteData, *callback_data_[1]); | 
| 649   ResetCallbackData(); | 660   ResetCallbackData(); | 
| 650 | 661 | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 668   // Verify that the invalid external data for |k20BytePolicy| has been replaced | 679   // Verify that the invalid external data for |k20BytePolicy| has been replaced | 
| 669   // with the downloaded valid data in the cache. | 680   // with the downloaded valid data in the cache. | 
| 670   EXPECT_TRUE(cache->Load(k20BytePolicy, base::SHA1HashString(k20ByteData), 20, | 681   EXPECT_TRUE(cache->Load(k20BytePolicy, base::SHA1HashString(k20ByteData), 20, | 
| 671                           &data)); | 682                           &data)); | 
| 672   EXPECT_EQ(k20ByteData, data); | 683   EXPECT_EQ(k20ByteData, data); | 
| 673 } | 684 } | 
| 674 | 685 | 
| 675 // Verifies that when the external data reference for a policy changes while a | 686 // Verifies that when the external data reference for a policy changes while a | 
| 676 // download of the external data for that policy is pending, the download is | 687 // download of the external data for that policy is pending, the download is | 
| 677 // immediately retried using the new reference. | 688 // immediately retried using the new reference. | 
| 678 TEST_F(CouldExternalDataManagerBaseTest, PolicyChangeWhileDownloadPending) { | 689 TEST_F(CloudExternalDataManagerBaseTest, PolicyChangeWhileDownloadPending) { | 
| 679   // Make attempts to download the external data for |k10BytePolicy| and | 690   // Make attempts to download the external data for |k10BytePolicy| and | 
| 680   // |k20BytePolicy| fail with an error. | 691   // |k20BytePolicy| fail with an error. | 
| 681   fetcher_factory_.SetFakeResponse(k10BytePolicyURL, std::string(), false); | 692   SetFakeResponse(k10BytePolicyURL, std::string(), false); | 
| 682   fetcher_factory_.SetFakeResponse(k20BytePolicyURL, std::string(), false); | 693   SetFakeResponse(k20BytePolicyURL, std::string(), false); | 
| 683   external_data_manager_->Connect(request_content_getter_); | 694   external_data_manager_->Connect(request_content_getter_); | 
| 684 | 695 | 
| 685   // Attempt to retrieve external data for |k10BytePolicy| and |k20BytePolicy|. | 696   // Attempt to retrieve external data for |k10BytePolicy| and |k20BytePolicy|. | 
| 686   // Verify that no callbacks are invoked as the download attempts fail and the | 697   // Verify that no callbacks are invoked as the download attempts fail and the | 
| 687   // requests remain pending. | 698   // requests remain pending. | 
| 688   external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 699   external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 
| 689   external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(1)); | 700   external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(1)); | 
| 690   base::RunLoop().RunUntilIdle(); | 701   base::RunLoop().RunUntilIdle(); | 
| 691   EXPECT_TRUE(callback_data_.empty()); | 702   EXPECT_TRUE(callback_data_.empty()); | 
| 692   ResetCallbackData(); | 703   ResetCallbackData(); | 
| 693 | 704 | 
| 694   // Modify the external data reference for |k10BytePolicy| to be invalid. | 705   // Modify the external data reference for |k10BytePolicy| to be invalid. | 
| 695   // Verify that the callback is invoked as the policy no longer has a valid | 706   // Verify that the callback is invoked as the policy no longer has a valid | 
| 696   // external data reference. | 707   // external data reference. | 
| 697   cloud_policy_store_.policy_map_.Erase(k10BytePolicy); | 708   cloud_policy_store_.policy_map_.Erase(k10BytePolicy); | 
| 698   cloud_policy_store_.NotifyStoreLoaded(); | 709   cloud_policy_store_.NotifyStoreLoaded(); | 
| 699   base::RunLoop().RunUntilIdle(); | 710   base::RunLoop().RunUntilIdle(); | 
| 700   EXPECT_EQ(1u, callback_data_.size()); | 711   EXPECT_EQ(1u, callback_data_.size()); | 
| 701   EXPECT_TRUE(callback_data_.find(0) != callback_data_.end()); | 712   EXPECT_TRUE(callback_data_.find(0) != callback_data_.end()); | 
| 702   EXPECT_FALSE(callback_data_[0]); | 713   EXPECT_FALSE(callback_data_[0]); | 
| 703   ResetCallbackData(); | 714   ResetCallbackData(); | 
| 704 | 715 | 
| 705   // Serve valid external data for |k20BytePolicy|. | 716   // Serve valid external data for |k20BytePolicy|. | 
| 706   fetcher_factory_.ClearFakeResponses(); | 717   fetcher_factory_.ClearFakeResponses(); | 
| 707   fetcher_factory_.SetFakeResponse(k20BytePolicyURL, k10ByteData, true); | 718   SetFakeResponse(k20BytePolicyURL, k10ByteData, true); | 
| 708 | 719 | 
| 709   // Modify the external data reference for |k20BytePolicy| to match the | 720   // Modify the external data reference for |k20BytePolicy| to match the | 
| 710   // external data now being served. Verify that the callback is invoked with | 721   // external data now being served. Verify that the callback is invoked with | 
| 711   // the downloaded data. | 722   // the downloaded data. | 
| 712   SetExternalDataReference( | 723   SetExternalDataReference( | 
| 713       k20BytePolicy, | 724       k20BytePolicy, | 
| 714       ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k10ByteData))); | 725       ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k10ByteData))); | 
| 715   cloud_policy_store_.NotifyStoreLoaded(); | 726   cloud_policy_store_.NotifyStoreLoaded(); | 
| 716   base::RunLoop().RunUntilIdle(); | 727   base::RunLoop().RunUntilIdle(); | 
| 717   EXPECT_EQ(1u, callback_data_.size()); | 728   EXPECT_EQ(1u, callback_data_.size()); | 
| 718   ASSERT_TRUE(callback_data_[1]); | 729   ASSERT_TRUE(callback_data_[1]); | 
| 719   EXPECT_EQ(k10ByteData, *callback_data_[1]); | 730   EXPECT_EQ(k10ByteData, *callback_data_[1]); | 
| 720   ResetCallbackData(); | 731   ResetCallbackData(); | 
| 721 } | 732 } | 
| 722 | 733 | 
| 723 }  // namespace policy | 734 }  // namespace policy | 
| OLD | NEW | 
|---|