Index: components/update_client/update_checker_unittest.cc |
diff --git a/components/update_client/update_checker_unittest.cc b/components/update_client/update_checker_unittest.cc |
index a6bd7e2b049cb8e700a1be57324a6fe2f52ca286..ae1c625644649de5e5484d6e8c621656f2ef326e 100644 |
--- a/components/update_client/update_checker_unittest.cc |
+++ b/components/update_client/update_checker_unittest.cc |
@@ -20,9 +20,10 @@ |
#include "base/version.h" |
#include "build/build_config.h" |
#include "components/prefs/testing_pref_service.h" |
-#include "components/update_client/crx_update_item.h" |
+#include "components/update_client/component.h" |
#include "components/update_client/persisted_data.h" |
#include "components/update_client/test_configurator.h" |
+#include "components/update_client/update_engine.h" |
#include "components/update_client/url_request_post_interceptor.h" |
#include "net/url_request/url_request_test_util.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -57,16 +58,14 @@ class UpdateCheckerTest : public testing::Test { |
void SetUp() override; |
void TearDown() override; |
- void UpdateCheckComplete(int error, |
- const UpdateResponse::Results& results, |
- int retry_after_sec); |
+ void UpdateCheckComplete(int error, int retry_after_sec); |
protected: |
void Quit(); |
void RunThreads(); |
void RunThreadsUntilIdle(); |
- std::unique_ptr<CrxUpdateItem> BuildCrxUpdateItem(); |
+ std::unique_ptr<Component> MakeComponent() const; |
scoped_refptr<TestConfigurator> config_; |
std::unique_ptr<TestingPrefServiceSimple> pref_; |
@@ -75,12 +74,17 @@ class UpdateCheckerTest : public testing::Test { |
std::unique_ptr<UpdateChecker> update_checker_; |
std::unique_ptr<InterceptorFactory> interceptor_factory_; |
- URLRequestPostInterceptor* post_interceptor_; // Owned by the factory. |
+ URLRequestPostInterceptor* post_interceptor_ = |
+ nullptr; // Owned by the factory. |
- int error_; |
- UpdateResponse::Results results_; |
+ int error_ = 0; |
+ int retry_after_sec_ = 0; |
+ |
+ std::unique_ptr<UpdateContext> update_context_; |
private: |
+ std::unique_ptr<UpdateContext> MakeFakeUpdateContext() const; |
+ |
base::MessageLoopForIO loop_; |
base::test::ScopedTaskScheduler scoped_task_scheduler_; |
base::Closure quit_closure_; |
@@ -88,34 +92,34 @@ class UpdateCheckerTest : public testing::Test { |
DISALLOW_COPY_AND_ASSIGN(UpdateCheckerTest); |
}; |
-UpdateCheckerTest::UpdateCheckerTest() |
- : post_interceptor_(NULL), error_(0), scoped_task_scheduler_(&loop_) {} |
+UpdateCheckerTest::UpdateCheckerTest() : scoped_task_scheduler_(&loop_) {} |
UpdateCheckerTest::~UpdateCheckerTest() { |
} |
void UpdateCheckerTest::SetUp() { |
- config_ = new TestConfigurator(base::ThreadTaskRunnerHandle::Get(), |
- base::ThreadTaskRunnerHandle::Get()); |
- pref_.reset(new TestingPrefServiceSimple()); |
+ config_ = base::MakeShared<TestConfigurator>( |
+ base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get()); |
+ pref_ = base::MakeUnique<TestingPrefServiceSimple>(); |
PersistedData::RegisterPrefs(pref_->registry()); |
- metadata_.reset(new PersistedData(pref_.get())); |
- interceptor_factory_.reset( |
- new InterceptorFactory(base::ThreadTaskRunnerHandle::Get())); |
+ metadata_ = base::MakeUnique<PersistedData>(pref_.get()); |
+ interceptor_factory_ = |
+ base::MakeUnique<InterceptorFactory>(base::ThreadTaskRunnerHandle::Get()); |
post_interceptor_ = interceptor_factory_->CreateInterceptor(); |
EXPECT_TRUE(post_interceptor_); |
- update_checker_.reset(); |
+ update_checker_ = nullptr; |
error_ = 0; |
- results_ = UpdateResponse::Results(); |
+ retry_after_sec_ = 0; |
+ update_context_ = MakeFakeUpdateContext(); |
} |
void UpdateCheckerTest::TearDown() { |
- update_checker_.reset(); |
+ update_checker_ = nullptr; |
- post_interceptor_ = NULL; |
- interceptor_factory_.reset(); |
+ post_interceptor_ = nullptr; |
+ interceptor_factory_ = nullptr; |
config_ = nullptr; |
@@ -145,16 +149,21 @@ void UpdateCheckerTest::Quit() { |
quit_closure_.Run(); |
} |
-void UpdateCheckerTest::UpdateCheckComplete( |
- int error, |
- const UpdateResponse::Results& results, |
- int retry_after_sec) { |
+void UpdateCheckerTest::UpdateCheckComplete(int error, int retry_after_sec) { |
error_ = error; |
- results_ = results; |
+ retry_after_sec_ = retry_after_sec; |
Quit(); |
} |
-std::unique_ptr<CrxUpdateItem> UpdateCheckerTest::BuildCrxUpdateItem() { |
+std::unique_ptr<UpdateContext> UpdateCheckerTest::MakeFakeUpdateContext() |
+ const { |
+ return base::MakeUnique<UpdateContext>( |
+ config_, false, std::vector<std::string>(), |
+ UpdateClient::CrxDataCallback(), UpdateEngine::NotifyObserversCallback(), |
+ UpdateEngine::Callback(), nullptr); |
+} |
+ |
+std::unique_ptr<Component> UpdateCheckerTest::MakeComponent() const { |
CrxComponent crx_component; |
crx_component.name = "test_jebg"; |
crx_component.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
@@ -162,13 +171,11 @@ std::unique_ptr<CrxUpdateItem> UpdateCheckerTest::BuildCrxUpdateItem() { |
crx_component.version = base::Version("0.9"); |
crx_component.fingerprint = "fp1"; |
- std::unique_ptr<CrxUpdateItem> crx_update_item = |
- base::MakeUnique<CrxUpdateItem>(); |
- crx_update_item->state = CrxUpdateItem::State::kNew; |
- crx_update_item->id = kUpdateItemId; |
- crx_update_item->component = crx_component; |
+ auto component = base::MakeUnique<Component>(*update_context_, kUpdateItemId); |
+ component->state_ = base::MakeUnique<Component::StateNew>(component.get()); |
+ component->crx_component_ = crx_component; |
- return crx_update_item; |
+ return component; |
} |
TEST_F(UpdateCheckerTest, UpdateCheckSuccess) { |
@@ -177,16 +184,17 @@ TEST_F(UpdateCheckerTest, UpdateCheckSuccess) { |
update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
- std::unique_ptr<CrxUpdateItem> item = BuildCrxUpdateItem(); |
- item->component.installer_attributes["ap"] = "some_ap"; |
- IdToCrxUpdateItemMap items_to_check; |
- items_to_check[kUpdateItemId] = std::move(item); |
+ IdToComponentPtrMap components; |
+ components[kUpdateItemId] = MakeComponent(); |
+ |
+ auto& component = components[kUpdateItemId]; |
+ component->crx_component_.installer_attributes["ap"] = "some_ap"; |
update_checker_->CheckForUpdates( |
- items_to_check, "extra=\"params\"", true, |
+ std::vector<std::string>{kUpdateItemId}, components, "extra=\"params\"", |
+ true, |
base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
base::Unretained(this))); |
- |
RunThreads(); |
EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
@@ -218,9 +226,12 @@ TEST_F(UpdateCheckerTest, UpdateCheckSuccess) { |
// Sanity check the arguments of the callback after parsing. |
EXPECT_EQ(0, error_); |
- EXPECT_EQ(1ul, results_.list.size()); |
- EXPECT_STREQ(kUpdateItemId, results_.list[0].extension_id.c_str()); |
- EXPECT_STREQ("1.0", results_.list[0].manifest.version.c_str()); |
+ |
+ EXPECT_EQ(base::Version("1.0"), component->next_version_); |
+ EXPECT_EQ(1u, component->crx_urls_.size()); |
+ EXPECT_EQ( |
+ GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"), |
+ component->crx_urls_.front()); |
#if (OS_WIN) |
EXPECT_NE(string::npos, request.find(" domainjoined=")); |
@@ -239,14 +250,15 @@ TEST_F(UpdateCheckerTest, UpdateCheckInvalidAp) { |
update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
- std::unique_ptr<CrxUpdateItem> item = BuildCrxUpdateItem(); |
+ IdToComponentPtrMap components; |
+ components[kUpdateItemId] = MakeComponent(); |
+ |
// Make "ap" too long. |
- item->component.installer_attributes["ap"] = std::string(257, 'a'); |
- IdToCrxUpdateItemMap items_to_check; |
- items_to_check[kUpdateItemId] = std::move(item); |
+ auto& component = components[kUpdateItemId]; |
+ component->crx_component_.installer_attributes["ap"] = std::string(257, 'a'); |
update_checker_->CheckForUpdates( |
- items_to_check, "", true, |
+ std::vector<std::string>{kUpdateItemId}, components, "", true, |
base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
base::Unretained(this))); |
@@ -268,12 +280,11 @@ TEST_F(UpdateCheckerTest, UpdateCheckSuccessNoBrand) { |
config_->SetBrand("TOOLONG"); // Sets an invalid brand code. |
update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
- std::unique_ptr<CrxUpdateItem> item = BuildCrxUpdateItem(); |
- IdToCrxUpdateItemMap items_to_check; |
- items_to_check[kUpdateItemId] = std::move(item); |
+ IdToComponentPtrMap components; |
+ components[kUpdateItemId] = MakeComponent(); |
update_checker_->CheckForUpdates( |
- items_to_check, "", true, |
+ std::vector<std::string>{kUpdateItemId}, components, "", true, |
base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
base::Unretained(this))); |
@@ -295,12 +306,13 @@ TEST_F(UpdateCheckerTest, UpdateCheckError) { |
update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
- std::unique_ptr<CrxUpdateItem> item = BuildCrxUpdateItem(); |
- IdToCrxUpdateItemMap items_to_check; |
- items_to_check[kUpdateItemId] = std::move(item); |
+ IdToComponentPtrMap components; |
+ components[kUpdateItemId] = MakeComponent(); |
+ |
+ auto& component = components[kUpdateItemId]; |
update_checker_->CheckForUpdates( |
- items_to_check, "", true, |
+ std::vector<std::string>{kUpdateItemId}, components, "", true, |
base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
base::Unretained(this))); |
RunThreads(); |
@@ -311,7 +323,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckError) { |
<< post_interceptor_->GetRequestsAsString(); |
EXPECT_EQ(403, error_); |
- EXPECT_EQ(0ul, results_.list.size()); |
+ EXPECT_FALSE(component->next_version_.IsValid()); |
} |
TEST_F(UpdateCheckerTest, UpdateCheckDownloadPreference) { |
@@ -322,12 +334,12 @@ TEST_F(UpdateCheckerTest, UpdateCheckDownloadPreference) { |
update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
- std::unique_ptr<CrxUpdateItem> item = BuildCrxUpdateItem(); |
- IdToCrxUpdateItemMap items_to_check; |
- items_to_check[kUpdateItemId] = std::move(item); |
+ IdToComponentPtrMap components; |
+ components[kUpdateItemId] = MakeComponent(); |
update_checker_->CheckForUpdates( |
- items_to_check, "extra=\"params\"", true, |
+ std::vector<std::string>{kUpdateItemId}, components, "extra=\"params\"", |
+ true, |
base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
base::Unretained(this))); |
@@ -348,12 +360,13 @@ TEST_F(UpdateCheckerTest, UpdateCheckCupError) { |
config_->SetEnabledCupSigning(true); |
update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
- std::unique_ptr<CrxUpdateItem> item = BuildCrxUpdateItem(); |
- IdToCrxUpdateItemMap items_to_check; |
- items_to_check[kUpdateItemId] = std::move(item); |
+ IdToComponentPtrMap components; |
+ components[kUpdateItemId] = MakeComponent(); |
+ |
+ const auto& component = components[kUpdateItemId]; |
update_checker_->CheckForUpdates( |
- items_to_check, "", true, |
+ std::vector<std::string>{kUpdateItemId}, components, "", true, |
base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
base::Unretained(this))); |
@@ -375,7 +388,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckCupError) { |
// Expect an error since the response is not trusted. |
EXPECT_EQ(-10000, error_); |
- EXPECT_EQ(0ul, results_.list.size()); |
+ EXPECT_FALSE(component->next_version_.IsValid()); |
} |
// Tests that the UpdateCheckers will not make an update check for a |
@@ -385,19 +398,20 @@ TEST_F(UpdateCheckerTest, UpdateCheckRequiresEncryptionError) { |
update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
- std::unique_ptr<CrxUpdateItem> item = BuildCrxUpdateItem(); |
- item->component.requires_network_encryption = true; |
- IdToCrxUpdateItemMap items_to_check; |
- items_to_check[kUpdateItemId] = std::move(item); |
+ IdToComponentPtrMap components; |
+ components[kUpdateItemId] = MakeComponent(); |
+ |
+ auto& component = components[kUpdateItemId]; |
+ component->crx_component_.requires_network_encryption = true; |
update_checker_->CheckForUpdates( |
- items_to_check, "", true, |
+ std::vector<std::string>{kUpdateItemId}, components, "", true, |
base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
base::Unretained(this))); |
RunThreads(); |
EXPECT_EQ(-1, error_); |
- EXPECT_EQ(0u, results_.list.size()); |
+ EXPECT_FALSE(component->next_version_.IsValid()); |
} |
// Tests that the PersistedData will get correctly update and reserialize |
@@ -410,19 +424,21 @@ TEST_F(UpdateCheckerTest, UpdateCheckDateLastRollCall) { |
update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
- std::unique_ptr<CrxUpdateItem> item = BuildCrxUpdateItem(); |
- IdToCrxUpdateItemMap items_to_check; |
- items_to_check[kUpdateItemId] = std::move(item); |
+ IdToComponentPtrMap components; |
+ components[kUpdateItemId] = MakeComponent(); |
// Do two update-checks. |
update_checker_->CheckForUpdates( |
- items_to_check, "extra=\"params\"", true, |
+ std::vector<std::string>{kUpdateItemId}, components, "extra=\"params\"", |
+ true, |
base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
base::Unretained(this))); |
RunThreads(); |
+ |
update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
update_checker_->CheckForUpdates( |
- items_to_check, "extra=\"params\"", true, |
+ std::vector<std::string>{kUpdateItemId}, components, "extra=\"params\"", |
+ true, |
base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
base::Unretained(this))); |
RunThreads(); |
@@ -444,8 +460,10 @@ TEST_F(UpdateCheckerTest, UpdateCheckUpdateDisabled) { |
config_->SetBrand(""); |
update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
- std::unique_ptr<CrxUpdateItem> item = BuildCrxUpdateItem(); |
- CrxUpdateItem* item_ptr = item.get(); |
+ IdToComponentPtrMap components; |
+ components[kUpdateItemId] = MakeComponent(); |
+ |
+ auto& component = components[kUpdateItemId]; |
// Tests the scenario where: |
// * the component does not support group policies. |
@@ -453,11 +471,10 @@ TEST_F(UpdateCheckerTest, UpdateCheckUpdateDisabled) { |
// Expects the group policy to be ignored and the update check to not |
// include the "updatedisabled" attribute. |
EXPECT_FALSE( |
- item_ptr->component.supports_group_policy_enable_component_updates); |
- IdToCrxUpdateItemMap items_to_check; |
- items_to_check[kUpdateItemId] = std::move(item); |
+ component->crx_component_.supports_group_policy_enable_component_updates); |
+ |
update_checker_->CheckForUpdates( |
- items_to_check, "", false, |
+ std::vector<std::string>{kUpdateItemId}, components, "", false, |
base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
base::Unretained(this))); |
RunThreads(); |
@@ -470,10 +487,11 @@ TEST_F(UpdateCheckerTest, UpdateCheckUpdateDisabled) { |
// * the component supports group policies. |
// * the component updates are disabled. |
// Expects the update check to include the "updatedisabled" attribute. |
- item_ptr->component.supports_group_policy_enable_component_updates = true; |
+ component->crx_component_.supports_group_policy_enable_component_updates = |
+ true; |
update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
update_checker_->CheckForUpdates( |
- items_to_check, "", false, |
+ std::vector<std::string>{kUpdateItemId}, components, "", false, |
base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
base::Unretained(this))); |
RunThreads(); |
@@ -486,10 +504,11 @@ TEST_F(UpdateCheckerTest, UpdateCheckUpdateDisabled) { |
// * the component does not support group policies. |
// * the component updates are enabled. |
// Expects the update check to not include the "updatedisabled" attribute. |
- item_ptr->component.supports_group_policy_enable_component_updates = false; |
+ component->crx_component_.supports_group_policy_enable_component_updates = |
+ false; |
update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
update_checker_->CheckForUpdates( |
- items_to_check, "", true, |
+ std::vector<std::string>{kUpdateItemId}, components, "", true, |
base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
base::Unretained(this))); |
RunThreads(); |
@@ -502,10 +521,11 @@ TEST_F(UpdateCheckerTest, UpdateCheckUpdateDisabled) { |
// * the component supports group policies. |
// * the component updates are enabled. |
// Expects the update check to not include the "updatedisabled" attribute. |
- item_ptr->component.supports_group_policy_enable_component_updates = true; |
+ component->crx_component_.supports_group_policy_enable_component_updates = |
+ true; |
update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
update_checker_->CheckForUpdates( |
- items_to_check, "", true, |
+ std::vector<std::string>{kUpdateItemId}, components, "", true, |
base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
base::Unretained(this))); |
RunThreads(); |