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

Unified Diff: chrome/installer/util/registry_key_backup_unittest.cc

Issue 7890069: Added CopyRegKeyWorkItem in support of IE low rights policy fixes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Ready for review Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/installer/util/registry_key_backup_unittest.cc
diff --git a/chrome/installer/util/registry_key_backup_unittest.cc b/chrome/installer/util/registry_key_backup_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..aa33c52a309add9d2ff4b8b3cbae8f1a8e52fc36
--- /dev/null
+++ b/chrome/installer/util/registry_key_backup_unittest.cc
@@ -0,0 +1,108 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <windows.h>
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/win/registry.h"
+#include "chrome/installer/util/registry_key_backup.h"
+#include "chrome/installer/util/work_item.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using base::win::RegKey;
+
+class RegistryKeyBackupTest : public testing::Test {
+ protected:
+ static const HKEY kRootKey;
+
+ static void SetUpTestCase() {
erikwright (departed) 2011/09/15 18:38:57 Same questions apply about SetUpTestCase vs. SetUp
grt (UTC plus 2) 2011/09/16 17:45:45 Done.
+ // Make some strings that we'll use.
+ temp_key_path_ = new std::wstring(L"SOFTWARE\\TmpTmp");
+ dest_key_path_ = new std::wstring(*temp_key_path_ + L"\\Destination");
+ non_empty_key_path_ = new std::wstring(*temp_key_path_ + L"\\NonEmptyKey");
+
+ // Put some data in the registry that the individual tests can use.
+ RegKey key;
+ ASSERT_EQ(ERROR_SUCCESS,
+ key.Create(kRootKey, non_empty_key_path_->c_str(), KEY_WRITE));
+ ASSERT_EQ(ERROR_SUCCESS,
+ key.WriteValue(NULL, non_empty_key_path_->c_str()));
+ ASSERT_EQ(ERROR_SUCCESS, key.CreateKey(L"Subkey", KEY_WRITE));
+ ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(L"SomeValue", 1U));
+ }
+
+ static void TearDownTestCase() {
+ // Clean up the temporary key
+ RegKey key(kRootKey, L"", KEY_QUERY_VALUE);
+ ASSERT_EQ(ERROR_SUCCESS, key.DeleteKey(temp_key_path_->c_str()));
+
+ delete temp_key_path_;
+ temp_key_path_ = NULL;
+ delete dest_key_path_;
+ dest_key_path_ = NULL;
+ delete non_empty_key_path_;
+ non_empty_key_path_ = NULL;
+
+ logging::CloseLogFile();
+ }
+
+ static std::wstring* temp_key_path_;
+ static std::wstring* dest_key_path_;
+ static std::wstring* non_empty_key_path_;
+};
+
+const HKEY RegistryKeyBackupTest::kRootKey = HKEY_CURRENT_USER;
+std::wstring* RegistryKeyBackupTest::temp_key_path_ = NULL;
+std::wstring* RegistryKeyBackupTest::dest_key_path_ = NULL;
+std::wstring* RegistryKeyBackupTest::non_empty_key_path_ = NULL;
+
+// Test that initialzing a backup with an invalid RegKey returns false.
+TEST_F(RegistryKeyBackupTest, InvalidKey) {
+ RegKey invalid;
+ RegistryKeyBackup backup;
+
+ ASSERT_FALSE(invalid.Valid()); // Santiy check.
+ EXPECT_FALSE(backup.Initialize(invalid));
+}
+
+// Test that writing an empty backup to the registry doesn't modify anything.
+TEST_F(RegistryKeyBackupTest, WriteEmptyBackup) {
+ RegKey dest;
+ RegistryKeyBackup backup;
+
+ // |backup| is empty, so writing must not modify the registry.
+ EXPECT_EQ(ERROR_SUCCESS,
+ dest.Create(kRootKey, dest_key_path_->c_str(),
+ KEY_READ | KEY_WRITE));
+ EXPECT_TRUE(backup.WriteTo(&dest));
+ DWORD num_subkeys = 0;
+ DWORD num_values = 0;
+ EXPECT_EQ(ERROR_SUCCESS,
+ RegQueryInfoKey(dest.Handle(), NULL, NULL, NULL, &num_subkeys,
+ NULL, NULL, &num_values, NULL, NULL, NULL, NULL));
+ EXPECT_EQ(0UL, num_subkeys);
+ EXPECT_EQ(0UL, num_values);
+}
+
+// Test that reading some data then writing it out does the right thing.
+TEST_F(RegistryKeyBackupTest, ReadWrite) {
+ RegKey key;
+ RegistryKeyBackup backup;
+
+ EXPECT_EQ(ERROR_SUCCESS,
+ key.Open(kRootKey, non_empty_key_path_->c_str(), KEY_READ));
+ EXPECT_TRUE(backup.Initialize(key));
+ EXPECT_EQ(ERROR_SUCCESS,
+ key.Create(kRootKey, dest_key_path_->c_str(),
+ KEY_READ | KEY_WRITE));
+ EXPECT_TRUE(backup.WriteTo(&key));
+ std::wstring str_value;
+ EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(NULL, &str_value));
+ EXPECT_EQ(*non_empty_key_path_, str_value);
+ EXPECT_EQ(ERROR_SUCCESS, key.OpenKey(L"Subkey", KEY_READ));
+ DWORD dw_value = 0;
+ EXPECT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"SomeValue", &dw_value));
+ EXPECT_EQ(1U, dw_value);
+}

Powered by Google App Engine
This is Rietveld 408576698