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 "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 base::ScopedTempDir temp_dir_; | 24 base::ScopedTempDir temp_dir_; |
25 }; | 25 }; |
26 }; | 26 }; |
27 | 27 |
28 TEST_F(CreateDirWorkItemTest, CreatePath) { | 28 TEST_F(CreateDirWorkItemTest, CreatePath) { |
29 base::FilePath parent_dir(temp_dir_.path()); | 29 base::FilePath parent_dir(temp_dir_.path()); |
30 parent_dir = parent_dir.AppendASCII("a"); | 30 parent_dir = parent_dir.AppendASCII("a"); |
31 file_util::CreateDirectory(parent_dir); | 31 file_util::CreateDirectory(parent_dir); |
32 ASSERT_TRUE(file_util::PathExists(parent_dir)); | 32 ASSERT_TRUE(base::PathExists(parent_dir)); |
33 | 33 |
34 base::FilePath top_dir_to_create(parent_dir); | 34 base::FilePath top_dir_to_create(parent_dir); |
35 top_dir_to_create = top_dir_to_create.AppendASCII("b"); | 35 top_dir_to_create = top_dir_to_create.AppendASCII("b"); |
36 | 36 |
37 base::FilePath dir_to_create(top_dir_to_create); | 37 base::FilePath dir_to_create(top_dir_to_create); |
38 dir_to_create = dir_to_create.AppendASCII("c"); | 38 dir_to_create = dir_to_create.AppendASCII("c"); |
39 dir_to_create = dir_to_create.AppendASCII("d"); | 39 dir_to_create = dir_to_create.AppendASCII("d"); |
40 | 40 |
41 scoped_ptr<CreateDirWorkItem> work_item( | 41 scoped_ptr<CreateDirWorkItem> work_item( |
42 WorkItem::CreateCreateDirWorkItem(dir_to_create)); | 42 WorkItem::CreateCreateDirWorkItem(dir_to_create)); |
43 | 43 |
44 EXPECT_TRUE(work_item->Do()); | 44 EXPECT_TRUE(work_item->Do()); |
45 | 45 |
46 EXPECT_TRUE(file_util::PathExists(dir_to_create)); | 46 EXPECT_TRUE(base::PathExists(dir_to_create)); |
47 | 47 |
48 work_item->Rollback(); | 48 work_item->Rollback(); |
49 | 49 |
50 // Rollback should delete all the paths up to top_dir_to_create. | 50 // Rollback should delete all the paths up to top_dir_to_create. |
51 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); | 51 EXPECT_FALSE(base::PathExists(top_dir_to_create)); |
52 EXPECT_TRUE(file_util::PathExists(parent_dir)); | 52 EXPECT_TRUE(base::PathExists(parent_dir)); |
53 } | 53 } |
54 | 54 |
55 TEST_F(CreateDirWorkItemTest, CreateExistingPath) { | 55 TEST_F(CreateDirWorkItemTest, CreateExistingPath) { |
56 base::FilePath dir_to_create(temp_dir_.path()); | 56 base::FilePath dir_to_create(temp_dir_.path()); |
57 dir_to_create = dir_to_create.AppendASCII("aa"); | 57 dir_to_create = dir_to_create.AppendASCII("aa"); |
58 file_util::CreateDirectory(dir_to_create); | 58 file_util::CreateDirectory(dir_to_create); |
59 ASSERT_TRUE(file_util::PathExists(dir_to_create)); | 59 ASSERT_TRUE(base::PathExists(dir_to_create)); |
60 | 60 |
61 scoped_ptr<CreateDirWorkItem> work_item( | 61 scoped_ptr<CreateDirWorkItem> work_item( |
62 WorkItem::CreateCreateDirWorkItem(dir_to_create)); | 62 WorkItem::CreateCreateDirWorkItem(dir_to_create)); |
63 | 63 |
64 EXPECT_TRUE(work_item->Do()); | 64 EXPECT_TRUE(work_item->Do()); |
65 | 65 |
66 EXPECT_TRUE(file_util::PathExists(dir_to_create)); | 66 EXPECT_TRUE(base::PathExists(dir_to_create)); |
67 | 67 |
68 work_item->Rollback(); | 68 work_item->Rollback(); |
69 | 69 |
70 // Rollback should not remove the path since it exists before | 70 // Rollback should not remove the path since it exists before |
71 // the CreateDirWorkItem is called. | 71 // the CreateDirWorkItem is called. |
72 EXPECT_TRUE(file_util::PathExists(dir_to_create)); | 72 EXPECT_TRUE(base::PathExists(dir_to_create)); |
73 } | 73 } |
74 | 74 |
75 TEST_F(CreateDirWorkItemTest, CreateSharedPath) { | 75 TEST_F(CreateDirWorkItemTest, CreateSharedPath) { |
76 base::FilePath dir_to_create_1(temp_dir_.path()); | 76 base::FilePath dir_to_create_1(temp_dir_.path()); |
77 dir_to_create_1 = dir_to_create_1.AppendASCII("aaa"); | 77 dir_to_create_1 = dir_to_create_1.AppendASCII("aaa"); |
78 | 78 |
79 base::FilePath dir_to_create_2(dir_to_create_1); | 79 base::FilePath dir_to_create_2(dir_to_create_1); |
80 dir_to_create_2 = dir_to_create_2.AppendASCII("bbb"); | 80 dir_to_create_2 = dir_to_create_2.AppendASCII("bbb"); |
81 | 81 |
82 base::FilePath dir_to_create_3(dir_to_create_2); | 82 base::FilePath dir_to_create_3(dir_to_create_2); |
83 dir_to_create_3 = dir_to_create_3.AppendASCII("ccc"); | 83 dir_to_create_3 = dir_to_create_3.AppendASCII("ccc"); |
84 | 84 |
85 scoped_ptr<CreateDirWorkItem> work_item( | 85 scoped_ptr<CreateDirWorkItem> work_item( |
86 WorkItem::CreateCreateDirWorkItem(dir_to_create_3)); | 86 WorkItem::CreateCreateDirWorkItem(dir_to_create_3)); |
87 | 87 |
88 EXPECT_TRUE(work_item->Do()); | 88 EXPECT_TRUE(work_item->Do()); |
89 | 89 |
90 EXPECT_TRUE(file_util::PathExists(dir_to_create_3)); | 90 EXPECT_TRUE(base::PathExists(dir_to_create_3)); |
91 | 91 |
92 // Create another directory under dir_to_create_2 | 92 // Create another directory under dir_to_create_2 |
93 base::FilePath dir_to_create_4(dir_to_create_2); | 93 base::FilePath dir_to_create_4(dir_to_create_2); |
94 dir_to_create_4 = dir_to_create_4.AppendASCII("ddd"); | 94 dir_to_create_4 = dir_to_create_4.AppendASCII("ddd"); |
95 file_util::CreateDirectory(dir_to_create_4); | 95 file_util::CreateDirectory(dir_to_create_4); |
96 ASSERT_TRUE(file_util::PathExists(dir_to_create_4)); | 96 ASSERT_TRUE(base::PathExists(dir_to_create_4)); |
97 | 97 |
98 work_item->Rollback(); | 98 work_item->Rollback(); |
99 | 99 |
100 // Rollback should delete dir_to_create_3. | 100 // Rollback should delete dir_to_create_3. |
101 EXPECT_FALSE(file_util::PathExists(dir_to_create_3)); | 101 EXPECT_FALSE(base::PathExists(dir_to_create_3)); |
102 | 102 |
103 // Rollback should not delete dir_to_create_2 as it is shared. | 103 // Rollback should not delete dir_to_create_2 as it is shared. |
104 EXPECT_TRUE(file_util::PathExists(dir_to_create_2)); | 104 EXPECT_TRUE(base::PathExists(dir_to_create_2)); |
105 EXPECT_TRUE(file_util::PathExists(dir_to_create_4)); | 105 EXPECT_TRUE(base::PathExists(dir_to_create_4)); |
106 } | 106 } |
107 | 107 |
108 TEST_F(CreateDirWorkItemTest, RollbackWithMissingDir) { | 108 TEST_F(CreateDirWorkItemTest, RollbackWithMissingDir) { |
109 base::FilePath dir_to_create_1(temp_dir_.path()); | 109 base::FilePath dir_to_create_1(temp_dir_.path()); |
110 dir_to_create_1 = dir_to_create_1.AppendASCII("aaaa"); | 110 dir_to_create_1 = dir_to_create_1.AppendASCII("aaaa"); |
111 | 111 |
112 base::FilePath dir_to_create_2(dir_to_create_1); | 112 base::FilePath dir_to_create_2(dir_to_create_1); |
113 dir_to_create_2 = dir_to_create_2.AppendASCII("bbbb"); | 113 dir_to_create_2 = dir_to_create_2.AppendASCII("bbbb"); |
114 | 114 |
115 base::FilePath dir_to_create_3(dir_to_create_2); | 115 base::FilePath dir_to_create_3(dir_to_create_2); |
116 dir_to_create_3 = dir_to_create_3.AppendASCII("cccc"); | 116 dir_to_create_3 = dir_to_create_3.AppendASCII("cccc"); |
117 | 117 |
118 scoped_ptr<CreateDirWorkItem> work_item( | 118 scoped_ptr<CreateDirWorkItem> work_item( |
119 WorkItem::CreateCreateDirWorkItem(dir_to_create_3)); | 119 WorkItem::CreateCreateDirWorkItem(dir_to_create_3)); |
120 | 120 |
121 EXPECT_TRUE(work_item->Do()); | 121 EXPECT_TRUE(work_item->Do()); |
122 | 122 |
123 EXPECT_TRUE(file_util::PathExists(dir_to_create_3)); | 123 EXPECT_TRUE(base::PathExists(dir_to_create_3)); |
124 | 124 |
125 RemoveDirectory(dir_to_create_3.value().c_str()); | 125 RemoveDirectory(dir_to_create_3.value().c_str()); |
126 ASSERT_FALSE(file_util::PathExists(dir_to_create_3)); | 126 ASSERT_FALSE(base::PathExists(dir_to_create_3)); |
127 | 127 |
128 work_item->Rollback(); | 128 work_item->Rollback(); |
129 | 129 |
130 // dir_to_create_3 has already been deleted, Rollback should delete | 130 // dir_to_create_3 has already been deleted, Rollback should delete |
131 // the rest. | 131 // the rest. |
132 EXPECT_FALSE(file_util::PathExists(dir_to_create_1)); | 132 EXPECT_FALSE(base::PathExists(dir_to_create_1)); |
133 } | 133 } |
OLD | NEW |