| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 ASSERT_TRUE(file_util::Delete(test_dir_, false)); | 30 ASSERT_TRUE(file_util::Delete(test_dir_, false)); |
| 31 ASSERT_FALSE(file_util::PathExists(test_dir_)); | 31 ASSERT_FALSE(file_util::PathExists(test_dir_)); |
| 32 } | 32 } |
| 33 | 33 |
| 34 // the path to temporary directory used to contain the test operations | 34 // the path to temporary directory used to contain the test operations |
| 35 FilePath test_dir_; | 35 FilePath test_dir_; |
| 36 }; | 36 }; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 TEST_F(CreateDirWorkItemTest, CreatePath) { | 39 TEST_F(CreateDirWorkItemTest, CreatePath) { |
| 40 std::wstring parent_dir(test_dir_.ToWStringHack()); | 40 FilePath parent_dir(test_dir_); |
| 41 file_util::AppendToPath(&parent_dir, L"a"); | 41 parent_dir = parent_dir.AppendASCII("a"); |
| 42 CreateDirectory(parent_dir.c_str(), NULL); | 42 CreateDirectory(parent_dir.value().c_str(), NULL); |
| 43 ASSERT_TRUE(file_util::PathExists(parent_dir)); | 43 ASSERT_TRUE(file_util::PathExists(parent_dir)); |
| 44 | 44 |
| 45 std::wstring top_dir_to_create(parent_dir); | 45 FilePath top_dir_to_create(parent_dir); |
| 46 file_util::AppendToPath(&top_dir_to_create, L"b"); | 46 top_dir_to_create = top_dir_to_create.AppendASCII("b"); |
| 47 | 47 |
| 48 std::wstring dir_to_create(top_dir_to_create); | 48 FilePath dir_to_create(top_dir_to_create); |
| 49 file_util::AppendToPath(&dir_to_create, L"c"); | 49 dir_to_create = dir_to_create.AppendASCII("c"); |
| 50 file_util::AppendToPath(&dir_to_create, L"d"); | 50 dir_to_create = dir_to_create.AppendASCII("d"); |
| 51 | 51 |
| 52 scoped_ptr<CreateDirWorkItem> work_item( | 52 scoped_ptr<CreateDirWorkItem> work_item( |
| 53 WorkItem::CreateCreateDirWorkItem(dir_to_create)); | 53 WorkItem::CreateCreateDirWorkItem(dir_to_create.ToWStringHack())); |
| 54 | 54 |
| 55 EXPECT_TRUE(work_item->Do()); | 55 EXPECT_TRUE(work_item->Do()); |
| 56 | 56 |
| 57 EXPECT_TRUE(file_util::PathExists(dir_to_create)); | 57 EXPECT_TRUE(file_util::PathExists(dir_to_create)); |
| 58 | 58 |
| 59 work_item->Rollback(); | 59 work_item->Rollback(); |
| 60 | 60 |
| 61 // Rollback should delete all the paths up to top_dir_to_create. | 61 // Rollback should delete all the paths up to top_dir_to_create. |
| 62 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); | 62 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); |
| 63 EXPECT_TRUE(file_util::PathExists(parent_dir)); | 63 EXPECT_TRUE(file_util::PathExists(parent_dir)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 TEST_F(CreateDirWorkItemTest, CreateExistingPath) { | 66 TEST_F(CreateDirWorkItemTest, CreateExistingPath) { |
| 67 std::wstring dir_to_create(test_dir_.ToWStringHack()); | 67 FilePath dir_to_create(test_dir_); |
| 68 file_util::AppendToPath(&dir_to_create, L"aa"); | 68 dir_to_create = dir_to_create.AppendASCII("aa"); |
| 69 CreateDirectory(dir_to_create.c_str(), NULL); | 69 CreateDirectory(dir_to_create.value().c_str(), NULL); |
| 70 ASSERT_TRUE(file_util::PathExists(dir_to_create)); | 70 ASSERT_TRUE(file_util::PathExists(dir_to_create)); |
| 71 | 71 |
| 72 scoped_ptr<CreateDirWorkItem> work_item( | 72 scoped_ptr<CreateDirWorkItem> work_item( |
| 73 WorkItem::CreateCreateDirWorkItem(dir_to_create)); | 73 WorkItem::CreateCreateDirWorkItem(dir_to_create.ToWStringHack())); |
| 74 | 74 |
| 75 EXPECT_TRUE(work_item->Do()); | 75 EXPECT_TRUE(work_item->Do()); |
| 76 | 76 |
| 77 EXPECT_TRUE(file_util::PathExists(dir_to_create)); | 77 EXPECT_TRUE(file_util::PathExists(dir_to_create)); |
| 78 | 78 |
| 79 work_item->Rollback(); | 79 work_item->Rollback(); |
| 80 | 80 |
| 81 // Rollback should not remove the path since it exists before | 81 // Rollback should not remove the path since it exists before |
| 82 // the CreateDirWorkItem is called. | 82 // the CreateDirWorkItem is called. |
| 83 EXPECT_TRUE(file_util::PathExists(dir_to_create)); | 83 EXPECT_TRUE(file_util::PathExists(dir_to_create)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 TEST_F(CreateDirWorkItemTest, CreateSharedPath) { | 86 TEST_F(CreateDirWorkItemTest, CreateSharedPath) { |
| 87 std::wstring dir_to_create_1(test_dir_.ToWStringHack()); | 87 FilePath dir_to_create_1(test_dir_); |
| 88 file_util::AppendToPath(&dir_to_create_1, L"aaa"); | 88 dir_to_create_1 = dir_to_create_1.AppendASCII("aaa"); |
| 89 | 89 |
| 90 std::wstring dir_to_create_2(dir_to_create_1); | 90 FilePath dir_to_create_2(dir_to_create_1); |
| 91 file_util::AppendToPath(&dir_to_create_2, L"bbb"); | 91 dir_to_create_2 = dir_to_create_2.AppendASCII("bbb"); |
| 92 | 92 |
| 93 std::wstring dir_to_create_3(dir_to_create_2); | 93 FilePath dir_to_create_3(dir_to_create_2); |
| 94 file_util::AppendToPath(&dir_to_create_3, L"ccc"); | 94 dir_to_create_3 = dir_to_create_3.AppendASCII("ccc"); |
| 95 | 95 |
| 96 scoped_ptr<CreateDirWorkItem> work_item( | 96 scoped_ptr<CreateDirWorkItem> work_item( |
| 97 WorkItem::CreateCreateDirWorkItem(dir_to_create_3)); | 97 WorkItem::CreateCreateDirWorkItem(dir_to_create_3.ToWStringHack())); |
| 98 | 98 |
| 99 EXPECT_TRUE(work_item->Do()); | 99 EXPECT_TRUE(work_item->Do()); |
| 100 | 100 |
| 101 EXPECT_TRUE(file_util::PathExists(dir_to_create_3)); | 101 EXPECT_TRUE(file_util::PathExists(dir_to_create_3)); |
| 102 | 102 |
| 103 // Create another directory under dir_to_create_2 | 103 // Create another directory under dir_to_create_2 |
| 104 std::wstring dir_to_create_4(dir_to_create_2); | 104 FilePath dir_to_create_4(dir_to_create_2); |
| 105 file_util::AppendToPath(&dir_to_create_4, L"ddd"); | 105 dir_to_create_4 = dir_to_create_4.AppendASCII("ddd"); |
| 106 CreateDirectory(dir_to_create_4.c_str(), NULL); | 106 CreateDirectory(dir_to_create_4.value().c_str(), NULL); |
| 107 ASSERT_TRUE(file_util::PathExists(dir_to_create_4)); | 107 ASSERT_TRUE(file_util::PathExists(dir_to_create_4)); |
| 108 | 108 |
| 109 work_item->Rollback(); | 109 work_item->Rollback(); |
| 110 | 110 |
| 111 // Rollback should delete dir_to_create_3. | 111 // Rollback should delete dir_to_create_3. |
| 112 EXPECT_FALSE(file_util::PathExists(dir_to_create_3)); | 112 EXPECT_FALSE(file_util::PathExists(dir_to_create_3)); |
| 113 | 113 |
| 114 // Rollback should not delete dir_to_create_2 as it is shared. | 114 // Rollback should not delete dir_to_create_2 as it is shared. |
| 115 EXPECT_TRUE(file_util::PathExists(dir_to_create_2)); | 115 EXPECT_TRUE(file_util::PathExists(dir_to_create_2)); |
| 116 EXPECT_TRUE(file_util::PathExists(dir_to_create_4)); | 116 EXPECT_TRUE(file_util::PathExists(dir_to_create_4)); |
| 117 } | 117 } |
| 118 | 118 |
| 119 TEST_F(CreateDirWorkItemTest, RollbackWithMissingDir) { | 119 TEST_F(CreateDirWorkItemTest, RollbackWithMissingDir) { |
| 120 std::wstring dir_to_create_1(test_dir_.ToWStringHack()); | 120 FilePath dir_to_create_1(test_dir_); |
| 121 file_util::AppendToPath(&dir_to_create_1, L"aaaa"); | 121 dir_to_create_1 = dir_to_create_1.AppendASCII("aaaa"); |
| 122 | 122 |
| 123 std::wstring dir_to_create_2(dir_to_create_1); | 123 FilePath dir_to_create_2(dir_to_create_1); |
| 124 file_util::AppendToPath(&dir_to_create_2, L"bbbb"); | 124 dir_to_create_2 = dir_to_create_2.AppendASCII("bbbb"); |
| 125 | 125 |
| 126 std::wstring dir_to_create_3(dir_to_create_2); | 126 FilePath dir_to_create_3(dir_to_create_2); |
| 127 file_util::AppendToPath(&dir_to_create_3, L"cccc"); | 127 dir_to_create_3 = dir_to_create_3.AppendASCII("cccc"); |
| 128 | 128 |
| 129 scoped_ptr<CreateDirWorkItem> work_item( | 129 scoped_ptr<CreateDirWorkItem> work_item( |
| 130 WorkItem::CreateCreateDirWorkItem(dir_to_create_3)); | 130 WorkItem::CreateCreateDirWorkItem(dir_to_create_3.ToWStringHack())); |
| 131 | 131 |
| 132 EXPECT_TRUE(work_item->Do()); | 132 EXPECT_TRUE(work_item->Do()); |
| 133 | 133 |
| 134 EXPECT_TRUE(file_util::PathExists(dir_to_create_3)); | 134 EXPECT_TRUE(file_util::PathExists(dir_to_create_3)); |
| 135 | 135 |
| 136 RemoveDirectory(dir_to_create_3.c_str()); | 136 RemoveDirectory(dir_to_create_3.value().c_str()); |
| 137 ASSERT_FALSE(file_util::PathExists(dir_to_create_3)); | 137 ASSERT_FALSE(file_util::PathExists(dir_to_create_3)); |
| 138 | 138 |
| 139 work_item->Rollback(); | 139 work_item->Rollback(); |
| 140 | 140 |
| 141 // dir_to_create_3 has already been deleted, Rollback should delete | 141 // dir_to_create_3 has already been deleted, Rollback should delete |
| 142 // the rest. | 142 // the rest. |
| 143 EXPECT_FALSE(file_util::PathExists(dir_to_create_1)); | 143 EXPECT_FALSE(file_util::PathExists(dir_to_create_1)); |
| 144 } | 144 } |
| OLD | NEW |