| Index: chrome/browser/policy/cloud/component_cloud_policy_updater_unittest.cc
|
| diff --git a/chrome/browser/policy/cloud/component_cloud_policy_updater_unittest.cc b/chrome/browser/policy/cloud/component_cloud_policy_updater_unittest.cc
|
| index 5154e9cb389e35f1941e4b3d007fa43a0a6ae0b5..4ea40cab28bfd4d1b73ff098e5e96f47be07ce26 100644
|
| --- a/chrome/browser/policy/cloud/component_cloud_policy_updater_unittest.cc
|
| +++ b/chrome/browser/policy/cloud/component_cloud_policy_updater_unittest.cc
|
| @@ -6,21 +6,22 @@
|
|
|
| #include <string>
|
|
|
| -#include "base/basictypes.h"
|
| +#include "base/compiler_specific.h"
|
| #include "base/files/scoped_temp_dir.h"
|
| -#include "base/memory/ref_counted.h"
|
| -#include "base/memory/scoped_ptr.h"
|
| +#include "base/sequenced_task_runner.h"
|
| #include "base/sha1.h"
|
| -#include "base/test/test_pending_task.h"
|
| #include "base/test/test_simple_task_runner.h"
|
| -#include "base/time.h"
|
| +#include "base/values.h"
|
| #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
|
| #include "chrome/browser/policy/cloud/component_cloud_policy_store.h"
|
| #include "chrome/browser/policy/cloud/policy_builder.h"
|
| #include "chrome/browser/policy/cloud/proto/chrome_extension_policy.pb.h"
|
| #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h"
|
| #include "chrome/browser/policy/cloud/resource_cache.h"
|
| -#include "net/base/net_errors.h"
|
| +#include "chrome/browser/policy/policy_bundle.h"
|
| +#include "chrome/browser/policy/policy_map.h"
|
| +#include "chrome/browser/policy/policy_types.h"
|
| +#include "googleurl/src/gurl.h"
|
| #include "net/url_request/test_url_fetcher_factory.h"
|
| #include "net/url_request/url_fetcher_delegate.h"
|
| #include "net/url_request/url_request_context_getter.h"
|
| @@ -39,7 +40,6 @@ const char kTestExtension[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
| const char kTestExtension2[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
|
| const char kTestDownload[] = "http://example.com/getpolicy?id=123";
|
| const char kTestDownload2[] = "http://example.com/getpolicy?id=456";
|
| -const char kTestDownload3[] = "http://example.com/getpolicy?id=789";
|
| const char kTestPolicy[] =
|
| "{"
|
| " \"Name\": {"
|
| @@ -63,58 +63,9 @@ class MockComponentCloudPolicyStoreDelegate
|
|
|
| class ComponentCloudPolicyUpdaterTest : public testing::Test {
|
| protected:
|
| - virtual void SetUp() OVERRIDE {
|
| - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| - cache_.reset(new ResourceCache(temp_dir_.path()));
|
| - store_.reset(new ComponentCloudPolicyStore(&store_delegate_, cache_.get()));
|
| - store_->SetCredentials(ComponentPolicyBuilder::kFakeUsername,
|
| - ComponentPolicyBuilder::kFakeToken);
|
| - fetcher_factory_.set_remove_fetcher_on_delete(true);
|
| - scoped_refptr<net::URLRequestContextGetter> request_context;
|
| - task_runner_ = new base::TestSimpleTaskRunner();
|
| - updater_.reset(new ComponentCloudPolicyUpdater(
|
| - task_runner_, request_context, store_.get()));
|
| - ASSERT_FALSE(GetCurrentFetcher());
|
| - ASSERT_TRUE(store_->policy().begin() == store_->policy().end());
|
| -
|
| - builder_.policy_data().set_policy_type(
|
| - dm_protocol::kChromeExtensionPolicyType);
|
| - builder_.policy_data().set_settings_entity_id(kTestExtension);
|
| - builder_.payload().set_download_url(kTestDownload);
|
| - builder_.payload().set_secure_hash(base::SHA1HashString(kTestPolicy));
|
| -
|
| - PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension);
|
| - PolicyMap& policy = expected_bundle_.Get(ns);
|
| - policy.Set("Name", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
|
| - base::Value::CreateStringValue("disabled"));
|
| - policy.Set("Second", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER,
|
| - base::Value::CreateStringValue("maybe"));
|
| - }
|
| -
|
| - net::TestURLFetcher* GetCurrentFetcher() {
|
| - return fetcher_factory_.GetFetcherByID(0);
|
| - }
|
| -
|
| - // Many tests also verify that a second fetcher is scheduled once the first
|
| - // completes, either successfully or with a failure. This helper starts two
|
| - // fetches immediately, so that the second is queued.
|
| - void StartTwoFetches() {
|
| - updater_->UpdateExternalPolicy(CreateResponse());
|
| -
|
| - builder_.payload().set_download_url(kTestDownload2);
|
| - builder_.policy_data().set_settings_entity_id(kTestExtension2);
|
| - updater_->UpdateExternalPolicy(CreateResponse());
|
| - }
|
| -
|
| - scoped_ptr<em::PolicyFetchResponse> CreateResponse() {
|
| - builder_.Build();
|
| - return make_scoped_ptr(new em::PolicyFetchResponse(builder_.policy()));
|
| - }
|
| -
|
| - std::string CreateSerializedResponse() {
|
| - builder_.Build();
|
| - return builder_.GetBlob();
|
| - }
|
| + virtual void SetUp() OVERRIDE;
|
| +
|
| + scoped_ptr<em::PolicyFetchResponse> CreateResponse();
|
|
|
| base::ScopedTempDir temp_dir_;
|
| scoped_ptr<ResourceCache> cache_;
|
| @@ -127,321 +78,218 @@ class ComponentCloudPolicyUpdaterTest : public testing::Test {
|
| PolicyBundle expected_bundle_;
|
| };
|
|
|
| +void ComponentCloudPolicyUpdaterTest::SetUp() OVERRIDE {
|
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| + cache_.reset(new ResourceCache(temp_dir_.path()));
|
| + store_.reset(new ComponentCloudPolicyStore(&store_delegate_, cache_.get()));
|
| + store_->SetCredentials(ComponentPolicyBuilder::kFakeUsername,
|
| + ComponentPolicyBuilder::kFakeToken);
|
| + fetcher_factory_.set_remove_fetcher_on_delete(true);
|
| + task_runner_ = new base::TestSimpleTaskRunner();
|
| + updater_.reset(new ComponentCloudPolicyUpdater(
|
| + task_runner_,
|
| + scoped_refptr<net::URLRequestContextGetter>(),
|
| + store_.get()));
|
| + ASSERT_EQ(store_->policy().end(), store_->policy().begin());
|
| +
|
| + builder_.policy_data().set_policy_type(
|
| + dm_protocol::kChromeExtensionPolicyType);
|
| + builder_.policy_data().set_settings_entity_id(kTestExtension);
|
| + builder_.payload().set_download_url(kTestDownload);
|
| + builder_.payload().set_secure_hash(base::SHA1HashString(kTestPolicy));
|
| +
|
| + PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension);
|
| + PolicyMap& policy = expected_bundle_.Get(ns);
|
| + policy.Set("Name", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
|
| + base::Value::CreateStringValue("disabled"));
|
| + policy.Set("Second", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER,
|
| + base::Value::CreateStringValue("maybe"));
|
| +}
|
| +
|
| +scoped_ptr<em::PolicyFetchResponse>
|
| + ComponentCloudPolicyUpdaterTest::CreateResponse() {
|
| + builder_.Build();
|
| + return make_scoped_ptr(new em::PolicyFetchResponse(builder_.policy()));
|
| +}
|
| +
|
| TEST_F(ComponentCloudPolicyUpdaterTest, FetchAndCache) {
|
| - StartTwoFetches();
|
| + // Submit a policy fetch response.
|
| + updater_->UpdateExternalPolicy(CreateResponse());
|
|
|
| - // The first fetch was scheduled; complete it.
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| + // Verify that a download has been started.
|
| + net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
|
| ASSERT_TRUE(fetcher);
|
| EXPECT_EQ(GURL(kTestDownload), fetcher->GetOriginalURL());
|
| +
|
| + // Complete the download.
|
| fetcher->set_response_code(200);
|
| fetcher->SetResponseString(kTestPolicy);
|
| EXPECT_CALL(store_delegate_, OnComponentCloudPolicyStoreUpdated());
|
| fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| Mock::VerifyAndClearExpectations(&store_delegate_);
|
|
|
| - // The second fetch was scheduled.
|
| - fetcher = GetCurrentFetcher();
|
| - ASSERT_TRUE(fetcher);
|
| - EXPECT_EQ(GURL(kTestDownload2), fetcher->GetOriginalURL());
|
| + // Verify that the download is no longer running.
|
| + ASSERT_FALSE(fetcher_factory_.GetFetcherByID(0));
|
|
|
| - // The policy is being served.
|
| + // Verify that the downloaded policy is being served.
|
| EXPECT_TRUE(store_->policy().Equals(expected_bundle_));
|
| -
|
| - // No retries have been scheduled.
|
| - EXPECT_TRUE(task_runner_->GetPendingTasks().empty());
|
| }
|
|
|
| -TEST_F(ComponentCloudPolicyUpdaterTest, LargeResponse) {
|
| +TEST_F(ComponentCloudPolicyUpdaterTest, PolicyFetchResponseTooLarge) {
|
| + // Submit a policy fetch response that exceeds the allowed maximum size.
|
| std::string long_download("http://example.com/get?id=");
|
| long_download.append(20 * 1024, '1');
|
| builder_.payload().set_download_url(long_download);
|
| updater_->UpdateExternalPolicy(CreateResponse());
|
|
|
| + // Submit a valid policy fetch response.
|
| builder_.policy_data().set_settings_entity_id(kTestExtension2);
|
| builder_.payload().set_download_url(kTestDownload2);
|
| updater_->UpdateExternalPolicy(CreateResponse());
|
|
|
| - // The first request was dropped, and the second was started.
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| + // Verify that the first policy fetch response has been ignored and a download
|
| + // has been started for the second instead.
|
| + net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
|
| ASSERT_TRUE(fetcher);
|
| EXPECT_EQ(GURL(kTestDownload2), fetcher->GetOriginalURL());
|
| -
|
| - // No retry is scheduled for the first request, because the policy was
|
| - // rejected (too large).
|
| - EXPECT_TRUE(task_runner_->GetPendingTasks().empty());
|
| }
|
|
|
| -TEST_F(ComponentCloudPolicyUpdaterTest, InvalidPolicy) {
|
| +TEST_F(ComponentCloudPolicyUpdaterTest, PolicyFetchResponseInvalid) {
|
| + // Submit an invalid policy fetch response.
|
| builder_.policy_data().set_username("wronguser@example.com");
|
| updater_->UpdateExternalPolicy(CreateResponse());
|
|
|
| + // Submit a valid policy fetch response.
|
| builder_.policy_data().set_username(ComponentPolicyBuilder::kFakeUsername);
|
| builder_.policy_data().set_settings_entity_id(kTestExtension2);
|
| builder_.payload().set_download_url(kTestDownload2);
|
| updater_->UpdateExternalPolicy(CreateResponse());
|
|
|
| - // The first request was dropped, and the second was started.
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| + // Verify that the first policy fetch response has been ignored and a download
|
| + // has been started for the second instead.
|
| + net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
|
| ASSERT_TRUE(fetcher);
|
| EXPECT_EQ(GURL(kTestDownload2), fetcher->GetOriginalURL());
|
| -
|
| - // No retry is scheduled for the first request, because the policy was
|
| - // rejected (invalid).
|
| - EXPECT_TRUE(task_runner_->GetPendingTasks().empty());
|
| }
|
|
|
| TEST_F(ComponentCloudPolicyUpdaterTest, AlreadyCached) {
|
| + // Cache policy for an extension.
|
| + builder_.Build();
|
| PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension);
|
| EXPECT_CALL(store_delegate_, OnComponentCloudPolicyStoreUpdated());
|
| EXPECT_TRUE(store_->Store(ns,
|
| - CreateSerializedResponse(),
|
| + builder_.GetBlob(),
|
| base::SHA1HashString(kTestPolicy),
|
| kTestPolicy));
|
| Mock::VerifyAndClearExpectations(&store_delegate_);
|
|
|
| - // Seeing the same policy data again won't trigger a new fetch.
|
| + // Submit a policy fetch response whose extension ID and hash match the
|
| + // already cached policy.
|
| updater_->UpdateExternalPolicy(CreateResponse());
|
| - EXPECT_FALSE(GetCurrentFetcher());
|
| -
|
| - // And no retry is scheduled either.
|
| - EXPECT_TRUE(task_runner_->GetPendingTasks().empty());
|
| -}
|
| -
|
| -TEST_F(ComponentCloudPolicyUpdaterTest, LargeFetch) {
|
| - StartTwoFetches();
|
| -
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| - ASSERT_TRUE(fetcher);
|
| - EXPECT_EQ(GURL(kTestDownload), fetcher->GetOriginalURL());
|
| - fetcher->delegate()->OnURLFetchDownloadProgress(fetcher, 6 * 1024 * 1024, -1);
|
|
|
| - // The second fetch was scheduled next.
|
| - fetcher = GetCurrentFetcher();
|
| - ASSERT_TRUE(fetcher);
|
| - EXPECT_EQ(GURL(kTestDownload2), fetcher->GetOriginalURL());
|
| -
|
| - // A retry is scheduled for the first fetcher.
|
| - EXPECT_EQ(1u, task_runner_->GetPendingTasks().size());
|
| + // Verify that no download has been started.
|
| + EXPECT_FALSE(fetcher_factory_.GetFetcherByID(0));
|
| }
|
|
|
| -TEST_F(ComponentCloudPolicyUpdaterTest, FetchFailed) {
|
| - StartTwoFetches();
|
| +TEST_F(ComponentCloudPolicyUpdaterTest, PolicyDataInvalid) {
|
| + // Submit two policy fetch responses.
|
| + updater_->UpdateExternalPolicy(CreateResponse());
|
| + builder_.payload().set_download_url(kTestDownload2);
|
| + builder_.policy_data().set_settings_entity_id(kTestExtension2);
|
| + updater_->UpdateExternalPolicy(CreateResponse());
|
|
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| + // Verify that the first download has been started.
|
| + net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
|
| ASSERT_TRUE(fetcher);
|
| EXPECT_EQ(GURL(kTestDownload), fetcher->GetOriginalURL());
|
| - fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED,
|
| - net::ERR_NETWORK_CHANGED));
|
| - fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| -
|
| - // The second fetch was scheduled next.
|
| - fetcher = GetCurrentFetcher();
|
| - ASSERT_TRUE(fetcher);
|
| - EXPECT_EQ(GURL(kTestDownload2), fetcher->GetOriginalURL());
|
|
|
| - // A retry is scheduled for the first fetcher.
|
| - EXPECT_EQ(1u, task_runner_->GetPendingTasks().size());
|
| -}
|
| -
|
| -TEST_F(ComponentCloudPolicyUpdaterTest, ServerFailed) {
|
| - StartTwoFetches();
|
| + // Indicate that the policy data size will exceed allowed maximum.
|
| + fetcher->delegate()->OnURLFetchDownloadProgress(fetcher, 6 * 1024 * 1024, -1);
|
|
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| - ASSERT_TRUE(fetcher);
|
| - EXPECT_EQ(GURL(kTestDownload), fetcher->GetOriginalURL());
|
| - fetcher->set_response_code(500);
|
| - fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| + // Verify that the first download is no longer running.
|
| + ASSERT_FALSE(fetcher_factory_.GetFetcherByID(0));
|
|
|
| - // The second fetch was scheduled next.
|
| - fetcher = GetCurrentFetcher();
|
| + // Verify that the second download has been started.
|
| + fetcher = fetcher_factory_.GetFetcherByID(1);
|
| ASSERT_TRUE(fetcher);
|
| EXPECT_EQ(GURL(kTestDownload2), fetcher->GetOriginalURL());
|
| -
|
| - // A retry is scheduled for the first fetcher.
|
| - EXPECT_EQ(1u, task_runner_->GetPendingTasks().size());
|
| }
|
|
|
| -TEST_F(ComponentCloudPolicyUpdaterTest, RetryLimit) {
|
| - updater_->UpdateExternalPolicy(CreateResponse());
|
| -
|
| - // Failing due to client errors retries up to 3 times.
|
| - for (int i = 0; i < 3; ++i) {
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| - ASSERT_TRUE(fetcher);
|
| - EXPECT_EQ(GURL(kTestDownload), fetcher->GetOriginalURL());
|
| -
|
| - // Make it fail with a 400 (bad request) client error.
|
| - fetcher->set_response_code(400);
|
| - fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| -
|
| - // A retry is scheduled.
|
| - EXPECT_EQ(1u, task_runner_->GetPendingTasks().size());
|
| - // Make it retry immediately.
|
| - task_runner_->RunPendingTasks();
|
| - EXPECT_TRUE(task_runner_->GetPendingTasks().empty());
|
| - }
|
| -
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| - ASSERT_TRUE(fetcher);
|
| - EXPECT_EQ(GURL(kTestDownload), fetcher->GetOriginalURL());
|
| -
|
| - // Make the last retry fail too; it won't retry anymore.
|
| - fetcher->set_response_code(400);
|
| - fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| - EXPECT_TRUE(task_runner_->GetPendingTasks().empty());
|
| -}
|
| -
|
| -TEST_F(ComponentCloudPolicyUpdaterTest, RetryWithBackoff) {
|
| +TEST_F(ComponentCloudPolicyUpdaterTest, FetchUpdatedData) {
|
| + // Submit a policy fetch response.
|
| updater_->UpdateExternalPolicy(CreateResponse());
|
|
|
| - base::TimeDelta expected_delay = base::TimeDelta::FromSeconds(60);
|
| - const base::TimeDelta delay_cap = base::TimeDelta::FromHours(12);
|
| -
|
| - // The backoff delay is capped at 12 hours, which is reached after 10 retries:
|
| - // 60 * 2^10 == 61440 > 43200 == 12 * 60 * 60
|
| - for (int i = 0; i < 20; ++i) {
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| - ASSERT_TRUE(fetcher);
|
| - EXPECT_EQ(GURL(kTestDownload), fetcher->GetOriginalURL());
|
| -
|
| - // Make it fail with a 500 server error.
|
| - fetcher->set_response_code(500);
|
| - fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| -
|
| - // A retry is scheduled. The delay is twice the last delay, with random
|
| - // jitter from 80% to 100%.
|
| - ASSERT_EQ(1u, task_runner_->GetPendingTasks().size());
|
| - const base::TestPendingTask& task = task_runner_->GetPendingTasks().front();
|
| - EXPECT_GT(task.delay,
|
| - base::TimeDelta::FromMilliseconds(
|
| - 0.799 * expected_delay.InMilliseconds()));
|
| - EXPECT_LE(task.delay, expected_delay);
|
| -
|
| - if (i < 10) {
|
| - // The delay cap hasn't been reached yet.
|
| - EXPECT_LT(expected_delay, delay_cap);
|
| - expected_delay *= 2;
|
| -
|
| - if (i == 9) {
|
| - // The last doubling reached the cap.
|
| - EXPECT_GT(expected_delay, delay_cap);
|
| - expected_delay = delay_cap;
|
| - }
|
| - }
|
| -
|
| - // Make it retry immediately.
|
| - task_runner_->RunPendingTasks();
|
| - EXPECT_TRUE(task_runner_->GetPendingTasks().empty());
|
| - }
|
| -}
|
| -
|
| -TEST_F(ComponentCloudPolicyUpdaterTest, DataValidationFails) {
|
| - StartTwoFetches();
|
| -
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| + // Verify that the first download has been started.
|
| + net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
|
| ASSERT_TRUE(fetcher);
|
| EXPECT_EQ(GURL(kTestDownload), fetcher->GetOriginalURL());
|
| - fetcher->set_response_code(200);
|
| - fetcher->SetResponseString("{ won't hash }");
|
| - fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| -
|
| - // The second fetch was scheduled next.
|
| - fetcher = GetCurrentFetcher();
|
| - ASSERT_TRUE(fetcher);
|
| - EXPECT_EQ(GURL(kTestDownload2), fetcher->GetOriginalURL());
|
| -
|
| - // A retry is scheduled for the first fetcher.
|
| - EXPECT_EQ(1u, task_runner_->GetPendingTasks().size());
|
| -}
|
|
|
| -TEST_F(ComponentCloudPolicyUpdaterTest, FetchUpdatedData) {
|
| - updater_->UpdateExternalPolicy(CreateResponse());
|
| -
|
| - // Same extension, but the download location has changed.
|
| + // Submit a second policy fetch response for the same extension with an
|
| + // updated download URL.
|
| builder_.payload().set_download_url(kTestDownload2);
|
| updater_->UpdateExternalPolicy(CreateResponse());
|
|
|
| - // The first was cancelled and overridden by the second.
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| + // Verify that the first download is no longer running.
|
| + ASSERT_FALSE(fetcher_factory_.GetFetcherByID(0));
|
| +
|
| + // Verify that the second download has been started.
|
| + fetcher = fetcher_factory_.GetFetcherByID(1);
|
| ASSERT_TRUE(fetcher);
|
| EXPECT_EQ(GURL(kTestDownload2), fetcher->GetOriginalURL());
|
| -
|
| - // No retries are scheduled.
|
| - EXPECT_TRUE(task_runner_->GetPendingTasks().empty());
|
| }
|
|
|
| TEST_F(ComponentCloudPolicyUpdaterTest, FetchUpdatedDataWithoutPolicy) {
|
| - // Fetch the initial policy data.
|
| + // Submit a policy fetch response.
|
| updater_->UpdateExternalPolicy(CreateResponse());
|
|
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| + // Verify that the download has been started.
|
| + net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
|
| ASSERT_TRUE(fetcher);
|
| EXPECT_EQ(GURL(kTestDownload), fetcher->GetOriginalURL());
|
| +
|
| + // Complete the download.
|
| fetcher->set_response_code(200);
|
| fetcher->SetResponseString(kTestPolicy);
|
| EXPECT_CALL(store_delegate_, OnComponentCloudPolicyStoreUpdated());
|
| fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| Mock::VerifyAndClearExpectations(&store_delegate_);
|
| - EXPECT_FALSE(GetCurrentFetcher());
|
|
|
| - // The policy is being served.
|
| + // Verify that the download is no longer running.
|
| + EXPECT_FALSE(fetcher_factory_.GetFetcherByID(0));
|
| +
|
| + // Verify that the downloaded policy is being served.
|
| EXPECT_TRUE(store_->policy().Equals(expected_bundle_));
|
|
|
| - // Same extension, but the download location has changed and is empty, meaning
|
| - // that no policy should be served anymore.
|
| - EXPECT_CALL(store_delegate_, OnComponentCloudPolicyStoreUpdated());
|
| + // Submit a second policy fetch response for the same extension with no
|
| + // download URL, meaning that no policy should be provided for this extension.
|
| builder_.payload().clear_download_url();
|
| builder_.payload().clear_secure_hash();
|
| + EXPECT_CALL(store_delegate_, OnComponentCloudPolicyStoreUpdated());
|
| updater_->UpdateExternalPolicy(CreateResponse());
|
| Mock::VerifyAndClearExpectations(&store_delegate_);
|
|
|
| - // No fetcher was started for that.
|
| - EXPECT_FALSE(GetCurrentFetcher());
|
| + // Verify that no download has been started.
|
| + EXPECT_FALSE(fetcher_factory_.GetFetcherByID(1));
|
|
|
| - // And the policy has been removed.
|
| + // Verify that the policy is no longer being served.
|
| const PolicyBundle empty_bundle;
|
| EXPECT_TRUE(store_->policy().Equals(empty_bundle));
|
| }
|
|
|
| -TEST_F(ComponentCloudPolicyUpdaterTest, InvalidatedJob) {
|
| - StartTwoFetches();
|
| -
|
| - // Start a new fetch for the second extension with a new download URL; the
|
| - // queued job is invalidated.
|
| - builder_.payload().set_download_url(kTestDownload3);
|
| - updater_->UpdateExternalPolicy(CreateResponse());
|
| -
|
| - // The first request is still pending.
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| - ASSERT_TRUE(fetcher);
|
| - EXPECT_EQ(GURL(kTestDownload), fetcher->GetOriginalURL());
|
| -
|
| - // Make it fail.
|
| - fetcher->set_response_code(500);
|
| - fetcher->delegate()->OnURLFetchComplete(fetcher);
|
| -
|
| - // Now the second job was invalidated, and the third job (for the same
|
| - // extension) is the next one.
|
| - fetcher = GetCurrentFetcher();
|
| - ASSERT_TRUE(fetcher);
|
| - EXPECT_EQ(GURL(kTestDownload3), fetcher->GetOriginalURL());
|
| -}
|
| -
|
| TEST_F(ComponentCloudPolicyUpdaterTest, NoPolicy) {
|
| - // Start a fetch with a valid download url.
|
| + // Submit a policy fetch response with a valid download URL.
|
| updater_->UpdateExternalPolicy(CreateResponse());
|
| - net::TestURLFetcher* fetcher = GetCurrentFetcher();
|
| - ASSERT_TRUE(fetcher);
|
|
|
| - // Now update the policy fetch response before the fetch completes. The new
|
| - // data does not have a download url.
|
| + // Verify that the download has been started.
|
| + ASSERT_TRUE(fetcher_factory_.GetFetcherByID(0));
|
| +
|
| + // Update the policy fetch response before the download has finished. The new
|
| + // policy fetch response has no download URL.
|
| builder_.payload().Clear();
|
| updater_->UpdateExternalPolicy(CreateResponse());
|
|
|
| - // The download has been cancelled.
|
| - fetcher = GetCurrentFetcher();
|
| - ASSERT_FALSE(fetcher);
|
| + // Verify that the download is no longer running.
|
| + ASSERT_FALSE(fetcher_factory_.GetFetcherByID(0));
|
| }
|
|
|
| } // namespace policy
|
|
|