| 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 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 75 } |
| 76 | 76 |
| 77 TEST_F(InstallUtilTest, UpdateInstallerStageAP) { | 77 TEST_F(InstallUtilTest, UpdateInstallerStageAP) { |
| 78 const bool system_level = false; | 78 const bool system_level = false; |
| 79 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 79 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 80 std::wstring state_key_path(L"PhonyClientState"); | 80 std::wstring state_key_path(L"PhonyClientState"); |
| 81 | 81 |
| 82 // Update the stage when there's no "ap" value. | 82 // Update the stage when there's no "ap" value. |
| 83 { | 83 { |
| 84 RegistryOverrideManager override_manager; | 84 RegistryOverrideManager override_manager; |
| 85 override_manager.OverrideRegistry(root, L"root_inst_res"); | 85 override_manager.OverrideRegistry(root); |
| 86 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE); | 86 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE); |
| 87 InstallUtil::UpdateInstallerStage(system_level, state_key_path, | 87 InstallUtil::UpdateInstallerStage(system_level, state_key_path, |
| 88 installer::BUILDING); | 88 installer::BUILDING); |
| 89 std::wstring value; | 89 std::wstring value; |
| 90 EXPECT_EQ(ERROR_SUCCESS, | 90 EXPECT_EQ(ERROR_SUCCESS, |
| 91 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) | 91 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) |
| 92 .ReadValue(google_update::kRegApField, &value)); | 92 .ReadValue(google_update::kRegApField, &value)); |
| 93 EXPECT_EQ(L"-stage:building", value); | 93 EXPECT_EQ(L"-stage:building", value); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Update the stage when there is an "ap" value. | 96 // Update the stage when there is an "ap" value. |
| 97 { | 97 { |
| 98 RegistryOverrideManager override_manager; | 98 RegistryOverrideManager override_manager; |
| 99 override_manager.OverrideRegistry(root, L"root_inst_res"); | 99 override_manager.OverrideRegistry(root); |
| 100 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) | 100 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) |
| 101 .WriteValue(google_update::kRegApField, L"2.0-dev"); | 101 .WriteValue(google_update::kRegApField, L"2.0-dev"); |
| 102 InstallUtil::UpdateInstallerStage(system_level, state_key_path, | 102 InstallUtil::UpdateInstallerStage(system_level, state_key_path, |
| 103 installer::BUILDING); | 103 installer::BUILDING); |
| 104 std::wstring value; | 104 std::wstring value; |
| 105 EXPECT_EQ(ERROR_SUCCESS, | 105 EXPECT_EQ(ERROR_SUCCESS, |
| 106 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) | 106 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) |
| 107 .ReadValue(google_update::kRegApField, &value)); | 107 .ReadValue(google_update::kRegApField, &value)); |
| 108 EXPECT_EQ(L"2.0-dev-stage:building", value); | 108 EXPECT_EQ(L"2.0-dev-stage:building", value); |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Clear the stage. | 111 // Clear the stage. |
| 112 { | 112 { |
| 113 RegistryOverrideManager override_manager; | 113 RegistryOverrideManager override_manager; |
| 114 override_manager.OverrideRegistry(root, L"root_inst_res"); | 114 override_manager.OverrideRegistry(root); |
| 115 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) | 115 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) |
| 116 .WriteValue(google_update::kRegApField, L"2.0-dev-stage:building"); | 116 .WriteValue(google_update::kRegApField, L"2.0-dev-stage:building"); |
| 117 InstallUtil::UpdateInstallerStage(system_level, state_key_path, | 117 InstallUtil::UpdateInstallerStage(system_level, state_key_path, |
| 118 installer::NO_STAGE); | 118 installer::NO_STAGE); |
| 119 std::wstring value; | 119 std::wstring value; |
| 120 EXPECT_EQ(ERROR_SUCCESS, | 120 EXPECT_EQ(ERROR_SUCCESS, |
| 121 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) | 121 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) |
| 122 .ReadValue(google_update::kRegApField, &value)); | 122 .ReadValue(google_update::kRegApField, &value)); |
| 123 EXPECT_EQ(L"2.0-dev", value); | 123 EXPECT_EQ(L"2.0-dev", value); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 TEST_F(InstallUtilTest, UpdateInstallerStage) { | 127 TEST_F(InstallUtilTest, UpdateInstallerStage) { |
| 128 const bool system_level = false; | 128 const bool system_level = false; |
| 129 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 129 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 130 std::wstring state_key_path(L"PhonyClientState"); | 130 std::wstring state_key_path(L"PhonyClientState"); |
| 131 | 131 |
| 132 // Update the stage when there's no "InstallerExtraCode1" value. | 132 // Update the stage when there's no "InstallerExtraCode1" value. |
| 133 { | 133 { |
| 134 RegistryOverrideManager override_manager; | 134 RegistryOverrideManager override_manager; |
| 135 override_manager.OverrideRegistry(root, L"root_inst_res"); | 135 override_manager.OverrideRegistry(root); |
| 136 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) | 136 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) |
| 137 .DeleteValue(installer::kInstallerExtraCode1); | 137 .DeleteValue(installer::kInstallerExtraCode1); |
| 138 InstallUtil::UpdateInstallerStage(system_level, state_key_path, | 138 InstallUtil::UpdateInstallerStage(system_level, state_key_path, |
| 139 installer::BUILDING); | 139 installer::BUILDING); |
| 140 DWORD value; | 140 DWORD value; |
| 141 EXPECT_EQ(ERROR_SUCCESS, | 141 EXPECT_EQ(ERROR_SUCCESS, |
| 142 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) | 142 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) |
| 143 .ReadValueDW(installer::kInstallerExtraCode1, &value)); | 143 .ReadValueDW(installer::kInstallerExtraCode1, &value)); |
| 144 EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value); | 144 EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value); |
| 145 } | 145 } |
| 146 | 146 |
| 147 // Update the stage when there is an "InstallerExtraCode1" value. | 147 // Update the stage when there is an "InstallerExtraCode1" value. |
| 148 { | 148 { |
| 149 RegistryOverrideManager override_manager; | 149 RegistryOverrideManager override_manager; |
| 150 override_manager.OverrideRegistry(root, L"root_inst_res"); | 150 override_manager.OverrideRegistry(root); |
| 151 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) | 151 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) |
| 152 .WriteValue(installer::kInstallerExtraCode1, | 152 .WriteValue(installer::kInstallerExtraCode1, |
| 153 static_cast<DWORD>(installer::UNPACKING)); | 153 static_cast<DWORD>(installer::UNPACKING)); |
| 154 InstallUtil::UpdateInstallerStage(system_level, state_key_path, | 154 InstallUtil::UpdateInstallerStage(system_level, state_key_path, |
| 155 installer::BUILDING); | 155 installer::BUILDING); |
| 156 DWORD value; | 156 DWORD value; |
| 157 EXPECT_EQ(ERROR_SUCCESS, | 157 EXPECT_EQ(ERROR_SUCCESS, |
| 158 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) | 158 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) |
| 159 .ReadValueDW(installer::kInstallerExtraCode1, &value)); | 159 .ReadValueDW(installer::kInstallerExtraCode1, &value)); |
| 160 EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value); | 160 EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Clear the stage. | 163 // Clear the stage. |
| 164 { | 164 { |
| 165 RegistryOverrideManager override_manager; | 165 RegistryOverrideManager override_manager; |
| 166 override_manager.OverrideRegistry(root, L"root_inst_res"); | 166 override_manager.OverrideRegistry(root); |
| 167 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) | 167 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) |
| 168 .WriteValue(installer::kInstallerExtraCode1, static_cast<DWORD>(5)); | 168 .WriteValue(installer::kInstallerExtraCode1, static_cast<DWORD>(5)); |
| 169 InstallUtil::UpdateInstallerStage(system_level, state_key_path, | 169 InstallUtil::UpdateInstallerStage(system_level, state_key_path, |
| 170 installer::NO_STAGE); | 170 installer::NO_STAGE); |
| 171 DWORD value; | 171 DWORD value; |
| 172 EXPECT_EQ(ERROR_FILE_NOT_FOUND, | 172 EXPECT_EQ(ERROR_FILE_NOT_FOUND, |
| 173 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) | 173 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) |
| 174 .ReadValueDW(installer::kInstallerExtraCode1, &value)); | 174 .ReadValueDW(installer::kInstallerExtraCode1, &value)); |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 TEST_F(InstallUtilTest, DeleteRegistryKeyIf) { | 178 TEST_F(InstallUtilTest, DeleteRegistryKeyIf) { |
| 179 const HKEY root = HKEY_CURRENT_USER; | 179 const HKEY root = HKEY_CURRENT_USER; |
| 180 std::wstring parent_key_path(L"SomeKey\\ToDelete"); | 180 std::wstring parent_key_path(L"SomeKey\\ToDelete"); |
| 181 std::wstring child_key_path(parent_key_path); | 181 std::wstring child_key_path(parent_key_path); |
| 182 child_key_path.append(L"\\ChildKey\\WithAValue"); | 182 child_key_path.append(L"\\ChildKey\\WithAValue"); |
| 183 const wchar_t value_name[] = L"some_value_name"; | 183 const wchar_t value_name[] = L"some_value_name"; |
| 184 const wchar_t value[] = L"hi mom"; | 184 const wchar_t value[] = L"hi mom"; |
| 185 | 185 |
| 186 { | 186 { |
| 187 RegistryOverrideManager override_manager; | 187 RegistryOverrideManager override_manager; |
| 188 override_manager.OverrideRegistry(root, L"root_key"); | 188 override_manager.OverrideRegistry(root); |
| 189 // Nothing to delete if the keys aren't even there. | 189 // Nothing to delete if the keys aren't even there. |
| 190 { | 190 { |
| 191 MockRegistryValuePredicate pred; | 191 MockRegistryValuePredicate pred; |
| 192 | 192 |
| 193 EXPECT_CALL(pred, Evaluate(_)).Times(0); | 193 EXPECT_CALL(pred, Evaluate(_)).Times(0); |
| 194 ASSERT_FALSE(RegKey(root, parent_key_path.c_str(), | 194 ASSERT_FALSE(RegKey(root, parent_key_path.c_str(), |
| 195 KEY_QUERY_VALUE).Valid()); | 195 KEY_QUERY_VALUE).Valid()); |
| 196 EXPECT_EQ(InstallUtil::NOT_FOUND, | 196 EXPECT_EQ(InstallUtil::NOT_FOUND, |
| 197 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, | 197 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, |
| 198 child_key_path, | 198 child_key_path, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 } | 286 } |
| 287 | 287 |
| 288 TEST_F(InstallUtilTest, DeleteRegistryValueIf) { | 288 TEST_F(InstallUtilTest, DeleteRegistryValueIf) { |
| 289 const HKEY root = HKEY_CURRENT_USER; | 289 const HKEY root = HKEY_CURRENT_USER; |
| 290 std::wstring key_path(L"SomeKey\\ToDelete"); | 290 std::wstring key_path(L"SomeKey\\ToDelete"); |
| 291 const wchar_t value_name[] = L"some_value_name"; | 291 const wchar_t value_name[] = L"some_value_name"; |
| 292 const wchar_t value[] = L"hi mom"; | 292 const wchar_t value[] = L"hi mom"; |
| 293 | 293 |
| 294 { | 294 { |
| 295 RegistryOverrideManager override_manager; | 295 RegistryOverrideManager override_manager; |
| 296 override_manager.OverrideRegistry(root, L"root_key"); | 296 override_manager.OverrideRegistry(root); |
| 297 // Nothing to delete if the key isn't even there. | 297 // Nothing to delete if the key isn't even there. |
| 298 { | 298 { |
| 299 MockRegistryValuePredicate pred; | 299 MockRegistryValuePredicate pred; |
| 300 | 300 |
| 301 EXPECT_CALL(pred, Evaluate(_)).Times(0); | 301 EXPECT_CALL(pred, Evaluate(_)).Times(0); |
| 302 ASSERT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 302 ASSERT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
| 303 EXPECT_EQ(InstallUtil::NOT_FOUND, | 303 EXPECT_EQ(InstallUtil::NOT_FOUND, |
| 304 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), | 304 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), |
| 305 WorkItem::kWow64Default, | 305 WorkItem::kWow64Default, |
| 306 value_name, pred)); | 306 value_name, pred)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 WorkItem::kWow64Default, | 350 WorkItem::kWow64Default, |
| 351 value_name, pred)); | 351 value_name, pred)); |
| 352 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 352 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
| 353 EXPECT_FALSE(RegKey(root, key_path.c_str(), | 353 EXPECT_FALSE(RegKey(root, key_path.c_str(), |
| 354 KEY_QUERY_VALUE).HasValue(value_name)); | 354 KEY_QUERY_VALUE).HasValue(value_name)); |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 | 357 |
| 358 { | 358 { |
| 359 RegistryOverrideManager override_manager; | 359 RegistryOverrideManager override_manager; |
| 360 override_manager.OverrideRegistry(root, L"root_key"); | 360 override_manager.OverrideRegistry(root); |
| 361 // Default value matches: delete using empty string. | 361 // Default value matches: delete using empty string. |
| 362 { | 362 { |
| 363 MockRegistryValuePredicate pred; | 363 MockRegistryValuePredicate pred; |
| 364 | 364 |
| 365 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); | 365 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); |
| 366 ASSERT_EQ(ERROR_SUCCESS, | 366 ASSERT_EQ(ERROR_SUCCESS, |
| 367 RegKey(root, key_path.c_str(), | 367 RegKey(root, key_path.c_str(), |
| 368 KEY_SET_VALUE).WriteValue(L"", value)); | 368 KEY_SET_VALUE).WriteValue(L"", value)); |
| 369 EXPECT_EQ(InstallUtil::DELETED, | 369 EXPECT_EQ(InstallUtil::DELETED, |
| 370 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), | 370 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), |
| 371 WorkItem::kWow64Default, L"", | 371 WorkItem::kWow64Default, L"", |
| 372 pred)); | 372 pred)); |
| 373 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 373 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
| 374 EXPECT_FALSE(RegKey(root, key_path.c_str(), | 374 EXPECT_FALSE(RegKey(root, key_path.c_str(), |
| 375 KEY_QUERY_VALUE).HasValue(L"")); | 375 KEY_QUERY_VALUE).HasValue(L"")); |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 | 378 |
| 379 { | 379 { |
| 380 RegistryOverrideManager override_manager; | 380 RegistryOverrideManager override_manager; |
| 381 override_manager.OverrideRegistry(root, L"root_key"); | 381 override_manager.OverrideRegistry(root); |
| 382 // Default value matches: delete using NULL. | 382 // Default value matches: delete using NULL. |
| 383 { | 383 { |
| 384 MockRegistryValuePredicate pred; | 384 MockRegistryValuePredicate pred; |
| 385 | 385 |
| 386 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); | 386 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); |
| 387 ASSERT_EQ(ERROR_SUCCESS, | 387 ASSERT_EQ(ERROR_SUCCESS, |
| 388 RegKey(root, key_path.c_str(), | 388 RegKey(root, key_path.c_str(), |
| 389 KEY_SET_VALUE).WriteValue(L"", value)); | 389 KEY_SET_VALUE).WriteValue(L"", value)); |
| 390 EXPECT_EQ(InstallUtil::DELETED, | 390 EXPECT_EQ(InstallUtil::DELETED, |
| 391 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), | 391 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 WriteInto(&short_expect, MAX_PATH), | 447 WriteInto(&short_expect, MAX_PATH), |
| 448 MAX_PATH); | 448 MAX_PATH); |
| 449 ASSERT_NE(static_cast<DWORD>(0), short_len); | 449 ASSERT_NE(static_cast<DWORD>(0), short_len); |
| 450 ASSERT_GT(static_cast<DWORD>(MAX_PATH), short_len); | 450 ASSERT_GT(static_cast<DWORD>(MAX_PATH), short_len); |
| 451 short_expect.resize(short_len); | 451 short_expect.resize(short_len); |
| 452 ASSERT_FALSE(base::FilePath::CompareEqualIgnoreCase(expect.value(), | 452 ASSERT_FALSE(base::FilePath::CompareEqualIgnoreCase(expect.value(), |
| 453 short_expect)); | 453 short_expect)); |
| 454 EXPECT_TRUE(InstallUtil::ProgramCompare(expect).Evaluate( | 454 EXPECT_TRUE(InstallUtil::ProgramCompare(expect).Evaluate( |
| 455 L"\"" + short_expect + L"\"")); | 455 L"\"" + short_expect + L"\"")); |
| 456 } | 456 } |
| OLD | NEW |