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" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); | 191 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); |
192 | 192 |
193 FileSystemURLSet urls; | 193 FileSystemURLSet urls; |
194 | 194 |
195 const char kPath0[] = "file a"; | 195 const char kPath0[] = "file a"; |
196 const char kPath1[] = "dir a"; | 196 const char kPath1[] = "dir a"; |
197 const char kPath2[] = "dir a/dir"; | 197 const char kPath2[] = "dir a/dir"; |
198 const char kPath3[] = "dir a/file a"; | 198 const char kPath3[] = "dir a/file a"; |
199 const char kPath4[] = "dir a/file b"; | 199 const char kPath4[] = "dir a/file b"; |
200 | 200 |
201 const char kPath0Copy[] = "file b"; // To be copied from kPath0 | |
202 const char kPath1Copy[] = "dir b"; // To be copied from kPath1 | |
203 const char kPath2Copy[] = "dir b/dir"; // To be copied from kPath2 | |
204 const char kPath3Copy[] = "dir b/file a"; // To be copied from kPath3 | |
205 const char kPath4Copy[] = "dir b/file b"; // To be copied from kPath4 | |
206 | |
207 file_system_.GetChangedURLsInTracker(&urls); | 201 file_system_.GetChangedURLsInTracker(&urls); |
208 ASSERT_EQ(0U, urls.size()); | 202 ASSERT_EQ(0U, urls.size()); |
209 | 203 |
210 const GURL blob_url("blob:test"); | 204 const GURL blob_url("blob:test"); |
211 const std::string kData("Lorem ipsum."); | 205 const std::string kData("Lorem ipsum."); |
212 MockBlobURLRequestContext url_request_context(file_system_context()); | 206 MockBlobURLRequestContext url_request_context(file_system_context()); |
213 ScopedTextBlob blob(url_request_context, blob_url, kData); | 207 ScopedTextBlob blob(url_request_context, blob_url, kData); |
214 | 208 |
215 // Creates files and nested directories. | 209 // Create files and nested directories. |
216 EXPECT_EQ(base::PLATFORM_FILE_OK, | 210 EXPECT_EQ(base::PLATFORM_FILE_OK, |
217 file_system_.CreateFile(URL(kPath0))); // Creates a file. | 211 file_system_.CreateFile(URL(kPath0))); // Creates a file. |
218 EXPECT_EQ(base::PLATFORM_FILE_OK, | 212 EXPECT_EQ(base::PLATFORM_FILE_OK, |
219 file_system_.CreateDirectory(URL(kPath1))); // Creates a dir. | 213 file_system_.CreateDirectory(URL(kPath1))); // Creates a dir. |
220 EXPECT_EQ(base::PLATFORM_FILE_OK, | 214 EXPECT_EQ(base::PLATFORM_FILE_OK, |
221 file_system_.CreateDirectory(URL(kPath2))); // Creates another dir. | 215 file_system_.CreateDirectory(URL(kPath2))); // Creates another dir. |
222 EXPECT_EQ(base::PLATFORM_FILE_OK, | 216 EXPECT_EQ(base::PLATFORM_FILE_OK, |
223 file_system_.CreateFile(URL(kPath3))); // Creates a file. | 217 file_system_.CreateFile(URL(kPath3))); // Creates a file. |
224 EXPECT_EQ(base::PLATFORM_FILE_OK, | 218 EXPECT_EQ(base::PLATFORM_FILE_OK, |
225 file_system_.TruncateFile(URL(kPath3), 1)); // Modifies the file. | 219 file_system_.TruncateFile(URL(kPath3), 1)); // Modifies the file. |
226 EXPECT_EQ(base::PLATFORM_FILE_OK, | 220 EXPECT_EQ(base::PLATFORM_FILE_OK, |
227 file_system_.CreateFile(URL(kPath4))); // Creates another file. | 221 file_system_.CreateFile(URL(kPath4))); // Creates another file. |
228 EXPECT_EQ(static_cast<int64>(kData.size()), | 222 EXPECT_EQ(static_cast<int64>(kData.size()), |
229 file_system_.Write(&url_request_context, | 223 file_system_.Write(&url_request_context, |
230 URL(kPath4), blob_url)); // Modifies the file. | 224 URL(kPath4), blob_url)); // Modifies the file. |
231 | 225 |
232 // Copies the file and the parent directory. | 226 // Verify the changes. |
233 EXPECT_EQ(base::PLATFORM_FILE_OK, | 227 file_system_.GetChangedURLsInTracker(&urls); |
234 file_system_.Copy(URL(kPath0), URL(kPath0Copy))); // Copy the file. | 228 EXPECT_EQ(5U, urls.size()); |
235 EXPECT_EQ(base::PLATFORM_FILE_OK, | |
236 file_system_.Copy(URL(kPath1), URL(kPath1Copy))); // Copy the dir. | |
237 | 229 |
238 file_system_.GetChangedURLsInTracker(&urls); | 230 // Reset the changes in in-memory tracker. |
239 EXPECT_EQ(10U, urls.size()); | |
240 | |
241 DropChangesInTracker(); | 231 DropChangesInTracker(); |
242 | 232 |
243 // Make sure we have no in-memory changes in the tracker. | 233 // Make sure we have no in-memory changes in the tracker. |
244 urls.clear(); | |
245 file_system_.GetChangedURLsInTracker(&urls); | 234 file_system_.GetChangedURLsInTracker(&urls); |
246 ASSERT_EQ(0U, urls.size()); | 235 ASSERT_EQ(0U, urls.size()); |
247 | 236 |
248 RestoreChangesFromTrackerDB(); | 237 RestoreChangesFromTrackerDB(); |
249 | 238 |
250 // Make sure the changes are restored from the DB. | 239 // Make sure the changes are restored from the DB. |
251 urls.clear(); | |
252 file_system_.GetChangedURLsInTracker(&urls); | 240 file_system_.GetChangedURLsInTracker(&urls); |
253 EXPECT_EQ(10U, urls.size()); | 241 EXPECT_EQ(5U, urls.size()); |
254 | 242 |
255 VerifyAndClearChange(URL(kPath0), | 243 VerifyAndClearChange(URL(kPath0), |
256 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 244 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
257 sync_file_system::SYNC_FILE_TYPE_FILE)); | 245 sync_file_system::SYNC_FILE_TYPE_FILE)); |
258 VerifyAndClearChange(URL(kPath1), | 246 VerifyAndClearChange(URL(kPath1), |
259 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 247 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
260 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); | 248 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
261 VerifyAndClearChange(URL(kPath2), | 249 VerifyAndClearChange(URL(kPath2), |
262 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 250 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
263 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); | 251 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
264 VerifyAndClearChange(URL(kPath3), | 252 VerifyAndClearChange(URL(kPath3), |
265 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 253 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
266 sync_file_system::SYNC_FILE_TYPE_FILE)); | 254 sync_file_system::SYNC_FILE_TYPE_FILE)); |
267 VerifyAndClearChange(URL(kPath4), | 255 VerifyAndClearChange(URL(kPath4), |
268 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 256 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
269 sync_file_system::SYNC_FILE_TYPE_FILE)); | 257 sync_file_system::SYNC_FILE_TYPE_FILE)); |
270 | |
271 VerifyAndClearChange(URL(kPath0Copy), | |
272 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | |
273 sync_file_system::SYNC_FILE_TYPE_FILE)); | |
274 VerifyAndClearChange(URL(kPath1Copy), | |
275 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | |
276 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); | |
277 VerifyAndClearChange(URL(kPath2Copy), | |
278 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | |
279 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); | |
280 VerifyAndClearChange(URL(kPath3Copy), | |
281 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | |
282 sync_file_system::SYNC_FILE_TYPE_FILE)); | |
283 VerifyAndClearChange(URL(kPath4Copy), | |
284 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | |
285 sync_file_system::SYNC_FILE_TYPE_FILE)); | |
286 } | 258 } |
287 | 259 |
288 TEST_F(LocalFileChangeTrackerTest, RestoreRemoveChanges) { | 260 TEST_F(LocalFileChangeTrackerTest, RestoreRemoveChanges) { |
289 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); | 261 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); |
290 | 262 |
291 FileSystemURLSet urls; | 263 FileSystemURLSet urls; |
292 | 264 |
293 const char kPath0[] = "file"; | 265 const char kPath0[] = "file"; |
294 const char kPath1[] = "dir a"; | 266 const char kPath1[] = "dir a"; |
295 const char kPath2[] = "dir b"; | 267 const char kPath2[] = "dir b"; |
(...skipping 21 matching lines...) Expand all Loading... |
317 file_system_.CreateDirectory(URL(kPath2))); | 289 file_system_.CreateDirectory(URL(kPath2))); |
318 EXPECT_EQ(base::PLATFORM_FILE_OK, | 290 EXPECT_EQ(base::PLATFORM_FILE_OK, |
319 file_system_.CreateFile(URL(kPath3))); | 291 file_system_.CreateFile(URL(kPath3))); |
320 EXPECT_EQ(base::PLATFORM_FILE_OK, | 292 EXPECT_EQ(base::PLATFORM_FILE_OK, |
321 file_system_.CreateDirectory(URL(kPath4))); | 293 file_system_.CreateDirectory(URL(kPath4))); |
322 EXPECT_EQ(base::PLATFORM_FILE_OK, | 294 EXPECT_EQ(base::PLATFORM_FILE_OK, |
323 file_system_.CreateFile(URL(kPath5))); | 295 file_system_.CreateFile(URL(kPath5))); |
324 EXPECT_EQ(base::PLATFORM_FILE_OK, | 296 EXPECT_EQ(base::PLATFORM_FILE_OK, |
325 file_system_.Remove(URL(kPath2), true /* recursive */)); | 297 file_system_.Remove(URL(kPath2), true /* recursive */)); |
326 | 298 |
327 urls.clear(); | |
328 file_system_.GetChangedURLsInTracker(&urls); | 299 file_system_.GetChangedURLsInTracker(&urls); |
329 EXPECT_EQ(3U, urls.size()); | 300 EXPECT_EQ(3U, urls.size()); |
330 | 301 |
331 DropChangesInTracker(); | 302 DropChangesInTracker(); |
332 | 303 |
333 // Make sure we have no in-memory changes in the tracker. | 304 // Make sure we have no in-memory changes in the tracker. |
334 urls.clear(); | |
335 file_system_.GetChangedURLsInTracker(&urls); | 305 file_system_.GetChangedURLsInTracker(&urls); |
336 ASSERT_EQ(0U, urls.size()); | 306 ASSERT_EQ(0U, urls.size()); |
337 | 307 |
338 RestoreChangesFromTrackerDB(); | 308 RestoreChangesFromTrackerDB(); |
339 | 309 |
340 // Make sure the changes are restored from the DB. | 310 // Make sure the changes are restored from the DB. |
341 urls.clear(); | |
342 file_system_.GetChangedURLsInTracker(&urls); | 311 file_system_.GetChangedURLsInTracker(&urls); |
343 // Since directories to have been reverted (kPath1, kPath2, kPath4) are | 312 // Since directories to have been reverted (kPath1, kPath2, kPath4) are |
344 // treated as FILE_CHANGE_DELETE, the number of changes should be 6. | 313 // treated as FILE_CHANGE_DELETE, the number of changes should be 6. |
345 EXPECT_EQ(6U, urls.size()); | 314 EXPECT_EQ(6U, urls.size()); |
346 | 315 |
347 VerifyAndClearChange(URL(kPath0), | 316 VerifyAndClearChange(URL(kPath0), |
348 FileChange(FileChange::FILE_CHANGE_DELETE, | 317 FileChange(FileChange::FILE_CHANGE_DELETE, |
349 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); | 318 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
350 VerifyAndClearChange(URL(kPath1), | 319 VerifyAndClearChange(URL(kPath1), |
351 FileChange(FileChange::FILE_CHANGE_DELETE, | 320 FileChange(FileChange::FILE_CHANGE_DELETE, |
352 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); | 321 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
353 VerifyAndClearChange(URL(kPath2), | 322 VerifyAndClearChange(URL(kPath2), |
354 FileChange(FileChange::FILE_CHANGE_DELETE, | 323 FileChange(FileChange::FILE_CHANGE_DELETE, |
355 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); | 324 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
356 VerifyAndClearChange(URL(kPath3), | 325 VerifyAndClearChange(URL(kPath3), |
357 FileChange(FileChange::FILE_CHANGE_DELETE, | 326 FileChange(FileChange::FILE_CHANGE_DELETE, |
358 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); | 327 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
359 VerifyAndClearChange(URL(kPath4), | 328 VerifyAndClearChange(URL(kPath4), |
360 FileChange(FileChange::FILE_CHANGE_DELETE, | 329 FileChange(FileChange::FILE_CHANGE_DELETE, |
361 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); | 330 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
362 VerifyAndClearChange(URL(kPath5), | 331 VerifyAndClearChange(URL(kPath5), |
363 FileChange(FileChange::FILE_CHANGE_DELETE, | 332 FileChange(FileChange::FILE_CHANGE_DELETE, |
364 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); | 333 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
365 } | 334 } |
366 | 335 |
| 336 TEST_F(LocalFileChangeTrackerTest, RestoreCopyChanges) { |
| 337 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); |
| 338 |
| 339 FileSystemURLSet urls; |
| 340 |
| 341 const char kPath0[] = "file a"; |
| 342 const char kPath1[] = "dir a"; |
| 343 const char kPath2[] = "dir a/dir"; |
| 344 const char kPath3[] = "dir a/file a"; |
| 345 const char kPath4[] = "dir a/file b"; |
| 346 |
| 347 const char kPath0Copy[] = "file b"; // To be copied from kPath0 |
| 348 const char kPath1Copy[] = "dir b"; // To be copied from kPath1 |
| 349 const char kPath2Copy[] = "dir b/dir"; // To be copied from kPath2 |
| 350 const char kPath3Copy[] = "dir b/file a"; // To be copied from kPath3 |
| 351 const char kPath4Copy[] = "dir b/file b"; // To be copied from kPath4 |
| 352 |
| 353 file_system_.GetChangedURLsInTracker(&urls); |
| 354 ASSERT_EQ(0U, urls.size()); |
| 355 |
| 356 const GURL blob_url("blob:test"); |
| 357 const std::string kData("Lorem ipsum."); |
| 358 MockBlobURLRequestContext url_request_context(file_system_context()); |
| 359 ScopedTextBlob blob(url_request_context, blob_url, kData); |
| 360 |
| 361 // Create files and nested directories. |
| 362 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 363 file_system_.CreateFile(URL(kPath0))); // Creates a file. |
| 364 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 365 file_system_.CreateDirectory(URL(kPath1))); // Creates a dir. |
| 366 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 367 file_system_.CreateDirectory(URL(kPath2))); // Creates another dir. |
| 368 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 369 file_system_.CreateFile(URL(kPath3))); // Creates a file. |
| 370 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 371 file_system_.TruncateFile(URL(kPath3), 1)); // Modifies the file. |
| 372 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 373 file_system_.CreateFile(URL(kPath4))); // Creates another file. |
| 374 EXPECT_EQ(static_cast<int64>(kData.size()), |
| 375 file_system_.Write(&url_request_context, |
| 376 URL(kPath4), blob_url)); // Modifies the file. |
| 377 |
| 378 // Verify we have 5 changes for preparation. |
| 379 file_system_.GetChangedURLsInTracker(&urls); |
| 380 EXPECT_EQ(5U, urls.size()); |
| 381 change_tracker()->ClearChangesForURL(URL(kPath0)); |
| 382 change_tracker()->ClearChangesForURL(URL(kPath1)); |
| 383 change_tracker()->ClearChangesForURL(URL(kPath2)); |
| 384 change_tracker()->ClearChangesForURL(URL(kPath3)); |
| 385 change_tracker()->ClearChangesForURL(URL(kPath4)); |
| 386 |
| 387 // Make sure we have no changes. |
| 388 file_system_.GetChangedURLsInTracker(&urls); |
| 389 EXPECT_TRUE(urls.empty()); |
| 390 |
| 391 // Copy the file and the parent directory. |
| 392 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 393 file_system_.Copy(URL(kPath0), URL(kPath0Copy))); // Copy the file. |
| 394 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 395 file_system_.Copy(URL(kPath1), URL(kPath1Copy))); // Copy the dir. |
| 396 |
| 397 file_system_.GetChangedURLsInTracker(&urls); |
| 398 EXPECT_EQ(5U, urls.size()); |
| 399 DropChangesInTracker(); |
| 400 |
| 401 // Make sure we have no in-memory changes in the tracker. |
| 402 file_system_.GetChangedURLsInTracker(&urls); |
| 403 ASSERT_EQ(0U, urls.size()); |
| 404 |
| 405 RestoreChangesFromTrackerDB(); |
| 406 |
| 407 // Make sure the changes are restored from the DB. |
| 408 file_system_.GetChangedURLsInTracker(&urls); |
| 409 EXPECT_EQ(5U, urls.size()); |
| 410 |
| 411 VerifyAndClearChange(URL(kPath0Copy), |
| 412 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
| 413 sync_file_system::SYNC_FILE_TYPE_FILE)); |
| 414 VerifyAndClearChange(URL(kPath1Copy), |
| 415 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
| 416 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
| 417 VerifyAndClearChange(URL(kPath2Copy), |
| 418 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
| 419 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
| 420 VerifyAndClearChange(URL(kPath3Copy), |
| 421 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
| 422 sync_file_system::SYNC_FILE_TYPE_FILE)); |
| 423 VerifyAndClearChange(URL(kPath4Copy), |
| 424 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
| 425 sync_file_system::SYNC_FILE_TYPE_FILE)); |
| 426 } |
| 427 |
367 TEST_F(LocalFileChangeTrackerTest, RestoreMoveChanges) { | 428 TEST_F(LocalFileChangeTrackerTest, RestoreMoveChanges) { |
368 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); | 429 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); |
369 | 430 |
370 FileSystemURLSet urls; | 431 FileSystemURLSet urls; |
371 | 432 |
372 const char kPath0[] = "file a"; | 433 const char kPath0[] = "file a"; |
373 const char kPath1[] = "dir a"; | 434 const char kPath1[] = "dir a"; |
374 const char kPath2[] = "dir a/file"; | 435 const char kPath2[] = "dir a/file"; |
375 const char kPath3[] = "dir a/dir"; | 436 const char kPath3[] = "dir a/dir"; |
376 const char kPath4[] = "dir a/dir/file"; | 437 const char kPath4[] = "dir a/dir/file"; |
377 | 438 |
378 const char kPath5[] = "file b"; // To be moved from kPath0. | 439 const char kPath5[] = "file b"; // To be moved from kPath0. |
379 const char kPath6[] = "dir b"; // To be moved from kPath1. | 440 const char kPath6[] = "dir b"; // To be moved from kPath1. |
380 const char kPath7[] = "dir b/file"; // To be moved from kPath2. | 441 const char kPath7[] = "dir b/file"; // To be moved from kPath2. |
381 const char kPath8[] = "dir b/dir"; // To be moved from kPath3. | 442 const char kPath8[] = "dir b/dir"; // To be moved from kPath3. |
382 const char kPath9[] = "dir b/dir/file"; // To be moved from kPath4. | 443 const char kPath9[] = "dir b/dir/file"; // To be moved from kPath4. |
383 | 444 |
384 file_system_.GetChangedURLsInTracker(&urls); | 445 file_system_.GetChangedURLsInTracker(&urls); |
385 ASSERT_EQ(0U, urls.size()); | 446 ASSERT_EQ(0U, urls.size()); |
386 | 447 |
387 // Creates and moves a same file. | 448 // Create files and nested directories. |
388 EXPECT_EQ(base::PLATFORM_FILE_OK, | 449 EXPECT_EQ(base::PLATFORM_FILE_OK, |
389 file_system_.CreateFile(URL(kPath0))); | 450 file_system_.CreateFile(URL(kPath0))); |
390 EXPECT_EQ(base::PLATFORM_FILE_OK, | 451 EXPECT_EQ(base::PLATFORM_FILE_OK, |
391 file_system_.Move(URL(kPath0), URL(kPath5))); | |
392 | |
393 // Creates files and nested directories, then moves the parent directory. | |
394 EXPECT_EQ(base::PLATFORM_FILE_OK, | |
395 file_system_.CreateDirectory(URL(kPath1))); | 452 file_system_.CreateDirectory(URL(kPath1))); |
396 EXPECT_EQ(base::PLATFORM_FILE_OK, | 453 EXPECT_EQ(base::PLATFORM_FILE_OK, |
397 file_system_.CreateFile(URL(kPath2))); | 454 file_system_.CreateFile(URL(kPath2))); |
398 EXPECT_EQ(base::PLATFORM_FILE_OK, | 455 EXPECT_EQ(base::PLATFORM_FILE_OK, |
399 file_system_.CreateDirectory(URL(kPath3))); | 456 file_system_.CreateDirectory(URL(kPath3))); |
400 EXPECT_EQ(base::PLATFORM_FILE_OK, | 457 EXPECT_EQ(base::PLATFORM_FILE_OK, |
401 file_system_.CreateFile(URL(kPath4))); | 458 file_system_.CreateFile(URL(kPath4))); |
| 459 |
| 460 // Verify we have 5 changes for preparation. |
| 461 file_system_.GetChangedURLsInTracker(&urls); |
| 462 EXPECT_EQ(5U, urls.size()); |
| 463 change_tracker()->ClearChangesForURL(URL(kPath0)); |
| 464 change_tracker()->ClearChangesForURL(URL(kPath1)); |
| 465 change_tracker()->ClearChangesForURL(URL(kPath2)); |
| 466 change_tracker()->ClearChangesForURL(URL(kPath3)); |
| 467 change_tracker()->ClearChangesForURL(URL(kPath4)); |
| 468 |
| 469 // Make sure we have no changes. |
| 470 file_system_.GetChangedURLsInTracker(&urls); |
| 471 EXPECT_TRUE(urls.empty()); |
| 472 |
| 473 // Move the file and the parent directory. |
| 474 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 475 file_system_.Move(URL(kPath0), URL(kPath5))); |
402 EXPECT_EQ(base::PLATFORM_FILE_OK, | 476 EXPECT_EQ(base::PLATFORM_FILE_OK, |
403 file_system_.Move(URL(kPath1), URL(kPath6))); | 477 file_system_.Move(URL(kPath1), URL(kPath6))); |
404 | 478 |
405 urls.clear(); | |
406 file_system_.GetChangedURLsInTracker(&urls); | 479 file_system_.GetChangedURLsInTracker(&urls); |
407 // Since kPath1 and kPath3 were reverted, the number of changes should be 8. | 480 EXPECT_EQ(10U, urls.size()); |
408 EXPECT_EQ(8U, urls.size()); | |
409 | 481 |
410 DropChangesInTracker(); | 482 DropChangesInTracker(); |
411 | 483 |
412 // Make sure we have no in-memory changes in the tracker. | 484 // Make sure we have no in-memory changes in the tracker. |
413 urls.clear(); | |
414 file_system_.GetChangedURLsInTracker(&urls); | 485 file_system_.GetChangedURLsInTracker(&urls); |
415 ASSERT_EQ(0U, urls.size()); | 486 ASSERT_EQ(0U, urls.size()); |
416 | 487 |
417 RestoreChangesFromTrackerDB(); | 488 RestoreChangesFromTrackerDB(); |
418 | 489 |
419 // Make sure the changes are restored from the DB. | 490 // Make sure the changes are restored from the DB. |
420 urls.clear(); | |
421 file_system_.GetChangedURLsInTracker(&urls); | 491 file_system_.GetChangedURLsInTracker(&urls); |
422 // Since directories to have been reverted (kPath1 and kPath3) are treated as | 492 // Deletion for children in the deleted directory cannot be restored, |
423 // FILE_CHANGE_DELETE, the number of changes should be 10. | 493 // so we will only have 7 changes. |
424 EXPECT_EQ(10U, urls.size()); | 494 EXPECT_EQ(7U, urls.size()); |
425 | 495 |
426 VerifyAndClearChange(URL(kPath0), | 496 VerifyAndClearChange(URL(kPath0), |
427 FileChange(FileChange::FILE_CHANGE_DELETE, | 497 FileChange(FileChange::FILE_CHANGE_DELETE, |
428 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); | 498 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
429 VerifyAndClearChange(URL(kPath1), | 499 VerifyAndClearChange(URL(kPath1), |
430 FileChange(FileChange::FILE_CHANGE_DELETE, | 500 FileChange(FileChange::FILE_CHANGE_DELETE, |
431 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); | 501 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); |
432 VerifyAndClearChange(URL(kPath2), | |
433 FileChange(FileChange::FILE_CHANGE_DELETE, | |
434 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); | |
435 VerifyAndClearChange(URL(kPath3), | |
436 FileChange(FileChange::FILE_CHANGE_DELETE, | |
437 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); | |
438 VerifyAndClearChange(URL(kPath4), | |
439 FileChange(FileChange::FILE_CHANGE_DELETE, | |
440 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); | |
441 VerifyAndClearChange(URL(kPath5), | 502 VerifyAndClearChange(URL(kPath5), |
442 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 503 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
443 sync_file_system::SYNC_FILE_TYPE_FILE)); | 504 sync_file_system::SYNC_FILE_TYPE_FILE)); |
444 VerifyAndClearChange(URL(kPath6), | 505 VerifyAndClearChange(URL(kPath6), |
445 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 506 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
446 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); | 507 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
447 VerifyAndClearChange(URL(kPath7), | 508 VerifyAndClearChange(URL(kPath7), |
448 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 509 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
449 sync_file_system::SYNC_FILE_TYPE_FILE)); | 510 sync_file_system::SYNC_FILE_TYPE_FILE)); |
450 VerifyAndClearChange(URL(kPath8), | 511 VerifyAndClearChange(URL(kPath8), |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 ASSERT_EQ(2U, urls_to_process.size()); | 592 ASSERT_EQ(2U, urls_to_process.size()); |
532 | 593 |
533 // The exact order of recursive removal cannot be determined. | 594 // The exact order of recursive removal cannot be determined. |
534 EXPECT_TRUE(URL(kPath1) == urls_to_process[0] || | 595 EXPECT_TRUE(URL(kPath1) == urls_to_process[0] || |
535 URL(kPath2) == urls_to_process[0]); | 596 URL(kPath2) == urls_to_process[0]); |
536 EXPECT_TRUE(URL(kPath1) == urls_to_process[1] || | 597 EXPECT_TRUE(URL(kPath1) == urls_to_process[1] || |
537 URL(kPath2) == urls_to_process[1]); | 598 URL(kPath2) == urls_to_process[1]); |
538 } | 599 } |
539 | 600 |
540 } // namespace sync_file_system | 601 } // namespace sync_file_system |
OLD | NEW |