| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/test/test_reg_util_win.h" |
| 10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 11 #include "base/win/registry.h" | 12 #include "base/win/registry.h" |
| 12 #include "chrome/installer/gcapi/gcapi.h" | 13 #include "chrome/installer/gcapi/gcapi.h" |
| 13 #include "chrome/installer/gcapi/gcapi_omaha_experiment.h" | 14 #include "chrome/installer/gcapi/gcapi_omaha_experiment.h" |
| 14 #include "chrome/installer/gcapi/gcapi_reactivation.h" | 15 #include "chrome/installer/gcapi/gcapi_reactivation.h" |
| 15 #include "chrome/installer/gcapi/gcapi_test_registry_overrider.h" | |
| 16 #include "chrome/installer/util/google_update_constants.h" | 16 #include "chrome/installer/util/google_update_constants.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using base::Time; | 19 using base::Time; |
| 20 using base::TimeDelta; | 20 using base::TimeDelta; |
| 21 using base::win::RegKey; | 21 using base::win::RegKey; |
| 22 | 22 |
| 23 class GCAPIReactivationTest : public ::testing::Test { | 23 class GCAPIReactivationTest : public ::testing::Test { |
| 24 protected: | 24 protected: |
| 25 GCAPIReactivationTest() {} | 25 GCAPIReactivationTest() {} |
| 26 | 26 |
| 27 void SetUp() override { |
| 28 ASSERT_NO_FATAL_FAILURE( |
| 29 override_manager_.OverrideRegistry(HKEY_CURRENT_USER)); |
| 30 ASSERT_NO_FATAL_FAILURE( |
| 31 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE)); |
| 32 } |
| 33 |
| 27 bool SetChromeInstallMarker(HKEY hive) { | 34 bool SetChromeInstallMarker(HKEY hive) { |
| 28 // Create the client state keys in the right places. | 35 // Create the client state keys in the right places. |
| 29 std::wstring reg_path(google_update::kRegPathClients); | 36 std::wstring reg_path(google_update::kRegPathClients); |
| 30 reg_path += L"\\"; | 37 reg_path += L"\\"; |
| 31 reg_path += google_update::kChromeUpgradeCode; | 38 reg_path += google_update::kChromeUpgradeCode; |
| 32 RegKey client_state(hive, | 39 RegKey client_state(hive, |
| 33 reg_path.c_str(), | 40 reg_path.c_str(), |
| 34 KEY_CREATE_SUB_KEY | KEY_SET_VALUE | KEY_WOW64_32KEY); | 41 KEY_CREATE_SUB_KEY | KEY_SET_VALUE | KEY_WOW64_32KEY); |
| 35 return (client_state.Valid() && | 42 return (client_state.Valid() && |
| 36 client_state.WriteValue( | 43 client_state.WriteValue( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 std::wstring actual_brand; | 91 std::wstring actual_brand; |
| 85 if (client_state.ReadValue(google_update::kRegRLZReactivationBrandField, | 92 if (client_state.ReadValue(google_update::kRegRLZReactivationBrandField, |
| 86 &actual_brand) == ERROR_SUCCESS) { | 93 &actual_brand) == ERROR_SUCCESS) { |
| 87 return actual_brand; | 94 return actual_brand; |
| 88 } | 95 } |
| 89 } | 96 } |
| 90 | 97 |
| 91 return L"ERROR"; | 98 return L"ERROR"; |
| 92 } | 99 } |
| 93 | 100 |
| 94 const GCAPITestRegistryOverrider gcapi_test_registry_overrider_; | 101 registry_util::RegistryOverrideManager override_manager_; |
| 95 }; | 102 }; |
| 96 | 103 |
| 97 TEST_F(GCAPIReactivationTest, CheckSetReactivationBrandCode) { | 104 TEST_F(GCAPIReactivationTest, CheckSetReactivationBrandCode) { |
| 98 EXPECT_TRUE(SetReactivationBrandCode(L"GAGA", GCAPI_INVOKED_STANDARD_SHELL)); | 105 EXPECT_TRUE(SetReactivationBrandCode(L"GAGA", GCAPI_INVOKED_STANDARD_SHELL)); |
| 99 EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER)); | 106 EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER)); |
| 100 | 107 |
| 101 EXPECT_TRUE(HasBeenReactivated()); | 108 EXPECT_TRUE(HasBeenReactivated()); |
| 102 } | 109 } |
| 103 | 110 |
| 104 TEST_F(GCAPIReactivationTest, CanOfferReactivation_Basic) { | 111 TEST_F(GCAPIReactivationTest, CanOfferReactivation_Basic) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER, | 208 EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER, |
| 202 hkcu_last_run.ToInternalValue())); | 209 hkcu_last_run.ToInternalValue())); |
| 203 | 210 |
| 204 EXPECT_TRUE(ReactivateChrome(L"GAGA", | 211 EXPECT_TRUE(ReactivateChrome(L"GAGA", |
| 205 GCAPI_INVOKED_STANDARD_SHELL, | 212 GCAPI_INVOKED_STANDARD_SHELL, |
| 206 &error)); | 213 &error)); |
| 207 EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER)); | 214 EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER)); |
| 208 | 215 |
| 209 EXPECT_TRUE(HasExperimentLabels(HKEY_CURRENT_USER)); | 216 EXPECT_TRUE(HasExperimentLabels(HKEY_CURRENT_USER)); |
| 210 } | 217 } |
| OLD | NEW |