OLD | NEW |
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 <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include <fstream> | 7 #include <fstream> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 EXPECT_FALSE(base::PathExists(from_file)); | 301 EXPECT_FALSE(base::PathExists(from_file)); |
302 EXPECT_TRUE(base::PathExists(to_dir)); | 302 EXPECT_TRUE(base::PathExists(to_dir)); |
303 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); | 303 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); |
304 | 304 |
305 // test rollback() | 305 // test rollback() |
306 work_item->Rollback(); | 306 work_item->Rollback(); |
307 | 307 |
308 EXPECT_TRUE(base::PathExists(from_dir)); | 308 EXPECT_TRUE(base::PathExists(from_dir)); |
309 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); | 309 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); |
310 EXPECT_TRUE(base::PathExists(to_dir)); | 310 EXPECT_TRUE(base::PathExists(to_dir)); |
311 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, to_file)); | 311 EXPECT_TRUE(base::ContentsEqual(exe_full_path, to_file)); |
312 | 312 |
313 TerminateProcess(pi.hProcess, 0); | 313 TerminateProcess(pi.hProcess, 0); |
314 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); | 314 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); |
315 CloseHandle(pi.hProcess); | 315 CloseHandle(pi.hProcess); |
316 CloseHandle(pi.hThread); | 316 CloseHandle(pi.hThread); |
317 } | 317 } |
318 | 318 |
319 // Move one file that is in use to destination. | 319 // Move one file that is in use to destination. |
320 TEST_F(MoveTreeWorkItemTest, MoveFileInUse) { | 320 TEST_F(MoveTreeWorkItemTest, MoveFileInUse) { |
321 // Create an executable for source by copying ourself to a new source dir. | 321 // Create an executable for source by copying ourself to a new source dir. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 scoped_ptr<MoveTreeWorkItem> work_item( | 356 scoped_ptr<MoveTreeWorkItem> work_item( |
357 WorkItem::CreateMoveTreeWorkItem(from_file, | 357 WorkItem::CreateMoveTreeWorkItem(from_file, |
358 to_file, | 358 to_file, |
359 temp_to_dir_.path(), | 359 temp_to_dir_.path(), |
360 WorkItem::ALWAYS_MOVE)); | 360 WorkItem::ALWAYS_MOVE)); |
361 EXPECT_TRUE(work_item->Do()); | 361 EXPECT_TRUE(work_item->Do()); |
362 | 362 |
363 EXPECT_TRUE(base::PathExists(from_dir)); | 363 EXPECT_TRUE(base::PathExists(from_dir)); |
364 EXPECT_FALSE(base::PathExists(from_file)); | 364 EXPECT_FALSE(base::PathExists(from_file)); |
365 EXPECT_TRUE(base::PathExists(to_dir)); | 365 EXPECT_TRUE(base::PathExists(to_dir)); |
366 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, to_file)); | 366 EXPECT_TRUE(base::ContentsEqual(exe_full_path, to_file)); |
367 | 367 |
368 // Close the process and make sure all the conditions after Do() are | 368 // Close the process and make sure all the conditions after Do() are |
369 // still true. | 369 // still true. |
370 TerminateProcess(pi.hProcess, 0); | 370 TerminateProcess(pi.hProcess, 0); |
371 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); | 371 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); |
372 CloseHandle(pi.hProcess); | 372 CloseHandle(pi.hProcess); |
373 CloseHandle(pi.hThread); | 373 CloseHandle(pi.hThread); |
374 | 374 |
375 EXPECT_TRUE(base::PathExists(from_dir)); | 375 EXPECT_TRUE(base::PathExists(from_dir)); |
376 EXPECT_FALSE(base::PathExists(from_file)); | 376 EXPECT_FALSE(base::PathExists(from_file)); |
377 EXPECT_TRUE(base::PathExists(to_dir)); | 377 EXPECT_TRUE(base::PathExists(to_dir)); |
378 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, to_file)); | 378 EXPECT_TRUE(base::ContentsEqual(exe_full_path, to_file)); |
379 | 379 |
380 // test rollback() | 380 // test rollback() |
381 work_item->Rollback(); | 381 work_item->Rollback(); |
382 | 382 |
383 EXPECT_TRUE(base::PathExists(from_dir)); | 383 EXPECT_TRUE(base::PathExists(from_dir)); |
384 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, from_file)); | 384 EXPECT_TRUE(base::ContentsEqual(exe_full_path, from_file)); |
385 EXPECT_TRUE(base::PathExists(to_dir)); | 385 EXPECT_TRUE(base::PathExists(to_dir)); |
386 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); | 386 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); |
387 } | 387 } |
388 | 388 |
389 // Move one directory from source to destination when destination already | 389 // Move one directory from source to destination when destination already |
390 // exists. | 390 // exists. |
391 TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExistsCheckForDuplicatesFull) { | 391 TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExistsCheckForDuplicatesFull) { |
392 // Create two level deep source dir | 392 // Create two level deep source dir |
393 base::FilePath from_dir1(temp_from_dir_.path()); | 393 base::FilePath from_dir1(temp_from_dir_.path()); |
394 from_dir1 = from_dir1.AppendASCII("From_Dir1"); | 394 from_dir1 = from_dir1.AppendASCII("From_Dir1"); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 // the source files. | 534 // the source files. |
535 EXPECT_TRUE(base::PathExists(from_dir1)); | 535 EXPECT_TRUE(base::PathExists(from_dir1)); |
536 EXPECT_TRUE(base::PathExists(to_dir)); | 536 EXPECT_TRUE(base::PathExists(to_dir)); |
537 EXPECT_TRUE(base::PathExists(orig_to_file)); | 537 EXPECT_TRUE(base::PathExists(orig_to_file)); |
538 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent1)); | 538 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent1)); |
539 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); | 539 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); |
540 | 540 |
541 // Also, after rollback the new "to" file should be gone. | 541 // Also, after rollback the new "to" file should be gone. |
542 EXPECT_FALSE(base::PathExists(new_to_file2)); | 542 EXPECT_FALSE(base::PathExists(new_to_file2)); |
543 } | 543 } |
OLD | NEW |