| 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 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/chromeos/policy/cloud_external_data_store.h" | 21 #include "chrome/browser/chromeos/policy/cloud_external_data_store.h" |
| 22 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" | 22 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" |
| 23 #include "chrome/browser/policy/cloud/resource_cache.h" | 23 #include "chrome/browser/policy/cloud/resource_cache.h" |
| 24 #include "chrome/browser/policy/external_data_fetcher.h" | 24 #include "chrome/browser/policy/external_data_fetcher.h" |
| 25 #include "chrome/browser/policy/policy_map.h" | 25 #include "chrome/browser/policy/policy_map.h" |
| 26 #include "chrome/browser/policy/policy_types.h" | 26 #include "chrome/browser/policy/policy_types.h" |
| 27 #include "net/http/http_status_code.h" | 27 #include "net/http/http_status_code.h" |
| 28 #include "net/url_request/test_url_fetcher_factory.h" | 28 #include "net/url_request/test_url_fetcher_factory.h" |
| 29 #include "net/url_request/url_fetcher.h" | 29 #include "net/url_request/url_fetcher.h" |
| 30 #include "net/url_request/url_fetcher_delegate.h" | 30 #include "net/url_request/url_fetcher_delegate.h" |
| 31 #include "net/url_request/url_request_status.h" |
| 31 #include "net/url_request/url_request_test_util.h" | 32 #include "net/url_request/url_request_test_util.h" |
| 32 #include "policy/policy_constants.h" | 33 #include "policy/policy_constants.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 35 | 36 |
| 36 namespace policy { | 37 namespace policy { |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 // A string policy. | 41 // A string policy. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 120 |
| 120 ExternalDataFetcher::FetchCallback ConstructFetchCallback(int id); | 121 ExternalDataFetcher::FetchCallback ConstructFetchCallback(int id); |
| 121 void ResetCallbackData(); | 122 void ResetCallbackData(); |
| 122 | 123 |
| 123 void OnFetchDone(int id, scoped_ptr<std::string> data); | 124 void OnFetchDone(int id, scoped_ptr<std::string> data); |
| 124 | 125 |
| 125 void FetchAll(); | 126 void FetchAll(); |
| 126 | 127 |
| 127 void SetFakeResponse(const std::string& url, | 128 void SetFakeResponse(const std::string& url, |
| 128 const std::string& repsonse_data, | 129 const std::string& repsonse_data, |
| 129 net::HttpStatusCode response_code); | 130 net::HttpStatusCode response_code, |
| 131 net::URLRequestStatus::Status status); |
| 130 | 132 |
| 131 base::MessageLoop message_loop_; | 133 base::MessageLoop message_loop_; |
| 132 base::ScopedTempDir temp_dir_; | 134 base::ScopedTempDir temp_dir_; |
| 133 scoped_ptr<ResourceCache> resource_cache_; | 135 scoped_ptr<ResourceCache> resource_cache_; |
| 134 MockCloudPolicyStore cloud_policy_store_; | 136 MockCloudPolicyStore cloud_policy_store_; |
| 135 scoped_refptr<net::TestURLRequestContextGetter> request_content_getter_; | 137 scoped_refptr<net::TestURLRequestContextGetter> request_content_getter_; |
| 136 FakeURLFetcherFactory fetcher_factory_; | 138 FakeURLFetcherFactory fetcher_factory_; |
| 137 | 139 |
| 138 scoped_ptr<CloudExternalDataManagerBase> external_data_manager_; | 140 scoped_ptr<CloudExternalDataManagerBase> external_data_manager_; |
| 139 | 141 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 callback_data_[id] = data.release(); | 232 callback_data_[id] = data.release(); |
| 231 } | 233 } |
| 232 | 234 |
| 233 void CloudExternalDataManagerBaseTest::FetchAll() { | 235 void CloudExternalDataManagerBaseTest::FetchAll() { |
| 234 external_data_manager_->FetchAll(); | 236 external_data_manager_->FetchAll(); |
| 235 } | 237 } |
| 236 | 238 |
| 237 void CloudExternalDataManagerBaseTest::SetFakeResponse( | 239 void CloudExternalDataManagerBaseTest::SetFakeResponse( |
| 238 const std::string& url, | 240 const std::string& url, |
| 239 const std::string& response_data, | 241 const std::string& response_data, |
| 240 net::HttpStatusCode response_code) { | 242 net::HttpStatusCode response_code, |
| 241 fetcher_factory_.SetFakeResponse(GURL(url), response_data, response_code); | 243 net::URLRequestStatus::Status status) { |
| 244 fetcher_factory_.SetFakeResponse( |
| 245 GURL(url), response_data, response_code, status); |
| 242 } | 246 } |
| 243 | 247 |
| 244 // Verifies that when no valid external data reference has been set for a | 248 // Verifies that when no valid external data reference has been set for a |
| 245 // policy, the attempt to retrieve the external data fails immediately. | 249 // policy, the attempt to retrieve the external data fails immediately. |
| 246 TEST_F(CloudExternalDataManagerBaseTest, FailToFetchInvalid) { | 250 TEST_F(CloudExternalDataManagerBaseTest, FailToFetchInvalid) { |
| 247 external_data_manager_->Connect(request_content_getter_); | 251 external_data_manager_->Connect(request_content_getter_); |
| 248 | 252 |
| 249 // Attempt to retrieve external data for |kStringPolicy|, which is a string | 253 // Attempt to retrieve external data for |kStringPolicy|, which is a string |
| 250 // policy that does not reference any external data. | 254 // policy that does not reference any external data. |
| 251 external_data_manager_->Fetch(kStringPolicy, ConstructFetchCallback(0)); | 255 external_data_manager_->Fetch(kStringPolicy, ConstructFetchCallback(0)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 277 EXPECT_TRUE(callback_data_.find(2) != callback_data_.end()); | 281 EXPECT_TRUE(callback_data_.find(2) != callback_data_.end()); |
| 278 EXPECT_FALSE(callback_data_[2]); | 282 EXPECT_FALSE(callback_data_[2]); |
| 279 ResetCallbackData(); | 283 ResetCallbackData(); |
| 280 } | 284 } |
| 281 | 285 |
| 282 // Verifies that external data referenced by a policy is downloaded and cached | 286 // Verifies that external data referenced by a policy is downloaded and cached |
| 283 // when first requested. Subsequent requests are served from the cache without | 287 // when first requested. Subsequent requests are served from the cache without |
| 284 // further download attempts. | 288 // further download attempts. |
| 285 TEST_F(CloudExternalDataManagerBaseTest, DownloadAndCache) { | 289 TEST_F(CloudExternalDataManagerBaseTest, DownloadAndCache) { |
| 286 // Serve valid external data for |k10BytePolicy|. | 290 // Serve valid external data for |k10BytePolicy|. |
| 287 SetFakeResponse(k10BytePolicyURL, k10ByteData, net::HTTP_OK); | 291 SetFakeResponse(k10BytePolicyURL, k10ByteData, net::HTTP_OK, |
| 292 net::URLRequestStatus::SUCCESS); |
| 288 external_data_manager_->Connect(request_content_getter_); | 293 external_data_manager_->Connect(request_content_getter_); |
| 289 | 294 |
| 290 // Retrieve external data for |k10BytePolicy|. Verify that a download happens | 295 // Retrieve external data for |k10BytePolicy|. Verify that a download happens |
| 291 // and the callback is invoked with the downloaded data. | 296 // and the callback is invoked with the downloaded data. |
| 292 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 297 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); |
| 293 base::RunLoop().RunUntilIdle(); | 298 base::RunLoop().RunUntilIdle(); |
| 294 EXPECT_EQ(1u, callback_data_.size()); | 299 EXPECT_EQ(1u, callback_data_.size()); |
| 295 ASSERT_TRUE(callback_data_[0]); | 300 ASSERT_TRUE(callback_data_[0]); |
| 296 EXPECT_EQ(k10ByteData, *callback_data_[0]); | 301 EXPECT_EQ(k10ByteData, *callback_data_[0]); |
| 297 ResetCallbackData(); | 302 ResetCallbackData(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 resource_cache_.get()).Load( | 337 resource_cache_.get()).Load( |
| 333 k10BytePolicy, base::SHA1HashString(k10ByteData), 10, &data)); | 338 k10BytePolicy, base::SHA1HashString(k10ByteData), 10, &data)); |
| 334 EXPECT_EQ(k10ByteData, data); | 339 EXPECT_EQ(k10ByteData, data); |
| 335 } | 340 } |
| 336 | 341 |
| 337 // Verifies that a request to download and cache all external data referenced by | 342 // Verifies that a request to download and cache all external data referenced by |
| 338 // policies is carried out correctly. Subsequent requests for the data are | 343 // policies is carried out correctly. Subsequent requests for the data are |
| 339 // served from the cache without further download attempts. | 344 // served from the cache without further download attempts. |
| 340 TEST_F(CloudExternalDataManagerBaseTest, DownloadAndCacheAll) { | 345 TEST_F(CloudExternalDataManagerBaseTest, DownloadAndCacheAll) { |
| 341 // Serve valid external data for |k10BytePolicy| and |k20BytePolicy|. | 346 // Serve valid external data for |k10BytePolicy| and |k20BytePolicy|. |
| 342 SetFakeResponse(k10BytePolicyURL, k10ByteData, net::HTTP_OK); | 347 SetFakeResponse(k10BytePolicyURL, k10ByteData, net::HTTP_OK, |
| 343 SetFakeResponse(k20BytePolicyURL, k20ByteData, net::HTTP_OK); | 348 net::URLRequestStatus::SUCCESS); |
| 349 SetFakeResponse(k20BytePolicyURL, k20ByteData, net::HTTP_OK, |
| 350 net::URLRequestStatus::SUCCESS); |
| 344 external_data_manager_->Connect(request_content_getter_); | 351 external_data_manager_->Connect(request_content_getter_); |
| 345 | 352 |
| 346 // Request that external data referenced by all policies be downloaded. | 353 // Request that external data referenced by all policies be downloaded. |
| 347 FetchAll(); | 354 FetchAll(); |
| 348 base::RunLoop().RunUntilIdle(); | 355 base::RunLoop().RunUntilIdle(); |
| 349 | 356 |
| 350 // Stop serving external data for |k10BytePolicy| and |k20BytePolicy|. | 357 // Stop serving external data for |k10BytePolicy| and |k20BytePolicy|. |
| 351 fetcher_factory_.ClearFakeResponses(); | 358 fetcher_factory_.ClearFakeResponses(); |
| 352 | 359 |
| 353 // Retrieve external data for |k10BytePolicy| and |k20BytePolicy|. Verify that | 360 // Retrieve external data for |k10BytePolicy| and |k20BytePolicy|. Verify that |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 TEST_F(CloudExternalDataManagerBaseTest, DownloadAfterConnect) { | 408 TEST_F(CloudExternalDataManagerBaseTest, DownloadAfterConnect) { |
| 402 // Attempt to retrieve external data for |k10BytePolicy|. Verify that the | 409 // Attempt to retrieve external data for |k10BytePolicy|. Verify that the |
| 403 // callback is not invoked as the request remains pending. | 410 // callback is not invoked as the request remains pending. |
| 404 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 411 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); |
| 405 base::RunLoop().RunUntilIdle(); | 412 base::RunLoop().RunUntilIdle(); |
| 406 EXPECT_TRUE(callback_data_.empty()); | 413 EXPECT_TRUE(callback_data_.empty()); |
| 407 ResetCallbackData(); | 414 ResetCallbackData(); |
| 408 | 415 |
| 409 // Serve valid external data for |k10BytePolicy| and allow the | 416 // Serve valid external data for |k10BytePolicy| and allow the |
| 410 // external_data_manager_ to perform downloads. | 417 // external_data_manager_ to perform downloads. |
| 411 SetFakeResponse(k10BytePolicyURL, k10ByteData, net::HTTP_OK); | 418 SetFakeResponse(k10BytePolicyURL, k10ByteData, net::HTTP_OK, |
| 419 net::URLRequestStatus::SUCCESS); |
| 412 external_data_manager_->Connect(request_content_getter_); | 420 external_data_manager_->Connect(request_content_getter_); |
| 413 | 421 |
| 414 // Verify that a download happens and the callback is invoked with the | 422 // Verify that a download happens and the callback is invoked with the |
| 415 // downloaded data. | 423 // downloaded data. |
| 416 base::RunLoop().RunUntilIdle(); | 424 base::RunLoop().RunUntilIdle(); |
| 417 EXPECT_EQ(1u, callback_data_.size()); | 425 EXPECT_EQ(1u, callback_data_.size()); |
| 418 ASSERT_TRUE(callback_data_[0]); | 426 ASSERT_TRUE(callback_data_[0]); |
| 419 EXPECT_EQ(k10ByteData, *callback_data_[0]); | 427 EXPECT_EQ(k10ByteData, *callback_data_[0]); |
| 420 ResetCallbackData(); | 428 ResetCallbackData(); |
| 421 } | 429 } |
| 422 | 430 |
| 423 // Verifies that when the external data referenced by a policy is not present in | 431 // Verifies that when the external data referenced by a policy is not present in |
| 424 // the cache and cannot be downloaded at this time, a request to retrieve the | 432 // the cache and cannot be downloaded at this time, a request to retrieve the |
| 425 // data is enqueued to be retried later. | 433 // data is enqueued to be retried later. |
| 426 TEST_F(CloudExternalDataManagerBaseTest, DownloadError) { | 434 TEST_F(CloudExternalDataManagerBaseTest, DownloadError) { |
| 427 // Make attempts to download the external data for |k20BytePolicy| fail with | 435 // Make attempts to download the external data for |k20BytePolicy| fail with |
| 428 // an error. | 436 // an error. |
| 429 SetFakeResponse(k20BytePolicyURL, std::string(), | 437 SetFakeResponse(k20BytePolicyURL, std::string(), |
| 430 net::HTTP_INTERNAL_SERVER_ERROR); | 438 net::HTTP_INTERNAL_SERVER_ERROR, |
| 439 net::URLRequestStatus::FAILED); |
| 431 external_data_manager_->Connect(request_content_getter_); | 440 external_data_manager_->Connect(request_content_getter_); |
| 432 | 441 |
| 433 // Attempt to retrieve external data for |k20BytePolicy|. Verify that the | 442 // Attempt to retrieve external data for |k20BytePolicy|. Verify that the |
| 434 // callback is not invoked as the download attempt fails and the request | 443 // callback is not invoked as the download attempt fails and the request |
| 435 // remains pending. | 444 // remains pending. |
| 436 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(0)); | 445 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(0)); |
| 437 base::RunLoop().RunUntilIdle(); | 446 base::RunLoop().RunUntilIdle(); |
| 438 EXPECT_TRUE(callback_data_.empty()); | 447 EXPECT_TRUE(callback_data_.empty()); |
| 439 ResetCallbackData(); | 448 ResetCallbackData(); |
| 440 | 449 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 455 | 464 |
| 456 // Modify the external data reference for |k20BytePolicy|, allowing the | 465 // Modify the external data reference for |k20BytePolicy|, allowing the |
| 457 // download to be retried immediately. | 466 // download to be retried immediately. |
| 458 SetExternalDataReference( | 467 SetExternalDataReference( |
| 459 k20BytePolicy, | 468 k20BytePolicy, |
| 460 ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k20ByteData))); | 469 ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k20ByteData))); |
| 461 cloud_policy_store_.NotifyStoreLoaded(); | 470 cloud_policy_store_.NotifyStoreLoaded(); |
| 462 | 471 |
| 463 // Serve external data for |k20BytePolicy| that does not match the hash | 472 // Serve external data for |k20BytePolicy| that does not match the hash |
| 464 // specified in its current external data reference. | 473 // specified in its current external data reference. |
| 465 SetFakeResponse(k20BytePolicyURL, k10ByteData, net::HTTP_OK); | 474 SetFakeResponse(k20BytePolicyURL, k10ByteData, net::HTTP_OK, |
| 475 net::URLRequestStatus::SUCCESS); |
| 466 | 476 |
| 467 // Attempt to retrieve external data for |k20BytePolicy| again. Verify that | 477 // Attempt to retrieve external data for |k20BytePolicy| again. Verify that |
| 468 // no callback is invoked still as the downloaded succeeds but returns data | 478 // no callback is invoked still as the downloaded succeeds but returns data |
| 469 // that does not match the external data reference. | 479 // that does not match the external data reference. |
| 470 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(2)); | 480 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(2)); |
| 471 base::RunLoop().RunUntilIdle(); | 481 base::RunLoop().RunUntilIdle(); |
| 472 EXPECT_TRUE(callback_data_.empty()); | 482 EXPECT_TRUE(callback_data_.empty()); |
| 473 ResetCallbackData(); | 483 ResetCallbackData(); |
| 474 | 484 |
| 475 // Modify the external data reference for |k20BytePolicy|, allowing the | 485 // Modify the external data reference for |k20BytePolicy|, allowing the |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 // Store external data for |k20BytePolicy| that is corrupted and does not | 634 // Store external data for |k20BytePolicy| that is corrupted and does not |
| 625 // match the expected hash. | 635 // match the expected hash. |
| 626 EXPECT_TRUE(cache->Store(k20BytePolicy, | 636 EXPECT_TRUE(cache->Store(k20BytePolicy, |
| 627 base::SHA1HashString(k20ByteData), | 637 base::SHA1HashString(k20ByteData), |
| 628 k10ByteData)); | 638 k10ByteData)); |
| 629 cache.reset(); | 639 cache.reset(); |
| 630 | 640 |
| 631 SetUpExternalDataManager(); | 641 SetUpExternalDataManager(); |
| 632 // Serve external data for |k10BytePolicy| that exceeds the maximal external | 642 // Serve external data for |k10BytePolicy| that exceeds the maximal external |
| 633 // data size allowed for that policy. | 643 // data size allowed for that policy. |
| 634 SetFakeResponse(k10BytePolicyURL, k20ByteData, net::HTTP_OK); | 644 SetFakeResponse(k10BytePolicyURL, k20ByteData, net::HTTP_OK, |
| 645 net::URLRequestStatus::SUCCESS); |
| 635 external_data_manager_->Connect(request_content_getter_); | 646 external_data_manager_->Connect(request_content_getter_); |
| 636 | 647 |
| 637 // Modify the external data reference for |k10BytePolicy| to match the | 648 // Modify the external data reference for |k10BytePolicy| to match the |
| 638 // external data being served. | 649 // external data being served. |
| 639 SetExternalDataReference( | 650 SetExternalDataReference( |
| 640 k10BytePolicy, | 651 k10BytePolicy, |
| 641 ConstructMetadata(k10BytePolicyURL, base::SHA1HashString(k20ByteData))); | 652 ConstructMetadata(k10BytePolicyURL, base::SHA1HashString(k20ByteData))); |
| 642 cloud_policy_store_.NotifyStoreLoaded(); | 653 cloud_policy_store_.NotifyStoreLoaded(); |
| 643 | 654 |
| 644 // Retrieve external data for |k10BytePolicy|. Verify that the callback is | 655 // Retrieve external data for |k10BytePolicy|. Verify that the callback is |
| 645 // not invoked as the cached and downloaded external data exceed the maximal | 656 // not invoked as the cached and downloaded external data exceed the maximal |
| 646 // size allowed for this policy and the request remains pending. | 657 // size allowed for this policy and the request remains pending. |
| 647 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 658 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); |
| 648 base::RunLoop().RunUntilIdle(); | 659 base::RunLoop().RunUntilIdle(); |
| 649 EXPECT_TRUE(callback_data_.empty()); | 660 EXPECT_TRUE(callback_data_.empty()); |
| 650 ResetCallbackData(); | 661 ResetCallbackData(); |
| 651 | 662 |
| 652 // Serve valid external data for |k20BytePolicy|. | 663 // Serve valid external data for |k20BytePolicy|. |
| 653 SetFakeResponse(k20BytePolicyURL, k20ByteData, net::HTTP_OK); | 664 SetFakeResponse(k20BytePolicyURL, k20ByteData, net::HTTP_OK, |
| 665 net::URLRequestStatus::SUCCESS); |
| 654 | 666 |
| 655 // Retrieve external data for |k20BytePolicy|. Verify that the callback is | 667 // Retrieve external data for |k20BytePolicy|. Verify that the callback is |
| 656 // invoked with the valid downloaded data, not the invalid data in the cache. | 668 // invoked with the valid downloaded data, not the invalid data in the cache. |
| 657 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(1)); | 669 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(1)); |
| 658 base::RunLoop().RunUntilIdle(); | 670 base::RunLoop().RunUntilIdle(); |
| 659 EXPECT_EQ(1u, callback_data_.size()); | 671 EXPECT_EQ(1u, callback_data_.size()); |
| 660 ASSERT_TRUE(callback_data_[1]); | 672 ASSERT_TRUE(callback_data_[1]); |
| 661 EXPECT_EQ(k20ByteData, *callback_data_[1]); | 673 EXPECT_EQ(k20ByteData, *callback_data_[1]); |
| 662 ResetCallbackData(); | 674 ResetCallbackData(); |
| 663 | 675 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 685 EXPECT_EQ(k20ByteData, data); | 697 EXPECT_EQ(k20ByteData, data); |
| 686 } | 698 } |
| 687 | 699 |
| 688 // Verifies that when the external data reference for a policy changes while a | 700 // Verifies that when the external data reference for a policy changes while a |
| 689 // download of the external data for that policy is pending, the download is | 701 // download of the external data for that policy is pending, the download is |
| 690 // immediately retried using the new reference. | 702 // immediately retried using the new reference. |
| 691 TEST_F(CloudExternalDataManagerBaseTest, PolicyChangeWhileDownloadPending) { | 703 TEST_F(CloudExternalDataManagerBaseTest, PolicyChangeWhileDownloadPending) { |
| 692 // Make attempts to download the external data for |k10BytePolicy| and | 704 // Make attempts to download the external data for |k10BytePolicy| and |
| 693 // |k20BytePolicy| fail with an error. | 705 // |k20BytePolicy| fail with an error. |
| 694 SetFakeResponse(k10BytePolicyURL, std::string(), | 706 SetFakeResponse(k10BytePolicyURL, std::string(), |
| 695 net::HTTP_INTERNAL_SERVER_ERROR); | 707 net::HTTP_INTERNAL_SERVER_ERROR, |
| 708 net::URLRequestStatus::FAILED); |
| 696 SetFakeResponse(k20BytePolicyURL, std::string(), | 709 SetFakeResponse(k20BytePolicyURL, std::string(), |
| 697 net::HTTP_INTERNAL_SERVER_ERROR); | 710 net::HTTP_INTERNAL_SERVER_ERROR, |
| 711 net::URLRequestStatus::FAILED); |
| 698 external_data_manager_->Connect(request_content_getter_); | 712 external_data_manager_->Connect(request_content_getter_); |
| 699 | 713 |
| 700 // Attempt to retrieve external data for |k10BytePolicy| and |k20BytePolicy|. | 714 // Attempt to retrieve external data for |k10BytePolicy| and |k20BytePolicy|. |
| 701 // Verify that no callbacks are invoked as the download attempts fail and the | 715 // Verify that no callbacks are invoked as the download attempts fail and the |
| 702 // requests remain pending. | 716 // requests remain pending. |
| 703 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 717 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); |
| 704 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(1)); | 718 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(1)); |
| 705 base::RunLoop().RunUntilIdle(); | 719 base::RunLoop().RunUntilIdle(); |
| 706 EXPECT_TRUE(callback_data_.empty()); | 720 EXPECT_TRUE(callback_data_.empty()); |
| 707 ResetCallbackData(); | 721 ResetCallbackData(); |
| 708 | 722 |
| 709 // Modify the external data reference for |k10BytePolicy| to be invalid. | 723 // Modify the external data reference for |k10BytePolicy| to be invalid. |
| 710 // Verify that the callback is invoked as the policy no longer has a valid | 724 // Verify that the callback is invoked as the policy no longer has a valid |
| 711 // external data reference. | 725 // external data reference. |
| 712 cloud_policy_store_.policy_map_.Erase(k10BytePolicy); | 726 cloud_policy_store_.policy_map_.Erase(k10BytePolicy); |
| 713 cloud_policy_store_.NotifyStoreLoaded(); | 727 cloud_policy_store_.NotifyStoreLoaded(); |
| 714 base::RunLoop().RunUntilIdle(); | 728 base::RunLoop().RunUntilIdle(); |
| 715 EXPECT_EQ(1u, callback_data_.size()); | 729 EXPECT_EQ(1u, callback_data_.size()); |
| 716 EXPECT_TRUE(callback_data_.find(0) != callback_data_.end()); | 730 EXPECT_TRUE(callback_data_.find(0) != callback_data_.end()); |
| 717 EXPECT_FALSE(callback_data_[0]); | 731 EXPECT_FALSE(callback_data_[0]); |
| 718 ResetCallbackData(); | 732 ResetCallbackData(); |
| 719 | 733 |
| 720 // Serve valid external data for |k20BytePolicy|. | 734 // Serve valid external data for |k20BytePolicy|. |
| 721 fetcher_factory_.ClearFakeResponses(); | 735 fetcher_factory_.ClearFakeResponses(); |
| 722 SetFakeResponse(k20BytePolicyURL, k10ByteData, net::HTTP_OK); | 736 SetFakeResponse(k20BytePolicyURL, k10ByteData, net::HTTP_OK, |
| 737 net::URLRequestStatus::SUCCESS); |
| 723 | 738 |
| 724 // Modify the external data reference for |k20BytePolicy| to match the | 739 // Modify the external data reference for |k20BytePolicy| to match the |
| 725 // external data now being served. Verify that the callback is invoked with | 740 // external data now being served. Verify that the callback is invoked with |
| 726 // the downloaded data. | 741 // the downloaded data. |
| 727 SetExternalDataReference( | 742 SetExternalDataReference( |
| 728 k20BytePolicy, | 743 k20BytePolicy, |
| 729 ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k10ByteData))); | 744 ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k10ByteData))); |
| 730 cloud_policy_store_.NotifyStoreLoaded(); | 745 cloud_policy_store_.NotifyStoreLoaded(); |
| 731 base::RunLoop().RunUntilIdle(); | 746 base::RunLoop().RunUntilIdle(); |
| 732 EXPECT_EQ(1u, callback_data_.size()); | 747 EXPECT_EQ(1u, callback_data_.size()); |
| 733 ASSERT_TRUE(callback_data_[1]); | 748 ASSERT_TRUE(callback_data_[1]); |
| 734 EXPECT_EQ(k10ByteData, *callback_data_[1]); | 749 EXPECT_EQ(k10ByteData, *callback_data_[1]); |
| 735 ResetCallbackData(); | 750 ResetCallbackData(); |
| 736 } | 751 } |
| 737 | 752 |
| 738 } // namespace policy | 753 } // namespace policy |
| OLD | NEW |