| 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 <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/file_util.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 const wchar_t kTextContent2[] = L"Overwrite Me"; | 55 const wchar_t kTextContent2[] = L"Overwrite Me"; |
| 56 }; // namespace | 56 }; // namespace |
| 57 | 57 |
| 58 // Move one directory from source to destination when destination does not | 58 // Move one directory from source to destination when destination does not |
| 59 // exist. | 59 // exist. |
| 60 TEST_F(MoveTreeWorkItemTest, MoveDirectory) { | 60 TEST_F(MoveTreeWorkItemTest, MoveDirectory) { |
| 61 // Create two level deep source dir | 61 // Create two level deep source dir |
| 62 base::FilePath from_dir1(temp_from_dir_.path()); | 62 base::FilePath from_dir1(temp_from_dir_.path()); |
| 63 from_dir1 = from_dir1.AppendASCII("From_Dir1"); | 63 from_dir1 = from_dir1.AppendASCII("From_Dir1"); |
| 64 file_util::CreateDirectory(from_dir1); | 64 file_util::CreateDirectory(from_dir1); |
| 65 ASSERT_TRUE(file_util::PathExists(from_dir1)); | 65 ASSERT_TRUE(base::PathExists(from_dir1)); |
| 66 | 66 |
| 67 base::FilePath from_dir2(from_dir1); | 67 base::FilePath from_dir2(from_dir1); |
| 68 from_dir2 = from_dir2.AppendASCII("From_Dir2"); | 68 from_dir2 = from_dir2.AppendASCII("From_Dir2"); |
| 69 file_util::CreateDirectory(from_dir2); | 69 file_util::CreateDirectory(from_dir2); |
| 70 ASSERT_TRUE(file_util::PathExists(from_dir2)); | 70 ASSERT_TRUE(base::PathExists(from_dir2)); |
| 71 | 71 |
| 72 base::FilePath from_file(from_dir2); | 72 base::FilePath from_file(from_dir2); |
| 73 from_file = from_file.AppendASCII("From_File"); | 73 from_file = from_file.AppendASCII("From_File"); |
| 74 CreateTextFile(from_file.value(), kTextContent1); | 74 CreateTextFile(from_file.value(), kTextContent1); |
| 75 ASSERT_TRUE(file_util::PathExists(from_file)); | 75 ASSERT_TRUE(base::PathExists(from_file)); |
| 76 | 76 |
| 77 // Generate destination path | 77 // Generate destination path |
| 78 base::FilePath to_dir(temp_from_dir_.path()); | 78 base::FilePath to_dir(temp_from_dir_.path()); |
| 79 to_dir = to_dir.AppendASCII("To_Dir"); | 79 to_dir = to_dir.AppendASCII("To_Dir"); |
| 80 ASSERT_FALSE(file_util::PathExists(to_dir)); | 80 ASSERT_FALSE(base::PathExists(to_dir)); |
| 81 | 81 |
| 82 base::FilePath to_file(to_dir); | 82 base::FilePath to_file(to_dir); |
| 83 to_file = to_file.AppendASCII("From_Dir2"); | 83 to_file = to_file.AppendASCII("From_Dir2"); |
| 84 to_file = to_file.AppendASCII("From_File"); | 84 to_file = to_file.AppendASCII("From_File"); |
| 85 ASSERT_FALSE(file_util::PathExists(to_file)); | 85 ASSERT_FALSE(base::PathExists(to_file)); |
| 86 | 86 |
| 87 // test Do() | 87 // test Do() |
| 88 scoped_ptr<MoveTreeWorkItem> work_item( | 88 scoped_ptr<MoveTreeWorkItem> work_item( |
| 89 WorkItem::CreateMoveTreeWorkItem(from_dir1, | 89 WorkItem::CreateMoveTreeWorkItem(from_dir1, |
| 90 to_dir, | 90 to_dir, |
| 91 temp_to_dir_.path(), | 91 temp_to_dir_.path(), |
| 92 WorkItem::ALWAYS_MOVE)); | 92 WorkItem::ALWAYS_MOVE)); |
| 93 EXPECT_TRUE(work_item->Do()); | 93 EXPECT_TRUE(work_item->Do()); |
| 94 | 94 |
| 95 EXPECT_FALSE(file_util::PathExists(from_dir1)); | 95 EXPECT_FALSE(base::PathExists(from_dir1)); |
| 96 EXPECT_TRUE(file_util::PathExists(to_dir)); | 96 EXPECT_TRUE(base::PathExists(to_dir)); |
| 97 EXPECT_TRUE(file_util::PathExists(to_file)); | 97 EXPECT_TRUE(base::PathExists(to_file)); |
| 98 | 98 |
| 99 // test rollback() | 99 // test rollback() |
| 100 work_item->Rollback(); | 100 work_item->Rollback(); |
| 101 | 101 |
| 102 EXPECT_TRUE(file_util::PathExists(from_dir1)); | 102 EXPECT_TRUE(base::PathExists(from_dir1)); |
| 103 EXPECT_TRUE(file_util::PathExists(from_file)); | 103 EXPECT_TRUE(base::PathExists(from_file)); |
| 104 EXPECT_FALSE(file_util::PathExists(to_dir)); | 104 EXPECT_FALSE(base::PathExists(to_dir)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Move one directory from source to destination when destination already | 107 // Move one directory from source to destination when destination already |
| 108 // exists. | 108 // exists. |
| 109 TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExists) { | 109 TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExists) { |
| 110 // Create two level deep source dir | 110 // Create two level deep source dir |
| 111 base::FilePath from_dir1(temp_from_dir_.path()); | 111 base::FilePath from_dir1(temp_from_dir_.path()); |
| 112 from_dir1 = from_dir1.AppendASCII("From_Dir1"); | 112 from_dir1 = from_dir1.AppendASCII("From_Dir1"); |
| 113 file_util::CreateDirectory(from_dir1); | 113 file_util::CreateDirectory(from_dir1); |
| 114 ASSERT_TRUE(file_util::PathExists(from_dir1)); | 114 ASSERT_TRUE(base::PathExists(from_dir1)); |
| 115 | 115 |
| 116 base::FilePath from_dir2(from_dir1); | 116 base::FilePath from_dir2(from_dir1); |
| 117 from_dir2 = from_dir2.AppendASCII("From_Dir2"); | 117 from_dir2 = from_dir2.AppendASCII("From_Dir2"); |
| 118 file_util::CreateDirectory(from_dir2); | 118 file_util::CreateDirectory(from_dir2); |
| 119 ASSERT_TRUE(file_util::PathExists(from_dir2)); | 119 ASSERT_TRUE(base::PathExists(from_dir2)); |
| 120 | 120 |
| 121 base::FilePath from_file(from_dir2); | 121 base::FilePath from_file(from_dir2); |
| 122 from_file = from_file.AppendASCII("From_File"); | 122 from_file = from_file.AppendASCII("From_File"); |
| 123 CreateTextFile(from_file.value(), kTextContent1); | 123 CreateTextFile(from_file.value(), kTextContent1); |
| 124 ASSERT_TRUE(file_util::PathExists(from_file)); | 124 ASSERT_TRUE(base::PathExists(from_file)); |
| 125 | 125 |
| 126 // Create destination path | 126 // Create destination path |
| 127 base::FilePath to_dir(temp_from_dir_.path()); | 127 base::FilePath to_dir(temp_from_dir_.path()); |
| 128 to_dir = to_dir.AppendASCII("To_Dir"); | 128 to_dir = to_dir.AppendASCII("To_Dir"); |
| 129 file_util::CreateDirectory(to_dir); | 129 file_util::CreateDirectory(to_dir); |
| 130 ASSERT_TRUE(file_util::PathExists(to_dir)); | 130 ASSERT_TRUE(base::PathExists(to_dir)); |
| 131 | 131 |
| 132 base::FilePath orig_to_file(to_dir); | 132 base::FilePath orig_to_file(to_dir); |
| 133 orig_to_file = orig_to_file.AppendASCII("To_File"); | 133 orig_to_file = orig_to_file.AppendASCII("To_File"); |
| 134 CreateTextFile(orig_to_file.value(), kTextContent2); | 134 CreateTextFile(orig_to_file.value(), kTextContent2); |
| 135 ASSERT_TRUE(file_util::PathExists(orig_to_file)); | 135 ASSERT_TRUE(base::PathExists(orig_to_file)); |
| 136 | 136 |
| 137 base::FilePath new_to_file(to_dir); | 137 base::FilePath new_to_file(to_dir); |
| 138 new_to_file = new_to_file.AppendASCII("From_Dir2"); | 138 new_to_file = new_to_file.AppendASCII("From_Dir2"); |
| 139 new_to_file = new_to_file.AppendASCII("From_File"); | 139 new_to_file = new_to_file.AppendASCII("From_File"); |
| 140 ASSERT_FALSE(file_util::PathExists(new_to_file)); | 140 ASSERT_FALSE(base::PathExists(new_to_file)); |
| 141 | 141 |
| 142 // test Do(), don't check for duplicates. | 142 // test Do(), don't check for duplicates. |
| 143 scoped_ptr<MoveTreeWorkItem> work_item( | 143 scoped_ptr<MoveTreeWorkItem> work_item( |
| 144 WorkItem::CreateMoveTreeWorkItem(from_dir1, | 144 WorkItem::CreateMoveTreeWorkItem(from_dir1, |
| 145 to_dir, | 145 to_dir, |
| 146 temp_to_dir_.path(), | 146 temp_to_dir_.path(), |
| 147 WorkItem::ALWAYS_MOVE)); | 147 WorkItem::ALWAYS_MOVE)); |
| 148 EXPECT_TRUE(work_item->Do()); | 148 EXPECT_TRUE(work_item->Do()); |
| 149 | 149 |
| 150 EXPECT_FALSE(file_util::PathExists(from_dir1)); | 150 EXPECT_FALSE(base::PathExists(from_dir1)); |
| 151 EXPECT_TRUE(file_util::PathExists(to_dir)); | 151 EXPECT_TRUE(base::PathExists(to_dir)); |
| 152 EXPECT_TRUE(file_util::PathExists(new_to_file)); | 152 EXPECT_TRUE(base::PathExists(new_to_file)); |
| 153 EXPECT_FALSE(file_util::PathExists(orig_to_file)); | 153 EXPECT_FALSE(base::PathExists(orig_to_file)); |
| 154 | 154 |
| 155 // test rollback() | 155 // test rollback() |
| 156 work_item->Rollback(); | 156 work_item->Rollback(); |
| 157 | 157 |
| 158 EXPECT_TRUE(file_util::PathExists(from_dir1)); | 158 EXPECT_TRUE(base::PathExists(from_dir1)); |
| 159 EXPECT_TRUE(file_util::PathExists(to_dir)); | 159 EXPECT_TRUE(base::PathExists(to_dir)); |
| 160 EXPECT_FALSE(file_util::PathExists(new_to_file)); | 160 EXPECT_FALSE(base::PathExists(new_to_file)); |
| 161 EXPECT_TRUE(file_util::PathExists(orig_to_file)); | 161 EXPECT_TRUE(base::PathExists(orig_to_file)); |
| 162 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent2)); | 162 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent2)); |
| 163 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); | 163 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // Move one file from source to destination when destination does not | 166 // Move one file from source to destination when destination does not |
| 167 // exist. | 167 // exist. |
| 168 TEST_F(MoveTreeWorkItemTest, MoveAFile) { | 168 TEST_F(MoveTreeWorkItemTest, MoveAFile) { |
| 169 // Create a file inside source dir | 169 // Create a file inside source dir |
| 170 base::FilePath from_dir(temp_from_dir_.path()); | 170 base::FilePath from_dir(temp_from_dir_.path()); |
| 171 from_dir = from_dir.AppendASCII("From_Dir"); | 171 from_dir = from_dir.AppendASCII("From_Dir"); |
| 172 file_util::CreateDirectory(from_dir); | 172 file_util::CreateDirectory(from_dir); |
| 173 ASSERT_TRUE(file_util::PathExists(from_dir)); | 173 ASSERT_TRUE(base::PathExists(from_dir)); |
| 174 | 174 |
| 175 base::FilePath from_file(from_dir); | 175 base::FilePath from_file(from_dir); |
| 176 from_file = from_file.AppendASCII("From_File"); | 176 from_file = from_file.AppendASCII("From_File"); |
| 177 CreateTextFile(from_file.value(), kTextContent1); | 177 CreateTextFile(from_file.value(), kTextContent1); |
| 178 ASSERT_TRUE(file_util::PathExists(from_file)); | 178 ASSERT_TRUE(base::PathExists(from_file)); |
| 179 | 179 |
| 180 // Generate destination file name | 180 // Generate destination file name |
| 181 base::FilePath to_file(temp_from_dir_.path()); | 181 base::FilePath to_file(temp_from_dir_.path()); |
| 182 to_file = to_file.AppendASCII("To_File"); | 182 to_file = to_file.AppendASCII("To_File"); |
| 183 ASSERT_FALSE(file_util::PathExists(to_file)); | 183 ASSERT_FALSE(base::PathExists(to_file)); |
| 184 | 184 |
| 185 // test Do() | 185 // test Do() |
| 186 scoped_ptr<MoveTreeWorkItem> work_item( | 186 scoped_ptr<MoveTreeWorkItem> work_item( |
| 187 WorkItem::CreateMoveTreeWorkItem(from_file, | 187 WorkItem::CreateMoveTreeWorkItem(from_file, |
| 188 to_file, | 188 to_file, |
| 189 temp_to_dir_.path(), | 189 temp_to_dir_.path(), |
| 190 WorkItem::ALWAYS_MOVE)); | 190 WorkItem::ALWAYS_MOVE)); |
| 191 EXPECT_TRUE(work_item->Do()); | 191 EXPECT_TRUE(work_item->Do()); |
| 192 | 192 |
| 193 EXPECT_TRUE(file_util::PathExists(from_dir)); | 193 EXPECT_TRUE(base::PathExists(from_dir)); |
| 194 EXPECT_FALSE(file_util::PathExists(from_file)); | 194 EXPECT_FALSE(base::PathExists(from_file)); |
| 195 EXPECT_TRUE(file_util::PathExists(to_file)); | 195 EXPECT_TRUE(base::PathExists(to_file)); |
| 196 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); | 196 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); |
| 197 | 197 |
| 198 // test rollback() | 198 // test rollback() |
| 199 work_item->Rollback(); | 199 work_item->Rollback(); |
| 200 | 200 |
| 201 EXPECT_TRUE(file_util::PathExists(from_dir)); | 201 EXPECT_TRUE(base::PathExists(from_dir)); |
| 202 EXPECT_TRUE(file_util::PathExists(from_file)); | 202 EXPECT_TRUE(base::PathExists(from_file)); |
| 203 EXPECT_FALSE(file_util::PathExists(to_file)); | 203 EXPECT_FALSE(base::PathExists(to_file)); |
| 204 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); | 204 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); |
| 205 } | 205 } |
| 206 | 206 |
| 207 // Move one file from source to destination when destination already | 207 // Move one file from source to destination when destination already |
| 208 // exists. | 208 // exists. |
| 209 TEST_F(MoveTreeWorkItemTest, MoveFileDestExists) { | 209 TEST_F(MoveTreeWorkItemTest, MoveFileDestExists) { |
| 210 // Create a file inside source dir | 210 // Create a file inside source dir |
| 211 base::FilePath from_dir(temp_from_dir_.path()); | 211 base::FilePath from_dir(temp_from_dir_.path()); |
| 212 from_dir = from_dir.AppendASCII("From_Dir"); | 212 from_dir = from_dir.AppendASCII("From_Dir"); |
| 213 file_util::CreateDirectory(from_dir); | 213 file_util::CreateDirectory(from_dir); |
| 214 ASSERT_TRUE(file_util::PathExists(from_dir)); | 214 ASSERT_TRUE(base::PathExists(from_dir)); |
| 215 | 215 |
| 216 base::FilePath from_file(from_dir); | 216 base::FilePath from_file(from_dir); |
| 217 from_file = from_file.AppendASCII("From_File"); | 217 from_file = from_file.AppendASCII("From_File"); |
| 218 CreateTextFile(from_file.value(), kTextContent1); | 218 CreateTextFile(from_file.value(), kTextContent1); |
| 219 ASSERT_TRUE(file_util::PathExists(from_file)); | 219 ASSERT_TRUE(base::PathExists(from_file)); |
| 220 | 220 |
| 221 // Create destination path | 221 // Create destination path |
| 222 base::FilePath to_dir(temp_from_dir_.path()); | 222 base::FilePath to_dir(temp_from_dir_.path()); |
| 223 to_dir = to_dir.AppendASCII("To_Dir"); | 223 to_dir = to_dir.AppendASCII("To_Dir"); |
| 224 file_util::CreateDirectory(to_dir); | 224 file_util::CreateDirectory(to_dir); |
| 225 ASSERT_TRUE(file_util::PathExists(to_dir)); | 225 ASSERT_TRUE(base::PathExists(to_dir)); |
| 226 | 226 |
| 227 base::FilePath to_file(to_dir); | 227 base::FilePath to_file(to_dir); |
| 228 to_file = to_file.AppendASCII("To_File"); | 228 to_file = to_file.AppendASCII("To_File"); |
| 229 CreateTextFile(to_file.value(), kTextContent2); | 229 CreateTextFile(to_file.value(), kTextContent2); |
| 230 ASSERT_TRUE(file_util::PathExists(to_file)); | 230 ASSERT_TRUE(base::PathExists(to_file)); |
| 231 | 231 |
| 232 // test Do() | 232 // test Do() |
| 233 scoped_ptr<MoveTreeWorkItem> work_item( | 233 scoped_ptr<MoveTreeWorkItem> work_item( |
| 234 WorkItem::CreateMoveTreeWorkItem(from_file, | 234 WorkItem::CreateMoveTreeWorkItem(from_file, |
| 235 to_dir, | 235 to_dir, |
| 236 temp_to_dir_.path(), | 236 temp_to_dir_.path(), |
| 237 WorkItem::ALWAYS_MOVE)); | 237 WorkItem::ALWAYS_MOVE)); |
| 238 EXPECT_TRUE(work_item->Do()); | 238 EXPECT_TRUE(work_item->Do()); |
| 239 | 239 |
| 240 EXPECT_TRUE(file_util::PathExists(from_dir)); | 240 EXPECT_TRUE(base::PathExists(from_dir)); |
| 241 EXPECT_FALSE(file_util::PathExists(from_file)); | 241 EXPECT_FALSE(base::PathExists(from_file)); |
| 242 EXPECT_TRUE(file_util::PathExists(to_dir)); | 242 EXPECT_TRUE(base::PathExists(to_dir)); |
| 243 EXPECT_FALSE(file_util::PathExists(to_file)); | 243 EXPECT_FALSE(base::PathExists(to_file)); |
| 244 EXPECT_EQ(0, ReadTextFile(to_dir).compare(kTextContent1)); | 244 EXPECT_EQ(0, ReadTextFile(to_dir).compare(kTextContent1)); |
| 245 | 245 |
| 246 // test rollback() | 246 // test rollback() |
| 247 work_item->Rollback(); | 247 work_item->Rollback(); |
| 248 | 248 |
| 249 EXPECT_TRUE(file_util::PathExists(from_dir)); | 249 EXPECT_TRUE(base::PathExists(from_dir)); |
| 250 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); | 250 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); |
| 251 EXPECT_TRUE(file_util::PathExists(to_dir)); | 251 EXPECT_TRUE(base::PathExists(to_dir)); |
| 252 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent2)); | 252 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent2)); |
| 253 } | 253 } |
| 254 | 254 |
| 255 // Move one file from source to destination when destination already | 255 // Move one file from source to destination when destination already |
| 256 // exists and is in use. | 256 // exists and is in use. |
| 257 TEST_F(MoveTreeWorkItemTest, MoveFileDestInUse) { | 257 TEST_F(MoveTreeWorkItemTest, MoveFileDestInUse) { |
| 258 // Create a file inside source dir | 258 // Create a file inside source dir |
| 259 base::FilePath from_dir(temp_from_dir_.path()); | 259 base::FilePath from_dir(temp_from_dir_.path()); |
| 260 from_dir = from_dir.AppendASCII("From_Dir"); | 260 from_dir = from_dir.AppendASCII("From_Dir"); |
| 261 file_util::CreateDirectory(from_dir); | 261 file_util::CreateDirectory(from_dir); |
| 262 ASSERT_TRUE(file_util::PathExists(from_dir)); | 262 ASSERT_TRUE(base::PathExists(from_dir)); |
| 263 | 263 |
| 264 base::FilePath from_file(from_dir); | 264 base::FilePath from_file(from_dir); |
| 265 from_file = from_file.AppendASCII("From_File"); | 265 from_file = from_file.AppendASCII("From_File"); |
| 266 CreateTextFile(from_file.value(), kTextContent1); | 266 CreateTextFile(from_file.value(), kTextContent1); |
| 267 ASSERT_TRUE(file_util::PathExists(from_file)); | 267 ASSERT_TRUE(base::PathExists(from_file)); |
| 268 | 268 |
| 269 // Create an executable in destination path by copying ourself to it. | 269 // Create an executable in destination path by copying ourself to it. |
| 270 base::FilePath to_dir(temp_from_dir_.path()); | 270 base::FilePath to_dir(temp_from_dir_.path()); |
| 271 to_dir = to_dir.AppendASCII("To_Dir"); | 271 to_dir = to_dir.AppendASCII("To_Dir"); |
| 272 file_util::CreateDirectory(to_dir); | 272 file_util::CreateDirectory(to_dir); |
| 273 ASSERT_TRUE(file_util::PathExists(to_dir)); | 273 ASSERT_TRUE(base::PathExists(to_dir)); |
| 274 | 274 |
| 275 wchar_t exe_full_path_str[MAX_PATH]; | 275 wchar_t exe_full_path_str[MAX_PATH]; |
| 276 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); | 276 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); |
| 277 base::FilePath exe_full_path(exe_full_path_str); | 277 base::FilePath exe_full_path(exe_full_path_str); |
| 278 base::FilePath to_file(to_dir); | 278 base::FilePath to_file(to_dir); |
| 279 to_file = to_file.AppendASCII("To_File"); | 279 to_file = to_file.AppendASCII("To_File"); |
| 280 base::CopyFile(exe_full_path, to_file); | 280 base::CopyFile(exe_full_path, to_file); |
| 281 ASSERT_TRUE(file_util::PathExists(to_file)); | 281 ASSERT_TRUE(base::PathExists(to_file)); |
| 282 | 282 |
| 283 // Run the executable in destination path | 283 // Run the executable in destination path |
| 284 STARTUPINFOW si = {sizeof(si)}; | 284 STARTUPINFOW si = {sizeof(si)}; |
| 285 PROCESS_INFORMATION pi = {0}; | 285 PROCESS_INFORMATION pi = {0}; |
| 286 ASSERT_TRUE(::CreateProcess(NULL, | 286 ASSERT_TRUE(::CreateProcess(NULL, |
| 287 const_cast<wchar_t*>(to_file.value().c_str()), | 287 const_cast<wchar_t*>(to_file.value().c_str()), |
| 288 NULL, NULL, FALSE, | 288 NULL, NULL, FALSE, |
| 289 CREATE_NO_WINDOW | CREATE_SUSPENDED, | 289 CREATE_NO_WINDOW | CREATE_SUSPENDED, |
| 290 NULL, NULL, &si, &pi)); | 290 NULL, NULL, &si, &pi)); |
| 291 | 291 |
| 292 // test Do() | 292 // test Do() |
| 293 scoped_ptr<MoveTreeWorkItem> work_item( | 293 scoped_ptr<MoveTreeWorkItem> work_item( |
| 294 WorkItem::CreateMoveTreeWorkItem(from_file, | 294 WorkItem::CreateMoveTreeWorkItem(from_file, |
| 295 to_file, | 295 to_file, |
| 296 temp_to_dir_.path(), | 296 temp_to_dir_.path(), |
| 297 WorkItem::ALWAYS_MOVE)); | 297 WorkItem::ALWAYS_MOVE)); |
| 298 EXPECT_TRUE(work_item->Do()); | 298 EXPECT_TRUE(work_item->Do()); |
| 299 | 299 |
| 300 EXPECT_TRUE(file_util::PathExists(from_dir)); | 300 EXPECT_TRUE(base::PathExists(from_dir)); |
| 301 EXPECT_FALSE(file_util::PathExists(from_file)); | 301 EXPECT_FALSE(base::PathExists(from_file)); |
| 302 EXPECT_TRUE(file_util::PathExists(to_dir)); | 302 EXPECT_TRUE(base::PathExists(to_dir)); |
| 303 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); | 303 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); |
| 304 | 304 |
| 305 // test rollback() | 305 // test rollback() |
| 306 work_item->Rollback(); | 306 work_item->Rollback(); |
| 307 | 307 |
| 308 EXPECT_TRUE(file_util::PathExists(from_dir)); | 308 EXPECT_TRUE(base::PathExists(from_dir)); |
| 309 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); | 309 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); |
| 310 EXPECT_TRUE(file_util::PathExists(to_dir)); | 310 EXPECT_TRUE(base::PathExists(to_dir)); |
| 311 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, to_file)); | 311 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, to_file)); |
| 312 | 312 |
| 313 TerminateProcess(pi.hProcess, 0); | 313 TerminateProcess(pi.hProcess, 0); |
| 314 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); | 314 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); |
| 315 CloseHandle(pi.hProcess); | 315 CloseHandle(pi.hProcess); |
| 316 CloseHandle(pi.hThread); | 316 CloseHandle(pi.hThread); |
| 317 } | 317 } |
| 318 | 318 |
| 319 // Move one file that is in use to destination. | 319 // Move one file that is in use to destination. |
| 320 TEST_F(MoveTreeWorkItemTest, MoveFileInUse) { | 320 TEST_F(MoveTreeWorkItemTest, MoveFileInUse) { |
| 321 // Create an executable for source by copying ourself to a new source dir. | 321 // Create an executable for source by copying ourself to a new source dir. |
| 322 base::FilePath from_dir(temp_from_dir_.path()); | 322 base::FilePath from_dir(temp_from_dir_.path()); |
| 323 from_dir = from_dir.AppendASCII("From_Dir"); | 323 from_dir = from_dir.AppendASCII("From_Dir"); |
| 324 file_util::CreateDirectory(from_dir); | 324 file_util::CreateDirectory(from_dir); |
| 325 ASSERT_TRUE(file_util::PathExists(from_dir)); | 325 ASSERT_TRUE(base::PathExists(from_dir)); |
| 326 | 326 |
| 327 wchar_t exe_full_path_str[MAX_PATH]; | 327 wchar_t exe_full_path_str[MAX_PATH]; |
| 328 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); | 328 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); |
| 329 base::FilePath exe_full_path(exe_full_path_str); | 329 base::FilePath exe_full_path(exe_full_path_str); |
| 330 base::FilePath from_file(from_dir); | 330 base::FilePath from_file(from_dir); |
| 331 from_file = from_file.AppendASCII("From_File"); | 331 from_file = from_file.AppendASCII("From_File"); |
| 332 base::CopyFile(exe_full_path, from_file); | 332 base::CopyFile(exe_full_path, from_file); |
| 333 ASSERT_TRUE(file_util::PathExists(from_file)); | 333 ASSERT_TRUE(base::PathExists(from_file)); |
| 334 | 334 |
| 335 // Create a destination source dir and generate destination file name. | 335 // Create a destination source dir and generate destination file name. |
| 336 base::FilePath to_dir(temp_from_dir_.path()); | 336 base::FilePath to_dir(temp_from_dir_.path()); |
| 337 to_dir = to_dir.AppendASCII("To_Dir"); | 337 to_dir = to_dir.AppendASCII("To_Dir"); |
| 338 file_util::CreateDirectory(to_dir); | 338 file_util::CreateDirectory(to_dir); |
| 339 ASSERT_TRUE(file_util::PathExists(to_dir)); | 339 ASSERT_TRUE(base::PathExists(to_dir)); |
| 340 | 340 |
| 341 base::FilePath to_file(to_dir); | 341 base::FilePath to_file(to_dir); |
| 342 to_file = to_file.AppendASCII("To_File"); | 342 to_file = to_file.AppendASCII("To_File"); |
| 343 CreateTextFile(to_file.value(), kTextContent1); | 343 CreateTextFile(to_file.value(), kTextContent1); |
| 344 ASSERT_TRUE(file_util::PathExists(to_file)); | 344 ASSERT_TRUE(base::PathExists(to_file)); |
| 345 | 345 |
| 346 // Run the executable in source path | 346 // Run the executable in source path |
| 347 STARTUPINFOW si = {sizeof(si)}; | 347 STARTUPINFOW si = {sizeof(si)}; |
| 348 PROCESS_INFORMATION pi = {0}; | 348 PROCESS_INFORMATION pi = {0}; |
| 349 ASSERT_TRUE(::CreateProcess(NULL, | 349 ASSERT_TRUE(::CreateProcess(NULL, |
| 350 const_cast<wchar_t*>(from_file.value().c_str()), | 350 const_cast<wchar_t*>(from_file.value().c_str()), |
| 351 NULL, NULL, FALSE, | 351 NULL, NULL, FALSE, |
| 352 CREATE_NO_WINDOW | CREATE_SUSPENDED, | 352 CREATE_NO_WINDOW | CREATE_SUSPENDED, |
| 353 NULL, NULL, &si, &pi)); | 353 NULL, NULL, &si, &pi)); |
| 354 | 354 |
| 355 // test Do() | 355 // test Do() |
| 356 scoped_ptr<MoveTreeWorkItem> work_item( | 356 scoped_ptr<MoveTreeWorkItem> work_item( |
| 357 WorkItem::CreateMoveTreeWorkItem(from_file, | 357 WorkItem::CreateMoveTreeWorkItem(from_file, |
| 358 to_file, | 358 to_file, |
| 359 temp_to_dir_.path(), | 359 temp_to_dir_.path(), |
| 360 WorkItem::ALWAYS_MOVE)); | 360 WorkItem::ALWAYS_MOVE)); |
| 361 EXPECT_TRUE(work_item->Do()); | 361 EXPECT_TRUE(work_item->Do()); |
| 362 | 362 |
| 363 EXPECT_TRUE(file_util::PathExists(from_dir)); | 363 EXPECT_TRUE(base::PathExists(from_dir)); |
| 364 EXPECT_FALSE(file_util::PathExists(from_file)); | 364 EXPECT_FALSE(base::PathExists(from_file)); |
| 365 EXPECT_TRUE(file_util::PathExists(to_dir)); | 365 EXPECT_TRUE(base::PathExists(to_dir)); |
| 366 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, to_file)); | 366 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, to_file)); |
| 367 | 367 |
| 368 // Close the process and make sure all the conditions after Do() are | 368 // Close the process and make sure all the conditions after Do() are |
| 369 // still true. | 369 // still true. |
| 370 TerminateProcess(pi.hProcess, 0); | 370 TerminateProcess(pi.hProcess, 0); |
| 371 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); | 371 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); |
| 372 CloseHandle(pi.hProcess); | 372 CloseHandle(pi.hProcess); |
| 373 CloseHandle(pi.hThread); | 373 CloseHandle(pi.hThread); |
| 374 | 374 |
| 375 EXPECT_TRUE(file_util::PathExists(from_dir)); | 375 EXPECT_TRUE(base::PathExists(from_dir)); |
| 376 EXPECT_FALSE(file_util::PathExists(from_file)); | 376 EXPECT_FALSE(base::PathExists(from_file)); |
| 377 EXPECT_TRUE(file_util::PathExists(to_dir)); | 377 EXPECT_TRUE(base::PathExists(to_dir)); |
| 378 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, to_file)); | 378 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, to_file)); |
| 379 | 379 |
| 380 // test rollback() | 380 // test rollback() |
| 381 work_item->Rollback(); | 381 work_item->Rollback(); |
| 382 | 382 |
| 383 EXPECT_TRUE(file_util::PathExists(from_dir)); | 383 EXPECT_TRUE(base::PathExists(from_dir)); |
| 384 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, from_file)); | 384 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, from_file)); |
| 385 EXPECT_TRUE(file_util::PathExists(to_dir)); | 385 EXPECT_TRUE(base::PathExists(to_dir)); |
| 386 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); | 386 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); |
| 387 } | 387 } |
| 388 | 388 |
| 389 // Move one directory from source to destination when destination already | 389 // Move one directory from source to destination when destination already |
| 390 // exists. | 390 // exists. |
| 391 TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExistsCheckForDuplicatesFull) { | 391 TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExistsCheckForDuplicatesFull) { |
| 392 // Create two level deep source dir | 392 // Create two level deep source dir |
| 393 base::FilePath from_dir1(temp_from_dir_.path()); | 393 base::FilePath from_dir1(temp_from_dir_.path()); |
| 394 from_dir1 = from_dir1.AppendASCII("From_Dir1"); | 394 from_dir1 = from_dir1.AppendASCII("From_Dir1"); |
| 395 file_util::CreateDirectory(from_dir1); | 395 file_util::CreateDirectory(from_dir1); |
| 396 ASSERT_TRUE(file_util::PathExists(from_dir1)); | 396 ASSERT_TRUE(base::PathExists(from_dir1)); |
| 397 | 397 |
| 398 base::FilePath from_dir2(from_dir1); | 398 base::FilePath from_dir2(from_dir1); |
| 399 from_dir2 = from_dir2.AppendASCII("From_Dir2"); | 399 from_dir2 = from_dir2.AppendASCII("From_Dir2"); |
| 400 file_util::CreateDirectory(from_dir2); | 400 file_util::CreateDirectory(from_dir2); |
| 401 ASSERT_TRUE(file_util::PathExists(from_dir2)); | 401 ASSERT_TRUE(base::PathExists(from_dir2)); |
| 402 | 402 |
| 403 base::FilePath from_file(from_dir2); | 403 base::FilePath from_file(from_dir2); |
| 404 from_file = from_file.AppendASCII("From_File"); | 404 from_file = from_file.AppendASCII("From_File"); |
| 405 CreateTextFile(from_file.value(), kTextContent1); | 405 CreateTextFile(from_file.value(), kTextContent1); |
| 406 ASSERT_TRUE(file_util::PathExists(from_file)); | 406 ASSERT_TRUE(base::PathExists(from_file)); |
| 407 | 407 |
| 408 // // Create a file hierarchy identical to the one in the source directory. | 408 // // Create a file hierarchy identical to the one in the source directory. |
| 409 base::FilePath to_dir(temp_from_dir_.path()); | 409 base::FilePath to_dir(temp_from_dir_.path()); |
| 410 to_dir = to_dir.AppendASCII("To_Dir"); | 410 to_dir = to_dir.AppendASCII("To_Dir"); |
| 411 ASSERT_TRUE(installer::test::CopyFileHierarchy(from_dir1, to_dir)); | 411 ASSERT_TRUE(installer::test::CopyFileHierarchy(from_dir1, to_dir)); |
| 412 | 412 |
| 413 // Lock one of the files in the to destination directory to prevent moves. | 413 // Lock one of the files in the to destination directory to prevent moves. |
| 414 base::FilePath orig_to_file( | 414 base::FilePath orig_to_file( |
| 415 to_dir.AppendASCII("From_Dir2").AppendASCII("From_File")); | 415 to_dir.AppendASCII("From_Dir2").AppendASCII("From_File")); |
| 416 base::MemoryMappedFile mapped_file; | 416 base::MemoryMappedFile mapped_file; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 428 // Now test Do() with the check for duplicates. This should pass. | 428 // Now test Do() with the check for duplicates. This should pass. |
| 429 work_item.reset( | 429 work_item.reset( |
| 430 WorkItem::CreateMoveTreeWorkItem(from_dir1, | 430 WorkItem::CreateMoveTreeWorkItem(from_dir1, |
| 431 to_dir, | 431 to_dir, |
| 432 temp_to_dir_.path(), | 432 temp_to_dir_.path(), |
| 433 WorkItem::CHECK_DUPLICATES)); | 433 WorkItem::CHECK_DUPLICATES)); |
| 434 EXPECT_TRUE(work_item->Do()); | 434 EXPECT_TRUE(work_item->Do()); |
| 435 | 435 |
| 436 // Make sure that we "moved" the files, i.e. that the source directory isn't | 436 // Make sure that we "moved" the files, i.e. that the source directory isn't |
| 437 // there anymore, | 437 // there anymore, |
| 438 EXPECT_FALSE(file_util::PathExists(from_dir1)); | 438 EXPECT_FALSE(base::PathExists(from_dir1)); |
| 439 // Make sure that the original directory structure and file are still present. | 439 // Make sure that the original directory structure and file are still present. |
| 440 EXPECT_TRUE(file_util::PathExists(to_dir)); | 440 EXPECT_TRUE(base::PathExists(to_dir)); |
| 441 EXPECT_TRUE(file_util::PathExists(orig_to_file)); | 441 EXPECT_TRUE(base::PathExists(orig_to_file)); |
| 442 // Make sure that the backup path is not empty. | 442 // Make sure that the backup path is not empty. |
| 443 EXPECT_FALSE(file_util::IsDirectoryEmpty(temp_to_dir_.path())); | 443 EXPECT_FALSE(file_util::IsDirectoryEmpty(temp_to_dir_.path())); |
| 444 | 444 |
| 445 // Check that the work item believes the source to have been moved. | 445 // Check that the work item believes the source to have been moved. |
| 446 EXPECT_TRUE(work_item->source_moved_to_backup_); | 446 EXPECT_TRUE(work_item->source_moved_to_backup_); |
| 447 EXPECT_FALSE(work_item->moved_to_dest_path_); | 447 EXPECT_FALSE(work_item->moved_to_dest_path_); |
| 448 EXPECT_FALSE(work_item->moved_to_backup_); | 448 EXPECT_FALSE(work_item->moved_to_backup_); |
| 449 | 449 |
| 450 // test rollback() | 450 // test rollback() |
| 451 work_item->Rollback(); | 451 work_item->Rollback(); |
| 452 | 452 |
| 453 // Once we rollback all the original files should still be there, as should | 453 // Once we rollback all the original files should still be there, as should |
| 454 // the source files. | 454 // the source files. |
| 455 EXPECT_TRUE(file_util::PathExists(from_dir1)); | 455 EXPECT_TRUE(base::PathExists(from_dir1)); |
| 456 EXPECT_TRUE(file_util::PathExists(to_dir)); | 456 EXPECT_TRUE(base::PathExists(to_dir)); |
| 457 EXPECT_TRUE(file_util::PathExists(orig_to_file)); | 457 EXPECT_TRUE(base::PathExists(orig_to_file)); |
| 458 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent1)); | 458 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent1)); |
| 459 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); | 459 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); |
| 460 } | 460 } |
| 461 | 461 |
| 462 // Move one directory from source to destination when destination already | 462 // Move one directory from source to destination when destination already |
| 463 // exists but contains only a subset of the files in source. | 463 // exists but contains only a subset of the files in source. |
| 464 TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExistsCheckForDuplicatesPartial) { | 464 TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExistsCheckForDuplicatesPartial) { |
| 465 // Create two level deep source dir | 465 // Create two level deep source dir |
| 466 base::FilePath from_dir1(temp_from_dir_.path()); | 466 base::FilePath from_dir1(temp_from_dir_.path()); |
| 467 from_dir1 = from_dir1.AppendASCII("From_Dir1"); | 467 from_dir1 = from_dir1.AppendASCII("From_Dir1"); |
| 468 file_util::CreateDirectory(from_dir1); | 468 file_util::CreateDirectory(from_dir1); |
| 469 ASSERT_TRUE(file_util::PathExists(from_dir1)); | 469 ASSERT_TRUE(base::PathExists(from_dir1)); |
| 470 | 470 |
| 471 base::FilePath from_dir2(from_dir1); | 471 base::FilePath from_dir2(from_dir1); |
| 472 from_dir2 = from_dir2.AppendASCII("From_Dir2"); | 472 from_dir2 = from_dir2.AppendASCII("From_Dir2"); |
| 473 file_util::CreateDirectory(from_dir2); | 473 file_util::CreateDirectory(from_dir2); |
| 474 ASSERT_TRUE(file_util::PathExists(from_dir2)); | 474 ASSERT_TRUE(base::PathExists(from_dir2)); |
| 475 | 475 |
| 476 base::FilePath from_file(from_dir2); | 476 base::FilePath from_file(from_dir2); |
| 477 from_file = from_file.AppendASCII("From_File"); | 477 from_file = from_file.AppendASCII("From_File"); |
| 478 CreateTextFile(from_file.value(), kTextContent1); | 478 CreateTextFile(from_file.value(), kTextContent1); |
| 479 ASSERT_TRUE(file_util::PathExists(from_file)); | 479 ASSERT_TRUE(base::PathExists(from_file)); |
| 480 | 480 |
| 481 base::FilePath from_file2(from_dir2); | 481 base::FilePath from_file2(from_dir2); |
| 482 from_file2 = from_file2.AppendASCII("From_File2"); | 482 from_file2 = from_file2.AppendASCII("From_File2"); |
| 483 CreateTextFile(from_file2.value(), kTextContent2); | 483 CreateTextFile(from_file2.value(), kTextContent2); |
| 484 ASSERT_TRUE(file_util::PathExists(from_file2)); | 484 ASSERT_TRUE(base::PathExists(from_file2)); |
| 485 | 485 |
| 486 // Create destination path | 486 // Create destination path |
| 487 base::FilePath to_dir(temp_from_dir_.path()); | 487 base::FilePath to_dir(temp_from_dir_.path()); |
| 488 to_dir = to_dir.AppendASCII("To_Dir"); | 488 to_dir = to_dir.AppendASCII("To_Dir"); |
| 489 file_util::CreateDirectory(to_dir); | 489 file_util::CreateDirectory(to_dir); |
| 490 ASSERT_TRUE(file_util::PathExists(to_dir)); | 490 ASSERT_TRUE(base::PathExists(to_dir)); |
| 491 | 491 |
| 492 // Create a sub-directory of the same name as in the source directory. | 492 // Create a sub-directory of the same name as in the source directory. |
| 493 base::FilePath to_dir2(to_dir); | 493 base::FilePath to_dir2(to_dir); |
| 494 to_dir2 = to_dir2.AppendASCII("From_Dir2"); | 494 to_dir2 = to_dir2.AppendASCII("From_Dir2"); |
| 495 file_util::CreateDirectory(to_dir2); | 495 file_util::CreateDirectory(to_dir2); |
| 496 ASSERT_TRUE(file_util::PathExists(to_dir2)); | 496 ASSERT_TRUE(base::PathExists(to_dir2)); |
| 497 | 497 |
| 498 // Create one of the files in the to sub-directory, but not the other. | 498 // Create one of the files in the to sub-directory, but not the other. |
| 499 base::FilePath orig_to_file(to_dir2); | 499 base::FilePath orig_to_file(to_dir2); |
| 500 orig_to_file = orig_to_file.AppendASCII("From_File"); | 500 orig_to_file = orig_to_file.AppendASCII("From_File"); |
| 501 CreateTextFile(orig_to_file.value(), kTextContent1); | 501 CreateTextFile(orig_to_file.value(), kTextContent1); |
| 502 ASSERT_TRUE(file_util::PathExists(orig_to_file)); | 502 ASSERT_TRUE(base::PathExists(orig_to_file)); |
| 503 | 503 |
| 504 // test Do(), check for duplicates. | 504 // test Do(), check for duplicates. |
| 505 scoped_ptr<MoveTreeWorkItem> work_item( | 505 scoped_ptr<MoveTreeWorkItem> work_item( |
| 506 WorkItem::CreateMoveTreeWorkItem(from_dir1, | 506 WorkItem::CreateMoveTreeWorkItem(from_dir1, |
| 507 to_dir, | 507 to_dir, |
| 508 temp_to_dir_.path(), | 508 temp_to_dir_.path(), |
| 509 WorkItem::CHECK_DUPLICATES)); | 509 WorkItem::CHECK_DUPLICATES)); |
| 510 EXPECT_TRUE(work_item->Do()); | 510 EXPECT_TRUE(work_item->Do()); |
| 511 | 511 |
| 512 // Make sure that we "moved" the files, i.e. that the source directory isn't | 512 // Make sure that we "moved" the files, i.e. that the source directory isn't |
| 513 // there anymore, | 513 // there anymore, |
| 514 EXPECT_FALSE(file_util::PathExists(from_dir1)); | 514 EXPECT_FALSE(base::PathExists(from_dir1)); |
| 515 // Make sure that the original directory structure and file are still present. | 515 // Make sure that the original directory structure and file are still present. |
| 516 EXPECT_TRUE(file_util::PathExists(to_dir)); | 516 EXPECT_TRUE(base::PathExists(to_dir)); |
| 517 EXPECT_TRUE(file_util::PathExists(orig_to_file)); | 517 EXPECT_TRUE(base::PathExists(orig_to_file)); |
| 518 // Make sure that the backup path is not empty. | 518 // Make sure that the backup path is not empty. |
| 519 EXPECT_FALSE(file_util::IsDirectoryEmpty(temp_to_dir_.path())); | 519 EXPECT_FALSE(file_util::IsDirectoryEmpty(temp_to_dir_.path())); |
| 520 // Make sure that the "new" file is also present. | 520 // Make sure that the "new" file is also present. |
| 521 base::FilePath new_to_file2(to_dir2); | 521 base::FilePath new_to_file2(to_dir2); |
| 522 new_to_file2 = new_to_file2.AppendASCII("From_File2"); | 522 new_to_file2 = new_to_file2.AppendASCII("From_File2"); |
| 523 EXPECT_TRUE(file_util::PathExists(new_to_file2)); | 523 EXPECT_TRUE(base::PathExists(new_to_file2)); |
| 524 | 524 |
| 525 // Check that the work item believes that this was a regular move. | 525 // Check that the work item believes that this was a regular move. |
| 526 EXPECT_FALSE(work_item->source_moved_to_backup_); | 526 EXPECT_FALSE(work_item->source_moved_to_backup_); |
| 527 EXPECT_TRUE(work_item->moved_to_dest_path_); | 527 EXPECT_TRUE(work_item->moved_to_dest_path_); |
| 528 EXPECT_TRUE(work_item->moved_to_backup_); | 528 EXPECT_TRUE(work_item->moved_to_backup_); |
| 529 | 529 |
| 530 // test rollback() | 530 // test rollback() |
| 531 work_item->Rollback(); | 531 work_item->Rollback(); |
| 532 | 532 |
| 533 // Once we rollback all the original files should still be there, as should | 533 // Once we rollback all the original files should still be there, as should |
| 534 // the source files. | 534 // the source files. |
| 535 EXPECT_TRUE(file_util::PathExists(from_dir1)); | 535 EXPECT_TRUE(base::PathExists(from_dir1)); |
| 536 EXPECT_TRUE(file_util::PathExists(to_dir)); | 536 EXPECT_TRUE(base::PathExists(to_dir)); |
| 537 EXPECT_TRUE(file_util::PathExists(orig_to_file)); | 537 EXPECT_TRUE(base::PathExists(orig_to_file)); |
| 538 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent1)); | 538 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent1)); |
| 539 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); | 539 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); |
| 540 | 540 |
| 541 // Also, after rollback the new "to" file should be gone. | 541 // Also, after rollback the new "to" file should be gone. |
| 542 EXPECT_FALSE(file_util::PathExists(new_to_file2)); | 542 EXPECT_FALSE(base::PathExists(new_to_file2)); |
| 543 } | 543 } |
| OLD | NEW |