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" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/message_loop/message_loop_proxy.h" | 14 #include "base/message_loop/message_loop_proxy.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/sha1.h" | 16 #include "base/sha1.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/test/test_simple_task_runner.h" | 19 #include "base/test/test_simple_task_runner.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
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/url_request/test_url_fetcher_factory.h" | 28 #include "net/url_request/test_url_fetcher_factory.h" |
28 #include "net/url_request/url_fetcher.h" | 29 #include "net/url_request/url_fetcher.h" |
29 #include "net/url_request/url_fetcher_delegate.h" | 30 #include "net/url_request/url_fetcher_delegate.h" |
30 #include "net/url_request/url_request_test_util.h" | 31 #include "net/url_request/url_request_test_util.h" |
31 #include "policy/policy_constants.h" | 32 #include "policy/policy_constants.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
34 | 35 |
35 namespace policy { | 36 namespace policy { |
36 | 37 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 119 |
119 ExternalDataFetcher::FetchCallback ConstructFetchCallback(int id); | 120 ExternalDataFetcher::FetchCallback ConstructFetchCallback(int id); |
120 void ResetCallbackData(); | 121 void ResetCallbackData(); |
121 | 122 |
122 void OnFetchDone(int id, scoped_ptr<std::string> data); | 123 void OnFetchDone(int id, scoped_ptr<std::string> data); |
123 | 124 |
124 void FetchAll(); | 125 void FetchAll(); |
125 | 126 |
126 void SetFakeResponse(const std::string& url, | 127 void SetFakeResponse(const std::string& url, |
127 const std::string& repsonse_data, | 128 const std::string& repsonse_data, |
128 bool success); | 129 net::HttpStatusCode response_code); |
129 | 130 |
130 base::MessageLoop message_loop_; | 131 base::MessageLoop message_loop_; |
131 base::ScopedTempDir temp_dir_; | 132 base::ScopedTempDir temp_dir_; |
132 scoped_ptr<ResourceCache> resource_cache_; | 133 scoped_ptr<ResourceCache> resource_cache_; |
133 MockCloudPolicyStore cloud_policy_store_; | 134 MockCloudPolicyStore cloud_policy_store_; |
134 scoped_refptr<net::TestURLRequestContextGetter> request_content_getter_; | 135 scoped_refptr<net::TestURLRequestContextGetter> request_content_getter_; |
135 FakeURLFetcherFactory fetcher_factory_; | 136 FakeURLFetcherFactory fetcher_factory_; |
136 | 137 |
137 scoped_ptr<CloudExternalDataManagerBase> external_data_manager_; | 138 scoped_ptr<CloudExternalDataManagerBase> external_data_manager_; |
138 | 139 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 callback_data_[id] = data.release(); | 230 callback_data_[id] = data.release(); |
230 } | 231 } |
231 | 232 |
232 void CloudExternalDataManagerBaseTest::FetchAll() { | 233 void CloudExternalDataManagerBaseTest::FetchAll() { |
233 external_data_manager_->FetchAll(); | 234 external_data_manager_->FetchAll(); |
234 } | 235 } |
235 | 236 |
236 void CloudExternalDataManagerBaseTest::SetFakeResponse( | 237 void CloudExternalDataManagerBaseTest::SetFakeResponse( |
237 const std::string& url, | 238 const std::string& url, |
238 const std::string& response_data, | 239 const std::string& response_data, |
239 bool success) { | 240 net::HttpStatusCode response_code) { |
240 fetcher_factory_.SetFakeResponse(GURL(url), response_data, success); | 241 fetcher_factory_.SetFakeResponse(GURL(url), response_data, response_code); |
241 } | 242 } |
242 | 243 |
243 // Verifies that when no valid external data reference has been set for a | 244 // Verifies that when no valid external data reference has been set for a |
244 // policy, the attempt to retrieve the external data fails immediately. | 245 // policy, the attempt to retrieve the external data fails immediately. |
245 TEST_F(CloudExternalDataManagerBaseTest, FailToFetchInvalid) { | 246 TEST_F(CloudExternalDataManagerBaseTest, FailToFetchInvalid) { |
246 external_data_manager_->Connect(request_content_getter_); | 247 external_data_manager_->Connect(request_content_getter_); |
247 | 248 |
248 // Attempt to retrieve external data for |kStringPolicy|, which is a string | 249 // Attempt to retrieve external data for |kStringPolicy|, which is a string |
249 // policy that does not reference any external data. | 250 // policy that does not reference any external data. |
250 external_data_manager_->Fetch(kStringPolicy, ConstructFetchCallback(0)); | 251 external_data_manager_->Fetch(kStringPolicy, ConstructFetchCallback(0)); |
(...skipping 25 matching lines...) Expand all Loading... |
276 EXPECT_TRUE(callback_data_.find(2) != callback_data_.end()); | 277 EXPECT_TRUE(callback_data_.find(2) != callback_data_.end()); |
277 EXPECT_FALSE(callback_data_[2]); | 278 EXPECT_FALSE(callback_data_[2]); |
278 ResetCallbackData(); | 279 ResetCallbackData(); |
279 } | 280 } |
280 | 281 |
281 // Verifies that external data referenced by a policy is downloaded and cached | 282 // Verifies that external data referenced by a policy is downloaded and cached |
282 // when first requested. Subsequent requests are served from the cache without | 283 // when first requested. Subsequent requests are served from the cache without |
283 // further download attempts. | 284 // further download attempts. |
284 TEST_F(CloudExternalDataManagerBaseTest, DownloadAndCache) { | 285 TEST_F(CloudExternalDataManagerBaseTest, DownloadAndCache) { |
285 // Serve valid external data for |k10BytePolicy|. | 286 // Serve valid external data for |k10BytePolicy|. |
286 SetFakeResponse(k10BytePolicyURL, k10ByteData, true); | 287 SetFakeResponse(k10BytePolicyURL, k10ByteData, net::HTTP_OK); |
287 external_data_manager_->Connect(request_content_getter_); | 288 external_data_manager_->Connect(request_content_getter_); |
288 | 289 |
289 // Retrieve external data for |k10BytePolicy|. Verify that a download happens | 290 // Retrieve external data for |k10BytePolicy|. Verify that a download happens |
290 // and the callback is invoked with the downloaded data. | 291 // and the callback is invoked with the downloaded data. |
291 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 292 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); |
292 base::RunLoop().RunUntilIdle(); | 293 base::RunLoop().RunUntilIdle(); |
293 EXPECT_EQ(1u, callback_data_.size()); | 294 EXPECT_EQ(1u, callback_data_.size()); |
294 ASSERT_TRUE(callback_data_[0]); | 295 ASSERT_TRUE(callback_data_[0]); |
295 EXPECT_EQ(k10ByteData, *callback_data_[0]); | 296 EXPECT_EQ(k10ByteData, *callback_data_[0]); |
296 ResetCallbackData(); | 297 ResetCallbackData(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 resource_cache_.get()).Load( | 332 resource_cache_.get()).Load( |
332 k10BytePolicy, base::SHA1HashString(k10ByteData), 10, &data)); | 333 k10BytePolicy, base::SHA1HashString(k10ByteData), 10, &data)); |
333 EXPECT_EQ(k10ByteData, data); | 334 EXPECT_EQ(k10ByteData, data); |
334 } | 335 } |
335 | 336 |
336 // Verifies that a request to download and cache all external data referenced by | 337 // Verifies that a request to download and cache all external data referenced by |
337 // policies is carried out correctly. Subsequent requests for the data are | 338 // policies is carried out correctly. Subsequent requests for the data are |
338 // served from the cache without further download attempts. | 339 // served from the cache without further download attempts. |
339 TEST_F(CloudExternalDataManagerBaseTest, DownloadAndCacheAll) { | 340 TEST_F(CloudExternalDataManagerBaseTest, DownloadAndCacheAll) { |
340 // Serve valid external data for |k10BytePolicy| and |k20BytePolicy|. | 341 // Serve valid external data for |k10BytePolicy| and |k20BytePolicy|. |
341 SetFakeResponse(k10BytePolicyURL, k10ByteData, true); | 342 SetFakeResponse(k10BytePolicyURL, k10ByteData, net::HTTP_OK); |
342 SetFakeResponse(k20BytePolicyURL, k20ByteData, true); | 343 SetFakeResponse(k20BytePolicyURL, k20ByteData, net::HTTP_OK); |
343 external_data_manager_->Connect(request_content_getter_); | 344 external_data_manager_->Connect(request_content_getter_); |
344 | 345 |
345 // Request that external data referenced by all policies be downloaded. | 346 // Request that external data referenced by all policies be downloaded. |
346 FetchAll(); | 347 FetchAll(); |
347 base::RunLoop().RunUntilIdle(); | 348 base::RunLoop().RunUntilIdle(); |
348 | 349 |
349 // Stop serving external data for |k10BytePolicy| and |k20BytePolicy|. | 350 // Stop serving external data for |k10BytePolicy| and |k20BytePolicy|. |
350 fetcher_factory_.ClearFakeResponses(); | 351 fetcher_factory_.ClearFakeResponses(); |
351 | 352 |
352 // Retrieve external data for |k10BytePolicy| and |k20BytePolicy|. Verify that | 353 // Retrieve external data for |k10BytePolicy| and |k20BytePolicy|. Verify that |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 TEST_F(CloudExternalDataManagerBaseTest, DownloadAfterConnect) { | 401 TEST_F(CloudExternalDataManagerBaseTest, DownloadAfterConnect) { |
401 // Attempt to retrieve external data for |k10BytePolicy|. Verify that the | 402 // Attempt to retrieve external data for |k10BytePolicy|. Verify that the |
402 // callback is not invoked as the request remains pending. | 403 // callback is not invoked as the request remains pending. |
403 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 404 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); |
404 base::RunLoop().RunUntilIdle(); | 405 base::RunLoop().RunUntilIdle(); |
405 EXPECT_TRUE(callback_data_.empty()); | 406 EXPECT_TRUE(callback_data_.empty()); |
406 ResetCallbackData(); | 407 ResetCallbackData(); |
407 | 408 |
408 // Serve valid external data for |k10BytePolicy| and allow the | 409 // Serve valid external data for |k10BytePolicy| and allow the |
409 // external_data_manager_ to perform downloads. | 410 // external_data_manager_ to perform downloads. |
410 SetFakeResponse(k10BytePolicyURL, k10ByteData, true); | 411 SetFakeResponse(k10BytePolicyURL, k10ByteData, net::HTTP_OK); |
411 external_data_manager_->Connect(request_content_getter_); | 412 external_data_manager_->Connect(request_content_getter_); |
412 | 413 |
413 // Verify that a download happens and the callback is invoked with the | 414 // Verify that a download happens and the callback is invoked with the |
414 // downloaded data. | 415 // downloaded data. |
415 base::RunLoop().RunUntilIdle(); | 416 base::RunLoop().RunUntilIdle(); |
416 EXPECT_EQ(1u, callback_data_.size()); | 417 EXPECT_EQ(1u, callback_data_.size()); |
417 ASSERT_TRUE(callback_data_[0]); | 418 ASSERT_TRUE(callback_data_[0]); |
418 EXPECT_EQ(k10ByteData, *callback_data_[0]); | 419 EXPECT_EQ(k10ByteData, *callback_data_[0]); |
419 ResetCallbackData(); | 420 ResetCallbackData(); |
420 } | 421 } |
421 | 422 |
422 // Verifies that when the external data referenced by a policy is not present in | 423 // Verifies that when the external data referenced by a policy is not present in |
423 // the cache and cannot be downloaded at this time, a request to retrieve the | 424 // the cache and cannot be downloaded at this time, a request to retrieve the |
424 // data is enqueued to be retried later. | 425 // data is enqueued to be retried later. |
425 TEST_F(CloudExternalDataManagerBaseTest, DownloadError) { | 426 TEST_F(CloudExternalDataManagerBaseTest, DownloadError) { |
426 // Make attempts to download the external data for |k20BytePolicy| fail with | 427 // Make attempts to download the external data for |k20BytePolicy| fail with |
427 // an error. | 428 // an error. |
428 SetFakeResponse(k20BytePolicyURL, std::string(), false); | 429 SetFakeResponse(k20BytePolicyURL, std::string(), |
| 430 net::HTTP_INTERNAL_SERVER_ERROR); |
429 external_data_manager_->Connect(request_content_getter_); | 431 external_data_manager_->Connect(request_content_getter_); |
430 | 432 |
431 // Attempt to retrieve external data for |k20BytePolicy|. Verify that the | 433 // Attempt to retrieve external data for |k20BytePolicy|. Verify that the |
432 // callback is not invoked as the download attempt fails and the request | 434 // callback is not invoked as the download attempt fails and the request |
433 // remains pending. | 435 // remains pending. |
434 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(0)); | 436 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(0)); |
435 base::RunLoop().RunUntilIdle(); | 437 base::RunLoop().RunUntilIdle(); |
436 EXPECT_TRUE(callback_data_.empty()); | 438 EXPECT_TRUE(callback_data_.empty()); |
437 ResetCallbackData(); | 439 ResetCallbackData(); |
438 | 440 |
(...skipping 14 matching lines...) Expand all Loading... |
453 | 455 |
454 // Modify the external data reference for |k20BytePolicy|, allowing the | 456 // Modify the external data reference for |k20BytePolicy|, allowing the |
455 // download to be retried immediately. | 457 // download to be retried immediately. |
456 SetExternalDataReference( | 458 SetExternalDataReference( |
457 k20BytePolicy, | 459 k20BytePolicy, |
458 ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k20ByteData))); | 460 ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k20ByteData))); |
459 cloud_policy_store_.NotifyStoreLoaded(); | 461 cloud_policy_store_.NotifyStoreLoaded(); |
460 | 462 |
461 // Serve external data for |k20BytePolicy| that does not match the hash | 463 // Serve external data for |k20BytePolicy| that does not match the hash |
462 // specified in its current external data reference. | 464 // specified in its current external data reference. |
463 SetFakeResponse(k20BytePolicyURL, k10ByteData, true); | 465 SetFakeResponse(k20BytePolicyURL, k10ByteData, net::HTTP_OK); |
464 | 466 |
465 // Attempt to retrieve external data for |k20BytePolicy| again. Verify that | 467 // Attempt to retrieve external data for |k20BytePolicy| again. Verify that |
466 // no callback is invoked still as the downloaded succeeds but returns data | 468 // no callback is invoked still as the downloaded succeeds but returns data |
467 // that does not match the external data reference. | 469 // that does not match the external data reference. |
468 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(2)); | 470 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(2)); |
469 base::RunLoop().RunUntilIdle(); | 471 base::RunLoop().RunUntilIdle(); |
470 EXPECT_TRUE(callback_data_.empty()); | 472 EXPECT_TRUE(callback_data_.empty()); |
471 ResetCallbackData(); | 473 ResetCallbackData(); |
472 | 474 |
473 // Modify the external data reference for |k20BytePolicy|, allowing the | 475 // Modify the external data reference for |k20BytePolicy|, allowing the |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 // Store external data for |k20BytePolicy| that is corrupted and does not | 624 // Store external data for |k20BytePolicy| that is corrupted and does not |
623 // match the expected hash. | 625 // match the expected hash. |
624 EXPECT_TRUE(cache->Store(k20BytePolicy, | 626 EXPECT_TRUE(cache->Store(k20BytePolicy, |
625 base::SHA1HashString(k20ByteData), | 627 base::SHA1HashString(k20ByteData), |
626 k10ByteData)); | 628 k10ByteData)); |
627 cache.reset(); | 629 cache.reset(); |
628 | 630 |
629 SetUpExternalDataManager(); | 631 SetUpExternalDataManager(); |
630 // Serve external data for |k10BytePolicy| that exceeds the maximal external | 632 // Serve external data for |k10BytePolicy| that exceeds the maximal external |
631 // data size allowed for that policy. | 633 // data size allowed for that policy. |
632 SetFakeResponse(k10BytePolicyURL, k20ByteData, true); | 634 SetFakeResponse(k10BytePolicyURL, k20ByteData, net::HTTP_OK); |
633 external_data_manager_->Connect(request_content_getter_); | 635 external_data_manager_->Connect(request_content_getter_); |
634 | 636 |
635 // Modify the external data reference for |k10BytePolicy| to match the | 637 // Modify the external data reference for |k10BytePolicy| to match the |
636 // external data being served. | 638 // external data being served. |
637 SetExternalDataReference( | 639 SetExternalDataReference( |
638 k10BytePolicy, | 640 k10BytePolicy, |
639 ConstructMetadata(k10BytePolicyURL, base::SHA1HashString(k20ByteData))); | 641 ConstructMetadata(k10BytePolicyURL, base::SHA1HashString(k20ByteData))); |
640 cloud_policy_store_.NotifyStoreLoaded(); | 642 cloud_policy_store_.NotifyStoreLoaded(); |
641 | 643 |
642 // Retrieve external data for |k10BytePolicy|. Verify that the callback is | 644 // Retrieve external data for |k10BytePolicy|. Verify that the callback is |
643 // not invoked as the cached and downloaded external data exceed the maximal | 645 // not invoked as the cached and downloaded external data exceed the maximal |
644 // size allowed for this policy and the request remains pending. | 646 // size allowed for this policy and the request remains pending. |
645 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 647 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); |
646 base::RunLoop().RunUntilIdle(); | 648 base::RunLoop().RunUntilIdle(); |
647 EXPECT_TRUE(callback_data_.empty()); | 649 EXPECT_TRUE(callback_data_.empty()); |
648 ResetCallbackData(); | 650 ResetCallbackData(); |
649 | 651 |
650 // Serve valid external data for |k20BytePolicy|. | 652 // Serve valid external data for |k20BytePolicy|. |
651 SetFakeResponse(k20BytePolicyURL, k20ByteData, true); | 653 SetFakeResponse(k20BytePolicyURL, k20ByteData, net::HTTP_OK); |
652 | 654 |
653 // Retrieve external data for |k20BytePolicy|. Verify that the callback is | 655 // Retrieve external data for |k20BytePolicy|. Verify that the callback is |
654 // invoked with the valid downloaded data, not the invalid data in the cache. | 656 // invoked with the valid downloaded data, not the invalid data in the cache. |
655 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(1)); | 657 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(1)); |
656 base::RunLoop().RunUntilIdle(); | 658 base::RunLoop().RunUntilIdle(); |
657 EXPECT_EQ(1u, callback_data_.size()); | 659 EXPECT_EQ(1u, callback_data_.size()); |
658 ASSERT_TRUE(callback_data_[1]); | 660 ASSERT_TRUE(callback_data_[1]); |
659 EXPECT_EQ(k20ByteData, *callback_data_[1]); | 661 EXPECT_EQ(k20ByteData, *callback_data_[1]); |
660 ResetCallbackData(); | 662 ResetCallbackData(); |
661 | 663 |
(...skipping 20 matching lines...) Expand all Loading... |
682 &data)); | 684 &data)); |
683 EXPECT_EQ(k20ByteData, data); | 685 EXPECT_EQ(k20ByteData, data); |
684 } | 686 } |
685 | 687 |
686 // Verifies that when the external data reference for a policy changes while a | 688 // Verifies that when the external data reference for a policy changes while a |
687 // download of the external data for that policy is pending, the download is | 689 // download of the external data for that policy is pending, the download is |
688 // immediately retried using the new reference. | 690 // immediately retried using the new reference. |
689 TEST_F(CloudExternalDataManagerBaseTest, PolicyChangeWhileDownloadPending) { | 691 TEST_F(CloudExternalDataManagerBaseTest, PolicyChangeWhileDownloadPending) { |
690 // Make attempts to download the external data for |k10BytePolicy| and | 692 // Make attempts to download the external data for |k10BytePolicy| and |
691 // |k20BytePolicy| fail with an error. | 693 // |k20BytePolicy| fail with an error. |
692 SetFakeResponse(k10BytePolicyURL, std::string(), false); | 694 SetFakeResponse(k10BytePolicyURL, std::string(), |
693 SetFakeResponse(k20BytePolicyURL, std::string(), false); | 695 net::HTTP_INTERNAL_SERVER_ERROR); |
| 696 SetFakeResponse(k20BytePolicyURL, std::string(), |
| 697 net::HTTP_INTERNAL_SERVER_ERROR); |
694 external_data_manager_->Connect(request_content_getter_); | 698 external_data_manager_->Connect(request_content_getter_); |
695 | 699 |
696 // Attempt to retrieve external data for |k10BytePolicy| and |k20BytePolicy|. | 700 // Attempt to retrieve external data for |k10BytePolicy| and |k20BytePolicy|. |
697 // Verify that no callbacks are invoked as the download attempts fail and the | 701 // Verify that no callbacks are invoked as the download attempts fail and the |
698 // requests remain pending. | 702 // requests remain pending. |
699 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); | 703 external_data_manager_->Fetch(k10BytePolicy, ConstructFetchCallback(0)); |
700 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(1)); | 704 external_data_manager_->Fetch(k20BytePolicy, ConstructFetchCallback(1)); |
701 base::RunLoop().RunUntilIdle(); | 705 base::RunLoop().RunUntilIdle(); |
702 EXPECT_TRUE(callback_data_.empty()); | 706 EXPECT_TRUE(callback_data_.empty()); |
703 ResetCallbackData(); | 707 ResetCallbackData(); |
704 | 708 |
705 // Modify the external data reference for |k10BytePolicy| to be invalid. | 709 // Modify the external data reference for |k10BytePolicy| to be invalid. |
706 // Verify that the callback is invoked as the policy no longer has a valid | 710 // Verify that the callback is invoked as the policy no longer has a valid |
707 // external data reference. | 711 // external data reference. |
708 cloud_policy_store_.policy_map_.Erase(k10BytePolicy); | 712 cloud_policy_store_.policy_map_.Erase(k10BytePolicy); |
709 cloud_policy_store_.NotifyStoreLoaded(); | 713 cloud_policy_store_.NotifyStoreLoaded(); |
710 base::RunLoop().RunUntilIdle(); | 714 base::RunLoop().RunUntilIdle(); |
711 EXPECT_EQ(1u, callback_data_.size()); | 715 EXPECT_EQ(1u, callback_data_.size()); |
712 EXPECT_TRUE(callback_data_.find(0) != callback_data_.end()); | 716 EXPECT_TRUE(callback_data_.find(0) != callback_data_.end()); |
713 EXPECT_FALSE(callback_data_[0]); | 717 EXPECT_FALSE(callback_data_[0]); |
714 ResetCallbackData(); | 718 ResetCallbackData(); |
715 | 719 |
716 // Serve valid external data for |k20BytePolicy|. | 720 // Serve valid external data for |k20BytePolicy|. |
717 fetcher_factory_.ClearFakeResponses(); | 721 fetcher_factory_.ClearFakeResponses(); |
718 SetFakeResponse(k20BytePolicyURL, k10ByteData, true); | 722 SetFakeResponse(k20BytePolicyURL, k10ByteData, net::HTTP_OK); |
719 | 723 |
720 // Modify the external data reference for |k20BytePolicy| to match the | 724 // Modify the external data reference for |k20BytePolicy| to match the |
721 // external data now being served. Verify that the callback is invoked with | 725 // external data now being served. Verify that the callback is invoked with |
722 // the downloaded data. | 726 // the downloaded data. |
723 SetExternalDataReference( | 727 SetExternalDataReference( |
724 k20BytePolicy, | 728 k20BytePolicy, |
725 ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k10ByteData))); | 729 ConstructMetadata(k20BytePolicyURL, base::SHA1HashString(k10ByteData))); |
726 cloud_policy_store_.NotifyStoreLoaded(); | 730 cloud_policy_store_.NotifyStoreLoaded(); |
727 base::RunLoop().RunUntilIdle(); | 731 base::RunLoop().RunUntilIdle(); |
728 EXPECT_EQ(1u, callback_data_.size()); | 732 EXPECT_EQ(1u, callback_data_.size()); |
729 ASSERT_TRUE(callback_data_[1]); | 733 ASSERT_TRUE(callback_data_[1]); |
730 EXPECT_EQ(k10ByteData, *callback_data_[1]); | 734 EXPECT_EQ(k10ByteData, *callback_data_[1]); |
731 ResetCallbackData(); | 735 ResetCallbackData(); |
732 } | 736 } |
733 | 737 |
734 } // namespace policy | 738 } // namespace policy |
OLD | NEW |