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

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: Another test fix. 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
« no previous file with comments | « components/update_client/update_checker.cc ('k') | components/update_client/update_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c41afdbf59826abf1a53a5ad294b8ae9a9cecb67..b866643024ef9211e289f6d0d67ef383319240a4 100644
--- a/components/update_client/update_checker_unittest.cc
+++ b/components/update_client/update_checker_unittest.cc
@@ -12,7 +12,9 @@
#include "base/run_loop.h"
#include "base/thread_task_runner_handle.h"
#include "base/version.h"
+#include "components/prefs/testing_pref_service.h"
#include "components/update_client/crx_update_item.h"
+#include "components/update_client/persisted_data.h"
#include "components/update_client/test_configurator.h"
#include "components/update_client/update_checker.h"
#include "components/update_client/url_request_post_interceptor.h"
@@ -59,6 +61,8 @@ class UpdateCheckerTest : public testing::Test {
CrxUpdateItem BuildCrxUpdateItem();
scoped_refptr<TestConfigurator> config_;
+ std::unique_ptr<TestingPrefServiceSimple> pref_;
+ std::unique_ptr<PersistedData> metadata_;
scoped_ptr<UpdateChecker> update_checker_;
@@ -84,6 +88,9 @@ UpdateCheckerTest::~UpdateCheckerTest() {
void UpdateCheckerTest::SetUp() {
config_ = new TestConfigurator(base::ThreadTaskRunnerHandle::Get(),
base::ThreadTaskRunnerHandle::Get());
+ pref_.reset(new TestingPrefServiceSimple());
+ PersistedData::RegisterPrefs(pref_->registry());
+ metadata_.reset(new PersistedData(pref_.get()));
interceptor_factory_.reset(
new InterceptorFactory(base::ThreadTaskRunnerHandle::Get()));
post_interceptor_ = interceptor_factory_->CreateInterceptor();
@@ -158,7 +165,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());
item.component.ap = "some_ap";
@@ -187,7 +194,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckSuccess) {
string::npos,
post_interceptor_->GetRequests()[0].find(
"<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" "
- "brand=\"TEST\" ap=\"some_ap\"><updatecheck />"
+ "brand=\"TEST\" ap=\"some_ap\"><updatecheck /><ping rd=\"-2\" />"
"<packages><package fp=\"fp1\"/></packages></app>"));
EXPECT_NE(string::npos,
@@ -206,7 +213,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckInvalidAp) {
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());
item.component.ap = std::string(257, 'a'); // Too long.
@@ -223,7 +230,7 @@ TEST_F(UpdateCheckerTest, UpdateCheckInvalidAp) {
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>"));
}
@@ -232,7 +239,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;
@@ -248,7 +255,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.
@@ -256,7 +264,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;
@@ -282,7 +290,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;
@@ -308,7 +316,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;
@@ -330,7 +338,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.
@@ -343,7 +351,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;
@@ -359,4 +367,41 @@ TEST_F(UpdateCheckerTest, UpdateCheckRequiresEncryptionError) {
EXPECT_EQ(0u, results_.list.size());
}
+// Tests that the PersistedData 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
« no previous file with comments | « components/update_client/update_checker.cc ('k') | components/update_client/update_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698