OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 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 <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include <fstream> | 7 #include <fstream> |
8 #include <iostream> | 8 #include <iostream> |
9 | 9 |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 | 53 |
54 wchar_t text_content_1[] = L"delete me"; | 54 wchar_t text_content_1[] = L"delete me"; |
55 wchar_t text_content_2[] = L"delete me as well"; | 55 wchar_t text_content_2[] = L"delete me as well"; |
56 }; | 56 }; |
57 | 57 |
58 // Delete version directories. Everything lower than the given version | 58 // Delete version directories. Everything lower than the given version |
59 // should be deleted. | 59 // should be deleted. |
60 TEST_F(SetupHelperTest, Delete) { | 60 TEST_F(SetupHelperTest, Delete) { |
61 // Create a Chrome dir | 61 // Create a Chrome dir |
62 std::wstring chrome_dir(test_dir_.ToWStringHack()); | 62 FilePath chrome_dir(test_dir_); |
63 file_util::AppendToPath(&chrome_dir, L"chrome"); | 63 chrome_dir = chrome_dir.AppendASCII("chrome"); |
64 CreateDirectory(chrome_dir.c_str(), NULL); | 64 CreateDirectory(chrome_dir.value().c_str(), NULL); |
65 ASSERT_TRUE(file_util::PathExists(chrome_dir)); | 65 ASSERT_TRUE(file_util::PathExists(chrome_dir)); |
66 | 66 |
67 std::wstring chrome_dir_1(chrome_dir); | 67 FilePath chrome_dir_1(chrome_dir); |
68 file_util::AppendToPath(&chrome_dir_1, L"1.0.1.0"); | 68 chrome_dir_1 = chrome_dir_1.AppendASCII("1.0.1.0"); |
69 CreateDirectory(chrome_dir_1.c_str(), NULL); | 69 CreateDirectory(chrome_dir_1.value().c_str(), NULL); |
70 ASSERT_TRUE(file_util::PathExists(chrome_dir_1)); | 70 ASSERT_TRUE(file_util::PathExists(chrome_dir_1)); |
71 | 71 |
72 std::wstring chrome_dir_2(chrome_dir); | 72 FilePath chrome_dir_2(chrome_dir); |
73 file_util::AppendToPath(&chrome_dir_2, L"1.0.2.0"); | 73 chrome_dir_2 = chrome_dir_2.AppendASCII("1.0.2.0"); |
74 CreateDirectory(chrome_dir_2.c_str(), NULL); | 74 CreateDirectory(chrome_dir_2.value().c_str(), NULL); |
75 ASSERT_TRUE(file_util::PathExists(chrome_dir_2)); | 75 ASSERT_TRUE(file_util::PathExists(chrome_dir_2)); |
76 | 76 |
77 std::wstring chrome_dir_3(chrome_dir); | 77 FilePath chrome_dir_3(chrome_dir); |
78 file_util::AppendToPath(&chrome_dir_3, L"1.0.3.0"); | 78 chrome_dir_3 = chrome_dir_3.AppendASCII("1.0.3.0"); |
79 CreateDirectory(chrome_dir_3.c_str(), NULL); | 79 CreateDirectory(chrome_dir_3.value().c_str(), NULL); |
80 ASSERT_TRUE(file_util::PathExists(chrome_dir_3)); | 80 ASSERT_TRUE(file_util::PathExists(chrome_dir_3)); |
81 | 81 |
82 std::wstring chrome_dir_4(chrome_dir); | 82 FilePath chrome_dir_4(chrome_dir); |
83 file_util::AppendToPath(&chrome_dir_4, L"1.0.4.0"); | 83 chrome_dir_4 = chrome_dir_4.AppendASCII("1.0.4.0"); |
84 CreateDirectory(chrome_dir_4.c_str(), NULL); | 84 CreateDirectory(chrome_dir_4.value().c_str(), NULL); |
85 ASSERT_TRUE(file_util::PathExists(chrome_dir_4)); | 85 ASSERT_TRUE(file_util::PathExists(chrome_dir_4)); |
86 | 86 |
87 std::wstring chrome_dll_1(chrome_dir_1); | 87 FilePath chrome_dll_1(chrome_dir_1); |
88 file_util::AppendToPath(&chrome_dll_1, L"chrome.dll"); | 88 chrome_dll_1 = chrome_dll_1.AppendASCII("chrome.dll"); |
89 CreateTextFile(chrome_dll_1, text_content_1); | 89 CreateTextFile(chrome_dll_1.value(), text_content_1); |
90 ASSERT_TRUE(file_util::PathExists(chrome_dll_1)); | 90 ASSERT_TRUE(file_util::PathExists(chrome_dll_1)); |
91 | 91 |
92 std::wstring chrome_dll_2(chrome_dir_2); | 92 FilePath chrome_dll_2(chrome_dir_2); |
93 file_util::AppendToPath(&chrome_dll_2, L"chrome.dll"); | 93 chrome_dll_2 = chrome_dll_2.AppendASCII("chrome.dll"); |
94 CreateTextFile(chrome_dll_2, text_content_1); | 94 CreateTextFile(chrome_dll_2.value(), text_content_1); |
95 ASSERT_TRUE(file_util::PathExists(chrome_dll_2)); | 95 ASSERT_TRUE(file_util::PathExists(chrome_dll_2)); |
96 | 96 |
97 std::wstring chrome_dll_3(chrome_dir_3); | 97 FilePath chrome_dll_3(chrome_dir_3); |
98 file_util::AppendToPath(&chrome_dll_3, L"chrome.dll"); | 98 chrome_dll_3 = chrome_dll_3.AppendASCII("chrome.dll"); |
99 CreateTextFile(chrome_dll_3, text_content_1); | 99 CreateTextFile(chrome_dll_3.value(), text_content_1); |
100 ASSERT_TRUE(file_util::PathExists(chrome_dll_3)); | 100 ASSERT_TRUE(file_util::PathExists(chrome_dll_3)); |
101 | 101 |
102 std::wstring chrome_dll_4(chrome_dir_4); | 102 FilePath chrome_dll_4(chrome_dir_4); |
103 file_util::AppendToPath(&chrome_dll_4, L"chrome.dll"); | 103 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); |
104 CreateTextFile(chrome_dll_4, text_content_1); | 104 CreateTextFile(chrome_dll_4.value(), text_content_1); |
105 ASSERT_TRUE(file_util::PathExists(chrome_dll_4)); | 105 ASSERT_TRUE(file_util::PathExists(chrome_dll_4)); |
106 | 106 |
107 std::wstring latest_version(L"1.0.4.0"); | 107 std::wstring latest_version(L"1.0.4.0"); |
108 installer::RemoveOldVersionDirs(chrome_dir, latest_version); | 108 installer::RemoveOldVersionDirs(chrome_dir.value(), latest_version); |
109 | 109 |
110 // old versions should be gone | 110 // old versions should be gone |
111 EXPECT_FALSE(file_util::PathExists(chrome_dir_1)); | 111 EXPECT_FALSE(file_util::PathExists(chrome_dir_1)); |
112 EXPECT_FALSE(file_util::PathExists(chrome_dir_2)); | 112 EXPECT_FALSE(file_util::PathExists(chrome_dir_2)); |
113 EXPECT_FALSE(file_util::PathExists(chrome_dir_3)); | 113 EXPECT_FALSE(file_util::PathExists(chrome_dir_3)); |
114 // the latest version should stay | 114 // the latest version should stay |
115 EXPECT_TRUE(file_util::PathExists(chrome_dll_4)); | 115 EXPECT_TRUE(file_util::PathExists(chrome_dll_4)); |
116 } | 116 } |
117 | 117 |
118 // Delete older version directories, keeping the one in used intact. | 118 // Delete older version directories, keeping the one in used intact. |
119 TEST_F(SetupHelperTest, DeleteInUsed) { | 119 TEST_F(SetupHelperTest, DeleteInUsed) { |
120 // Create a Chrome dir | 120 // Create a Chrome dir |
121 std::wstring chrome_dir(test_dir_.ToWStringHack()); | 121 FilePath chrome_dir(test_dir_); |
122 file_util::AppendToPath(&chrome_dir, L"chrome"); | 122 chrome_dir = chrome_dir.AppendASCII("chrome"); |
123 CreateDirectory(chrome_dir.c_str(), NULL); | 123 CreateDirectory(chrome_dir.value().c_str(), NULL); |
124 ASSERT_TRUE(file_util::PathExists(chrome_dir)); | 124 ASSERT_TRUE(file_util::PathExists(chrome_dir)); |
125 | 125 |
126 std::wstring chrome_dir_1(chrome_dir); | 126 FilePath chrome_dir_1(chrome_dir); |
127 file_util::AppendToPath(&chrome_dir_1, L"1.0.1.0"); | 127 chrome_dir_1 = chrome_dir_1.AppendASCII("1.0.1.0"); |
128 CreateDirectory(chrome_dir_1.c_str(), NULL); | 128 CreateDirectory(chrome_dir_1.value().c_str(), NULL); |
129 ASSERT_TRUE(file_util::PathExists(chrome_dir_1)); | 129 ASSERT_TRUE(file_util::PathExists(chrome_dir_1)); |
130 | 130 |
131 std::wstring chrome_dir_2(chrome_dir); | 131 FilePath chrome_dir_2(chrome_dir); |
132 file_util::AppendToPath(&chrome_dir_2, L"1.0.2.0"); | 132 chrome_dir_2 = chrome_dir_2.AppendASCII("1.0.2.0"); |
133 CreateDirectory(chrome_dir_2.c_str(), NULL); | 133 CreateDirectory(chrome_dir_2.value().c_str(), NULL); |
134 ASSERT_TRUE(file_util::PathExists(chrome_dir_2)); | 134 ASSERT_TRUE(file_util::PathExists(chrome_dir_2)); |
135 | 135 |
136 std::wstring chrome_dir_3(chrome_dir); | 136 FilePath chrome_dir_3(chrome_dir); |
137 file_util::AppendToPath(&chrome_dir_3, L"1.0.3.0"); | 137 chrome_dir_3 = chrome_dir_3.AppendASCII("1.0.3.0"); |
138 CreateDirectory(chrome_dir_3.c_str(), NULL); | 138 CreateDirectory(chrome_dir_3.value().c_str(), NULL); |
139 ASSERT_TRUE(file_util::PathExists(chrome_dir_3)); | 139 ASSERT_TRUE(file_util::PathExists(chrome_dir_3)); |
140 | 140 |
141 std::wstring chrome_dir_4(chrome_dir); | 141 FilePath chrome_dir_4(chrome_dir); |
142 file_util::AppendToPath(&chrome_dir_4, L"1.0.4.0"); | 142 chrome_dir_4 = chrome_dir_4.AppendASCII("1.0.4.0"); |
143 CreateDirectory(chrome_dir_4.c_str(), NULL); | 143 CreateDirectory(chrome_dir_4.value().c_str(), NULL); |
144 ASSERT_TRUE(file_util::PathExists(chrome_dir_4)); | 144 ASSERT_TRUE(file_util::PathExists(chrome_dir_4)); |
145 | 145 |
146 std::wstring chrome_dll_1(chrome_dir_1); | 146 FilePath chrome_dll_1(chrome_dir_1); |
147 file_util::AppendToPath(&chrome_dll_1, L"chrome.dll"); | 147 chrome_dll_1 = chrome_dll_1.AppendASCII("chrome.dll"); |
148 CreateTextFile(chrome_dll_1, text_content_1); | 148 CreateTextFile(chrome_dll_1.value(), text_content_1); |
149 ASSERT_TRUE(file_util::PathExists(chrome_dll_1)); | 149 ASSERT_TRUE(file_util::PathExists(chrome_dll_1)); |
150 | 150 |
151 std::wstring chrome_dll_2(chrome_dir_2); | 151 FilePath chrome_dll_2(chrome_dir_2); |
152 file_util::AppendToPath(&chrome_dll_2, L"chrome.dll"); | 152 chrome_dll_2 = chrome_dll_2.AppendASCII("chrome.dll"); |
153 CreateTextFile(chrome_dll_2, text_content_1); | 153 CreateTextFile(chrome_dll_2.value(), text_content_1); |
154 ASSERT_TRUE(file_util::PathExists(chrome_dll_2)); | 154 ASSERT_TRUE(file_util::PathExists(chrome_dll_2)); |
155 | 155 |
156 // Open the file to make it in use. | 156 // Open the file to make it in use. |
157 std::ofstream file; | 157 std::ofstream file; |
158 file.open(chrome_dll_2.c_str()); | 158 file.open(chrome_dll_2.value().c_str()); |
159 | 159 |
160 std::wstring chrome_othera_2(chrome_dir_2); | 160 FilePath chrome_othera_2(chrome_dir_2); |
161 file_util::AppendToPath(&chrome_othera_2, L"othera.dll"); | 161 chrome_othera_2 = chrome_othera_2.AppendASCII("othera.dll"); |
162 CreateTextFile(chrome_othera_2, text_content_2); | 162 CreateTextFile(chrome_othera_2.value(), text_content_2); |
163 ASSERT_TRUE(file_util::PathExists(chrome_othera_2)); | 163 ASSERT_TRUE(file_util::PathExists(chrome_othera_2)); |
164 | 164 |
165 std::wstring chrome_otherb_2(chrome_dir_2); | 165 FilePath chrome_otherb_2(chrome_dir_2); |
166 file_util::AppendToPath(&chrome_otherb_2, L"otherb.dll"); | 166 chrome_otherb_2 = chrome_otherb_2.AppendASCII("otherb.dll"); |
167 CreateTextFile(chrome_otherb_2, text_content_2); | 167 CreateTextFile(chrome_otherb_2.value(), text_content_2); |
168 ASSERT_TRUE(file_util::PathExists(chrome_otherb_2)); | 168 ASSERT_TRUE(file_util::PathExists(chrome_otherb_2)); |
169 | 169 |
170 std::wstring chrome_dll_3(chrome_dir_3); | 170 FilePath chrome_dll_3(chrome_dir_3); |
171 file_util::AppendToPath(&chrome_dll_3, L"chrome.dll"); | 171 chrome_dll_3 = chrome_dll_3.AppendASCII("chrome.dll"); |
172 CreateTextFile(chrome_dll_3, text_content_1); | 172 CreateTextFile(chrome_dll_3.value(), text_content_1); |
173 ASSERT_TRUE(file_util::PathExists(chrome_dll_3)); | 173 ASSERT_TRUE(file_util::PathExists(chrome_dll_3)); |
174 | 174 |
175 std::wstring chrome_dll_4(chrome_dir_4); | 175 FilePath chrome_dll_4(chrome_dir_4); |
176 file_util::AppendToPath(&chrome_dll_4, L"chrome.dll"); | 176 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); |
177 CreateTextFile(chrome_dll_4, text_content_1); | 177 CreateTextFile(chrome_dll_4.value(), text_content_1); |
178 ASSERT_TRUE(file_util::PathExists(chrome_dll_4)); | 178 ASSERT_TRUE(file_util::PathExists(chrome_dll_4)); |
179 | 179 |
180 std::wstring latest_version(L"1.0.4.0"); | 180 std::wstring latest_version(L"1.0.4.0"); |
181 installer::RemoveOldVersionDirs(chrome_dir, latest_version); | 181 installer::RemoveOldVersionDirs(chrome_dir.value(), latest_version); |
182 | 182 |
183 // old versions not in used should be gone | 183 // old versions not in used should be gone |
184 EXPECT_FALSE(file_util::PathExists(chrome_dir_1)); | 184 EXPECT_FALSE(file_util::PathExists(chrome_dir_1)); |
185 EXPECT_FALSE(file_util::PathExists(chrome_dir_3)); | 185 EXPECT_FALSE(file_util::PathExists(chrome_dir_3)); |
186 // every thing under in used version should stay | 186 // every thing under in used version should stay |
187 EXPECT_TRUE(file_util::PathExists(chrome_dir_2)); | 187 EXPECT_TRUE(file_util::PathExists(chrome_dir_2)); |
188 EXPECT_TRUE(file_util::PathExists(chrome_dll_2)); | 188 EXPECT_TRUE(file_util::PathExists(chrome_dll_2)); |
189 EXPECT_TRUE(file_util::PathExists(chrome_othera_2)); | 189 EXPECT_TRUE(file_util::PathExists(chrome_othera_2)); |
190 EXPECT_TRUE(file_util::PathExists(chrome_otherb_2)); | 190 EXPECT_TRUE(file_util::PathExists(chrome_otherb_2)); |
191 // the latest version should stay | 191 // the latest version should stay |
192 EXPECT_TRUE(file_util::PathExists(chrome_dll_4)); | 192 EXPECT_TRUE(file_util::PathExists(chrome_dll_4)); |
193 } | 193 } |
OLD | NEW |