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 10 matching lines...) Expand all Loading... |
21 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 21 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
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 base::CreateDirectory(parent_dir); |
32 ASSERT_TRUE(base::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(base::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(base::PathExists(top_dir_to_create)); | 51 EXPECT_FALSE(base::PathExists(top_dir_to_create)); |
52 EXPECT_TRUE(base::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 base::CreateDirectory(dir_to_create); |
59 ASSERT_TRUE(base::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(base::PathExists(dir_to_create)); | 66 EXPECT_TRUE(base::PathExists(dir_to_create)); |
67 | 67 |
68 work_item->Rollback(); | 68 work_item->Rollback(); |
(...skipping 16 matching lines...) Expand all Loading... |
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(base::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 base::CreateDirectory(dir_to_create_4); |
96 ASSERT_TRUE(base::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(base::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(base::PathExists(dir_to_create_2)); | 104 EXPECT_TRUE(base::PathExists(dir_to_create_2)); |
105 EXPECT_TRUE(base::PathExists(dir_to_create_4)); | 105 EXPECT_TRUE(base::PathExists(dir_to_create_4)); |
(...skipping 18 matching lines...) Expand all Loading... |
124 | 124 |
125 RemoveDirectory(dir_to_create_3.value().c_str()); | 125 RemoveDirectory(dir_to_create_3.value().c_str()); |
126 ASSERT_FALSE(base::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(base::PathExists(dir_to_create_1)); | 132 EXPECT_FALSE(base::PathExists(dir_to_create_1)); |
133 } | 133 } |
OLD | NEW |