| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 CouldExternalDataManagerBaseTest::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& repsonse_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(CouldExternalDataManagerBaseTest, 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()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 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(CouldExternalDataManagerBaseTest, 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(CouldExternalDataManagerBaseTest, 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 TEST_F(CouldExternalDataManagerBaseTest, DownloadAfterConnect) { | 400 TEST_F(CouldExternalDataManagerBaseTest, 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(CouldExternalDataManagerBaseTest, 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 20 matching lines...) Expand all Loading... |
| 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(CouldExternalDataManagerBaseTest, 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 |