| OLD | NEW |
| 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 "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "components/update_client/updater_state.h" | 9 #include "components/update_client/updater_state.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace update_client { | 12 namespace update_client { |
| 13 | 13 |
| 14 class UpdaterStateTest : public testing::Test { | 14 class UpdaterStateTest : public testing::Test { |
| 15 public: | 15 public: |
| 16 UpdaterStateTest() {} | 16 UpdaterStateTest() {} |
| 17 ~UpdaterStateTest() override {} | 17 ~UpdaterStateTest() override {} |
| 18 | 18 |
| 19 private: | 19 private: |
| 20 DISALLOW_COPY_AND_ASSIGN(UpdaterStateTest); | 20 DISALLOW_COPY_AND_ASSIGN(UpdaterStateTest); |
| 21 }; | 21 }; |
| 22 | 22 |
| 23 TEST_F(UpdaterStateTest, Serialize) { | 23 TEST_F(UpdaterStateTest, Serialize) { |
| 24 UpdaterState updater_state(false); | 24 UpdaterState updater_state(false); |
| 25 | 25 |
| 26 updater_state.updater_name_ = "the updater"; | 26 updater_state.updater_name_ = "the updater"; |
| 27 updater_state.updater_version_ = base::Version("1.0"); | 27 updater_state.updater_version_ = base::Version("1.0"); |
| 28 updater_state.last_autoupdate_started_ = base::Time::NowFromSystemTime(); | 28 updater_state.last_autoupdate_started_ = base::Time::NowFromSystemTime(); |
| 29 updater_state.last_checked_ = base::Time::NowFromSystemTime(); | 29 updater_state.last_checked_ = base::Time::NowFromSystemTime(); |
| 30 updater_state.is_joined_to_domain_ = false; | 30 updater_state.is_enterprise_managed_ = false; |
| 31 updater_state.is_autoupdate_check_enabled_ = true; | 31 updater_state.is_autoupdate_check_enabled_ = true; |
| 32 updater_state.update_policy_ = 1; | 32 updater_state.update_policy_ = 1; |
| 33 | 33 |
| 34 auto attributes = updater_state.BuildAttributes(); | 34 auto attributes = updater_state.BuildAttributes(); |
| 35 | 35 |
| 36 // Sanity check all members. | 36 // Sanity check all members. |
| 37 EXPECT_STREQ("the updater", attributes.at("name").c_str()); | 37 EXPECT_STREQ("the updater", attributes.at("name").c_str()); |
| 38 EXPECT_STREQ("1.0", attributes.at("version").c_str()); | 38 EXPECT_STREQ("1.0", attributes.at("version").c_str()); |
| 39 EXPECT_STREQ("0", attributes.at("laststarted").c_str()); | 39 EXPECT_STREQ("0", attributes.at("laststarted").c_str()); |
| 40 EXPECT_STREQ("0", attributes.at("lastchecked").c_str()); | 40 EXPECT_STREQ("0", attributes.at("lastchecked").c_str()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 updater_state.last_checked_ = | 82 updater_state.last_checked_ = |
| 83 base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(90); | 83 base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(90); |
| 84 attributes = updater_state.BuildAttributes(); | 84 attributes = updater_state.BuildAttributes(); |
| 85 EXPECT_STREQ("1344", attributes.at("lastchecked").c_str()); | 85 EXPECT_STREQ("1344", attributes.at("lastchecked").c_str()); |
| 86 | 86 |
| 87 // Don't serialize the time if it could not be read (the value is invalid). | 87 // Don't serialize the time if it could not be read (the value is invalid). |
| 88 updater_state.last_checked_ = base::Time(); | 88 updater_state.last_checked_ = base::Time(); |
| 89 attributes = updater_state.BuildAttributes(); | 89 attributes = updater_state.BuildAttributes(); |
| 90 EXPECT_EQ(0u, attributes.count("lastchecked")); | 90 EXPECT_EQ(0u, attributes.count("lastchecked")); |
| 91 | 91 |
| 92 updater_state.is_joined_to_domain_ = true; | 92 updater_state.is_enterprise_managed_ = true; |
| 93 attributes = updater_state.BuildAttributes(); | 93 attributes = updater_state.BuildAttributes(); |
| 94 EXPECT_STREQ("1", attributes.at("domainjoined").c_str()); | 94 EXPECT_STREQ("1", attributes.at("domainjoined").c_str()); |
| 95 | 95 |
| 96 updater_state.is_autoupdate_check_enabled_ = false; | 96 updater_state.is_autoupdate_check_enabled_ = false; |
| 97 attributes = updater_state.BuildAttributes(); | 97 attributes = updater_state.BuildAttributes(); |
| 98 EXPECT_STREQ("0", attributes.at("autoupdatecheckenabled").c_str()); | 98 EXPECT_STREQ("0", attributes.at("autoupdatecheckenabled").c_str()); |
| 99 | 99 |
| 100 updater_state.update_policy_ = 0; | 100 updater_state.update_policy_ = 0; |
| 101 attributes = updater_state.BuildAttributes(); | 101 attributes = updater_state.BuildAttributes(); |
| 102 EXPECT_STREQ("0", attributes.at("updatepolicy").c_str()); | 102 EXPECT_STREQ("0", attributes.at("updatepolicy").c_str()); |
| 103 | 103 |
| 104 updater_state.update_policy_ = -1; | 104 updater_state.update_policy_ = -1; |
| 105 attributes = updater_state.BuildAttributes(); | 105 attributes = updater_state.BuildAttributes(); |
| 106 EXPECT_STREQ("-1", attributes.at("updatepolicy").c_str()); | 106 EXPECT_STREQ("-1", attributes.at("updatepolicy").c_str()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 } // namespace update_client | 109 } // namespace update_client |
| OLD | NEW |