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

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

Issue 271099: Re-try r29078: Remove some deprecated file_util wstring functions. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // Simple function to dump some text into a new file. 54 // Simple function to dump some text into a new file.
55 void CreateTextFile(const std::wstring& filename, 55 void CreateTextFile(const std::wstring& filename,
56 const std::wstring& contents) { 56 const std::wstring& contents) {
57 std::ofstream file; 57 std::ofstream file;
58 file.open(filename.c_str()); 58 file.open(filename.c_str());
59 ASSERT_TRUE(file.is_open()); 59 ASSERT_TRUE(file.is_open());
60 file << contents; 60 file << contents;
61 file.close(); 61 file.close();
62 } 62 }
63 63
64 bool IsFileInUse(const std::wstring& path) { 64 bool IsFileInUse(const FilePath& path) {
65 if (!file_util::PathExists(path)) 65 if (!file_util::PathExists(path))
66 return false; 66 return false;
67 67
68 HANDLE handle = ::CreateFile(path.c_str(), FILE_ALL_ACCESS, 68 HANDLE handle = ::CreateFile(path.value().c_str(), FILE_ALL_ACCESS,
69 NULL, NULL, OPEN_EXISTING, NULL, NULL); 69 NULL, NULL, OPEN_EXISTING, NULL, NULL);
70 if (handle == INVALID_HANDLE_VALUE) 70 if (handle == INVALID_HANDLE_VALUE)
71 return true; 71 return true;
72 72
73 CloseHandle(handle); 73 CloseHandle(handle);
74 return false; 74 return false;
75 } 75 }
76 76
77 // Simple function to read text from a file. 77 // Simple function to read text from a file.
78 std::wstring ReadTextFile(const std::wstring& filename) { 78 std::wstring ReadTextFile(const std::wstring& filename) {
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 // make sure the handle is closed. 471 // make sure the handle is closed.
472 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); 472 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0);
473 CloseHandle(pi.hProcess); 473 CloseHandle(pi.hProcess);
474 CloseHandle(pi.hThread); 474 CloseHandle(pi.hThread);
475 475
476 // Now the process has terminated, lets try overwriting the file again 476 // Now the process has terminated, lets try overwriting the file again
477 work_item.reset(WorkItem::CreateCopyTreeWorkItem( 477 work_item.reset(WorkItem::CreateCopyTreeWorkItem(
478 file_name_from.ToWStringHack(), file_name_to.ToWStringHack(), 478 file_name_from.ToWStringHack(), file_name_to.ToWStringHack(),
479 temp_dir_.ToWStringHack(), WorkItem::NEW_NAME_IF_IN_USE, 479 temp_dir_.ToWStringHack(), WorkItem::NEW_NAME_IF_IN_USE,
480 alternate_to.ToWStringHack())); 480 alternate_to.ToWStringHack()));
481 if (IsFileInUse(file_name_to.value())) 481 if (IsFileInUse(file_name_to))
482 PlatformThread::Sleep(2000); 482 PlatformThread::Sleep(2000);
483 // If file is still in use, the rest of the test will fail. 483 // If file is still in use, the rest of the test will fail.
484 ASSERT_FALSE(IsFileInUse(file_name_to.value())); 484 ASSERT_FALSE(IsFileInUse(file_name_to));
485 EXPECT_TRUE(work_item->Do()); 485 EXPECT_TRUE(work_item->Do());
486 486
487 EXPECT_TRUE(file_util::PathExists(file_name_from)); 487 EXPECT_TRUE(file_util::PathExists(file_name_from));
488 EXPECT_TRUE(file_util::PathExists(file_name_to)); 488 EXPECT_TRUE(file_util::PathExists(file_name_to));
489 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 489 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
490 EXPECT_TRUE(file_util::ContentsEqual(file_name_from, file_name_to)); 490 EXPECT_TRUE(file_util::ContentsEqual(file_name_from, file_name_to));
491 // verify that the backup path does exist 491 // verify that the backup path does exist
492 EXPECT_TRUE(file_util::PathExists(backup_file)); 492 EXPECT_TRUE(file_util::PathExists(backup_file));
493 EXPECT_FALSE(file_util::PathExists(alternate_to)); 493 EXPECT_FALSE(file_util::PathExists(alternate_to));
494 494
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 EXPECT_TRUE(file_util::ContentsEqual(file_name_from_1, file_name_to_1)); 705 EXPECT_TRUE(file_util::ContentsEqual(file_name_from_1, file_name_to_1));
706 706
707 FilePath file_name_to_2(dir_name_to); 707 FilePath file_name_to_2(dir_name_to);
708 file_name_to_2 = file_name_to_2.AppendASCII("2"); 708 file_name_to_2 = file_name_to_2.AppendASCII("2");
709 file_name_to_2 = file_name_to_2.AppendASCII("File_2.txt"); 709 file_name_to_2 = file_name_to_2.AppendASCII("File_2.txt");
710 EXPECT_TRUE(file_util::PathExists(file_name_to_2)); 710 EXPECT_TRUE(file_util::PathExists(file_name_to_2));
711 LOG(INFO) << "compare " 711 LOG(INFO) << "compare "
712 << file_name_from_2.value() << " and " << file_name_to_2.value(); 712 << file_name_from_2.value() << " and " << file_name_to_2.value();
713 EXPECT_TRUE(file_util::ContentsEqual(file_name_from_2, file_name_to_2)); 713 EXPECT_TRUE(file_util::ContentsEqual(file_name_from_2, file_name_to_2));
714 } 714 }
OLDNEW
« no previous file with comments | « chrome/installer/util/copy_tree_work_item.cc ('k') | chrome/installer/util/delete_after_reboot_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698