| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/test/test_reg_util_win.h" | 9 #include "base/test/test_reg_util_win.h" |
| 10 #include "base/win/registry.h" | 10 #include "base/win/registry.h" |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 MockRegistryValuePredicate pred; | 286 MockRegistryValuePredicate pred; |
| 287 | 287 |
| 288 EXPECT_CALL(pred, Evaluate(StrEq(L"foosball!"))).WillOnce(Return(false)); | 288 EXPECT_CALL(pred, Evaluate(StrEq(L"foosball!"))).WillOnce(Return(false)); |
| 289 ASSERT_EQ(ERROR_SUCCESS, | 289 ASSERT_EQ(ERROR_SUCCESS, |
| 290 RegKey(root, key_path.c_str(), | 290 RegKey(root, key_path.c_str(), |
| 291 KEY_SET_VALUE).WriteValue(value_name, L"foosball!")); | 291 KEY_SET_VALUE).WriteValue(value_name, L"foosball!")); |
| 292 EXPECT_TRUE(InstallUtil::DeleteRegistryValueIf( | 292 EXPECT_TRUE(InstallUtil::DeleteRegistryValueIf( |
| 293 root, key_path.c_str(), value_name, pred)); | 293 root, key_path.c_str(), value_name, pred)); |
| 294 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 294 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
| 295 EXPECT_TRUE(RegKey(root, key_path.c_str(), | 295 EXPECT_TRUE(RegKey(root, key_path.c_str(), |
| 296 KEY_QUERY_VALUE).ValueExists(value_name)); | 296 KEY_QUERY_VALUE).HasValue(value_name)); |
| 297 } | 297 } |
| 298 | 298 |
| 299 // Value exists, and matches: delete. | 299 // Value exists, and matches: delete. |
| 300 { | 300 { |
| 301 MockRegistryValuePredicate pred; | 301 MockRegistryValuePredicate pred; |
| 302 | 302 |
| 303 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); | 303 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); |
| 304 ASSERT_EQ(ERROR_SUCCESS, | 304 ASSERT_EQ(ERROR_SUCCESS, |
| 305 RegKey(root, key_path.c_str(), | 305 RegKey(root, key_path.c_str(), |
| 306 KEY_SET_VALUE).WriteValue(value_name, value)); | 306 KEY_SET_VALUE).WriteValue(value_name, value)); |
| 307 EXPECT_TRUE(InstallUtil::DeleteRegistryValueIf( | 307 EXPECT_TRUE(InstallUtil::DeleteRegistryValueIf( |
| 308 root, key_path.c_str(), value_name, pred)); | 308 root, key_path.c_str(), value_name, pred)); |
| 309 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 309 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
| 310 EXPECT_FALSE(RegKey(root, key_path.c_str(), | 310 EXPECT_FALSE(RegKey(root, key_path.c_str(), |
| 311 KEY_QUERY_VALUE).ValueExists(value_name)); | 311 KEY_QUERY_VALUE).HasValue(value_name)); |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 | 314 |
| 315 { | 315 { |
| 316 RegistryOverrideManager override_manager; | 316 RegistryOverrideManager override_manager; |
| 317 override_manager.OverrideRegistry(root, L"root_key"); | 317 override_manager.OverrideRegistry(root, L"root_key"); |
| 318 // Default value matches: delete. | 318 // Default value matches: delete. |
| 319 { | 319 { |
| 320 MockRegistryValuePredicate pred; | 320 MockRegistryValuePredicate pred; |
| 321 | 321 |
| 322 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); | 322 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); |
| 323 ASSERT_EQ(ERROR_SUCCESS, | 323 ASSERT_EQ(ERROR_SUCCESS, |
| 324 RegKey(root, key_path.c_str(), | 324 RegKey(root, key_path.c_str(), |
| 325 KEY_SET_VALUE).WriteValue(L"", value)); | 325 KEY_SET_VALUE).WriteValue(L"", value)); |
| 326 EXPECT_TRUE(InstallUtil::DeleteRegistryValueIf( | 326 EXPECT_TRUE(InstallUtil::DeleteRegistryValueIf( |
| 327 root, key_path.c_str(), L"", pred)); | 327 root, key_path.c_str(), L"", pred)); |
| 328 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 328 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
| 329 EXPECT_FALSE(RegKey(root, key_path.c_str(), | 329 EXPECT_FALSE(RegKey(root, key_path.c_str(), |
| 330 KEY_QUERY_VALUE).ValueExists(L"")); | 330 KEY_QUERY_VALUE).HasValue(L"")); |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 | 334 |
| 335 TEST_F(InstallUtilTest, ValueEquals) { | 335 TEST_F(InstallUtilTest, ValueEquals) { |
| 336 InstallUtil::ValueEquals pred(L"howdy"); | 336 InstallUtil::ValueEquals pred(L"howdy"); |
| 337 | 337 |
| 338 EXPECT_FALSE(pred.Evaluate(L"")); | 338 EXPECT_FALSE(pred.Evaluate(L"")); |
| 339 EXPECT_FALSE(pred.Evaluate(L"Howdy")); | 339 EXPECT_FALSE(pred.Evaluate(L"Howdy")); |
| 340 EXPECT_FALSE(pred.Evaluate(L"howdy!")); | 340 EXPECT_FALSE(pred.Evaluate(L"howdy!")); |
| 341 EXPECT_FALSE(pred.Evaluate(L"!howdy")); | 341 EXPECT_FALSE(pred.Evaluate(L"!howdy")); |
| 342 EXPECT_TRUE(pred.Evaluate(L"howdy")); | 342 EXPECT_TRUE(pred.Evaluate(L"howdy")); |
| 343 } | 343 } |
| OLD | NEW |