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

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

Issue 145693005: [FileAPI] Replace default leveldb::Env with leveldb::MemEnv in tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 10 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/canned_syncable_file_system.h" 12 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h"
13 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" 13 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
14 #include "chrome/browser/sync_file_system/local/local_file_sync_service.h" 14 #include "chrome/browser/sync_file_system/local/local_file_sync_service.h"
15 #include "chrome/browser/sync_file_system/local/mock_sync_status_observer.h" 15 #include "chrome/browser/sync_file_system/local/mock_sync_status_observer.h"
16 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" 16 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
17 #include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h" 17 #include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h"
18 #include "chrome/browser/sync_file_system/sync_callbacks.h" 18 #include "chrome/browser/sync_file_system/sync_callbacks.h"
19 #include "chrome/browser/sync_file_system/sync_event_observer.h" 19 #include "chrome/browser/sync_file_system/sync_event_observer.h"
20 #include "chrome/browser/sync_file_system/sync_file_metadata.h" 20 #include "chrome/browser/sync_file_system/sync_file_metadata.h"
21 #include "chrome/browser/sync_file_system/sync_file_system_service.h" 21 #include "chrome/browser/sync_file_system/sync_file_system_service.h"
22 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h" 22 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h"
23 #include "chrome/browser/sync_file_system/sync_status_code.h" 23 #include "chrome/browser/sync_file_system/sync_status_code.h"
24 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" 24 #include "chrome/browser/sync_file_system/syncable_file_system_util.h"
25 #include "chrome/test/base/testing_profile.h" 25 #include "chrome/test/base/testing_profile.h"
26 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/test/test_browser_thread_bundle.h" 27 #include "content/public/test/test_browser_thread_bundle.h"
28 #include "content/public/test/test_utils.h" 28 #include "content/public/test/test_utils.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h"
31 #include "third_party/leveldatabase/src/include/leveldb/env.h"
30 #include "webkit/browser/fileapi/file_system_context.h" 32 #include "webkit/browser/fileapi/file_system_context.h"
31 33
32 using content::BrowserThread; 34 using content::BrowserThread;
33 using fileapi::FileSystemURL; 35 using fileapi::FileSystemURL;
34 using fileapi::FileSystemURLSet; 36 using fileapi::FileSystemURLSet;
35 using ::testing::AnyNumber; 37 using ::testing::AnyNumber;
36 using ::testing::AtLeast; 38 using ::testing::AtLeast;
37 using ::testing::InSequence; 39 using ::testing::InSequence;
38 using ::testing::InvokeWithoutArgs; 40 using ::testing::InvokeWithoutArgs;
39 using ::testing::Return; 41 using ::testing::Return;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 FROM_HERE, base::Bind(arg0, status, url)); 117 FROM_HERE, base::Bind(arg0, status, url));
116 } 118 }
117 119
118 class SyncFileSystemServiceTest : public testing::Test { 120 class SyncFileSystemServiceTest : public testing::Test {
119 protected: 121 protected:
120 SyncFileSystemServiceTest() 122 SyncFileSystemServiceTest()
121 : thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD | 123 : thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD |
122 content::TestBrowserThreadBundle::REAL_IO_THREAD) {} 124 content::TestBrowserThreadBundle::REAL_IO_THREAD) {}
123 125
124 virtual void SetUp() OVERRIDE { 126 virtual void SetUp() OVERRIDE {
127 in_memory_env_.reset(leveldb::NewMemEnv(leveldb::Env::Default()));
125 file_system_.reset(new CannedSyncableFileSystem( 128 file_system_.reset(new CannedSyncableFileSystem(
126 GURL(kOrigin), 129 GURL(kOrigin),
130 in_memory_env_.get(),
127 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), 131 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
128 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); 132 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
129 133
130 local_service_ = new LocalFileSyncService(&profile_); 134 scoped_ptr<LocalFileSyncService> local_service =
135 LocalFileSyncService::CreateForTesting(&profile_, in_memory_env_.get());
131 remote_service_ = new StrictMock<MockRemoteFileSyncService>; 136 remote_service_ = new StrictMock<MockRemoteFileSyncService>;
132 sync_service_.reset(new SyncFileSystemService(&profile_)); 137 sync_service_.reset(new SyncFileSystemService(&profile_));
133 138
134 EXPECT_CALL(*mock_remote_service(), 139 EXPECT_CALL(*mock_remote_service(),
135 AddServiceObserver(_)).Times(1); 140 AddServiceObserver(_)).Times(1);
136 EXPECT_CALL(*mock_remote_service(), 141 EXPECT_CALL(*mock_remote_service(),
137 AddFileStatusObserver(sync_service_.get())).Times(1); 142 AddFileStatusObserver(sync_service_.get())).Times(1);
138 EXPECT_CALL(*mock_remote_service(), 143 EXPECT_CALL(*mock_remote_service(),
139 GetLocalChangeProcessor()) 144 GetLocalChangeProcessor())
140 .WillRepeatedly(Return(&local_change_processor_)); 145 .WillRepeatedly(Return(&local_change_processor_));
141 EXPECT_CALL(*mock_remote_service(), 146 EXPECT_CALL(*mock_remote_service(),
142 SetRemoteChangeProcessor(local_service_)).Times(1); 147 SetRemoteChangeProcessor(local_service.get())).Times(1);
143 148
144 sync_service_->Initialize( 149 sync_service_->Initialize(
145 make_scoped_ptr(local_service_), 150 local_service.Pass(),
146 scoped_ptr<RemoteFileSyncService>(remote_service_)); 151 scoped_ptr<RemoteFileSyncService>(remote_service_));
147 152
148 // Disable auto sync by default. 153 // Disable auto sync by default.
149 EXPECT_CALL(*mock_remote_service(), SetSyncEnabled(false)).Times(1); 154 EXPECT_CALL(*mock_remote_service(), SetSyncEnabled(false)).Times(1);
150 sync_service_->SetSyncEnabledForTesting(false); 155 sync_service_->SetSyncEnabledForTesting(false);
151 156
152 file_system_->SetUp(); 157 file_system_->SetUp();
153 } 158 }
154 159
155 virtual void TearDown() OVERRIDE { 160 virtual void TearDown() OVERRIDE {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 249 }
245 250
246 void EnableSync() { 251 void EnableSync() {
247 EXPECT_CALL(*mock_remote_service(), SetSyncEnabled(true)).Times(1); 252 EXPECT_CALL(*mock_remote_service(), SetSyncEnabled(true)).Times(1);
248 sync_service_->SetSyncEnabledForTesting(true); 253 sync_service_->SetSyncEnabledForTesting(true);
249 } 254 }
250 255
251 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_; 256 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_;
252 257
253 content::TestBrowserThreadBundle thread_bundle_; 258 content::TestBrowserThreadBundle thread_bundle_;
259 scoped_ptr<leveldb::Env> in_memory_env_;
254 TestingProfile profile_; 260 TestingProfile profile_;
255 scoped_ptr<CannedSyncableFileSystem> file_system_; 261 scoped_ptr<CannedSyncableFileSystem> file_system_;
256 262
257 // Their ownerships are transferred to SyncFileSystemService. 263 // Their ownerships are transferred to SyncFileSystemService.
258 LocalFileSyncService* local_service_;
259 StrictMock<MockRemoteFileSyncService>* remote_service_; 264 StrictMock<MockRemoteFileSyncService>* remote_service_;
260 StrictMock<MockLocalChangeProcessor> local_change_processor_; 265 StrictMock<MockLocalChangeProcessor> local_change_processor_;
261 266
262 scoped_ptr<SyncFileSystemService> sync_service_; 267 scoped_ptr<SyncFileSystemService> sync_service_;
263 }; 268 };
264 269
265 TEST_F(SyncFileSystemServiceTest, InitializeForApp) { 270 TEST_F(SyncFileSystemServiceTest, InitializeForApp) {
266 InitializeApp(); 271 InitializeApp();
267 } 272 }
268 273
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 base::Bind(&AssignValueAndQuit<SyncFileStatus>, 511 base::Bind(&AssignValueAndQuit<SyncFileStatus>,
507 &run_loop, &status, &sync_file_status)); 512 &run_loop, &status, &sync_file_status));
508 run_loop.Run(); 513 run_loop.Run();
509 514
510 EXPECT_EQ(SYNC_STATUS_OK, status); 515 EXPECT_EQ(SYNC_STATUS_OK, status);
511 EXPECT_EQ(SYNC_FILE_STATUS_CONFLICTING, sync_file_status); 516 EXPECT_EQ(SYNC_FILE_STATUS_CONFLICTING, sync_file_status);
512 } 517 }
513 } 518 }
514 519
515 } // namespace sync_file_system 520 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698