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

Unified Diff: components/update_client/updater_state_unittest.cc

Issue 2498873003: Refactor how the updater state data is serialized in update checks. (Closed)
Patch Set: Created 4 years, 1 month 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/updater_state.cc ('k') | components/update_client/updater_state_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/update_client/updater_state_unittest.cc
diff --git a/components/update_client/updater_state_unittest.cc b/components/update_client/updater_state_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..74828596c8d0b10453c97ec8ce29edc07c97e498
--- /dev/null
+++ b/components/update_client/updater_state_unittest.cc
@@ -0,0 +1,108 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/macros.h"
+#include "base/time/time.h"
+#include "base/version.h"
+#include "components/update_client/updater_state.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace update_client {
+
+class UpdaterStateTest : public testing::Test {
+ public:
+ UpdaterStateTest() {}
+ ~UpdaterStateTest() override {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(UpdaterStateTest);
+};
+
+TEST_F(UpdaterStateTest, Serialize) {
+ UpdaterState updater_state(false);
+
+ updater_state.updater_name_ = "the updater";
+ updater_state.updater_version_ = base::Version("1.0");
+ updater_state.last_autoupdate_started_ = base::Time::NowFromSystemTime();
+ updater_state.last_checked_ = base::Time::NowFromSystemTime();
+ updater_state.is_joined_to_domain_ = false;
+ updater_state.is_autoupdate_check_enabled_ = true;
+ updater_state.update_policy_ = 1;
+
+ auto attributes = updater_state.BuildAttributes();
+
+ // Sanity check all members.
+ EXPECT_STREQ("the updater", attributes.at("name").c_str());
+ EXPECT_STREQ("1.0", attributes.at("version").c_str());
+ EXPECT_STREQ("0", attributes.at("laststarted").c_str());
+ EXPECT_STREQ("0", attributes.at("lastchecked").c_str());
+ EXPECT_STREQ("0", attributes.at("domainjoined").c_str());
+ EXPECT_STREQ("1", attributes.at("autoupdatecheckenabled").c_str());
+ EXPECT_STREQ("1", attributes.at("updatepolicy").c_str());
+
+ // Tests some of the remaining values.
+ updater_state = UpdaterState(false);
+
+#if defined(GOOGLE_CHROME_BUILD)
+ // The name of the Windows updater for Chrome.
+ EXPECT_STREQ("Omaha", attributes.at("name").c_str());
+#endif // GOOGLE_CHROME_BUILD
+
+ // Don't serialize an invalid version if it could not be read.
+ updater_state.updater_version_ = base::Version();
+ attributes = updater_state.BuildAttributes();
+ EXPECT_EQ(0u, attributes.count("version"));
+
+ updater_state.updater_version_ = base::Version("0.0.0.0");
+ attributes = updater_state.BuildAttributes();
+ EXPECT_STREQ("0.0.0.0", attributes.at("version").c_str());
+
+ updater_state.last_autoupdate_started_ =
+ base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(15);
+ attributes = updater_state.BuildAttributes();
+ EXPECT_STREQ("408", attributes.at("laststarted").c_str());
+
+ updater_state.last_autoupdate_started_ =
+ base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(90);
+ attributes = updater_state.BuildAttributes();
+ EXPECT_STREQ("1344", attributes.at("laststarted").c_str());
+
+ // Don't serialize the time if it could not be read.
+ updater_state.last_autoupdate_started_ = base::Time();
+ attributes = updater_state.BuildAttributes();
+ EXPECT_EQ(0u, attributes.count("laststarted"));
+
+ updater_state.last_checked_ =
+ base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(15);
+ attributes = updater_state.BuildAttributes();
+ EXPECT_STREQ("408", attributes.at("lastchecked").c_str());
+
+ updater_state.last_checked_ =
+ base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(90);
+ attributes = updater_state.BuildAttributes();
+ EXPECT_STREQ("1344", attributes.at("lastchecked").c_str());
+
+ // Don't serialize the time if it could not be read (the value is invalid).
+ updater_state.last_checked_ = base::Time();
+ attributes = updater_state.BuildAttributes();
+ EXPECT_EQ(0u, attributes.count("lastchecked"));
+
+ updater_state.is_joined_to_domain_ = true;
+ attributes = updater_state.BuildAttributes();
+ EXPECT_STREQ("1", attributes.at("domainjoined").c_str());
+
+ updater_state.is_autoupdate_check_enabled_ = false;
+ attributes = updater_state.BuildAttributes();
+ EXPECT_STREQ("0", attributes.at("autoupdatecheckenabled").c_str());
+
+ updater_state.update_policy_ = 0;
+ attributes = updater_state.BuildAttributes();
+ EXPECT_STREQ("0", attributes.at("updatepolicy").c_str());
+
+ updater_state.update_policy_ = -1;
+ attributes = updater_state.BuildAttributes();
+ EXPECT_STREQ("-1", attributes.at("updatepolicy").c_str());
+}
+
+} // namespace update_client
« no previous file with comments | « components/update_client/updater_state.cc ('k') | components/update_client/updater_state_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698