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

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: sync'd to ToT again 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
« no previous file with comments | « chrome/installer/util/registry_key_backup.cc ('k') | chrome/installer/util/registry_test_data.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..db33aa4af2f7d724f922e7772dd5ad5d097ec502
--- /dev/null
+++ b/chrome/installer/util/registry_key_backup_unittest.cc
@@ -0,0 +1,85 @@
+// 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/registry_test_data.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 void TearDownTestCase() {
+ logging::CloseLogFile();
+ }
+
+ virtual void SetUp() {
+ ASSERT_TRUE(test_data_.Initialize(HKEY_CURRENT_USER, L"SOFTWARE\\TmpTmp"));
+ destination_path_.assign(test_data_.base_path()).append(L"\\Destination");
+ }
+
+ RegistryTestData test_data_;
+ std::wstring destination_path_;
+};
+
+// Test that writing an uninitialized backup does nothing.
+TEST_F(RegistryKeyBackupTest, Uninitialized) {
+ RegistryKeyBackup backup;
+
+ EXPECT_TRUE(backup.WriteTo(test_data_.root_key(), destination_path_.c_str()));
+ EXPECT_FALSE(RegKey(test_data_.root_key(), destination_path_.c_str(),
+ KEY_READ).Valid());
+}
+
+// Test that initializing a backup with a non-existent key works, and that
+// writing it back out does nothing.
+TEST_F(RegistryKeyBackupTest, MissingKey) {
+ std::wstring non_existent_key_path(test_data_.base_path() + L"\\NoKeyHere");
+ RegistryKeyBackup backup;
+
+ EXPECT_TRUE(backup.Initialize(test_data_.root_key(),
+ non_existent_key_path.c_str()));
+ EXPECT_TRUE(backup.WriteTo(test_data_.root_key(), destination_path_.c_str()));
+ EXPECT_FALSE(RegKey(test_data_.root_key(), destination_path_.c_str(),
+ KEY_READ).Valid());
+}
+
+// Test that reading some data then writing it out does the right thing.
+TEST_F(RegistryKeyBackupTest, ReadWrite) {
+ RegistryKeyBackup backup;
+
+ EXPECT_TRUE(backup.Initialize(test_data_.root_key(),
+ test_data_.non_empty_key_path().c_str()));
+ EXPECT_TRUE(backup.WriteTo(test_data_.root_key(), destination_path_.c_str()));
+ test_data_.ExpectMatchesNonEmptyKey(test_data_.root_key(),
+ destination_path_.c_str());
+}
+
+// Test that reading some data, swapping, then writing it out does the right
+// thing.
+TEST_F(RegistryKeyBackupTest, Swap) {
+ RegistryKeyBackup backup;
+ RegistryKeyBackup other_backup;
+
+ EXPECT_TRUE(backup.Initialize(test_data_.root_key(),
+ test_data_.non_empty_key_path().c_str()));
+ backup.swap(other_backup);
+ EXPECT_TRUE(other_backup.WriteTo(test_data_.root_key(),
+ destination_path_.c_str()));
+
+ // Now make sure the one we started with is truly empty.
+ EXPECT_EQ(ERROR_SUCCESS,
+ RegKey(test_data_.root_key(), L"", KEY_QUERY_VALUE)
+ .DeleteKey(destination_path_.c_str()));
+ EXPECT_TRUE(backup.WriteTo(test_data_.root_key(),
+ destination_path_.c_str()));
+ EXPECT_FALSE(RegKey(test_data_.root_key(), destination_path_.c_str(),
+ KEY_READ).Valid());
+}
« no previous file with comments | « chrome/installer/util/registry_key_backup.cc ('k') | chrome/installer/util/registry_test_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698