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

Unified Diff: components/component_updater/updater_state_unittest_win.cc

Issue 2286483002: Serialize Google Update state as part of the recovery component update checks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove unused Created 4 years, 4 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/component_updater/updater_state_unittest_win.cc
diff --git a/components/component_updater/updater_state_unittest_win.cc b/components/component_updater/updater_state_unittest_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bda3094254c24268bdb2e66296d93d1eacec9d71
--- /dev/null
+++ b/components/component_updater/updater_state_unittest_win.cc
@@ -0,0 +1,103 @@
+// 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/component_updater/updater_state_win.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace component_updater {
+
+class UpdaterStateTest : public testing::Test {
+ public:
+ UpdaterStateTest() {}
+ ~UpdaterStateTest() override {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(UpdaterStateTest);
+};
+
+TEST_F(UpdaterStateTest, MakeInstallerAttributes) {
+ // is_machine argument does not make a difference in this test as, the
+ // values of the |updater_state| are fake.
+ auto updater_state = UpdaterState::Create(false);
+
+ // Sanity check all members.
+ updater_state->google_update_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->chrome_update_policy_ = 1;
+
+ auto installer_attributes = updater_state->MakeInstallerAttributes();
+
+ EXPECT_STREQ("1.0", installer_attributes.at("googleupdatever").c_str());
+ EXPECT_STREQ("0", installer_attributes.at("laststarted").c_str());
+ EXPECT_STREQ("0", installer_attributes.at("lastchecked").c_str());
+ EXPECT_STREQ("0", installer_attributes.at("domainjoined").c_str());
+ EXPECT_STREQ("1", installer_attributes.at("autoupdatecheckenabled").c_str());
+ EXPECT_STREQ("1", installer_attributes.at("chromeupdatepolicy").c_str());
+
+ // Tests some of the remaining values.
+ updater_state = UpdaterState::Create(false);
+
+ // Don't serialize an invalid version if it could not be read.
+ updater_state->google_update_version_ = base::Version();
+ installer_attributes = updater_state->MakeInstallerAttributes();
+ EXPECT_EQ(0u, installer_attributes.count("googleupdatever"));
+
+ updater_state->google_update_version_ = base::Version("0.0.0.0");
+ installer_attributes = updater_state->MakeInstallerAttributes();
+ EXPECT_STREQ("0.0.0.0", installer_attributes.at("googleupdatever").c_str());
+
+ updater_state->last_autoupdate_started_ =
+ base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(15);
+ installer_attributes = updater_state->MakeInstallerAttributes();
+ EXPECT_STREQ("408", installer_attributes.at("laststarted").c_str());
+
+ updater_state->last_autoupdate_started_ =
+ base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(90);
+ installer_attributes = updater_state->MakeInstallerAttributes();
+ EXPECT_STREQ("1344", installer_attributes.at("laststarted").c_str());
+
+ // Don't serialize the time if it could not be read.
+ updater_state->last_autoupdate_started_ = base::Time();
+ installer_attributes = updater_state->MakeInstallerAttributes();
+ EXPECT_EQ(0u, installer_attributes.count("laststarted"));
+
+ updater_state->last_checked_ =
+ base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(15);
+ installer_attributes = updater_state->MakeInstallerAttributes();
+ EXPECT_STREQ("408", installer_attributes.at("lastchecked").c_str());
+
+ updater_state->last_checked_ =
+ base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(90);
+ installer_attributes = updater_state->MakeInstallerAttributes();
+ EXPECT_STREQ("1344", installer_attributes.at("lastchecked").c_str());
+
+ // Don't serialize the time if it could not be read.
+ updater_state->last_checked_ = base::Time();
+ installer_attributes = updater_state->MakeInstallerAttributes();
+ EXPECT_EQ(0u, installer_attributes.count("lastchecked"));
+
+ updater_state->is_joined_to_domain_ = true;
+ installer_attributes = updater_state->MakeInstallerAttributes();
+ EXPECT_STREQ("1", installer_attributes.at("domainjoined").c_str());
+
+ updater_state->is_autoupdate_check_enabled_ = false;
+ installer_attributes = updater_state->MakeInstallerAttributes();
+ EXPECT_STREQ("0", installer_attributes.at("autoupdatecheckenabled").c_str());
+
+ updater_state->chrome_update_policy_ = 0;
+ installer_attributes = updater_state->MakeInstallerAttributes();
+ EXPECT_STREQ("0", installer_attributes.at("chromeupdatepolicy").c_str());
+
+ updater_state->chrome_update_policy_ = -1;
+ installer_attributes = updater_state->MakeInstallerAttributes();
+ EXPECT_STREQ("-1", installer_attributes.at("chromeupdatepolicy").c_str());
+}
+
+} // namespace component_updater
« no previous file with comments | « components/component_updater/component_updater_service_internal.h ('k') | components/component_updater/updater_state_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698