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

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

Issue 6288009: More installer refactoring in the interest of fixing some bugs and cleaning t... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
« no previous file with comments | « chrome/installer/util/helper.cc ('k') | chrome/installer/util/install_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <windows.h>
6
7 #include <fstream>
8
9 #include "base/base_paths.h"
10 #include "base/file_util.h"
11 #include "base/path_service.h"
12 #include "base/process_util.h"
13 #include "base/string_util.h"
14 #include "base/version.h"
15 #include "chrome/installer/util/helper.h"
16 #include "chrome/installer/util/package.h"
17 #include "chrome/installer/util/package_properties.h"
18 #include "chrome/installer/util/work_item.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 using installer::ChromePackageProperties;
22 using installer::Package;
23
24 namespace {
25 class SetupHelperTest : public testing::Test {
26 protected:
27 virtual void SetUp() {
28 // Name a subdirectory of the user temp directory.
29 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
30 test_dir_ = test_dir_.AppendASCII("SetupHelperTest");
31
32 // Create a fresh, empty copy of this test directory.
33 file_util::Delete(test_dir_, true);
34 file_util::CreateDirectoryW(test_dir_);
35 ASSERT_TRUE(file_util::PathExists(test_dir_));
36 }
37
38 virtual void TearDown() {
39 logging::CloseLogFile();
40 // Clean up test directory
41 ASSERT_TRUE(file_util::Delete(test_dir_, true));
42 ASSERT_FALSE(file_util::PathExists(test_dir_));
43 }
44
45 // the path to temporary directory used to contain the test operations
46 FilePath test_dir_;
47 };
48
49 // Simple function to dump some text into a new file.
50 void CreateTextFile(const std::wstring& filename,
51 const std::wstring& contents) {
52 std::ofstream file;
53 file.open(filename.c_str());
54 ASSERT_TRUE(file.is_open());
55 file << contents;
56 file.close();
57 }
58
59 wchar_t text_content_1[] = L"delete me";
60 wchar_t text_content_2[] = L"delete me as well";
61 };
62
63 // Delete version directories. Everything lower than the given version
64 // should be deleted.
65 TEST_F(SetupHelperTest, Delete) {
66 // Create a Chrome dir
67 FilePath chrome_dir(test_dir_);
68 chrome_dir = chrome_dir.AppendASCII("chrome");
69 file_util::CreateDirectory(chrome_dir);
70 ASSERT_TRUE(file_util::PathExists(chrome_dir));
71
72 FilePath chrome_dir_1(chrome_dir);
73 chrome_dir_1 = chrome_dir_1.AppendASCII("1.0.1.0");
74 file_util::CreateDirectory(chrome_dir_1);
75 ASSERT_TRUE(file_util::PathExists(chrome_dir_1));
76
77 FilePath chrome_dir_2(chrome_dir);
78 chrome_dir_2 = chrome_dir_2.AppendASCII("1.0.2.0");
79 file_util::CreateDirectory(chrome_dir_2);
80 ASSERT_TRUE(file_util::PathExists(chrome_dir_2));
81
82 FilePath chrome_dir_3(chrome_dir);
83 chrome_dir_3 = chrome_dir_3.AppendASCII("1.0.3.0");
84 file_util::CreateDirectory(chrome_dir_3);
85 ASSERT_TRUE(file_util::PathExists(chrome_dir_3));
86
87 FilePath chrome_dir_4(chrome_dir);
88 chrome_dir_4 = chrome_dir_4.AppendASCII("1.0.4.0");
89 file_util::CreateDirectory(chrome_dir_4);
90 ASSERT_TRUE(file_util::PathExists(chrome_dir_4));
91
92 FilePath chrome_dll_1(chrome_dir_1);
93 chrome_dll_1 = chrome_dll_1.AppendASCII("chrome.dll");
94 CreateTextFile(chrome_dll_1.value(), text_content_1);
95 ASSERT_TRUE(file_util::PathExists(chrome_dll_1));
96
97 FilePath chrome_dll_2(chrome_dir_2);
98 chrome_dll_2 = chrome_dll_2.AppendASCII("chrome.dll");
99 CreateTextFile(chrome_dll_2.value(), text_content_1);
100 ASSERT_TRUE(file_util::PathExists(chrome_dll_2));
101
102 FilePath chrome_dll_3(chrome_dir_3);
103 chrome_dll_3 = chrome_dll_3.AppendASCII("chrome.dll");
104 CreateTextFile(chrome_dll_3.value(), text_content_1);
105 ASSERT_TRUE(file_util::PathExists(chrome_dll_3));
106
107 FilePath chrome_dll_4(chrome_dir_4);
108 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll");
109 CreateTextFile(chrome_dll_4.value(), text_content_1);
110 ASSERT_TRUE(file_util::PathExists(chrome_dll_4));
111
112 scoped_ptr<Version> latest_version(Version::GetVersionFromString("1.0.4.0"));
113 ChromePackageProperties properties;
114 scoped_refptr<Package> package(new Package(false, true, chrome_dir,
115 &properties));
116 package->RemoveOldVersionDirectories(*latest_version.get());
117
118 // old versions should be gone
119 EXPECT_FALSE(file_util::PathExists(chrome_dir_1));
120 EXPECT_FALSE(file_util::PathExists(chrome_dir_2));
121 EXPECT_FALSE(file_util::PathExists(chrome_dir_3));
122 // the latest version should stay
123 EXPECT_TRUE(file_util::PathExists(chrome_dll_4));
124 }
125
126 // Delete older version directories, keeping the one in used intact.
127 TEST_F(SetupHelperTest, DeleteInUsed) {
128 // Create a Chrome dir
129 FilePath chrome_dir(test_dir_);
130 chrome_dir = chrome_dir.AppendASCII("chrome");
131 file_util::CreateDirectory(chrome_dir);
132 ASSERT_TRUE(file_util::PathExists(chrome_dir));
133
134 FilePath chrome_dir_1(chrome_dir);
135 chrome_dir_1 = chrome_dir_1.AppendASCII("1.0.1.0");
136 file_util::CreateDirectory(chrome_dir_1);
137 ASSERT_TRUE(file_util::PathExists(chrome_dir_1));
138
139 FilePath chrome_dir_2(chrome_dir);
140 chrome_dir_2 = chrome_dir_2.AppendASCII("1.0.2.0");
141 file_util::CreateDirectory(chrome_dir_2);
142 ASSERT_TRUE(file_util::PathExists(chrome_dir_2));
143
144 FilePath chrome_dir_3(chrome_dir);
145 chrome_dir_3 = chrome_dir_3.AppendASCII("1.0.3.0");
146 file_util::CreateDirectory(chrome_dir_3);
147 ASSERT_TRUE(file_util::PathExists(chrome_dir_3));
148
149 FilePath chrome_dir_4(chrome_dir);
150 chrome_dir_4 = chrome_dir_4.AppendASCII("1.0.4.0");
151 file_util::CreateDirectory(chrome_dir_4);
152 ASSERT_TRUE(file_util::PathExists(chrome_dir_4));
153
154 FilePath chrome_dll_1(chrome_dir_1);
155 chrome_dll_1 = chrome_dll_1.AppendASCII("chrome.dll");
156 CreateTextFile(chrome_dll_1.value(), text_content_1);
157 ASSERT_TRUE(file_util::PathExists(chrome_dll_1));
158
159 FilePath chrome_dll_2(chrome_dir_2);
160 chrome_dll_2 = chrome_dll_2.AppendASCII("chrome.dll");
161 CreateTextFile(chrome_dll_2.value(), text_content_1);
162 ASSERT_TRUE(file_util::PathExists(chrome_dll_2));
163
164 // Open the file to make it in use.
165 std::ofstream file;
166 file.open(chrome_dll_2.value().c_str());
167
168 FilePath chrome_othera_2(chrome_dir_2);
169 chrome_othera_2 = chrome_othera_2.AppendASCII("othera.dll");
170 CreateTextFile(chrome_othera_2.value(), text_content_2);
171 ASSERT_TRUE(file_util::PathExists(chrome_othera_2));
172
173 FilePath chrome_otherb_2(chrome_dir_2);
174 chrome_otherb_2 = chrome_otherb_2.AppendASCII("otherb.dll");
175 CreateTextFile(chrome_otherb_2.value(), text_content_2);
176 ASSERT_TRUE(file_util::PathExists(chrome_otherb_2));
177
178 FilePath chrome_dll_3(chrome_dir_3);
179 chrome_dll_3 = chrome_dll_3.AppendASCII("chrome.dll");
180 CreateTextFile(chrome_dll_3.value(), text_content_1);
181 ASSERT_TRUE(file_util::PathExists(chrome_dll_3));
182
183 FilePath chrome_dll_4(chrome_dir_4);
184 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll");
185 CreateTextFile(chrome_dll_4.value(), text_content_1);
186 ASSERT_TRUE(file_util::PathExists(chrome_dll_4));
187
188 scoped_ptr<Version> latest_version(Version::GetVersionFromString("1.0.4.0"));
189 ChromePackageProperties properties;
190 scoped_refptr<Package> install_path(new Package(false, true, chrome_dir,
191 &properties));
192 install_path->RemoveOldVersionDirectories(*latest_version.get());
193
194 // old versions not in used should be gone
195 EXPECT_FALSE(file_util::PathExists(chrome_dir_1));
196 EXPECT_FALSE(file_util::PathExists(chrome_dir_3));
197 // every thing under in used version should stay
198 EXPECT_TRUE(file_util::PathExists(chrome_dir_2));
199 EXPECT_TRUE(file_util::PathExists(chrome_dll_2));
200 EXPECT_TRUE(file_util::PathExists(chrome_othera_2));
201 EXPECT_TRUE(file_util::PathExists(chrome_otherb_2));
202 // the latest version should stay
203 EXPECT_TRUE(file_util::PathExists(chrome_dll_4));
204 }
OLDNEW
« no previous file with comments | « chrome/installer/util/helper.cc ('k') | chrome/installer/util/install_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698