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

Side by Side 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, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/macros.h"
6 #include "base/time/time.h"
7 #include "base/version.h"
8 #include "components/component_updater/updater_state_win.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace component_updater {
12
13 class UpdaterStateTest : public testing::Test {
14 public:
15 UpdaterStateTest() {}
16 ~UpdaterStateTest() override {}
17
18 private:
19 DISALLOW_COPY_AND_ASSIGN(UpdaterStateTest);
20 };
21
22 TEST_F(UpdaterStateTest, MakeInstallerAttributes) {
23 // is_machine argument does not make a difference in this test as, the
24 // values of the |updater_state| are fake.
25 auto updater_state = UpdaterState::Create(false);
26
27 // Sanity check all members.
28 updater_state->google_update_version_ = base::Version("1.0");
29 updater_state->last_autoupdate_started_ = base::Time::NowFromSystemTime();
30 updater_state->last_checked_ = base::Time::NowFromSystemTime();
31 updater_state->is_joined_to_domain_ = false;
32 updater_state->is_autoupdate_check_enabled_ = true;
33 updater_state->chrome_update_policy_ = 1;
34
35 auto installer_attributes = updater_state->MakeInstallerAttributes();
36
37 EXPECT_STREQ("1.0", installer_attributes.at("googleupdatever").c_str());
38 EXPECT_STREQ("0", installer_attributes.at("laststarted").c_str());
39 EXPECT_STREQ("0", installer_attributes.at("lastchecked").c_str());
40 EXPECT_STREQ("0", installer_attributes.at("domainjoined").c_str());
41 EXPECT_STREQ("1", installer_attributes.at("autoupdatecheckenabled").c_str());
42 EXPECT_STREQ("1", installer_attributes.at("chromeupdatepolicy").c_str());
43
44 // Tests some of the remaining values.
45 updater_state = UpdaterState::Create(false);
46
47 // Don't serialize an invalid version if it could not be read.
48 updater_state->google_update_version_ = base::Version();
49 installer_attributes = updater_state->MakeInstallerAttributes();
50 EXPECT_EQ(0u, installer_attributes.count("googleupdatever"));
51
52 updater_state->google_update_version_ = base::Version("0.0.0.0");
53 installer_attributes = updater_state->MakeInstallerAttributes();
54 EXPECT_STREQ("0.0.0.0", installer_attributes.at("googleupdatever").c_str());
55
56 updater_state->last_autoupdate_started_ =
57 base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(15);
58 installer_attributes = updater_state->MakeInstallerAttributes();
59 EXPECT_STREQ("408", installer_attributes.at("laststarted").c_str());
60
61 updater_state->last_autoupdate_started_ =
62 base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(90);
63 installer_attributes = updater_state->MakeInstallerAttributes();
64 EXPECT_STREQ("1344", installer_attributes.at("laststarted").c_str());
65
66 // Don't serialize the time if it could not be read.
67 updater_state->last_autoupdate_started_ = base::Time();
68 installer_attributes = updater_state->MakeInstallerAttributes();
69 EXPECT_EQ(0u, installer_attributes.count("laststarted"));
70
71 updater_state->last_checked_ =
72 base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(15);
73 installer_attributes = updater_state->MakeInstallerAttributes();
74 EXPECT_STREQ("408", installer_attributes.at("lastchecked").c_str());
75
76 updater_state->last_checked_ =
77 base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(90);
78 installer_attributes = updater_state->MakeInstallerAttributes();
79 EXPECT_STREQ("1344", installer_attributes.at("lastchecked").c_str());
80
81 // Don't serialize the time if it could not be read.
82 updater_state->last_checked_ = base::Time();
83 installer_attributes = updater_state->MakeInstallerAttributes();
84 EXPECT_EQ(0u, installer_attributes.count("lastchecked"));
85
86 updater_state->is_joined_to_domain_ = true;
87 installer_attributes = updater_state->MakeInstallerAttributes();
88 EXPECT_STREQ("1", installer_attributes.at("domainjoined").c_str());
89
90 updater_state->is_autoupdate_check_enabled_ = false;
91 installer_attributes = updater_state->MakeInstallerAttributes();
92 EXPECT_STREQ("0", installer_attributes.at("autoupdatecheckenabled").c_str());
93
94 updater_state->chrome_update_policy_ = 0;
95 installer_attributes = updater_state->MakeInstallerAttributes();
96 EXPECT_STREQ("0", installer_attributes.at("chromeupdatepolicy").c_str());
97
98 updater_state->chrome_update_policy_ = -1;
99 installer_attributes = updater_state->MakeInstallerAttributes();
100 EXPECT_STREQ("-1", installer_attributes.at("chromeupdatepolicy").c_str());
101 }
102
103 } // namespace component_updater
OLDNEW
« 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