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