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

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

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix InstantNTP test. Created 7 years, 5 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"
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 #include "chrome/browser/sync_file_system/local_file_sync_service.h" 12 #include "chrome/browser/sync_file_system/local_file_sync_service.h"
13 #include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h" 13 #include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h"
14 #include "chrome/browser/sync_file_system/sync_event_observer.h" 14 #include "chrome/browser/sync_file_system/sync_event_observer.h"
15 #include "chrome/browser/sync_file_system/sync_file_system_service.h" 15 #include "chrome/browser/sync_file_system/sync_file_system_service.h"
16 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h" 16 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h"
17 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "content/public/test/test_utils.h"
18 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
19 #include "webkit/browser/fileapi/file_system_context.h" 22 #include "webkit/browser/fileapi/file_system_context.h"
20 #include "webkit/browser/fileapi/syncable/canned_syncable_file_system.h" 23 #include "webkit/browser/fileapi/syncable/canned_syncable_file_system.h"
21 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h" 24 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h"
22 #include "webkit/browser/fileapi/syncable/mock_sync_status_observer.h" 25 #include "webkit/browser/fileapi/syncable/mock_sync_status_observer.h"
23 #include "webkit/browser/fileapi/syncable/sync_callbacks.h" 26 #include "webkit/browser/fileapi/syncable/sync_callbacks.h"
24 #include "webkit/browser/fileapi/syncable/sync_file_metadata.h" 27 #include "webkit/browser/fileapi/syncable/sync_file_metadata.h"
25 #include "webkit/browser/fileapi/syncable/sync_status_code.h" 28 #include "webkit/browser/fileapi/syncable/sync_status_code.h"
26 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" 29 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h"
27 30
31 using content::BrowserThread;
28 using fileapi::FileSystemURL; 32 using fileapi::FileSystemURL;
29 using fileapi::FileSystemURLSet; 33 using fileapi::FileSystemURLSet;
30 using ::testing::AnyNumber; 34 using ::testing::AnyNumber;
31 using ::testing::AtLeast; 35 using ::testing::AtLeast;
32 using ::testing::InSequence; 36 using ::testing::InSequence;
33 using ::testing::InvokeWithoutArgs; 37 using ::testing::InvokeWithoutArgs;
34 using ::testing::Return; 38 using ::testing::Return;
35 using ::testing::StrictMock; 39 using ::testing::StrictMock;
36 using ::testing::_; 40 using ::testing::_;
37 41
(...skipping 18 matching lines...) Expand all
56 typename AssignTrait<R>::ArgumentType value) { 60 typename AssignTrait<R>::ArgumentType value) {
57 DCHECK(status_out); 61 DCHECK(status_out);
58 DCHECK(value_out); 62 DCHECK(value_out);
59 DCHECK(run_loop); 63 DCHECK(run_loop);
60 *status_out = status; 64 *status_out = status;
61 *value_out = value; 65 *value_out = value;
62 run_loop->Quit(); 66 run_loop->Quit();
63 } 67 }
64 68
65 // This is called on IO thread. 69 // This is called on IO thread.
66 void VerifyFileError(base::WaitableEvent* event, 70 void VerifyFileError(base::RunLoop* run_loop,
67 base::PlatformFileError error) { 71 base::PlatformFileError error) {
68 DCHECK(event); 72 DCHECK(run_loop);
69 EXPECT_EQ(base::PLATFORM_FILE_OK, error); 73 EXPECT_EQ(base::PLATFORM_FILE_OK, error);
70 event->Signal(); 74 run_loop->Quit();
71 } 75 }
72 76
73 } // namespace 77 } // namespace
74 78
75 class MockSyncEventObserver : public SyncEventObserver { 79 class MockSyncEventObserver : public SyncEventObserver {
76 public: 80 public:
77 MockSyncEventObserver() {} 81 MockSyncEventObserver() {}
78 virtual ~MockSyncEventObserver() {} 82 virtual ~MockSyncEventObserver() {}
79 83
80 MOCK_METHOD3(OnSyncStateUpdated, 84 MOCK_METHOD3(OnSyncStateUpdated,
(...skipping 24 matching lines...) Expand all
105 FROM_HERE, base::Bind(arg4, status)); 109 FROM_HERE, base::Bind(arg4, status));
106 } 110 }
107 111
108 ACTION_P2(MockSyncFileCallback, status, url) { 112 ACTION_P2(MockSyncFileCallback, status, url) {
109 base::MessageLoopProxy::current()->PostTask( 113 base::MessageLoopProxy::current()->PostTask(
110 FROM_HERE, base::Bind(arg0, status, url)); 114 FROM_HERE, base::Bind(arg0, status, url));
111 } 115 }
112 116
113 class SyncFileSystemServiceTest : public testing::Test { 117 class SyncFileSystemServiceTest : public testing::Test {
114 protected: 118 protected:
115 SyncFileSystemServiceTest() {} 119 SyncFileSystemServiceTest()
116 virtual ~SyncFileSystemServiceTest() {} 120 : thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD |
121 content::TestBrowserThreadBundle::REAL_IO_THREAD) {}
117 122
118 virtual void SetUp() OVERRIDE { 123 virtual void SetUp() OVERRIDE {
119 thread_helper_.SetUp();
120
121 file_system_.reset(new CannedSyncableFileSystem( 124 file_system_.reset(new CannedSyncableFileSystem(
122 GURL(kOrigin), 125 GURL(kOrigin),
123 thread_helper_.io_task_runner(), 126 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
124 thread_helper_.file_task_runner())); 127 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
125 128
126 local_service_ = new LocalFileSyncService(&profile_); 129 local_service_ = new LocalFileSyncService(&profile_);
127 remote_service_ = new StrictMock<MockRemoteFileSyncService>; 130 remote_service_ = new StrictMock<MockRemoteFileSyncService>;
128 sync_service_.reset(new SyncFileSystemService(&profile_)); 131 sync_service_.reset(new SyncFileSystemService(&profile_));
129 132
130 EXPECT_CALL(*mock_remote_service(), 133 EXPECT_CALL(*mock_remote_service(),
131 AddServiceObserver(sync_service_.get())).Times(1); 134 AddServiceObserver(sync_service_.get())).Times(1);
132 EXPECT_CALL(*mock_remote_service(), 135 EXPECT_CALL(*mock_remote_service(),
133 AddFileStatusObserver(sync_service_.get())).Times(1); 136 AddFileStatusObserver(sync_service_.get())).Times(1);
134 EXPECT_CALL(*mock_remote_service(), 137 EXPECT_CALL(*mock_remote_service(),
135 GetLocalChangeProcessor()) 138 GetLocalChangeProcessor())
136 .WillOnce(Return(&local_change_processor_)); 139 .WillOnce(Return(&local_change_processor_));
137 EXPECT_CALL(*mock_remote_service(), 140 EXPECT_CALL(*mock_remote_service(),
138 SetRemoteChangeProcessor(local_service_)).Times(1); 141 SetRemoteChangeProcessor(local_service_)).Times(1);
139 142
140 sync_service_->Initialize( 143 sync_service_->Initialize(
141 make_scoped_ptr(local_service_), 144 make_scoped_ptr(local_service_),
142 scoped_ptr<RemoteFileSyncService>(remote_service_)); 145 scoped_ptr<RemoteFileSyncService>(remote_service_));
143 146
144 // Disable auto sync by default. 147 // Disable auto sync by default.
145 EXPECT_CALL(*mock_remote_service(), SetSyncEnabled(false)).Times(1); 148 EXPECT_CALL(*mock_remote_service(), SetSyncEnabled(false)).Times(1);
146 sync_service_->SetSyncEnabledForTesting(false); 149 sync_service_->SetSyncEnabledForTesting(false);
147 150
148 file_system_->SetUp(); 151 file_system_->SetUp();
149 } 152 }
150 153
151 virtual void TearDown() OVERRIDE { 154 virtual void TearDown() OVERRIDE {
152 sync_service_->Shutdown(); 155 sync_service_->Shutdown();
153
154 file_system_->TearDown(); 156 file_system_->TearDown();
155 RevokeSyncableFileSystem(); 157 RevokeSyncableFileSystem();
156 thread_helper_.TearDown(); 158 content::RunAllPendingInMessageLoop(BrowserThread::FILE);
157 } 159 }
158 160
159 void InitializeApp() { 161 void InitializeApp() {
160 base::RunLoop run_loop; 162 base::RunLoop run_loop;
161 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 163 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
162 164
163 EXPECT_CALL(*mock_remote_service(), 165 EXPECT_CALL(*mock_remote_service(),
164 RegisterOriginForTrackingChanges(GURL(kOrigin), _)).Times(1); 166 RegisterOriginForTrackingChanges(GURL(kOrigin), _)).Times(1);
165 167
166 sync_service_->InitializeForApp( 168 sync_service_->InitializeForApp(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 return &local_change_processor_; 232 return &local_change_processor_;
231 } 233 }
232 234
233 void EnableSync() { 235 void EnableSync() {
234 EXPECT_CALL(*mock_remote_service(), SetSyncEnabled(true)).Times(1); 236 EXPECT_CALL(*mock_remote_service(), SetSyncEnabled(true)).Times(1);
235 sync_service_->SetSyncEnabledForTesting(true); 237 sync_service_->SetSyncEnabledForTesting(true);
236 } 238 }
237 239
238 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_; 240 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_;
239 241
240 MultiThreadTestHelper thread_helper_; 242 content::TestBrowserThreadBundle thread_bundle_;
241 TestingProfile profile_; 243 TestingProfile profile_;
242 scoped_ptr<CannedSyncableFileSystem> file_system_; 244 scoped_ptr<CannedSyncableFileSystem> file_system_;
243 245
244 // Their ownerships are transferred to SyncFileSystemService. 246 // Their ownerships are transferred to SyncFileSystemService.
245 LocalFileSyncService* local_service_; 247 LocalFileSyncService* local_service_;
246 StrictMock<MockRemoteFileSyncService>* remote_service_; 248 StrictMock<MockRemoteFileSyncService>* remote_service_;
247 StrictMock<MockLocalChangeProcessor> local_change_processor_; 249 StrictMock<MockLocalChangeProcessor> local_change_processor_;
248 250
249 scoped_ptr<SyncFileSystemService> sync_service_; 251 scoped_ptr<SyncFileSystemService> sync_service_;
250 }; 252 };
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 // We might also see an activity for local sync as we're going to make 387 // We might also see an activity for local sync as we're going to make
386 // a local write operation on kFile. 388 // a local write operation on kFile.
387 EXPECT_CALL(*mock_local_change_processor(), 389 EXPECT_CALL(*mock_local_change_processor(),
388 ApplyLocalChange(_, _, _, kFile, _)) 390 ApplyLocalChange(_, _, _, kFile, _))
389 .Times(AnyNumber()); 391 .Times(AnyNumber());
390 392
391 // This should trigger a remote sync. 393 // This should trigger a remote sync.
392 mock_remote_service()->NotifyRemoteChangeQueueUpdated(1); 394 mock_remote_service()->NotifyRemoteChangeQueueUpdated(1);
393 395
394 // Start a local operation on the same file (to make it BUSY). 396 // Start a local operation on the same file (to make it BUSY).
395 base::WaitableEvent event(false, false); 397 base::RunLoop verify_file_error_run_loop;
396 thread_helper_.io_task_runner()->PostTask( 398 BrowserThread::PostTask(
397 FROM_HERE, base::Bind(&CannedSyncableFileSystem::DoCreateFile, 399 BrowserThread::IO,
398 base::Unretained(file_system_.get()), 400 FROM_HERE,
399 kFile, base::Bind(&VerifyFileError, &event))); 401 base::Bind(&CannedSyncableFileSystem::DoCreateFile,
402 base::Unretained(file_system_.get()),
403 kFile, base::Bind(&VerifyFileError,
404 &verify_file_error_run_loop)));
400 405
401 run_loop.Run(); 406 run_loop.Run();
402 407
403 mock_remote_service()->NotifyRemoteChangeQueueUpdated(0); 408 mock_remote_service()->NotifyRemoteChangeQueueUpdated(0);
404 409
405 event.Wait(); 410 verify_file_error_run_loop.Run();
406 } 411 }
407 412
408 TEST_F(SyncFileSystemServiceTest, GetFileSyncStatus) { 413 TEST_F(SyncFileSystemServiceTest, GetFileSyncStatus) {
409 InitializeApp(); 414 InitializeApp();
410 415
411 const FileSystemURL kFile(file_system_->URL("foo")); 416 const FileSystemURL kFile(file_system_->URL("foo"));
412 417
413 SyncStatusCode status; 418 SyncStatusCode status;
414 SyncFileStatus sync_file_status; 419 SyncFileStatus sync_file_status;
415 420
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 base::Bind(&AssignValueAndQuit<SyncFileStatus>, 490 base::Bind(&AssignValueAndQuit<SyncFileStatus>,
486 &run_loop, &status, &sync_file_status)); 491 &run_loop, &status, &sync_file_status));
487 run_loop.Run(); 492 run_loop.Run();
488 493
489 EXPECT_EQ(SYNC_STATUS_OK, status); 494 EXPECT_EQ(SYNC_STATUS_OK, status);
490 EXPECT_EQ(SYNC_FILE_STATUS_CONFLICTING, sync_file_status); 495 EXPECT_EQ(SYNC_FILE_STATUS_CONFLICTING, sync_file_status);
491 } 496 }
492 } 497 }
493 498
494 } // namespace sync_file_system 499 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698