// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include #include #include #include #include "base/command_line.h" #include "base/scoped_ptr.h" #include "base/time.h" #include "chrome/browser/sync/engine/model_safe_worker.h" #include "chrome/browser/sync/engine/syncer_thread.h" #include "chrome/browser/sync/engine/syncer_thread_timed_stop.h" #include "chrome/test/sync/engine/mock_server_connection.h" #include "chrome/test/sync/engine/test_directory_setter_upper.h" #include "testing/gtest/include/gtest/gtest.h" using base::Time; using base::TimeDelta; namespace browser_sync { typedef testing::Test SyncerThreadTest; class SyncerThreadWithSyncerTest : public testing::Test { public: SyncerThreadWithSyncerTest() {} virtual void SetUp() { metadb_.SetUp(); connection_.reset(new MockConnectionManager(metadb_.manager(), metadb_.name())); allstatus_.reset(new AllStatus()); syncer_thread_ = SyncerThreadFactory::Create(NULL, metadb_.manager(), connection_.get(), allstatus_.get(), new ModelSafeWorker()); allstatus_->WatchSyncerThread(syncer_thread_); syncer_thread_->SetConnected(true); } virtual void TearDown() { syncer_thread_ = NULL; allstatus_.reset(); connection_.reset(); metadb_.TearDown(); } ManuallyOpenedTestDirectorySetterUpper* metadb() { return &metadb_; } MockConnectionManager* connection() { return connection_.get(); } SyncerThread* syncer_thread() { return syncer_thread_; } private: ManuallyOpenedTestDirectorySetterUpper metadb_; scoped_ptr connection_; scoped_ptr allstatus_; scoped_refptr syncer_thread_; DISALLOW_COPY_AND_ASSIGN(SyncerThreadWithSyncerTest); }; class SyncShareIntercept : public MockConnectionManager::MidCommitObserver { public: SyncShareIntercept() : sync_occured_(false, false) {} virtual ~SyncShareIntercept() {} virtual void Observe() { times_sync_occured_.push_back(Time::NowFromSystemTime()); sync_occured_.Signal(); } void WaitForSyncShare(int at_least_this_many, TimeDelta max_wait) { while (at_least_this_many-- > 0) sync_occured_.TimedWait(max_wait); } std::vector