Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1630)

Unified Diff: components/update_client/update_checker_unittest.cc

Issue 1861383004: Add module for counting date-last-roll-call and persisting those counts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 334899611f8323b22e910f0645b5037572e22c1b..803c070efb76cbaa6628241b349d164dad2a6137 100644
--- a/components/update_client/update_checker_unittest.cc
+++ b/components/update_client/update_checker_unittest.cc
@@ -12,6 +12,7 @@
#include "base/run_loop.h"
#include "base/thread_task_runner_handle.h"
#include "base/version.h"
+#include "components/update_client/component_metadata.h"
#include "components/update_client/crx_update_item.h"
#include "components/update_client/test_configurator.h"
#include "components/update_client/update_checker.h"
@@ -59,6 +60,7 @@ class UpdateCheckerTest : public testing::Test {
CrxUpdateItem BuildCrxUpdateItem();
scoped_refptr<TestConfigurator> config_;
+ scoped_refptr<ComponentMetadata> metadata_;
scoped_ptr<UpdateChecker> update_checker_;
@@ -84,6 +86,8 @@ UpdateCheckerTest::~UpdateCheckerTest() {
void UpdateCheckerTest::SetUp() {
config_ = new TestConfigurator(base::ThreadTaskRunnerHandle::Get(),
base::ThreadTaskRunnerHandle::Get());
+ metadata_ = new ComponentMetadata(base::FilePath(),
+ base::ThreadTaskRunnerHandle::Get());
interceptor_factory_.reset(
new InterceptorFactory(base::ThreadTaskRunnerHandle::Get()));
post_interceptor_ = interceptor_factory_->CreateInterceptor();
@@ -158,7 +162,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckSuccess) {
EXPECT_TRUE(post_interceptor_->ExpectRequest(
new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
- update_checker_ = UpdateChecker::Create(config_);
+ update_checker_ = UpdateChecker::Create(config_, metadata_);
CrxUpdateItem item(BuildCrxUpdateItem());
std::vector<CrxUpdateItem*> items_to_check;
@@ -186,7 +190,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckSuccess) {
string::npos,
post_interceptor_->GetRequests()[0].find(
"app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" "
- "brand=\"TEST\"><updatecheck />"
+ "brand=\"TEST\"><updatecheck /><ping rd=\"-2\" />"
"<packages><package fp=\"fp1\"/></packages></app>"));
EXPECT_NE(string::npos,
@@ -205,7 +209,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckSuccessNoBrand) {
new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
config_->SetBrand("TOOLONG"); // Sets an invalid brand code.
- update_checker_ = UpdateChecker::Create(config_);
+ update_checker_ = UpdateChecker::Create(config_, metadata_);
CrxUpdateItem item(BuildCrxUpdateItem());
std::vector<CrxUpdateItem*> items_to_check;
@@ -221,7 +225,8 @@ TEST_F(UpdateCheckerTest, UpdateCheckSuccessNoBrand) {
string::npos,
post_interceptor_->GetRequests()[0].find(
"app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">"
- "<updatecheck /><packages><package fp=\"fp1\"/></packages></app>"));
+ "<updatecheck /><ping rd=\"-2\" /><packages><package fp=\"fp1\"/>"
+ "</packages></app>"));
}
// Simulates a 403 server response error.
@@ -229,7 +234,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckError) {
EXPECT_TRUE(
post_interceptor_->ExpectRequest(new PartialMatch("updatecheck"), 403));
- update_checker_ = UpdateChecker::Create(config_);
+ update_checker_ = UpdateChecker::Create(config_, metadata_);
CrxUpdateItem item(BuildCrxUpdateItem());
std::vector<CrxUpdateItem*> items_to_check;
@@ -255,7 +260,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckDownloadPreference) {
config_->SetDownloadPreference(string("cacheable"));
- update_checker_ = UpdateChecker::Create(config_);
+ update_checker_ = UpdateChecker::Create(config_, metadata_);
CrxUpdateItem item(BuildCrxUpdateItem());
std::vector<CrxUpdateItem*> items_to_check;
@@ -281,7 +286,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckCupError) {
new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
config_->SetUseCupSigning(true);
- update_checker_ = UpdateChecker::Create(config_);
+ update_checker_ = UpdateChecker::Create(config_, metadata_);
CrxUpdateItem item(BuildCrxUpdateItem());
std::vector<CrxUpdateItem*> items_to_check;
@@ -303,7 +308,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckCupError) {
string::npos,
post_interceptor_->GetRequests()[0].find(
"app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" "
- "brand=\"TEST\"><updatecheck />"
+ "brand=\"TEST\"><updatecheck /><ping rd=\"-2\" />"
"<packages><package fp=\"fp1\"/></packages></app>"));
// Expect an error since the response is not trusted.
@@ -316,7 +321,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckCupError) {
TEST_F(UpdateCheckerTest, UpdateCheckRequiresEncryptionError) {
config_->SetUpdateCheckUrl(GURL("http:\\foo\bar"));
- update_checker_ = UpdateChecker::Create(config_);
+ update_checker_ = UpdateChecker::Create(config_, metadata_);
CrxUpdateItem item(BuildCrxUpdateItem());
item.component.requires_network_encryption = true;
@@ -332,4 +337,43 @@ TEST_F(UpdateCheckerTest, UpdateCheckRequiresEncryptionError) {
EXPECT_EQ(0u, results_.list.size());
}
+// Tests that the ComponentMetadata will get correctly update and reserialize
+// the elapsed_days value.
+TEST_F(UpdateCheckerTest, UpdateCheckDateLastRollCall) {
+ EXPECT_TRUE(post_interceptor_->ExpectRequest(
+ new PartialMatch("updatecheck"), test_file("updatecheck_reply_4.xml")));
+ EXPECT_TRUE(post_interceptor_->ExpectRequest(
+ new PartialMatch("updatecheck"), test_file("updatecheck_reply_4.xml")));
+
+ update_checker_ = UpdateChecker::Create(config_, metadata_);
+
+ CrxUpdateItem item(BuildCrxUpdateItem());
+ std::vector<CrxUpdateItem*> items_to_check;
+ items_to_check.push_back(&item);
+
+ // Do two update-checks.
+ update_checker_->CheckForUpdates(
+ items_to_check, "extra=\"params\"",
+ base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
+ base::Unretained(this)));
+ RunThreads();
+ update_checker_ = UpdateChecker::Create(config_, metadata_);
+ update_checker_->CheckForUpdates(
+ items_to_check, "extra=\"params\"",
+ base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
+ base::Unretained(this)));
+ RunThreads();
+
+ EXPECT_EQ(2, post_interceptor_->GetHitCount())
+ << post_interceptor_->GetRequestsAsString();
+ ASSERT_EQ(2, post_interceptor_->GetCount())
+ << post_interceptor_->GetRequestsAsString();
+ EXPECT_NE(
+ string::npos,
+ post_interceptor_->GetRequests()[0].find("<ping rd=\"-2\" />"));
+ EXPECT_NE(
+ string::npos,
+ post_interceptor_->GetRequests()[1].find("<ping rd=\"3383\" />"));
+}
+
} // namespace update_client

Powered by Google App Engine
This is Rietveld 408576698