#include "base/basictypes.h"
#include "base/bind.h"
#include "base/run_loop.h"
+#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/synchronization/waitable_event.h"
+#include "base/thread_task_runner_handle.h"
#include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h"
#include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
#include "chrome/browser/sync_file_system/local/local_file_sync_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_utils.h"
+#include "storage/browser/fileapi/file_system_context.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "webkit/browser/fileapi/file_system_context.h"
+#include "third_party/leveldatabase/src/helpers/memenv/memenv.h"
+#include "third_party/leveldatabase/src/include/leveldb/env.h"
using content::BrowserThread;
-using fileapi::FileSystemURL;
-using fileapi::FileSystemURLSet;
+using storage::FileSystemURL;
+using storage::FileSystemURLSet;
using ::testing::AnyNumber;
using ::testing::AtLeast;
using ::testing::InSequence;
// This is called on IO thread.
void VerifyFileError(base::RunLoop* run_loop,
- base::PlatformFileError error) {
+ base::File::Error error) {
DCHECK(run_loop);
- EXPECT_EQ(base::PLATFORM_FILE_OK, error);
+ EXPECT_EQ(base::File::FILE_OK, error);
run_loop->Quit();
}
void(const GURL& app_origin,
SyncServiceState state,
const std::string& description));
- MOCK_METHOD4(OnFileSynced,
- void(const fileapi::FileSystemURL& url,
+ MOCK_METHOD5(OnFileSynced,
+ void(const storage::FileSystemURL& url,
+ SyncFileType file_type,
SyncFileStatus status,
SyncAction action,
SyncDirection direction));
mock_remote_service, service_state, operation_status) {
mock_remote_service->NotifyRemoteServiceStateUpdated(
service_state, "Test event.");
- base::MessageLoopProxy::current()->PostTask(
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(arg1, operation_status));
}
}
ACTION_P(MockStatusCallback, status) {
- base::MessageLoopProxy::current()->PostTask(
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(arg4, status));
}
ACTION_P2(MockSyncFileCallback, status, url) {
- base::MessageLoopProxy::current()->PostTask(
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(arg0, status, url));
}
+ACTION(InvokeCompletionClosure) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(arg0));
+}
+
class SyncFileSystemServiceTest : public testing::Test {
protected:
SyncFileSystemServiceTest()
: thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD |
content::TestBrowserThreadBundle::REAL_IO_THREAD) {}
- virtual void SetUp() OVERRIDE {
+ virtual void SetUp() override {
+ in_memory_env_.reset(leveldb::NewMemEnv(leveldb::Env::Default()));
file_system_.reset(new CannedSyncableFileSystem(
GURL(kOrigin),
+ in_memory_env_.get(),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
- local_service_ = new LocalFileSyncService(&profile_);
+ scoped_ptr<LocalFileSyncService> local_service =
+ LocalFileSyncService::CreateForTesting(&profile_, in_memory_env_.get());
remote_service_ = new StrictMock<MockRemoteFileSyncService>;
sync_service_.reset(new SyncFileSystemService(&profile_));
EXPECT_CALL(*mock_remote_service(),
- AddServiceObserver(sync_service_.get())).Times(1);
+ AddServiceObserver(_)).Times(1);
EXPECT_CALL(*mock_remote_service(),
AddFileStatusObserver(sync_service_.get())).Times(1);
EXPECT_CALL(*mock_remote_service(),
GetLocalChangeProcessor())
- .WillOnce(Return(&local_change_processor_));
+ .WillRepeatedly(Return(&local_change_processor_));
EXPECT_CALL(*mock_remote_service(),
- SetRemoteChangeProcessor(local_service_)).Times(1);
+ SetRemoteChangeProcessor(local_service.get())).Times(1);
sync_service_->Initialize(
- make_scoped_ptr(local_service_),
+ local_service.Pass(),
scoped_ptr<RemoteFileSyncService>(remote_service_));
// Disable auto sync by default.
EXPECT_CALL(*mock_remote_service(), SetSyncEnabled(false)).Times(1);
sync_service_->SetSyncEnabledForTesting(false);
- file_system_->SetUp();
+ file_system_->SetUp(CannedSyncableFileSystem::QUOTA_ENABLED);
}
- virtual void TearDown() OVERRIDE {
+ virtual void TearDown() override {
sync_service_->Shutdown();
file_system_->TearDown();
RevokeSyncableFileSystem();
run_loop.Run();
EXPECT_EQ(SYNC_STATUS_OK, status);
- EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->OpenFileSystem());
+ EXPECT_EQ(base::File::FILE_OK, file_system_->OpenFileSystem());
}
// Calls InitializeForApp after setting up the mock remote service to
sync_service_->SetSyncEnabledForTesting(true);
}
- ScopedEnableSyncFSDirectoryOperation enable_directory_operation_;
-
content::TestBrowserThreadBundle thread_bundle_;
+ scoped_ptr<leveldb::Env> in_memory_env_;
TestingProfile profile_;
scoped_ptr<CannedSyncableFileSystem> file_system_;
// Their ownerships are transferred to SyncFileSystemService.
- LocalFileSyncService* local_service_;
StrictMock<MockRemoteFileSyncService>* remote_service_;
StrictMock<MockLocalChangeProcessor> local_change_processor_;
EXPECT_CALL(*mock_local_change_processor(),
ApplyLocalChange(change, _, _, kFile, _))
.WillOnce(MockStatusCallback(SYNC_STATUS_OK));
+ EXPECT_CALL(*mock_remote_service(), ProcessRemoteChange(_))
+ .WillRepeatedly(MockSyncFileCallback(SYNC_STATUS_NO_CHANGE_TO_SYNC,
+ FileSystemURL()));
+
+ EXPECT_CALL(*mock_remote_service(), PromoteDemotedChanges(_))
+ .WillRepeatedly(InvokeCompletionClosure());
- EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->CreateFile(kFile));
+ EXPECT_EQ(base::File::FILE_OK, file_system_->CreateFile(kFile));
run_loop.Run();
.WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
}
+ EXPECT_CALL(*mock_remote_service(), PromoteDemotedChanges(_))
+ .WillRepeatedly(InvokeCompletionClosure());
+
// We might also see an activity for local sync as we're going to make
// a local write operation on kFile.
EXPECT_CALL(*mock_local_change_processor(),
SyncStatusCode status;
SyncFileStatus sync_file_status;
- // 1. The file is not in conflicting nor in pending change state.
+ // 1. The file is synced state.
{
base::RunLoop run_loop;
- EXPECT_CALL(*mock_remote_service(), IsConflicting(kFile))
- .WillOnce(Return(false));
-
status = SYNC_STATUS_UNKNOWN;
sync_file_status = SYNC_FILE_STATUS_UNKNOWN;
sync_service_->GetFileSyncStatus(
EXPECT_EQ(SYNC_FILE_STATUS_SYNCED, sync_file_status);
}
- // 2. Conflicting case.
+ // 2. The file has pending local changes.
{
base::RunLoop run_loop;
- EXPECT_CALL(*mock_remote_service(), IsConflicting(kFile))
- .WillOnce(Return(true));
-
- status = SYNC_STATUS_UNKNOWN;
- sync_file_status = SYNC_FILE_STATUS_UNKNOWN;
- sync_service_->GetFileSyncStatus(
- kFile,
- base::Bind(&AssignValueAndQuit<SyncFileStatus>,
- &run_loop, &status, &sync_file_status));
- run_loop.Run();
-
- EXPECT_EQ(SYNC_STATUS_OK, status);
- EXPECT_EQ(SYNC_FILE_STATUS_CONFLICTING, sync_file_status);
- }
-
- // 3. The file has pending local changes.
- {
- EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->CreateFile(kFile));
-
- base::RunLoop run_loop;
- EXPECT_CALL(*mock_remote_service(), IsConflicting(kFile))
- .WillOnce(Return(false));
+ EXPECT_EQ(base::File::FILE_OK, file_system_->CreateFile(kFile));
status = SYNC_STATUS_UNKNOWN;
sync_file_status = SYNC_FILE_STATUS_UNKNOWN;
EXPECT_EQ(SYNC_STATUS_OK, status);
EXPECT_EQ(SYNC_FILE_STATUS_HAS_PENDING_CHANGES, sync_file_status);
}
-
- // 4. The file has a conflict and pending local changes. In this case
- // we return SYNC_FILE_STATUS_CONFLICTING.
- {
- EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->TruncateFile(kFile, 1U));
-
- base::RunLoop run_loop;
- EXPECT_CALL(*mock_remote_service(), IsConflicting(kFile))
- .WillOnce(Return(true));
-
- status = SYNC_STATUS_UNKNOWN;
- sync_file_status = SYNC_FILE_STATUS_UNKNOWN;
- sync_service_->GetFileSyncStatus(
- kFile,
- base::Bind(&AssignValueAndQuit<SyncFileStatus>,
- &run_loop, &status, &sync_file_status));
- run_loop.Run();
-
- EXPECT_EQ(SYNC_STATUS_OK, status);
- EXPECT_EQ(SYNC_FILE_STATUS_CONFLICTING, sync_file_status);
- }
}
} // namespace sync_file_system