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

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

Issue 1878313003: Convert //chrome/installer from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert decompress.cc in mini_installer. Created 4 years, 8 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
« no previous file with comments | « chrome/installer/util/module_util_win.cc ('k') | chrome/installer/util/product.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/move_tree_work_item.h"
6
5 #include <windows.h> 7 #include <windows.h>
6 8
7 #include <fstream> 9 #include <fstream>
10 #include <memory>
8 11
9 #include "base/base_paths.h" 12 #include "base/base_paths.h"
10 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
11 #include "base/files/memory_mapped_file.h" 14 #include "base/files/memory_mapped_file.h"
12 #include "base/macros.h" 15 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/installer/util/installer_util_test_common.h" 18 #include "chrome/installer/util/installer_util_test_common.h"
17 #include "chrome/installer/util/move_tree_work_item.h"
18 #include "chrome/installer/util/work_item.h" 19 #include "chrome/installer/util/work_item.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace { 22 namespace {
22 class MoveTreeWorkItemTest : public testing::Test { 23 class MoveTreeWorkItemTest : public testing::Test {
23 protected: 24 protected:
24 void SetUp() override { 25 void SetUp() override {
25 ASSERT_TRUE(temp_from_dir_.CreateUniqueTempDir()); 26 ASSERT_TRUE(temp_from_dir_.CreateUniqueTempDir());
26 ASSERT_TRUE(temp_to_dir_.CreateUniqueTempDir()); 27 ASSERT_TRUE(temp_to_dir_.CreateUniqueTempDir());
27 } 28 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 base::FilePath to_dir(temp_from_dir_.path()); 79 base::FilePath to_dir(temp_from_dir_.path());
79 to_dir = to_dir.AppendASCII("To_Dir"); 80 to_dir = to_dir.AppendASCII("To_Dir");
80 ASSERT_FALSE(base::PathExists(to_dir)); 81 ASSERT_FALSE(base::PathExists(to_dir));
81 82
82 base::FilePath to_file(to_dir); 83 base::FilePath to_file(to_dir);
83 to_file = to_file.AppendASCII("From_Dir2"); 84 to_file = to_file.AppendASCII("From_Dir2");
84 to_file = to_file.AppendASCII("From_File"); 85 to_file = to_file.AppendASCII("From_File");
85 ASSERT_FALSE(base::PathExists(to_file)); 86 ASSERT_FALSE(base::PathExists(to_file));
86 87
87 // test Do() 88 // test Do()
88 scoped_ptr<MoveTreeWorkItem> work_item( 89 std::unique_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem(
89 WorkItem::CreateMoveTreeWorkItem(from_dir1, 90 from_dir1, to_dir, temp_to_dir_.path(), WorkItem::ALWAYS_MOVE));
90 to_dir,
91 temp_to_dir_.path(),
92 WorkItem::ALWAYS_MOVE));
93 EXPECT_TRUE(work_item->Do()); 91 EXPECT_TRUE(work_item->Do());
94 92
95 EXPECT_FALSE(base::PathExists(from_dir1)); 93 EXPECT_FALSE(base::PathExists(from_dir1));
96 EXPECT_TRUE(base::PathExists(to_dir)); 94 EXPECT_TRUE(base::PathExists(to_dir));
97 EXPECT_TRUE(base::PathExists(to_file)); 95 EXPECT_TRUE(base::PathExists(to_file));
98 96
99 // test rollback() 97 // test rollback()
100 work_item->Rollback(); 98 work_item->Rollback();
101 99
102 EXPECT_TRUE(base::PathExists(from_dir1)); 100 EXPECT_TRUE(base::PathExists(from_dir1));
(...skipping 30 matching lines...) Expand all
133 orig_to_file = orig_to_file.AppendASCII("To_File"); 131 orig_to_file = orig_to_file.AppendASCII("To_File");
134 CreateTextFile(orig_to_file.value(), kTextContent2); 132 CreateTextFile(orig_to_file.value(), kTextContent2);
135 ASSERT_TRUE(base::PathExists(orig_to_file)); 133 ASSERT_TRUE(base::PathExists(orig_to_file));
136 134
137 base::FilePath new_to_file(to_dir); 135 base::FilePath new_to_file(to_dir);
138 new_to_file = new_to_file.AppendASCII("From_Dir2"); 136 new_to_file = new_to_file.AppendASCII("From_Dir2");
139 new_to_file = new_to_file.AppendASCII("From_File"); 137 new_to_file = new_to_file.AppendASCII("From_File");
140 ASSERT_FALSE(base::PathExists(new_to_file)); 138 ASSERT_FALSE(base::PathExists(new_to_file));
141 139
142 // test Do(), don't check for duplicates. 140 // test Do(), don't check for duplicates.
143 scoped_ptr<MoveTreeWorkItem> work_item( 141 std::unique_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem(
144 WorkItem::CreateMoveTreeWorkItem(from_dir1, 142 from_dir1, to_dir, temp_to_dir_.path(), WorkItem::ALWAYS_MOVE));
145 to_dir,
146 temp_to_dir_.path(),
147 WorkItem::ALWAYS_MOVE));
148 EXPECT_TRUE(work_item->Do()); 143 EXPECT_TRUE(work_item->Do());
149 144
150 EXPECT_FALSE(base::PathExists(from_dir1)); 145 EXPECT_FALSE(base::PathExists(from_dir1));
151 EXPECT_TRUE(base::PathExists(to_dir)); 146 EXPECT_TRUE(base::PathExists(to_dir));
152 EXPECT_TRUE(base::PathExists(new_to_file)); 147 EXPECT_TRUE(base::PathExists(new_to_file));
153 EXPECT_FALSE(base::PathExists(orig_to_file)); 148 EXPECT_FALSE(base::PathExists(orig_to_file));
154 149
155 // test rollback() 150 // test rollback()
156 work_item->Rollback(); 151 work_item->Rollback();
157 152
(...skipping 18 matching lines...) Expand all
176 from_file = from_file.AppendASCII("From_File"); 171 from_file = from_file.AppendASCII("From_File");
177 CreateTextFile(from_file.value(), kTextContent1); 172 CreateTextFile(from_file.value(), kTextContent1);
178 ASSERT_TRUE(base::PathExists(from_file)); 173 ASSERT_TRUE(base::PathExists(from_file));
179 174
180 // Generate destination file name 175 // Generate destination file name
181 base::FilePath to_file(temp_from_dir_.path()); 176 base::FilePath to_file(temp_from_dir_.path());
182 to_file = to_file.AppendASCII("To_File"); 177 to_file = to_file.AppendASCII("To_File");
183 ASSERT_FALSE(base::PathExists(to_file)); 178 ASSERT_FALSE(base::PathExists(to_file));
184 179
185 // test Do() 180 // test Do()
186 scoped_ptr<MoveTreeWorkItem> work_item( 181 std::unique_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem(
187 WorkItem::CreateMoveTreeWorkItem(from_file, 182 from_file, to_file, temp_to_dir_.path(), WorkItem::ALWAYS_MOVE));
188 to_file,
189 temp_to_dir_.path(),
190 WorkItem::ALWAYS_MOVE));
191 EXPECT_TRUE(work_item->Do()); 183 EXPECT_TRUE(work_item->Do());
192 184
193 EXPECT_TRUE(base::PathExists(from_dir)); 185 EXPECT_TRUE(base::PathExists(from_dir));
194 EXPECT_FALSE(base::PathExists(from_file)); 186 EXPECT_FALSE(base::PathExists(from_file));
195 EXPECT_TRUE(base::PathExists(to_file)); 187 EXPECT_TRUE(base::PathExists(to_file));
196 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); 188 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1));
197 189
198 // test rollback() 190 // test rollback()
199 work_item->Rollback(); 191 work_item->Rollback();
200 192
(...skipping 22 matching lines...) Expand all
223 to_dir = to_dir.AppendASCII("To_Dir"); 215 to_dir = to_dir.AppendASCII("To_Dir");
224 base::CreateDirectory(to_dir); 216 base::CreateDirectory(to_dir);
225 ASSERT_TRUE(base::PathExists(to_dir)); 217 ASSERT_TRUE(base::PathExists(to_dir));
226 218
227 base::FilePath to_file(to_dir); 219 base::FilePath to_file(to_dir);
228 to_file = to_file.AppendASCII("To_File"); 220 to_file = to_file.AppendASCII("To_File");
229 CreateTextFile(to_file.value(), kTextContent2); 221 CreateTextFile(to_file.value(), kTextContent2);
230 ASSERT_TRUE(base::PathExists(to_file)); 222 ASSERT_TRUE(base::PathExists(to_file));
231 223
232 // test Do() 224 // test Do()
233 scoped_ptr<MoveTreeWorkItem> work_item( 225 std::unique_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem(
234 WorkItem::CreateMoveTreeWorkItem(from_file, 226 from_file, to_dir, temp_to_dir_.path(), WorkItem::ALWAYS_MOVE));
235 to_dir,
236 temp_to_dir_.path(),
237 WorkItem::ALWAYS_MOVE));
238 EXPECT_TRUE(work_item->Do()); 227 EXPECT_TRUE(work_item->Do());
239 228
240 EXPECT_TRUE(base::PathExists(from_dir)); 229 EXPECT_TRUE(base::PathExists(from_dir));
241 EXPECT_FALSE(base::PathExists(from_file)); 230 EXPECT_FALSE(base::PathExists(from_file));
242 EXPECT_TRUE(base::PathExists(to_dir)); 231 EXPECT_TRUE(base::PathExists(to_dir));
243 EXPECT_FALSE(base::PathExists(to_file)); 232 EXPECT_FALSE(base::PathExists(to_file));
244 EXPECT_EQ(0, ReadTextFile(to_dir).compare(kTextContent1)); 233 EXPECT_EQ(0, ReadTextFile(to_dir).compare(kTextContent1));
245 234
246 // test rollback() 235 // test rollback()
247 work_item->Rollback(); 236 work_item->Rollback();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // Run the executable in destination path 272 // Run the executable in destination path
284 STARTUPINFOW si = {sizeof(si)}; 273 STARTUPINFOW si = {sizeof(si)};
285 PROCESS_INFORMATION pi = {0}; 274 PROCESS_INFORMATION pi = {0};
286 ASSERT_TRUE(::CreateProcess(NULL, 275 ASSERT_TRUE(::CreateProcess(NULL,
287 const_cast<wchar_t*>(to_file.value().c_str()), 276 const_cast<wchar_t*>(to_file.value().c_str()),
288 NULL, NULL, FALSE, 277 NULL, NULL, FALSE,
289 CREATE_NO_WINDOW | CREATE_SUSPENDED, 278 CREATE_NO_WINDOW | CREATE_SUSPENDED,
290 NULL, NULL, &si, &pi)); 279 NULL, NULL, &si, &pi));
291 280
292 // test Do() 281 // test Do()
293 scoped_ptr<MoveTreeWorkItem> work_item( 282 std::unique_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem(
294 WorkItem::CreateMoveTreeWorkItem(from_file, 283 from_file, to_file, temp_to_dir_.path(), WorkItem::ALWAYS_MOVE));
295 to_file,
296 temp_to_dir_.path(),
297 WorkItem::ALWAYS_MOVE));
298 EXPECT_TRUE(work_item->Do()); 284 EXPECT_TRUE(work_item->Do());
299 285
300 EXPECT_TRUE(base::PathExists(from_dir)); 286 EXPECT_TRUE(base::PathExists(from_dir));
301 EXPECT_FALSE(base::PathExists(from_file)); 287 EXPECT_FALSE(base::PathExists(from_file));
302 EXPECT_TRUE(base::PathExists(to_dir)); 288 EXPECT_TRUE(base::PathExists(to_dir));
303 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); 289 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1));
304 290
305 // test rollback() 291 // test rollback()
306 work_item->Rollback(); 292 work_item->Rollback();
307 293
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 // Run the executable in source path 332 // Run the executable in source path
347 STARTUPINFOW si = {sizeof(si)}; 333 STARTUPINFOW si = {sizeof(si)};
348 PROCESS_INFORMATION pi = {0}; 334 PROCESS_INFORMATION pi = {0};
349 ASSERT_TRUE(::CreateProcess(NULL, 335 ASSERT_TRUE(::CreateProcess(NULL,
350 const_cast<wchar_t*>(from_file.value().c_str()), 336 const_cast<wchar_t*>(from_file.value().c_str()),
351 NULL, NULL, FALSE, 337 NULL, NULL, FALSE,
352 CREATE_NO_WINDOW | CREATE_SUSPENDED, 338 CREATE_NO_WINDOW | CREATE_SUSPENDED,
353 NULL, NULL, &si, &pi)); 339 NULL, NULL, &si, &pi));
354 340
355 // test Do() 341 // test Do()
356 scoped_ptr<MoveTreeWorkItem> work_item( 342 std::unique_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem(
357 WorkItem::CreateMoveTreeWorkItem(from_file, 343 from_file, to_file, temp_to_dir_.path(), WorkItem::ALWAYS_MOVE));
358 to_file,
359 temp_to_dir_.path(),
360 WorkItem::ALWAYS_MOVE));
361 EXPECT_TRUE(work_item->Do()); 344 EXPECT_TRUE(work_item->Do());
362 345
363 EXPECT_TRUE(base::PathExists(from_dir)); 346 EXPECT_TRUE(base::PathExists(from_dir));
364 EXPECT_FALSE(base::PathExists(from_file)); 347 EXPECT_FALSE(base::PathExists(from_file));
365 EXPECT_TRUE(base::PathExists(to_dir)); 348 EXPECT_TRUE(base::PathExists(to_dir));
366 EXPECT_TRUE(base::ContentsEqual(exe_full_path, to_file)); 349 EXPECT_TRUE(base::ContentsEqual(exe_full_path, to_file));
367 350
368 // Close the process and make sure all the conditions after Do() are 351 // Close the process and make sure all the conditions after Do() are
369 // still true. 352 // still true.
370 TerminateProcess(pi.hProcess, 0); 353 TerminateProcess(pi.hProcess, 0);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 to_dir = to_dir.AppendASCII("To_Dir"); 393 to_dir = to_dir.AppendASCII("To_Dir");
411 ASSERT_TRUE(installer::test::CopyFileHierarchy(from_dir1, to_dir)); 394 ASSERT_TRUE(installer::test::CopyFileHierarchy(from_dir1, to_dir));
412 395
413 // Lock one of the files in the to destination directory to prevent moves. 396 // Lock one of the files in the to destination directory to prevent moves.
414 base::FilePath orig_to_file( 397 base::FilePath orig_to_file(
415 to_dir.AppendASCII("From_Dir2").AppendASCII("From_File")); 398 to_dir.AppendASCII("From_Dir2").AppendASCII("From_File"));
416 base::MemoryMappedFile mapped_file; 399 base::MemoryMappedFile mapped_file;
417 EXPECT_TRUE(mapped_file.Initialize(orig_to_file)); 400 EXPECT_TRUE(mapped_file.Initialize(orig_to_file));
418 401
419 // First check that we can't do the regular Move(). 402 // First check that we can't do the regular Move().
420 scoped_ptr<MoveTreeWorkItem> work_item( 403 std::unique_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem(
421 WorkItem::CreateMoveTreeWorkItem(from_dir1, 404 from_dir1, to_dir, temp_to_dir_.path(), WorkItem::ALWAYS_MOVE));
422 to_dir,
423 temp_to_dir_.path(),
424 WorkItem::ALWAYS_MOVE));
425 EXPECT_FALSE(work_item->Do()); 405 EXPECT_FALSE(work_item->Do());
426 work_item->Rollback(); 406 work_item->Rollback();
427 407
428 // Now test Do() with the check for duplicates. This should pass. 408 // Now test Do() with the check for duplicates. This should pass.
429 work_item.reset( 409 work_item.reset(
430 WorkItem::CreateMoveTreeWorkItem(from_dir1, 410 WorkItem::CreateMoveTreeWorkItem(from_dir1,
431 to_dir, 411 to_dir,
432 temp_to_dir_.path(), 412 temp_to_dir_.path(),
433 WorkItem::CHECK_DUPLICATES)); 413 WorkItem::CHECK_DUPLICATES));
434 EXPECT_TRUE(work_item->Do()); 414 EXPECT_TRUE(work_item->Do());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 base::CreateDirectory(to_dir2); 475 base::CreateDirectory(to_dir2);
496 ASSERT_TRUE(base::PathExists(to_dir2)); 476 ASSERT_TRUE(base::PathExists(to_dir2));
497 477
498 // Create one of the files in the to sub-directory, but not the other. 478 // Create one of the files in the to sub-directory, but not the other.
499 base::FilePath orig_to_file(to_dir2); 479 base::FilePath orig_to_file(to_dir2);
500 orig_to_file = orig_to_file.AppendASCII("From_File"); 480 orig_to_file = orig_to_file.AppendASCII("From_File");
501 CreateTextFile(orig_to_file.value(), kTextContent1); 481 CreateTextFile(orig_to_file.value(), kTextContent1);
502 ASSERT_TRUE(base::PathExists(orig_to_file)); 482 ASSERT_TRUE(base::PathExists(orig_to_file));
503 483
504 // test Do(), check for duplicates. 484 // test Do(), check for duplicates.
505 scoped_ptr<MoveTreeWorkItem> work_item( 485 std::unique_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem(
506 WorkItem::CreateMoveTreeWorkItem(from_dir1, 486 from_dir1, to_dir, temp_to_dir_.path(), WorkItem::CHECK_DUPLICATES));
507 to_dir,
508 temp_to_dir_.path(),
509 WorkItem::CHECK_DUPLICATES));
510 EXPECT_TRUE(work_item->Do()); 487 EXPECT_TRUE(work_item->Do());
511 488
512 // Make sure that we "moved" the files, i.e. that the source directory isn't 489 // Make sure that we "moved" the files, i.e. that the source directory isn't
513 // there anymore, 490 // there anymore,
514 EXPECT_FALSE(base::PathExists(from_dir1)); 491 EXPECT_FALSE(base::PathExists(from_dir1));
515 // Make sure that the original directory structure and file are still present. 492 // Make sure that the original directory structure and file are still present.
516 EXPECT_TRUE(base::PathExists(to_dir)); 493 EXPECT_TRUE(base::PathExists(to_dir));
517 EXPECT_TRUE(base::PathExists(orig_to_file)); 494 EXPECT_TRUE(base::PathExists(orig_to_file));
518 // Make sure that the backup path is not empty. 495 // Make sure that the backup path is not empty.
519 EXPECT_FALSE(base::IsDirectoryEmpty(temp_to_dir_.path())); 496 EXPECT_FALSE(base::IsDirectoryEmpty(temp_to_dir_.path()));
(...skipping 14 matching lines...) Expand all
534 // the source files. 511 // the source files.
535 EXPECT_TRUE(base::PathExists(from_dir1)); 512 EXPECT_TRUE(base::PathExists(from_dir1));
536 EXPECT_TRUE(base::PathExists(to_dir)); 513 EXPECT_TRUE(base::PathExists(to_dir));
537 EXPECT_TRUE(base::PathExists(orig_to_file)); 514 EXPECT_TRUE(base::PathExists(orig_to_file));
538 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent1)); 515 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent1));
539 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); 516 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1));
540 517
541 // Also, after rollback the new "to" file should be gone. 518 // Also, after rollback the new "to" file should be gone.
542 EXPECT_FALSE(base::PathExists(new_to_file2)); 519 EXPECT_FALSE(base::PathExists(new_to_file2));
543 } 520 }
OLDNEW
« no previous file with comments | « chrome/installer/util/module_util_win.cc ('k') | chrome/installer/util/product.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698