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

Side by Side Diff: components/update_client/updater_state_unittest.cc

Issue 2581353002: Use the Windows MDM API to check if the machine is being managed. (Closed)
Patch Set: Fix components tests Created 4 years 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/macros.h" 5 #include "base/macros.h"
6 #include "base/time/time.h" 6 #include "base/time/time.h"
7 #include "base/version.h" 7 #include "base/version.h"
8 #include "components/update_client/updater_state.h" 8 #include "components/update_client/updater_state.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace update_client { 11 namespace update_client {
12 12
13 class UpdaterStateTest : public testing::Test { 13 class UpdaterStateTest : public testing::Test {
14 public: 14 public:
15 UpdaterStateTest() {} 15 UpdaterStateTest() {}
16 ~UpdaterStateTest() override {} 16 ~UpdaterStateTest() override {}
17 17
18 private: 18 private:
19 DISALLOW_COPY_AND_ASSIGN(UpdaterStateTest); 19 DISALLOW_COPY_AND_ASSIGN(UpdaterStateTest);
20 }; 20 };
21 21
22 TEST_F(UpdaterStateTest, Serialize) { 22 TEST_F(UpdaterStateTest, Serialize) {
23 UpdaterState updater_state(false); 23 UpdaterState updater_state(false);
24 24
25 updater_state.updater_name_ = "the updater"; 25 updater_state.updater_name_ = "the updater";
26 updater_state.updater_version_ = base::Version("1.0"); 26 updater_state.updater_version_ = base::Version("1.0");
27 updater_state.last_autoupdate_started_ = base::Time::NowFromSystemTime(); 27 updater_state.last_autoupdate_started_ = base::Time::NowFromSystemTime();
28 updater_state.last_checked_ = base::Time::NowFromSystemTime(); 28 updater_state.last_checked_ = base::Time::NowFromSystemTime();
29 updater_state.is_joined_to_domain_ = false; 29 updater_state.is_enterprise_user_ = false;
30 updater_state.is_autoupdate_check_enabled_ = true; 30 updater_state.is_autoupdate_check_enabled_ = true;
31 updater_state.update_policy_ = 1; 31 updater_state.update_policy_ = 1;
32 32
33 auto attributes = updater_state.BuildAttributes(); 33 auto attributes = updater_state.BuildAttributes();
34 34
35 // Sanity check all members. 35 // Sanity check all members.
36 EXPECT_STREQ("the updater", attributes.at("name").c_str()); 36 EXPECT_STREQ("the updater", attributes.at("name").c_str());
37 EXPECT_STREQ("1.0", attributes.at("version").c_str()); 37 EXPECT_STREQ("1.0", attributes.at("version").c_str());
38 EXPECT_STREQ("0", attributes.at("laststarted").c_str()); 38 EXPECT_STREQ("0", attributes.at("laststarted").c_str());
39 EXPECT_STREQ("0", attributes.at("lastchecked").c_str()); 39 EXPECT_STREQ("0", attributes.at("lastchecked").c_str());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 updater_state.last_checked_ = 81 updater_state.last_checked_ =
82 base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(90); 82 base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(90);
83 attributes = updater_state.BuildAttributes(); 83 attributes = updater_state.BuildAttributes();
84 EXPECT_STREQ("1344", attributes.at("lastchecked").c_str()); 84 EXPECT_STREQ("1344", attributes.at("lastchecked").c_str());
85 85
86 // Don't serialize the time if it could not be read (the value is invalid). 86 // Don't serialize the time if it could not be read (the value is invalid).
87 updater_state.last_checked_ = base::Time(); 87 updater_state.last_checked_ = base::Time();
88 attributes = updater_state.BuildAttributes(); 88 attributes = updater_state.BuildAttributes();
89 EXPECT_EQ(0u, attributes.count("lastchecked")); 89 EXPECT_EQ(0u, attributes.count("lastchecked"));
90 90
91 updater_state.is_joined_to_domain_ = true; 91 updater_state.is_enterprise_user_ = true;
92 attributes = updater_state.BuildAttributes(); 92 attributes = updater_state.BuildAttributes();
93 EXPECT_STREQ("1", attributes.at("domainjoined").c_str()); 93 EXPECT_STREQ("1", attributes.at("domainjoined").c_str());
94 94
95 updater_state.is_autoupdate_check_enabled_ = false; 95 updater_state.is_autoupdate_check_enabled_ = false;
96 attributes = updater_state.BuildAttributes(); 96 attributes = updater_state.BuildAttributes();
97 EXPECT_STREQ("0", attributes.at("autoupdatecheckenabled").c_str()); 97 EXPECT_STREQ("0", attributes.at("autoupdatecheckenabled").c_str());
98 98
99 updater_state.update_policy_ = 0; 99 updater_state.update_policy_ = 0;
100 attributes = updater_state.BuildAttributes(); 100 attributes = updater_state.BuildAttributes();
101 EXPECT_STREQ("0", attributes.at("updatepolicy").c_str()); 101 EXPECT_STREQ("0", attributes.at("updatepolicy").c_str());
102 102
103 updater_state.update_policy_ = -1; 103 updater_state.update_policy_ = -1;
104 attributes = updater_state.BuildAttributes(); 104 attributes = updater_state.BuildAttributes();
105 EXPECT_STREQ("-1", attributes.at("updatepolicy").c_str()); 105 EXPECT_STREQ("-1", attributes.at("updatepolicy").c_str());
106 } 106 }
107 107
108 } // namespace update_client 108 } // namespace update_client
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698