| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/sync_file_system/local/local_file_change_tracker.h" | 5 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 198 |
| 199 const char kPath0[] = "file a"; | 199 const char kPath0[] = "file a"; |
| 200 const char kPath1[] = "dir a"; | 200 const char kPath1[] = "dir a"; |
| 201 const char kPath2[] = "dir a/dir"; | 201 const char kPath2[] = "dir a/dir"; |
| 202 const char kPath3[] = "dir a/file a"; | 202 const char kPath3[] = "dir a/file a"; |
| 203 const char kPath4[] = "dir a/file b"; | 203 const char kPath4[] = "dir a/file b"; |
| 204 | 204 |
| 205 file_system_.GetChangedURLsInTracker(&urls); | 205 file_system_.GetChangedURLsInTracker(&urls); |
| 206 ASSERT_EQ(0U, urls.size()); | 206 ASSERT_EQ(0U, urls.size()); |
| 207 | 207 |
| 208 const GURL blob_url("blob:test"); | |
| 209 const std::string kData("Lorem ipsum."); | 208 const std::string kData("Lorem ipsum."); |
| 210 MockBlobURLRequestContext url_request_context(file_system_context()); | 209 MockBlobURLRequestContext url_request_context(file_system_context()); |
| 211 ScopedTextBlob blob(url_request_context, blob_url, kData); | 210 ScopedTextBlob blob(url_request_context, "blob_id:test", kData); |
| 212 | 211 |
| 213 // Create files and nested directories. | 212 // Create files and nested directories. |
| 214 EXPECT_EQ(base::PLATFORM_FILE_OK, | 213 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 215 file_system_.CreateFile(URL(kPath0))); // Creates a file. | 214 file_system_.CreateFile(URL(kPath0))); // Creates a file. |
| 216 EXPECT_EQ(base::PLATFORM_FILE_OK, | 215 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 217 file_system_.CreateDirectory(URL(kPath1))); // Creates a dir. | 216 file_system_.CreateDirectory(URL(kPath1))); // Creates a dir. |
| 218 EXPECT_EQ(base::PLATFORM_FILE_OK, | 217 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 219 file_system_.CreateDirectory(URL(kPath2))); // Creates another dir. | 218 file_system_.CreateDirectory(URL(kPath2))); // Creates another dir. |
| 220 EXPECT_EQ(base::PLATFORM_FILE_OK, | 219 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 221 file_system_.CreateFile(URL(kPath3))); // Creates a file. | 220 file_system_.CreateFile(URL(kPath3))); // Creates a file. |
| 222 EXPECT_EQ(base::PLATFORM_FILE_OK, | 221 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 223 file_system_.TruncateFile(URL(kPath3), 1)); // Modifies the file. | 222 file_system_.TruncateFile(URL(kPath3), 1)); // Modifies the file. |
| 224 EXPECT_EQ(base::PLATFORM_FILE_OK, | 223 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 225 file_system_.CreateFile(URL(kPath4))); // Creates another file. | 224 file_system_.CreateFile(URL(kPath4))); // Creates another file. |
| 226 EXPECT_EQ(static_cast<int64>(kData.size()), | 225 EXPECT_EQ(static_cast<int64>(kData.size()), // Modifies the file. |
| 227 file_system_.Write(&url_request_context, | 226 file_system_.Write(&url_request_context, |
| 228 URL(kPath4), blob_url)); // Modifies the file. | 227 URL(kPath4), blob.GetBlobDataHandle())); |
| 229 | 228 |
| 230 // Verify the changes. | 229 // Verify the changes. |
| 231 file_system_.GetChangedURLsInTracker(&urls); | 230 file_system_.GetChangedURLsInTracker(&urls); |
| 232 EXPECT_EQ(5U, urls.size()); | 231 EXPECT_EQ(5U, urls.size()); |
| 233 | 232 |
| 234 // Reset the changes in in-memory tracker. | 233 // Reset the changes in in-memory tracker. |
| 235 DropChangesInTracker(); | 234 DropChangesInTracker(); |
| 236 | 235 |
| 237 // Make sure we have no in-memory changes in the tracker. | 236 // Make sure we have no in-memory changes in the tracker. |
| 238 file_system_.GetChangedURLsInTracker(&urls); | 237 file_system_.GetChangedURLsInTracker(&urls); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 349 |
| 351 const char kPath0Copy[] = "file b"; // To be copied from kPath0 | 350 const char kPath0Copy[] = "file b"; // To be copied from kPath0 |
| 352 const char kPath1Copy[] = "dir b"; // To be copied from kPath1 | 351 const char kPath1Copy[] = "dir b"; // To be copied from kPath1 |
| 353 const char kPath2Copy[] = "dir b/dir"; // To be copied from kPath2 | 352 const char kPath2Copy[] = "dir b/dir"; // To be copied from kPath2 |
| 354 const char kPath3Copy[] = "dir b/file a"; // To be copied from kPath3 | 353 const char kPath3Copy[] = "dir b/file a"; // To be copied from kPath3 |
| 355 const char kPath4Copy[] = "dir b/file b"; // To be copied from kPath4 | 354 const char kPath4Copy[] = "dir b/file b"; // To be copied from kPath4 |
| 356 | 355 |
| 357 file_system_.GetChangedURLsInTracker(&urls); | 356 file_system_.GetChangedURLsInTracker(&urls); |
| 358 ASSERT_EQ(0U, urls.size()); | 357 ASSERT_EQ(0U, urls.size()); |
| 359 | 358 |
| 360 const GURL blob_url("blob:test"); | |
| 361 const std::string kData("Lorem ipsum."); | 359 const std::string kData("Lorem ipsum."); |
| 362 MockBlobURLRequestContext url_request_context(file_system_context()); | 360 MockBlobURLRequestContext url_request_context(file_system_context()); |
| 363 ScopedTextBlob blob(url_request_context, blob_url, kData); | 361 ScopedTextBlob blob(url_request_context, "blob_id:test", kData); |
| 364 | 362 |
| 365 // Create files and nested directories. | 363 // Create files and nested directories. |
| 366 EXPECT_EQ(base::PLATFORM_FILE_OK, | 364 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 367 file_system_.CreateFile(URL(kPath0))); // Creates a file. | 365 file_system_.CreateFile(URL(kPath0))); // Creates a file. |
| 368 EXPECT_EQ(base::PLATFORM_FILE_OK, | 366 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 369 file_system_.CreateDirectory(URL(kPath1))); // Creates a dir. | 367 file_system_.CreateDirectory(URL(kPath1))); // Creates a dir. |
| 370 EXPECT_EQ(base::PLATFORM_FILE_OK, | 368 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 371 file_system_.CreateDirectory(URL(kPath2))); // Creates another dir. | 369 file_system_.CreateDirectory(URL(kPath2))); // Creates another dir. |
| 372 EXPECT_EQ(base::PLATFORM_FILE_OK, | 370 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 373 file_system_.CreateFile(URL(kPath3))); // Creates a file. | 371 file_system_.CreateFile(URL(kPath3))); // Creates a file. |
| 374 EXPECT_EQ(base::PLATFORM_FILE_OK, | 372 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 375 file_system_.TruncateFile(URL(kPath3), 1)); // Modifies the file. | 373 file_system_.TruncateFile(URL(kPath3), 1)); // Modifies the file. |
| 376 EXPECT_EQ(base::PLATFORM_FILE_OK, | 374 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 377 file_system_.CreateFile(URL(kPath4))); // Creates another file. | 375 file_system_.CreateFile(URL(kPath4))); // Creates another file. |
| 378 EXPECT_EQ(static_cast<int64>(kData.size()), | 376 EXPECT_EQ(static_cast<int64>(kData.size()), |
| 379 file_system_.Write(&url_request_context, | 377 file_system_.Write(&url_request_context, // Modifies the file. |
| 380 URL(kPath4), blob_url)); // Modifies the file. | 378 URL(kPath4), blob.GetBlobDataHandle())); |
| 381 | 379 |
| 382 // Verify we have 5 changes for preparation. | 380 // Verify we have 5 changes for preparation. |
| 383 file_system_.GetChangedURLsInTracker(&urls); | 381 file_system_.GetChangedURLsInTracker(&urls); |
| 384 EXPECT_EQ(5U, urls.size()); | 382 EXPECT_EQ(5U, urls.size()); |
| 385 change_tracker()->ClearChangesForURL(URL(kPath0)); | 383 change_tracker()->ClearChangesForURL(URL(kPath0)); |
| 386 change_tracker()->ClearChangesForURL(URL(kPath1)); | 384 change_tracker()->ClearChangesForURL(URL(kPath1)); |
| 387 change_tracker()->ClearChangesForURL(URL(kPath2)); | 385 change_tracker()->ClearChangesForURL(URL(kPath2)); |
| 388 change_tracker()->ClearChangesForURL(URL(kPath3)); | 386 change_tracker()->ClearChangesForURL(URL(kPath3)); |
| 389 change_tracker()->ClearChangesForURL(URL(kPath4)); | 387 change_tracker()->ClearChangesForURL(URL(kPath4)); |
| 390 | 388 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 ASSERT_EQ(2U, urls_to_process.size()); | 594 ASSERT_EQ(2U, urls_to_process.size()); |
| 597 | 595 |
| 598 // The exact order of recursive removal cannot be determined. | 596 // The exact order of recursive removal cannot be determined. |
| 599 EXPECT_TRUE(URL(kPath1) == urls_to_process[0] || | 597 EXPECT_TRUE(URL(kPath1) == urls_to_process[0] || |
| 600 URL(kPath2) == urls_to_process[0]); | 598 URL(kPath2) == urls_to_process[0]); |
| 601 EXPECT_TRUE(URL(kPath1) == urls_to_process[1] || | 599 EXPECT_TRUE(URL(kPath1) == urls_to_process[1] || |
| 602 URL(kPath2) == urls_to_process[1]); | 600 URL(kPath2) == urls_to_process[1]); |
| 603 } | 601 } |
| 604 | 602 |
| 605 } // namespace sync_file_system | 603 } // namespace sync_file_system |
| OLD | NEW |