OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/fileapi/syncable/local_file_change_tracker.h" | 5 #include "webkit/fileapi/syncable/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" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/message_loop_proxy.h" | 14 #include "base/message_loop_proxy.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "webkit/blob/mock_blob_url_request_context.h" | 17 #include "webkit/blob/mock_blob_url_request_context.h" |
18 #include "webkit/fileapi/file_system_context.h" | 18 #include "webkit/fileapi/file_system_context.h" |
19 #include "webkit/fileapi/file_system_task_runners.h" | 19 #include "webkit/fileapi/file_system_task_runners.h" |
20 #include "webkit/fileapi/syncable/canned_syncable_file_system.h" | 20 #include "webkit/fileapi/syncable/canned_syncable_file_system.h" |
21 #include "webkit/fileapi/syncable/local_file_sync_context.h" | 21 #include "webkit/fileapi/syncable/local_file_sync_context.h" |
22 #include "webkit/fileapi/syncable/sync_status_code.h" | 22 #include "webkit/fileapi/syncable/sync_status_code.h" |
23 #include "webkit/fileapi/syncable/syncable_file_system_util.h" | 23 #include "webkit/fileapi/syncable/syncable_file_system_util.h" |
24 #include "webkit/quota/quota_manager.h" | 24 #include "webkit/quota/quota_manager.h" |
25 | 25 |
| 26 using sync_file_system::FileChange; |
| 27 using sync_file_system::FileChangeList; |
26 using webkit_blob::MockBlobURLRequestContext; | 28 using webkit_blob::MockBlobURLRequestContext; |
27 using webkit_blob::ScopedTextBlob; | 29 using webkit_blob::ScopedTextBlob; |
28 | 30 |
29 namespace fileapi { | 31 namespace fileapi { |
30 | 32 |
31 class LocalFileChangeTrackerTest : public testing::Test { | 33 class LocalFileChangeTrackerTest : public testing::Test { |
32 public: | 34 public: |
33 LocalFileChangeTrackerTest() | 35 LocalFileChangeTrackerTest() |
34 : message_loop_(MessageLoop::TYPE_IO), | 36 : message_loop_(MessageLoop::TYPE_IO), |
35 file_system_(GURL("http://example.com"), "test", | 37 file_system_(GURL("http://example.com"), "test", |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 change_tracker()->GetNextChangedURLs(&urls_to_process, 0); | 164 change_tracker()->GetNextChangedURLs(&urls_to_process, 0); |
163 ASSERT_EQ(5U, urls_to_process.size()); | 165 ASSERT_EQ(5U, urls_to_process.size()); |
164 EXPECT_EQ(URL(kPath1), urls_to_process[0]); | 166 EXPECT_EQ(URL(kPath1), urls_to_process[0]); |
165 EXPECT_EQ(URL(kPath2), urls_to_process[1]); | 167 EXPECT_EQ(URL(kPath2), urls_to_process[1]); |
166 EXPECT_EQ(URL(kPath3), urls_to_process[2]); | 168 EXPECT_EQ(URL(kPath3), urls_to_process[2]); |
167 EXPECT_EQ(URL(kPath5), urls_to_process[3]); | 169 EXPECT_EQ(URL(kPath5), urls_to_process[3]); |
168 EXPECT_EQ(URL(kPath4), urls_to_process[4]); | 170 EXPECT_EQ(URL(kPath4), urls_to_process[4]); |
169 | 171 |
170 VerifyAndClearChange(URL(kPath1), | 172 VerifyAndClearChange(URL(kPath1), |
171 FileChange(FileChange::FILE_CHANGE_DELETE, | 173 FileChange(FileChange::FILE_CHANGE_DELETE, |
172 SYNC_FILE_TYPE_DIRECTORY)); | 174 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
173 VerifyAndClearChange(URL(kPath2), | 175 VerifyAndClearChange(URL(kPath2), |
174 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 176 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
175 SYNC_FILE_TYPE_DIRECTORY)); | 177 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
176 VerifyAndClearChange(URL(kPath3), | 178 VerifyAndClearChange(URL(kPath3), |
177 FileChange(FileChange::FILE_CHANGE_DELETE, | 179 FileChange(FileChange::FILE_CHANGE_DELETE, |
178 SYNC_FILE_TYPE_FILE)); | 180 sync_file_system::SYNC_FILE_TYPE_FILE)); |
179 VerifyAndClearChange(URL(kPath4), | 181 VerifyAndClearChange(URL(kPath4), |
180 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 182 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
181 SYNC_FILE_TYPE_FILE)); | 183 sync_file_system::SYNC_FILE_TYPE_FILE)); |
182 VerifyAndClearChange(URL(kPath5), | 184 VerifyAndClearChange(URL(kPath5), |
183 FileChange(FileChange::FILE_CHANGE_DELETE, | 185 FileChange(FileChange::FILE_CHANGE_DELETE, |
184 SYNC_FILE_TYPE_FILE)); | 186 sync_file_system::SYNC_FILE_TYPE_FILE)); |
185 } | 187 } |
186 | 188 |
187 TEST_F(LocalFileChangeTrackerTest, RestoreCreateAndModifyChanges) { | 189 TEST_F(LocalFileChangeTrackerTest, RestoreCreateAndModifyChanges) { |
188 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); | 190 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); |
189 | 191 |
190 FileSystemURLSet urls; | 192 FileSystemURLSet urls; |
191 | 193 |
192 const char kPath0[] = "file a"; | 194 const char kPath0[] = "file a"; |
193 const char kPath1[] = "dir a"; | 195 const char kPath1[] = "dir a"; |
194 const char kPath2[] = "dir a/dir"; | 196 const char kPath2[] = "dir a/dir"; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 246 |
245 RestoreChangesFromTrackerDB(); | 247 RestoreChangesFromTrackerDB(); |
246 | 248 |
247 // Make sure the changes are restored from the DB. | 249 // Make sure the changes are restored from the DB. |
248 urls.clear(); | 250 urls.clear(); |
249 file_system_.GetChangedURLsInTracker(&urls); | 251 file_system_.GetChangedURLsInTracker(&urls); |
250 EXPECT_EQ(10U, urls.size()); | 252 EXPECT_EQ(10U, urls.size()); |
251 | 253 |
252 VerifyAndClearChange(URL(kPath0), | 254 VerifyAndClearChange(URL(kPath0), |
253 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 255 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
254 SYNC_FILE_TYPE_FILE)); | 256 sync_file_system::SYNC_FILE_TYPE_FILE)); |
255 VerifyAndClearChange(URL(kPath1), | 257 VerifyAndClearChange(URL(kPath1), |
256 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 258 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
257 SYNC_FILE_TYPE_DIRECTORY)); | 259 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
258 VerifyAndClearChange(URL(kPath2), | 260 VerifyAndClearChange(URL(kPath2), |
259 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 261 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
260 SYNC_FILE_TYPE_DIRECTORY)); | 262 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
261 VerifyAndClearChange(URL(kPath3), | 263 VerifyAndClearChange(URL(kPath3), |
262 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 264 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
263 SYNC_FILE_TYPE_FILE)); | 265 sync_file_system::SYNC_FILE_TYPE_FILE)); |
264 VerifyAndClearChange(URL(kPath4), | 266 VerifyAndClearChange(URL(kPath4), |
265 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 267 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
266 SYNC_FILE_TYPE_FILE)); | 268 sync_file_system::SYNC_FILE_TYPE_FILE)); |
267 | 269 |
268 VerifyAndClearChange(URL(kPath0Copy), | 270 VerifyAndClearChange(URL(kPath0Copy), |
269 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 271 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
270 SYNC_FILE_TYPE_FILE)); | 272 sync_file_system::SYNC_FILE_TYPE_FILE)); |
271 VerifyAndClearChange(URL(kPath1Copy), | 273 VerifyAndClearChange(URL(kPath1Copy), |
272 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 274 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
273 SYNC_FILE_TYPE_DIRECTORY)); | 275 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
274 VerifyAndClearChange(URL(kPath2Copy), | 276 VerifyAndClearChange(URL(kPath2Copy), |
275 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 277 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
276 SYNC_FILE_TYPE_DIRECTORY)); | 278 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
277 VerifyAndClearChange(URL(kPath3Copy), | 279 VerifyAndClearChange(URL(kPath3Copy), |
278 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 280 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
279 SYNC_FILE_TYPE_FILE)); | 281 sync_file_system::SYNC_FILE_TYPE_FILE)); |
280 VerifyAndClearChange(URL(kPath4Copy), | 282 VerifyAndClearChange(URL(kPath4Copy), |
281 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 283 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
282 SYNC_FILE_TYPE_FILE)); | 284 sync_file_system::SYNC_FILE_TYPE_FILE)); |
283 } | 285 } |
284 | 286 |
285 TEST_F(LocalFileChangeTrackerTest, RestoreRemoveChanges) { | 287 TEST_F(LocalFileChangeTrackerTest, RestoreRemoveChanges) { |
286 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); | 288 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); |
287 | 289 |
288 FileSystemURLSet urls; | 290 FileSystemURLSet urls; |
289 | 291 |
290 const char kPath0[] = "file"; | 292 const char kPath0[] = "file"; |
291 const char kPath1[] = "dir a"; | 293 const char kPath1[] = "dir a"; |
292 const char kPath2[] = "dir b"; | 294 const char kPath2[] = "dir b"; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 338 |
337 // Make sure the changes are restored from the DB. | 339 // Make sure the changes are restored from the DB. |
338 urls.clear(); | 340 urls.clear(); |
339 file_system_.GetChangedURLsInTracker(&urls); | 341 file_system_.GetChangedURLsInTracker(&urls); |
340 // Since directories to have been reverted (kPath1, kPath2, kPath4) are | 342 // Since directories to have been reverted (kPath1, kPath2, kPath4) are |
341 // treated as FILE_CHANGE_DELETE, the number of changes should be 6. | 343 // treated as FILE_CHANGE_DELETE, the number of changes should be 6. |
342 EXPECT_EQ(6U, urls.size()); | 344 EXPECT_EQ(6U, urls.size()); |
343 | 345 |
344 VerifyAndClearChange(URL(kPath0), | 346 VerifyAndClearChange(URL(kPath0), |
345 FileChange(FileChange::FILE_CHANGE_DELETE, | 347 FileChange(FileChange::FILE_CHANGE_DELETE, |
346 SYNC_FILE_TYPE_UNKNOWN)); | 348 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
347 VerifyAndClearChange(URL(kPath1), | 349 VerifyAndClearChange(URL(kPath1), |
348 FileChange(FileChange::FILE_CHANGE_DELETE, | 350 FileChange(FileChange::FILE_CHANGE_DELETE, |
349 SYNC_FILE_TYPE_UNKNOWN)); | 351 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
350 VerifyAndClearChange(URL(kPath2), | 352 VerifyAndClearChange(URL(kPath2), |
351 FileChange(FileChange::FILE_CHANGE_DELETE, | 353 FileChange(FileChange::FILE_CHANGE_DELETE, |
352 SYNC_FILE_TYPE_UNKNOWN)); | 354 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
353 VerifyAndClearChange(URL(kPath3), | 355 VerifyAndClearChange(URL(kPath3), |
354 FileChange(FileChange::FILE_CHANGE_DELETE, | 356 FileChange(FileChange::FILE_CHANGE_DELETE, |
355 SYNC_FILE_TYPE_UNKNOWN)); | 357 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
356 VerifyAndClearChange(URL(kPath4), | 358 VerifyAndClearChange(URL(kPath4), |
357 FileChange(FileChange::FILE_CHANGE_DELETE, | 359 FileChange(FileChange::FILE_CHANGE_DELETE, |
358 SYNC_FILE_TYPE_UNKNOWN)); | 360 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
359 VerifyAndClearChange(URL(kPath5), | 361 VerifyAndClearChange(URL(kPath5), |
360 FileChange(FileChange::FILE_CHANGE_DELETE, | 362 FileChange(FileChange::FILE_CHANGE_DELETE, |
361 SYNC_FILE_TYPE_UNKNOWN)); | 363 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
362 } | 364 } |
363 | 365 |
364 TEST_F(LocalFileChangeTrackerTest, RestoreMoveChanges) { | 366 TEST_F(LocalFileChangeTrackerTest, RestoreMoveChanges) { |
365 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); | 367 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); |
366 | 368 |
367 FileSystemURLSet urls; | 369 FileSystemURLSet urls; |
368 | 370 |
369 const char kPath0[] = "file a"; | 371 const char kPath0[] = "file a"; |
370 const char kPath1[] = "dir a"; | 372 const char kPath1[] = "dir a"; |
371 const char kPath2[] = "dir a/file"; | 373 const char kPath2[] = "dir a/file"; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 417 |
416 // Make sure the changes are restored from the DB. | 418 // Make sure the changes are restored from the DB. |
417 urls.clear(); | 419 urls.clear(); |
418 file_system_.GetChangedURLsInTracker(&urls); | 420 file_system_.GetChangedURLsInTracker(&urls); |
419 // Since directories to have been reverted (kPath1 and kPath3) are treated as | 421 // Since directories to have been reverted (kPath1 and kPath3) are treated as |
420 // FILE_CHANGE_DELETE, the number of changes should be 10. | 422 // FILE_CHANGE_DELETE, the number of changes should be 10. |
421 EXPECT_EQ(10U, urls.size()); | 423 EXPECT_EQ(10U, urls.size()); |
422 | 424 |
423 VerifyAndClearChange(URL(kPath0), | 425 VerifyAndClearChange(URL(kPath0), |
424 FileChange(FileChange::FILE_CHANGE_DELETE, | 426 FileChange(FileChange::FILE_CHANGE_DELETE, |
425 SYNC_FILE_TYPE_UNKNOWN)); | 427 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
426 VerifyAndClearChange(URL(kPath1), | 428 VerifyAndClearChange(URL(kPath1), |
427 FileChange(FileChange::FILE_CHANGE_DELETE, | 429 FileChange(FileChange::FILE_CHANGE_DELETE, |
428 SYNC_FILE_TYPE_UNKNOWN)); | 430 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
429 VerifyAndClearChange(URL(kPath2), | 431 VerifyAndClearChange(URL(kPath2), |
430 FileChange(FileChange::FILE_CHANGE_DELETE, | 432 FileChange(FileChange::FILE_CHANGE_DELETE, |
431 SYNC_FILE_TYPE_UNKNOWN)); | 433 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
432 VerifyAndClearChange(URL(kPath3), | 434 VerifyAndClearChange(URL(kPath3), |
433 FileChange(FileChange::FILE_CHANGE_DELETE, | 435 FileChange(FileChange::FILE_CHANGE_DELETE, |
434 SYNC_FILE_TYPE_UNKNOWN)); | 436 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
435 VerifyAndClearChange(URL(kPath4), | 437 VerifyAndClearChange(URL(kPath4), |
436 FileChange(FileChange::FILE_CHANGE_DELETE, | 438 FileChange(FileChange::FILE_CHANGE_DELETE, |
437 SYNC_FILE_TYPE_UNKNOWN)); | 439 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
438 VerifyAndClearChange(URL(kPath5), | 440 VerifyAndClearChange(URL(kPath5), |
439 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 441 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
440 SYNC_FILE_TYPE_FILE)); | 442 sync_file_system::SYNC_FILE_TYPE_FILE)); |
441 VerifyAndClearChange(URL(kPath6), | 443 VerifyAndClearChange(URL(kPath6), |
442 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 444 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
443 SYNC_FILE_TYPE_DIRECTORY)); | 445 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
444 VerifyAndClearChange(URL(kPath7), | 446 VerifyAndClearChange(URL(kPath7), |
445 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 447 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
446 SYNC_FILE_TYPE_FILE)); | 448 sync_file_system::SYNC_FILE_TYPE_FILE)); |
447 VerifyAndClearChange(URL(kPath8), | 449 VerifyAndClearChange(URL(kPath8), |
448 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 450 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
449 SYNC_FILE_TYPE_DIRECTORY)); | 451 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
450 VerifyAndClearChange(URL(kPath9), | 452 VerifyAndClearChange(URL(kPath9), |
451 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 453 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
452 SYNC_FILE_TYPE_FILE)); | 454 sync_file_system::SYNC_FILE_TYPE_FILE)); |
453 } | 455 } |
454 | 456 |
455 TEST_F(LocalFileChangeTrackerTest, NextChangedURLsWithRecursiveCopy) { | 457 TEST_F(LocalFileChangeTrackerTest, NextChangedURLsWithRecursiveCopy) { |
456 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); | 458 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); |
457 | 459 |
458 FileSystemURLSet urls; | 460 FileSystemURLSet urls; |
459 | 461 |
460 const char kPath0[] = "dir a"; | 462 const char kPath0[] = "dir a"; |
461 const char kPath1[] = "dir a/file"; | 463 const char kPath1[] = "dir a/file"; |
462 const char kPath2[] = "dir a/dir"; | 464 const char kPath2[] = "dir a/dir"; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 ASSERT_EQ(2U, urls_to_process.size()); | 530 ASSERT_EQ(2U, urls_to_process.size()); |
529 | 531 |
530 // The exact order of recursive removal cannot be determined. | 532 // The exact order of recursive removal cannot be determined. |
531 EXPECT_TRUE(URL(kPath1) == urls_to_process[0] || | 533 EXPECT_TRUE(URL(kPath1) == urls_to_process[0] || |
532 URL(kPath2) == urls_to_process[0]); | 534 URL(kPath2) == urls_to_process[0]); |
533 EXPECT_TRUE(URL(kPath1) == urls_to_process[1] || | 535 EXPECT_TRUE(URL(kPath1) == urls_to_process[1] || |
534 URL(kPath2) == urls_to_process[1]); | 536 URL(kPath2) == urls_to_process[1]); |
535 } | 537 } |
536 | 538 |
537 } // namespace fileapi | 539 } // namespace fileapi |
OLD | NEW |