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

Side by Side Diff: chrome/installer/util/product_unittest.cc

Issue 7669061: Tommi: I need an owner review for the chrome frame changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Making use of scoped cleanup where it helps Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
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 "chrome/installer/util/product_unittest.h" 5 #include "chrome/installer/util/product_unittest.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/test/test_reg_util_win.h"
8 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
9 #include "chrome/installer/util/chrome_frame_distribution.h" 10 #include "chrome/installer/util/chrome_frame_distribution.h"
10 #include "chrome/installer/util/google_update_constants.h" 11 #include "chrome/installer/util/google_update_constants.h"
11 #include "chrome/installer/util/installation_state.h" 12 #include "chrome/installer/util/installation_state.h"
12 #include "chrome/installer/util/installer_state.h" 13 #include "chrome/installer/util/installer_state.h"
13 #include "chrome/installer/util/master_preferences.h" 14 #include "chrome/installer/util/master_preferences.h"
14 #include "chrome/installer/util/product.h" 15 #include "chrome/installer/util/product.h"
15 16
16 using base::win::RegKey; 17 using base::win::RegKey;
17 using installer::Product; 18 using installer::Product;
18 using installer::MasterPreferences; 19 using installer::MasterPreferences;
20 using registry_util::ScopedRegistryKeyOverride;
19 21
20 void TestWithTempDir::SetUp() { 22 void TestWithTempDir::SetUp() {
21 // Name a subdirectory of the user temp directory. 23 // Name a subdirectory of the user temp directory.
22 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); 24 ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
23 } 25 }
24 26
25 void TestWithTempDir::TearDown() { 27 void TestWithTempDir::TearDown() {
26 logging::CloseLogFile(); 28 logging::CloseLogFile();
27 ASSERT_TRUE(test_dir_.Delete()); 29 ASSERT_TRUE(test_dir_.Delete());
28 } 30 }
29 31
30 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
31 33
32 void TestWithTempDirAndDeleteTempOverrideKeys::SetUp() { 34 void TestWithTempDirAndDeleteTempOverrideKeys::SetUp() {
33 TempRegKeyOverride::DeleteAllTempKeys(); 35 ScopedRegistryKeyOverride::DeleteAllTempKeys();
34 TestWithTempDir::SetUp(); 36 TestWithTempDir::SetUp();
35 } 37 }
36 38
37 void TestWithTempDirAndDeleteTempOverrideKeys::TearDown() { 39 void TestWithTempDirAndDeleteTempOverrideKeys::TearDown() {
38 TestWithTempDir::TearDown(); 40 TestWithTempDir::TearDown();
39 TempRegKeyOverride::DeleteAllTempKeys(); 41 ScopedRegistryKeyOverride::DeleteAllTempKeys();
40 }
41
42 ////////////////////////////////////////////////////////////////////////////////
43 const wchar_t TempRegKeyOverride::kTempTestKeyPath[] =
44 L"Software\\Chromium\\TempTestKeys";
45
46 TempRegKeyOverride::TempRegKeyOverride(HKEY override, const wchar_t* temp_name)
47 : override_(override), temp_name_(temp_name) {
48 DCHECK(temp_name && lstrlenW(temp_name));
49 std::wstring key_path(kTempTestKeyPath);
50 key_path += L"\\" + temp_name_;
51 EXPECT_EQ(ERROR_SUCCESS,
52 temp_key_.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_ALL_ACCESS));
53 EXPECT_EQ(ERROR_SUCCESS,
54 ::RegOverridePredefKey(override_, temp_key_.Handle()));
55 }
56
57 TempRegKeyOverride::~TempRegKeyOverride() {
58 ::RegOverridePredefKey(override_, NULL);
59 // The temp key will be deleted via a call to DeleteAllTempKeys().
60 }
61
62 // static
63 void TempRegKeyOverride::DeleteAllTempKeys() {
64 RegKey key;
65 if (key.Open(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS) == ERROR_SUCCESS) {
66 key.DeleteKey(kTempTestKeyPath);
67 }
68 } 42 }
69 43
70 //////////////////////////////////////////////////////////////////////////////// 44 ////////////////////////////////////////////////////////////////////////////////
71 45
72 class ProductTest : public TestWithTempDirAndDeleteTempOverrideKeys { 46 class ProductTest : public TestWithTempDirAndDeleteTempOverrideKeys {
73 protected: 47 protected:
74 }; 48 };
75 49
76 TEST_F(ProductTest, ProductInstallBasic) { 50 TEST_F(ProductTest, ProductInstallBasic) {
77 // TODO(tommi): We should mock this and use our mocked distribution. 51 // TODO(tommi): We should mock this and use our mocked distribution.
(...skipping 25 matching lines...) Expand all
103 EXPECT_EQ(std::wstring::npos, 77 EXPECT_EQ(std::wstring::npos,
104 user_data.value().find(program_files.value())); 78 user_data.value().find(program_files.value()));
105 79
106 // There should be no installed version in the registry. 80 // There should be no installed version in the registry.
107 machine_state.Initialize(); 81 machine_state.Initialize();
108 EXPECT_TRUE(machine_state.GetProductState( 82 EXPECT_TRUE(machine_state.GetProductState(
109 system_level, distribution->GetType()) == NULL); 83 system_level, distribution->GetType()) == NULL);
110 84
111 HKEY root = installer_state.root_key(); 85 HKEY root = installer_state.root_key();
112 { 86 {
113 TempRegKeyOverride override(root, L"root_pit"); 87 ScopedRegistryKeyOverride override(root, L"root_pit");
114 88
115 // Let's pretend chrome is installed. 89 // Let's pretend chrome is installed.
116 RegKey version_key(root, distribution->GetVersionKey().c_str(), 90 RegKey version_key(root, distribution->GetVersionKey().c_str(),
117 KEY_ALL_ACCESS); 91 KEY_ALL_ACCESS);
118 ASSERT_TRUE(version_key.Valid()); 92 ASSERT_TRUE(version_key.Valid());
119 93
120 const char kCurrentVersion[] = "1.2.3.4"; 94 const char kCurrentVersion[] = "1.2.3.4";
121 scoped_ptr<Version> current_version( 95 scoped_ptr<Version> current_version(
122 Version::GetVersionFromString(kCurrentVersion)); 96 Version::GetVersionFromString(kCurrentVersion));
123 version_key.WriteValue(google_update::kRegVersionField, 97 version_key.WriteValue(google_update::kRegVersionField,
(...skipping 24 matching lines...) Expand all
148 if (chrome_state != NULL) 122 if (chrome_state != NULL)
149 EXPECT_TRUE(chrome_state->is_msi()); 123 EXPECT_TRUE(chrome_state->is_msi());
150 } 124 }
151 } 125 }
152 126
153 TEST_F(ProductTest, LaunchChrome) { 127 TEST_F(ProductTest, LaunchChrome) {
154 // TODO(tommi): Test Product::LaunchChrome and 128 // TODO(tommi): Test Product::LaunchChrome and
155 // Product::LaunchChromeAndWait. 129 // Product::LaunchChromeAndWait.
156 LOG(ERROR) << "Test not implemented."; 130 LOG(ERROR) << "Test not implemented.";
157 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698