| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "base/win/registry.h" | 10 #include "base/win/registry.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 protected: | 24 protected: |
| 25 GCAPIReactivationTest() {} | 25 GCAPIReactivationTest() {} |
| 26 | 26 |
| 27 bool SetChromeInstallMarker(HKEY hive) { | 27 bool SetChromeInstallMarker(HKEY hive) { |
| 28 // Create the client state keys in the right places. | 28 // Create the client state keys in the right places. |
| 29 std::wstring reg_path(google_update::kRegPathClients); | 29 std::wstring reg_path(google_update::kRegPathClients); |
| 30 reg_path += L"\\"; | 30 reg_path += L"\\"; |
| 31 reg_path += google_update::kChromeUpgradeCode; | 31 reg_path += google_update::kChromeUpgradeCode; |
| 32 RegKey client_state(hive, | 32 RegKey client_state(hive, |
| 33 reg_path.c_str(), | 33 reg_path.c_str(), |
| 34 KEY_CREATE_SUB_KEY | KEY_SET_VALUE | KEY_WOW64_32KEY); | 34 KEY_CREATE_SUB_KEY | KEY_SET_VALUE); |
| 35 return (client_state.Valid() && | 35 return (client_state.Valid() && |
| 36 client_state.WriteValue( | 36 client_state.WriteValue( |
| 37 google_update::kRegVersionField, L"1.2.3.4") == ERROR_SUCCESS); | 37 google_update::kRegVersionField, L"1.2.3.4") == ERROR_SUCCESS); |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool SetLastRunTime(HKEY hive, int64 last_run_time) { | 40 bool SetLastRunTime(HKEY hive, int64 last_run_time) { |
| 41 return SetLastRunTimeString(hive, base::Int64ToString16(last_run_time)); | 41 return SetLastRunTimeString(hive, base::Int64ToString16(last_run_time)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 bool SetLastRunTimeString(HKEY hive, | 44 bool SetLastRunTimeString(HKEY hive, |
| 45 const base::string16& last_run_time_string) { | 45 const base::string16& last_run_time_string) { |
| 46 const wchar_t* base_path = | 46 const wchar_t* base_path = |
| 47 (hive == HKEY_LOCAL_MACHINE) ? | 47 (hive == HKEY_LOCAL_MACHINE) ? |
| 48 google_update::kRegPathClientStateMedium : | 48 google_update::kRegPathClientStateMedium : |
| 49 google_update::kRegPathClientState; | 49 google_update::kRegPathClientState; |
| 50 std::wstring path(base_path); | 50 std::wstring path(base_path); |
| 51 path += L"\\"; | 51 path += L"\\"; |
| 52 path += google_update::kChromeUpgradeCode; | 52 path += google_update::kChromeUpgradeCode; |
| 53 | 53 |
| 54 RegKey client_state(hive, path.c_str(), KEY_SET_VALUE | KEY_WOW64_32KEY); | 54 RegKey client_state(hive, path.c_str(), KEY_SET_VALUE); |
| 55 return (client_state.Valid() && | 55 return (client_state.Valid() && |
| 56 client_state.WriteValue( | 56 client_state.WriteValue( |
| 57 google_update::kRegLastRunTimeField, | 57 google_update::kRegLastRunTimeField, |
| 58 last_run_time_string.c_str()) == ERROR_SUCCESS); | 58 last_run_time_string.c_str()) == ERROR_SUCCESS); |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool HasExperimentLabels(HKEY hive) { | 61 bool HasExperimentLabels(HKEY hive) { |
| 62 base::string16 client_state_path(google_update::kRegPathClientState); | 62 base::string16 client_state_path(google_update::kRegPathClientState); |
| 63 client_state_path.push_back(L'\\'); | 63 client_state_path.push_back(L'\\'); |
| 64 client_state_path.append(google_update::kChromeUpgradeCode); | 64 client_state_path.append(google_update::kChromeUpgradeCode); |
| 65 | 65 |
| 66 RegKey client_state_key(hive, | 66 RegKey client_state_key(hive, |
| 67 client_state_path.c_str(), | 67 client_state_path.c_str(), |
| 68 KEY_QUERY_VALUE | KEY_WOW64_32KEY); | 68 KEY_QUERY_VALUE); |
| 69 return client_state_key.Valid() && | 69 return client_state_key.Valid() && |
| 70 client_state_key.HasValue(google_update::kExperimentLabels); | 70 client_state_key.HasValue(google_update::kExperimentLabels); |
| 71 } | 71 } |
| 72 | 72 |
| 73 std::wstring GetReactivationString(HKEY hive) { | 73 std::wstring GetReactivationString(HKEY hive) { |
| 74 const wchar_t* base_path = | 74 const wchar_t* base_path = |
| 75 (hive == HKEY_LOCAL_MACHINE) ? | 75 (hive == HKEY_LOCAL_MACHINE) ? |
| 76 google_update::kRegPathClientStateMedium : | 76 google_update::kRegPathClientStateMedium : |
| 77 google_update::kRegPathClientState; | 77 google_update::kRegPathClientState; |
| 78 std::wstring path(base_path); | 78 std::wstring path(base_path); |
| 79 path += L"\\"; | 79 path += L"\\"; |
| 80 path += google_update::kChromeUpgradeCode; | 80 path += google_update::kChromeUpgradeCode; |
| 81 | 81 |
| 82 RegKey client_state(hive, path.c_str(), KEY_QUERY_VALUE | KEY_WOW64_32KEY); | 82 RegKey client_state(hive, path.c_str(), KEY_QUERY_VALUE); |
| 83 if (client_state.Valid()) { | 83 if (client_state.Valid()) { |
| 84 std::wstring actual_brand; | 84 std::wstring actual_brand; |
| 85 if (client_state.ReadValue(google_update::kRegRLZReactivationBrandField, | 85 if (client_state.ReadValue(google_update::kRegRLZReactivationBrandField, |
| 86 &actual_brand) == ERROR_SUCCESS) { | 86 &actual_brand) == ERROR_SUCCESS) { |
| 87 return actual_brand; | 87 return actual_brand; |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 return L"ERROR"; | 91 return L"ERROR"; |
| 92 } | 92 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER, | 201 EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER, |
| 202 hkcu_last_run.ToInternalValue())); | 202 hkcu_last_run.ToInternalValue())); |
| 203 | 203 |
| 204 EXPECT_TRUE(ReactivateChrome(L"GAGA", | 204 EXPECT_TRUE(ReactivateChrome(L"GAGA", |
| 205 GCAPI_INVOKED_STANDARD_SHELL, | 205 GCAPI_INVOKED_STANDARD_SHELL, |
| 206 &error)); | 206 &error)); |
| 207 EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER)); | 207 EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER)); |
| 208 | 208 |
| 209 EXPECT_TRUE(HasExperimentLabels(HKEY_CURRENT_USER)); | 209 EXPECT_TRUE(HasExperimentLabels(HKEY_CURRENT_USER)); |
| 210 } | 210 } |
| OLD | NEW |