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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/test/test_reg_util_win.h" | 7 #include "base/test/test_reg_util_win.h" |
8 #include "chrome/install_static/install_details.h" | 8 #include "chrome/install_static/install_details.h" |
9 #include "chrome/install_static/user_data_dir.h" | 9 #include "chrome/install_static/user_data_dir.h" |
10 #include "chrome_elf/nt_registry/nt_registry.h" | 10 #include "chrome_elf/nt_registry/nt_registry.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 nt::SetTestingOverride(root_, base::string16()); | 42 nt::SetTestingOverride(root_, base::string16()); |
43 } | 43 } |
44 | 44 |
45 private: | 45 private: |
46 nt::ROOT_KEY root_; | 46 nt::ROOT_KEY root_; |
47 }; | 47 }; |
48 | 48 |
49 TEST(UserDataDir, EmptyResultsInDefault) { | 49 TEST(UserDataDir, EmptyResultsInDefault) { |
50 std::wstring result, invalid; | 50 std::wstring result, invalid; |
51 | 51 |
52 install_static::GetUserDataDirectoryImpl(L"", kFakeInstallConstants, &result, | 52 install_static::DeriveUserDataDirectoryImpl(L"", kFakeInstallConstants, |
53 &invalid); | 53 &result, &invalid); |
54 EXPECT_TRUE(EndsWith(result, kUserDataDirNameSuffix)); | 54 EXPECT_TRUE(EndsWith(result, kUserDataDirNameSuffix)); |
55 EXPECT_EQ(std::wstring(), invalid); | 55 EXPECT_EQ(std::wstring(), invalid); |
56 } | 56 } |
57 | 57 |
58 TEST(UserDataDir, InvalidResultsInDefault) { | 58 TEST(UserDataDir, InvalidResultsInDefault) { |
59 std::wstring result, invalid; | 59 std::wstring result, invalid; |
60 | 60 |
61 install_static::GetUserDataDirectoryImpl(L"<>|:", kFakeInstallConstants, | 61 install_static::DeriveUserDataDirectoryImpl(L"<>|:", kFakeInstallConstants, |
62 &result, &invalid); | 62 &result, &invalid); |
63 EXPECT_TRUE(EndsWith(result, kUserDataDirNameSuffix)); | 63 EXPECT_TRUE(EndsWith(result, kUserDataDirNameSuffix)); |
64 EXPECT_EQ(L"<>|:", invalid); | 64 EXPECT_EQ(L"<>|:", invalid); |
65 } | 65 } |
66 | 66 |
67 TEST(UserDataDir, RegistrySettingsInHKLMOverrides) { | 67 TEST(UserDataDir, RegistrySettingsInHKLMOverrides) { |
68 std::wstring result, invalid; | 68 std::wstring result, invalid; |
69 | 69 |
70 // Override the registry to say one value in HKLM, and confirm it takes | 70 // Override the registry to say one value in HKLM, and confirm it takes |
71 // precedence over the command line in both implementations. | 71 // precedence over the command line in both implementations. |
72 registry_util::RegistryOverrideManager override_manager; | 72 registry_util::RegistryOverrideManager override_manager; |
73 base::string16 temp; | 73 base::string16 temp; |
74 ASSERT_NO_FATAL_FAILURE( | 74 ASSERT_NO_FATAL_FAILURE( |
75 override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp)); | 75 override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp)); |
76 ScopedNTRegistryTestingOverride nt_override(nt::HKLM, temp); | 76 ScopedNTRegistryTestingOverride nt_override(nt::HKLM, temp); |
77 | 77 |
78 base::win::RegKey key(HKEY_LOCAL_MACHINE, kPolicyRegistryKey, KEY_WRITE); | 78 base::win::RegKey key(HKEY_LOCAL_MACHINE, kPolicyRegistryKey, KEY_WRITE); |
79 LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"yyy"); | 79 LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"yyy"); |
80 ASSERT_EQ(rv, ERROR_SUCCESS); | 80 ASSERT_EQ(rv, ERROR_SUCCESS); |
81 | 81 |
82 install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants, | 82 install_static::DeriveUserDataDirectoryImpl(L"xxx", kFakeInstallConstants, |
83 &result, &invalid); | 83 &result, &invalid); |
84 | 84 |
85 EXPECT_TRUE(EndsWith(result, L"\\yyy")); | 85 EXPECT_TRUE(EndsWith(result, L"\\yyy")); |
86 EXPECT_EQ(std::wstring(), invalid); | 86 EXPECT_EQ(std::wstring(), invalid); |
87 } | 87 } |
88 | 88 |
89 TEST(UserDataDir, RegistrySettingsInHKCUOverrides) { | 89 TEST(UserDataDir, RegistrySettingsInHKCUOverrides) { |
90 std::wstring result, invalid; | 90 std::wstring result, invalid; |
91 | 91 |
92 // Override the registry to say one value in HKCU, and confirm it takes | 92 // Override the registry to say one value in HKCU, and confirm it takes |
93 // precedence over the command line in both implementations. | 93 // precedence over the command line in both implementations. |
94 registry_util::RegistryOverrideManager override_manager; | 94 registry_util::RegistryOverrideManager override_manager; |
95 base::string16 temp; | 95 base::string16 temp; |
96 ASSERT_NO_FATAL_FAILURE( | 96 ASSERT_NO_FATAL_FAILURE( |
97 override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp)); | 97 override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp)); |
98 ScopedNTRegistryTestingOverride nt_override(nt::HKCU, temp); | 98 ScopedNTRegistryTestingOverride nt_override(nt::HKCU, temp); |
99 | 99 |
100 base::win::RegKey key(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE); | 100 base::win::RegKey key(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE); |
101 LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"yyy"); | 101 LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"yyy"); |
102 ASSERT_EQ(rv, ERROR_SUCCESS); | 102 ASSERT_EQ(rv, ERROR_SUCCESS); |
103 | 103 |
104 install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants, | 104 install_static::DeriveUserDataDirectoryImpl(L"xxx", kFakeInstallConstants, |
105 &result, &invalid); | 105 &result, &invalid); |
106 | 106 |
107 EXPECT_TRUE(EndsWith(result, L"\\yyy")); | 107 EXPECT_TRUE(EndsWith(result, L"\\yyy")); |
108 EXPECT_EQ(std::wstring(), invalid); | 108 EXPECT_EQ(std::wstring(), invalid); |
109 } | 109 } |
110 | 110 |
111 TEST(UserDataDir, RegistrySettingsInHKLMTakesPrecedenceOverHKCU) { | 111 TEST(UserDataDir, RegistrySettingsInHKLMTakesPrecedenceOverHKCU) { |
112 std::wstring result, invalid; | 112 std::wstring result, invalid; |
113 | 113 |
114 // Override the registry in both HKLM and HKCU, and confirm HKLM takes | 114 // Override the registry in both HKLM and HKCU, and confirm HKLM takes |
115 // precedence. | 115 // precedence. |
116 registry_util::RegistryOverrideManager override_manager; | 116 registry_util::RegistryOverrideManager override_manager; |
117 base::string16 temp; | 117 base::string16 temp; |
118 ASSERT_NO_FATAL_FAILURE( | 118 ASSERT_NO_FATAL_FAILURE( |
119 override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp)); | 119 override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp)); |
120 ScopedNTRegistryTestingOverride nt_override(nt::HKLM, temp); | 120 ScopedNTRegistryTestingOverride nt_override(nt::HKLM, temp); |
121 LONG rv; | 121 LONG rv; |
122 base::win::RegKey key1(HKEY_LOCAL_MACHINE, kPolicyRegistryKey, KEY_WRITE); | 122 base::win::RegKey key1(HKEY_LOCAL_MACHINE, kPolicyRegistryKey, KEY_WRITE); |
123 rv = key1.WriteValue(kUserDataDirRegistryKey, L"111"); | 123 rv = key1.WriteValue(kUserDataDirRegistryKey, L"111"); |
124 ASSERT_EQ(rv, ERROR_SUCCESS); | 124 ASSERT_EQ(rv, ERROR_SUCCESS); |
125 | 125 |
126 ASSERT_NO_FATAL_FAILURE( | 126 ASSERT_NO_FATAL_FAILURE( |
127 override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp)); | 127 override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp)); |
128 ScopedNTRegistryTestingOverride nt_override2(nt::HKCU, temp); | 128 ScopedNTRegistryTestingOverride nt_override2(nt::HKCU, temp); |
129 base::win::RegKey key2(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE); | 129 base::win::RegKey key2(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE); |
130 rv = key2.WriteValue(kUserDataDirRegistryKey, L"222"); | 130 rv = key2.WriteValue(kUserDataDirRegistryKey, L"222"); |
131 ASSERT_EQ(rv, ERROR_SUCCESS); | 131 ASSERT_EQ(rv, ERROR_SUCCESS); |
132 | 132 |
133 install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants, | 133 install_static::DeriveUserDataDirectoryImpl(L"xxx", kFakeInstallConstants, |
134 &result, &invalid); | 134 &result, &invalid); |
135 | 135 |
136 EXPECT_TRUE(EndsWith(result, L"\\111")); | 136 EXPECT_TRUE(EndsWith(result, L"\\111")); |
137 EXPECT_EQ(std::wstring(), invalid); | 137 EXPECT_EQ(std::wstring(), invalid); |
138 } | 138 } |
139 | 139 |
140 TEST(UserDataDir, RegistrySettingWithPathExpansionHKCU) { | 140 TEST(UserDataDir, RegistrySettingWithPathExpansionHKCU) { |
141 std::wstring result, invalid; | 141 std::wstring result, invalid; |
142 | 142 |
143 registry_util::RegistryOverrideManager override_manager; | 143 registry_util::RegistryOverrideManager override_manager; |
144 base::string16 temp; | 144 base::string16 temp; |
145 ASSERT_NO_FATAL_FAILURE( | 145 ASSERT_NO_FATAL_FAILURE( |
146 override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp)); | 146 override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp)); |
147 ScopedNTRegistryTestingOverride nt_override(nt::HKCU, temp); | 147 ScopedNTRegistryTestingOverride nt_override(nt::HKCU, temp); |
148 base::win::RegKey key(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE); | 148 base::win::RegKey key(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE); |
149 LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"${windows}"); | 149 LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"${windows}"); |
150 ASSERT_EQ(rv, ERROR_SUCCESS); | 150 ASSERT_EQ(rv, ERROR_SUCCESS); |
151 | 151 |
152 install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants, | 152 install_static::DeriveUserDataDirectoryImpl(L"xxx", kFakeInstallConstants, |
153 &result, &invalid); | 153 &result, &invalid); |
154 | 154 |
155 EXPECT_EQ(strlen("X:\\WINDOWS"), result.size()); | 155 EXPECT_EQ(strlen("X:\\WINDOWS"), result.size()); |
156 EXPECT_EQ(std::wstring::npos, result.find(L"${windows}")); | 156 EXPECT_EQ(std::wstring::npos, result.find(L"${windows}")); |
157 std::wstring upper; | 157 std::wstring upper; |
158 std::transform(result.begin(), result.end(), std::back_inserter(upper), | 158 std::transform(result.begin(), result.end(), std::back_inserter(upper), |
159 toupper); | 159 toupper); |
160 EXPECT_TRUE(EndsWith(upper, L"\\WINDOWS")); | 160 EXPECT_TRUE(EndsWith(upper, L"\\WINDOWS")); |
161 EXPECT_EQ(std::wstring(), invalid); | 161 EXPECT_EQ(std::wstring(), invalid); |
162 } | 162 } |
163 | 163 |
164 } // namespace | 164 } // namespace |
165 } // namespace install_static | 165 } // namespace install_static |
OLD | NEW |