Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: chrome/browser/sync_file_system/sync_file_system_service_unittest.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 DCHECK(status_out); 62 DCHECK(status_out);
63 DCHECK(value_out); 63 DCHECK(value_out);
64 DCHECK(run_loop); 64 DCHECK(run_loop);
65 *status_out = status; 65 *status_out = status;
66 *value_out = value; 66 *value_out = value;
67 run_loop->Quit(); 67 run_loop->Quit();
68 } 68 }
69 69
70 // This is called on IO thread. 70 // This is called on IO thread.
71 void VerifyFileError(base::RunLoop* run_loop, 71 void VerifyFileError(base::RunLoop* run_loop,
72 base::PlatformFileError error) { 72 base::File::Error error) {
73 DCHECK(run_loop); 73 DCHECK(run_loop);
74 EXPECT_EQ(base::PLATFORM_FILE_OK, error); 74 EXPECT_EQ(base::File::FILE_OK, error);
75 run_loop->Quit(); 75 run_loop->Quit();
76 } 76 }
77 77
78 } // namespace 78 } // namespace
79 79
80 class MockSyncEventObserver : public SyncEventObserver { 80 class MockSyncEventObserver : public SyncEventObserver {
81 public: 81 public:
82 MockSyncEventObserver() {} 82 MockSyncEventObserver() {}
83 virtual ~MockSyncEventObserver() {} 83 virtual ~MockSyncEventObserver() {}
84 84
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 .Times(AnyNumber()) 172 .Times(AnyNumber())
173 .WillRepeatedly(Return(REMOTE_SERVICE_OK)); 173 .WillRepeatedly(Return(REMOTE_SERVICE_OK));
174 174
175 sync_service_->InitializeForApp( 175 sync_service_->InitializeForApp(
176 file_system_->file_system_context(), 176 file_system_->file_system_context(),
177 GURL(kOrigin), 177 GURL(kOrigin),
178 AssignAndQuitCallback(&run_loop, &status)); 178 AssignAndQuitCallback(&run_loop, &status));
179 run_loop.Run(); 179 run_loop.Run();
180 180
181 EXPECT_EQ(SYNC_STATUS_OK, status); 181 EXPECT_EQ(SYNC_STATUS_OK, status);
182 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->OpenFileSystem()); 182 EXPECT_EQ(base::File::FILE_OK, file_system_->OpenFileSystem());
183 } 183 }
184 184
185 // Calls InitializeForApp after setting up the mock remote service to 185 // Calls InitializeForApp after setting up the mock remote service to
186 // perform following when RegisterOrigin is called: 186 // perform following when RegisterOrigin is called:
187 // 1. Notify RemoteFileSyncService's observers of |state_to_notify| 187 // 1. Notify RemoteFileSyncService's observers of |state_to_notify|
188 // 2. Run the given callback with |status_to_return|. 188 // 2. Run the given callback with |status_to_return|.
189 // 189 //
190 // ..and verifies if following conditions are met: 190 // ..and verifies if following conditions are met:
191 // 1. The SyncEventObserver of the service is called with 191 // 1. The SyncEventObserver of the service is called with
192 // |expected_states| service state values. 192 // |expected_states| service state values.
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 } 337 }
338 338
339 // The local_change_processor's ApplyLocalChange should be called once 339 // The local_change_processor's ApplyLocalChange should be called once
340 // with ADD_OR_UPDATE change for TYPE_FILE. 340 // with ADD_OR_UPDATE change for TYPE_FILE.
341 const FileChange change(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 341 const FileChange change(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
342 SYNC_FILE_TYPE_FILE); 342 SYNC_FILE_TYPE_FILE);
343 EXPECT_CALL(*mock_local_change_processor(), 343 EXPECT_CALL(*mock_local_change_processor(),
344 ApplyLocalChange(change, _, _, kFile, _)) 344 ApplyLocalChange(change, _, _, kFile, _))
345 .WillOnce(MockStatusCallback(SYNC_STATUS_OK)); 345 .WillOnce(MockStatusCallback(SYNC_STATUS_OK));
346 346
347 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->CreateFile(kFile)); 347 EXPECT_EQ(base::File::FILE_OK, file_system_->CreateFile(kFile));
348 348
349 run_loop.Run(); 349 run_loop.Run();
350 350
351 file_system_->RemoveSyncStatusObserver(&status_observer); 351 file_system_->RemoveSyncStatusObserver(&status_observer);
352 } 352 }
353 353
354 TEST_F(SyncFileSystemServiceTest, SimpleRemoteSyncFlow) { 354 TEST_F(SyncFileSystemServiceTest, SimpleRemoteSyncFlow) {
355 InitializeApp(); 355 InitializeApp();
356 356
357 EnableSync(); 357 EnableSync();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 base::Bind(&AssignValueAndQuit<SyncFileStatus>, 465 base::Bind(&AssignValueAndQuit<SyncFileStatus>,
466 &run_loop, &status, &sync_file_status)); 466 &run_loop, &status, &sync_file_status));
467 run_loop.Run(); 467 run_loop.Run();
468 468
469 EXPECT_EQ(SYNC_STATUS_OK, status); 469 EXPECT_EQ(SYNC_STATUS_OK, status);
470 EXPECT_EQ(SYNC_FILE_STATUS_CONFLICTING, sync_file_status); 470 EXPECT_EQ(SYNC_FILE_STATUS_CONFLICTING, sync_file_status);
471 } 471 }
472 472
473 // 3. The file has pending local changes. 473 // 3. The file has pending local changes.
474 { 474 {
475 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->CreateFile(kFile)); 475 EXPECT_EQ(base::File::FILE_OK, file_system_->CreateFile(kFile));
476 476
477 base::RunLoop run_loop; 477 base::RunLoop run_loop;
478 EXPECT_CALL(*mock_remote_service(), IsConflicting(kFile)) 478 EXPECT_CALL(*mock_remote_service(), IsConflicting(kFile))
479 .WillOnce(Return(false)); 479 .WillOnce(Return(false));
480 480
481 status = SYNC_STATUS_UNKNOWN; 481 status = SYNC_STATUS_UNKNOWN;
482 sync_file_status = SYNC_FILE_STATUS_UNKNOWN; 482 sync_file_status = SYNC_FILE_STATUS_UNKNOWN;
483 sync_service_->GetFileSyncStatus( 483 sync_service_->GetFileSyncStatus(
484 kFile, 484 kFile,
485 base::Bind(&AssignValueAndQuit<SyncFileStatus>, 485 base::Bind(&AssignValueAndQuit<SyncFileStatus>,
486 &run_loop, &status, &sync_file_status)); 486 &run_loop, &status, &sync_file_status));
487 run_loop.Run(); 487 run_loop.Run();
488 488
489 EXPECT_EQ(SYNC_STATUS_OK, status); 489 EXPECT_EQ(SYNC_STATUS_OK, status);
490 EXPECT_EQ(SYNC_FILE_STATUS_HAS_PENDING_CHANGES, sync_file_status); 490 EXPECT_EQ(SYNC_FILE_STATUS_HAS_PENDING_CHANGES, sync_file_status);
491 } 491 }
492 492
493 // 4. The file has a conflict and pending local changes. In this case 493 // 4. The file has a conflict and pending local changes. In this case
494 // we return SYNC_FILE_STATUS_CONFLICTING. 494 // we return SYNC_FILE_STATUS_CONFLICTING.
495 { 495 {
496 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->TruncateFile(kFile, 1U)); 496 EXPECT_EQ(base::File::FILE_OK, file_system_->TruncateFile(kFile, 1U));
497 497
498 base::RunLoop run_loop; 498 base::RunLoop run_loop;
499 EXPECT_CALL(*mock_remote_service(), IsConflicting(kFile)) 499 EXPECT_CALL(*mock_remote_service(), IsConflicting(kFile))
500 .WillOnce(Return(true)); 500 .WillOnce(Return(true));
501 501
502 status = SYNC_STATUS_UNKNOWN; 502 status = SYNC_STATUS_UNKNOWN;
503 sync_file_status = SYNC_FILE_STATUS_UNKNOWN; 503 sync_file_status = SYNC_FILE_STATUS_UNKNOWN;
504 sync_service_->GetFileSyncStatus( 504 sync_service_->GetFileSyncStatus(
505 kFile, 505 kFile,
506 base::Bind(&AssignValueAndQuit<SyncFileStatus>, 506 base::Bind(&AssignValueAndQuit<SyncFileStatus>,
507 &run_loop, &status, &sync_file_status)); 507 &run_loop, &status, &sync_file_status));
508 run_loop.Run(); 508 run_loop.Run();
509 509
510 EXPECT_EQ(SYNC_STATUS_OK, status); 510 EXPECT_EQ(SYNC_STATUS_OK, status);
511 EXPECT_EQ(SYNC_FILE_STATUS_CONFLICTING, sync_file_status); 511 EXPECT_EQ(SYNC_FILE_STATUS_CONFLICTING, sync_file_status);
512 } 512 }
513 } 513 }
514 514
515 } // namespace sync_file_system 515 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698