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

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

Issue 497083004: Change base/file_utils.h includes to base/files/file_utils.h in chrome/, part 2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@file_util
Patch Set: Created 6 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/threading/platform_thread.h" 16 #include "base/threading/platform_thread.h"
17 #include "chrome/installer/util/copy_tree_work_item.h" 17 #include "chrome/installer/util/copy_tree_work_item.h"
18 #include "chrome/installer/util/work_item.h" 18 #include "chrome/installer/util/work_item.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 namespace { 21 namespace {
22 class CopyTreeWorkItemTest : public testing::Test {
23 protected:
24 virtual void SetUp() {
25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
26 ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
27 }
28 22
29 virtual void TearDown() { 23 class CopyTreeWorkItemTest : public testing::Test {
30 logging::CloseLogFile(); 24 protected:
31 } 25 virtual void SetUp() {
32 26 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
33 // the path to temporary directory used to contain the test operations 27 ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
34 base::ScopedTempDir test_dir_;
35 base::ScopedTempDir temp_dir_;
36 };
37
38 // Simple function to dump some text into a new file.
39 void CreateTextFile(const std::wstring& filename,
40 const std::wstring& contents) {
41 std::ofstream file;
42 file.open(filename.c_str());
43 ASSERT_TRUE(file.is_open());
44 file << contents;
45 file.close();
46 } 28 }
47 29
48 bool IsFileInUse(const base::FilePath& path) { 30 virtual void TearDown() {
49 if (!base::PathExists(path)) 31 logging::CloseLogFile();
50 return false;
51
52 HANDLE handle = ::CreateFile(path.value().c_str(), FILE_ALL_ACCESS,
53 NULL, NULL, OPEN_EXISTING, NULL, NULL);
54 if (handle == INVALID_HANDLE_VALUE)
55 return true;
56
57 CloseHandle(handle);
58 return false;
59 } 32 }
60 33
61 // Simple function to read text from a file. 34 // the path to temporary directory used to contain the test operations
62 std::wstring ReadTextFile(const std::wstring& filename) { 35 base::ScopedTempDir test_dir_;
63 WCHAR contents[64]; 36 base::ScopedTempDir temp_dir_;
64 std::wifstream file; 37 };
65 file.open(filename.c_str());
66 EXPECT_TRUE(file.is_open());
67 file.getline(contents, 64);
68 file.close();
69 return std::wstring(contents);
70 }
71 38
72 wchar_t text_content_1[] = L"Gooooooooooooooooooooogle"; 39 // Simple function to dump some text into a new file.
73 wchar_t text_content_2[] = L"Overwrite Me"; 40 void CreateTextFile(const std::wstring& filename,
74 }; 41 const std::wstring& contents) {
42 std::ofstream file;
43 file.open(filename.c_str());
44 ASSERT_TRUE(file.is_open());
45 file << contents;
46 file.close();
47 }
48
49 bool IsFileInUse(const base::FilePath& path) {
50 if (!base::PathExists(path))
51 return false;
52
53 HANDLE handle = ::CreateFile(path.value().c_str(), FILE_ALL_ACCESS,
54 NULL, NULL, OPEN_EXISTING, NULL, NULL);
55 if (handle == INVALID_HANDLE_VALUE)
56 return true;
57
58 CloseHandle(handle);
59 return false;
60 }
61
62 // Simple function to read text from a file.
63 std::wstring ReadTextFile(const std::wstring& filename) {
64 WCHAR contents[64];
65 std::wifstream file;
66 file.open(filename.c_str());
67 EXPECT_TRUE(file.is_open());
68 file.getline(contents, 64);
69 file.close();
70 return std::wstring(contents);
71 }
72
73 const wchar_t text_content_1[] = L"Gooooooooooooooooooooogle";
74 const wchar_t text_content_2[] = L"Overwrite Me";
75
76 } // namespace
75 77
76 // Copy one file from source to destination. 78 // Copy one file from source to destination.
77 TEST_F(CopyTreeWorkItemTest, CopyFile) { 79 TEST_F(CopyTreeWorkItemTest, CopyFile) {
78 // Create source file 80 // Create source file
79 base::FilePath file_name_from(test_dir_.path()); 81 base::FilePath file_name_from(test_dir_.path());
80 file_name_from = file_name_from.AppendASCII("File_From.txt"); 82 file_name_from = file_name_from.AppendASCII("File_From.txt");
81 CreateTextFile(file_name_from.value(), text_content_1); 83 CreateTextFile(file_name_from.value(), text_content_1);
82 ASSERT_TRUE(base::PathExists(file_name_from)); 84 ASSERT_TRUE(base::PathExists(file_name_from));
83 85
84 // Create destination path 86 // Create destination path
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 EXPECT_TRUE(base::ContentsEqual(file_name_from_1, file_name_to_1)); 715 EXPECT_TRUE(base::ContentsEqual(file_name_from_1, file_name_to_1));
714 716
715 base::FilePath file_name_to_2(dir_name_to); 717 base::FilePath file_name_to_2(dir_name_to);
716 file_name_to_2 = file_name_to_2.AppendASCII("2"); 718 file_name_to_2 = file_name_to_2.AppendASCII("2");
717 file_name_to_2 = file_name_to_2.AppendASCII("File_2.txt"); 719 file_name_to_2 = file_name_to_2.AppendASCII("File_2.txt");
718 EXPECT_TRUE(base::PathExists(file_name_to_2)); 720 EXPECT_TRUE(base::PathExists(file_name_to_2));
719 VLOG(1) << "compare " << file_name_from_2.value() 721 VLOG(1) << "compare " << file_name_from_2.value()
720 << " and " << file_name_to_2.value(); 722 << " and " << file_name_to_2.value();
721 EXPECT_TRUE(base::ContentsEqual(file_name_from_2, file_name_to_2)); 723 EXPECT_TRUE(base::ContentsEqual(file_name_from_2, file_name_to_2));
722 } 724 }
OLDNEW
« no previous file with comments | « chrome/installer/util/copy_tree_work_item.cc ('k') | chrome/installer/util/create_dir_work_item.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698