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

Side by Side Diff: chrome/install_static/user_data_dir_win_unittest.cc

Issue 2692843002: Fail tests fast if overriding the Windows registry fails. (Closed)
Patch Set: sync to position 450085 Created 3 years, 10 months 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 <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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp); 74 ASSERT_NO_FATAL_FAILURE(
75 override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp));
75 ScopedNTRegistryTestingOverride nt_override(nt::HKLM, temp); 76 ScopedNTRegistryTestingOverride nt_override(nt::HKLM, temp);
76 77
77 base::win::RegKey key(HKEY_LOCAL_MACHINE, kPolicyRegistryKey, KEY_WRITE); 78 base::win::RegKey key(HKEY_LOCAL_MACHINE, kPolicyRegistryKey, KEY_WRITE);
78 LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"yyy"); 79 LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"yyy");
79 ASSERT_EQ(rv, ERROR_SUCCESS); 80 ASSERT_EQ(rv, ERROR_SUCCESS);
80 81
81 install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants, 82 install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants,
82 &result, &invalid); 83 &result, &invalid);
83 84
84 EXPECT_TRUE(EndsWith(result, L"\\yyy")); 85 EXPECT_TRUE(EndsWith(result, L"\\yyy"));
85 EXPECT_EQ(std::wstring(), invalid); 86 EXPECT_EQ(std::wstring(), invalid);
86 } 87 }
87 88
88 TEST(UserDataDir, RegistrySettingsInHKCUOverrides) { 89 TEST(UserDataDir, RegistrySettingsInHKCUOverrides) {
89 std::wstring result, invalid; 90 std::wstring result, invalid;
90 91
91 // 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
92 // precedence over the command line in both implementations. 93 // precedence over the command line in both implementations.
93 registry_util::RegistryOverrideManager override_manager; 94 registry_util::RegistryOverrideManager override_manager;
94 base::string16 temp; 95 base::string16 temp;
95 override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp); 96 ASSERT_NO_FATAL_FAILURE(
97 override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp));
96 ScopedNTRegistryTestingOverride nt_override(nt::HKCU, temp); 98 ScopedNTRegistryTestingOverride nt_override(nt::HKCU, temp);
97 99
98 base::win::RegKey key(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE); 100 base::win::RegKey key(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE);
99 LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"yyy"); 101 LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"yyy");
100 ASSERT_EQ(rv, ERROR_SUCCESS); 102 ASSERT_EQ(rv, ERROR_SUCCESS);
101 103
102 install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants, 104 install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants,
103 &result, &invalid); 105 &result, &invalid);
104 106
105 EXPECT_TRUE(EndsWith(result, L"\\yyy")); 107 EXPECT_TRUE(EndsWith(result, L"\\yyy"));
106 EXPECT_EQ(std::wstring(), invalid); 108 EXPECT_EQ(std::wstring(), invalid);
107 } 109 }
108 110
109 TEST(UserDataDir, RegistrySettingsInHKLMTakesPrecedenceOverHKCU) { 111 TEST(UserDataDir, RegistrySettingsInHKLMTakesPrecedenceOverHKCU) {
110 std::wstring result, invalid; 112 std::wstring result, invalid;
111 113
112 // 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
113 // precedence. 115 // precedence.
114 registry_util::RegistryOverrideManager override_manager; 116 registry_util::RegistryOverrideManager override_manager;
115 base::string16 temp; 117 base::string16 temp;
116 override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp); 118 ASSERT_NO_FATAL_FAILURE(
119 override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp));
117 ScopedNTRegistryTestingOverride nt_override(nt::HKLM, temp); 120 ScopedNTRegistryTestingOverride nt_override(nt::HKLM, temp);
118 LONG rv; 121 LONG rv;
119 base::win::RegKey key1(HKEY_LOCAL_MACHINE, kPolicyRegistryKey, KEY_WRITE); 122 base::win::RegKey key1(HKEY_LOCAL_MACHINE, kPolicyRegistryKey, KEY_WRITE);
120 rv = key1.WriteValue(kUserDataDirRegistryKey, L"111"); 123 rv = key1.WriteValue(kUserDataDirRegistryKey, L"111");
121 ASSERT_EQ(rv, ERROR_SUCCESS); 124 ASSERT_EQ(rv, ERROR_SUCCESS);
122 125
123 override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp); 126 ASSERT_NO_FATAL_FAILURE(
127 override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp));
124 ScopedNTRegistryTestingOverride nt_override2(nt::HKCU, temp); 128 ScopedNTRegistryTestingOverride nt_override2(nt::HKCU, temp);
125 base::win::RegKey key2(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE); 129 base::win::RegKey key2(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE);
126 rv = key2.WriteValue(kUserDataDirRegistryKey, L"222"); 130 rv = key2.WriteValue(kUserDataDirRegistryKey, L"222");
127 ASSERT_EQ(rv, ERROR_SUCCESS); 131 ASSERT_EQ(rv, ERROR_SUCCESS);
128 132
129 install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants, 133 install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants,
130 &result, &invalid); 134 &result, &invalid);
131 135
132 EXPECT_TRUE(EndsWith(result, L"\\111")); 136 EXPECT_TRUE(EndsWith(result, L"\\111"));
133 EXPECT_EQ(std::wstring(), invalid); 137 EXPECT_EQ(std::wstring(), invalid);
134 } 138 }
135 139
136 TEST(UserDataDir, RegistrySettingWithPathExpansionHKCU) { 140 TEST(UserDataDir, RegistrySettingWithPathExpansionHKCU) {
137 std::wstring result, invalid; 141 std::wstring result, invalid;
138 142
139 registry_util::RegistryOverrideManager override_manager; 143 registry_util::RegistryOverrideManager override_manager;
140 base::string16 temp; 144 base::string16 temp;
141 override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp); 145 ASSERT_NO_FATAL_FAILURE(
146 override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp));
142 ScopedNTRegistryTestingOverride nt_override(nt::HKCU, temp); 147 ScopedNTRegistryTestingOverride nt_override(nt::HKCU, temp);
143 base::win::RegKey key(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE); 148 base::win::RegKey key(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE);
144 LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"${windows}"); 149 LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"${windows}");
145 ASSERT_EQ(rv, ERROR_SUCCESS); 150 ASSERT_EQ(rv, ERROR_SUCCESS);
146 151
147 install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants, 152 install_static::GetUserDataDirectoryImpl(L"xxx", kFakeInstallConstants,
148 &result, &invalid); 153 &result, &invalid);
149 154
150 EXPECT_EQ(strlen("X:\\WINDOWS"), result.size()); 155 EXPECT_EQ(strlen("X:\\WINDOWS"), result.size());
151 EXPECT_EQ(std::wstring::npos, result.find(L"${windows}")); 156 EXPECT_EQ(std::wstring::npos, result.find(L"${windows}"));
152 std::wstring upper; 157 std::wstring upper;
153 std::transform(result.begin(), result.end(), std::back_inserter(upper), 158 std::transform(result.begin(), result.end(), std::back_inserter(upper),
154 toupper); 159 toupper);
155 EXPECT_TRUE(EndsWith(upper, L"\\WINDOWS")); 160 EXPECT_TRUE(EndsWith(upper, L"\\WINDOWS"));
156 EXPECT_EQ(std::wstring(), invalid); 161 EXPECT_EQ(std::wstring(), invalid);
157 } 162 }
158 163
159 } // namespace 164 } // namespace
160 } // namespace install_static 165 } // namespace install_static
OLDNEW
« no previous file with comments | « chrome/install_static/product_install_details_unittest.cc ('k') | chrome/installer/gcapi/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698