Home | History | Annotate | Download | only in sync
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
      6 
      7 #include "base/bind.h"
      8 #include "base/bind_helpers.h"
      9 #include "base/location.h"
     10 #include "base/run_loop.h"
     11 #include "chrome/browser/sync/test_profile_sync_service.h"
     12 #include "content/public/test/test_utils.h"
     13 #include "sync/internal_api/public/test/test_user_share.h"
     14 #include "sync/internal_api/public/write_transaction.h"
     15 #include "sync/protocol/sync.pb.h"
     16 #include "sync/util/cryptographer.h"
     17 
     18 using syncer::ModelType;
     19 using syncer::UserShare;
     20 
     21 /* static */
     22 syncer::ImmutableChangeRecordList
     23     ProfileSyncServiceTestHelper::MakeSingletonChangeRecordList(
     24         int64 node_id, syncer::ChangeRecord::Action action) {
     25   syncer::ChangeRecord record;
     26   record.action = action;
     27   record.id = node_id;
     28   syncer::ChangeRecordList records(1, record);
     29   return syncer::ImmutableChangeRecordList(&records);
     30 }
     31 
     32 /* static */
     33 syncer::ImmutableChangeRecordList
     34     ProfileSyncServiceTestHelper::MakeSingletonDeletionChangeRecordList(
     35         int64 node_id, const sync_pb::EntitySpecifics& specifics) {
     36   syncer::ChangeRecord record;
     37   record.action = syncer::ChangeRecord::ACTION_DELETE;
     38   record.id = node_id;
     39   record.specifics = specifics;
     40   syncer::ChangeRecordList records(1, record);
     41   return syncer::ImmutableChangeRecordList(&records);
     42 }
     43 
     44 AbstractProfileSyncServiceTest::AbstractProfileSyncServiceTest()
     45     : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD |
     46                      content::TestBrowserThreadBundle::REAL_FILE_THREAD |
     47                      content::TestBrowserThreadBundle::REAL_IO_THREAD),
     48       sync_service_(NULL) {
     49 }
     50 
     51 AbstractProfileSyncServiceTest::~AbstractProfileSyncServiceTest() {}
     52 
     53 void AbstractProfileSyncServiceTest::SetUp() {
     54 }
     55 
     56 void AbstractProfileSyncServiceTest::TearDown() {
     57   // Pump messages posted by the sync core thread (which may end up
     58   // posting on the IO thread).
     59   base::RunLoop().RunUntilIdle();
     60   content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
     61   base::RunLoop().RunUntilIdle();
     62 }
     63 
     64 bool AbstractProfileSyncServiceTest::CreateRoot(ModelType model_type) {
     65   return syncer::TestUserShare::CreateRoot(model_type,
     66                                            sync_service_->GetUserShare());
     67 }
     68 
     69 CreateRootHelper::CreateRootHelper(AbstractProfileSyncServiceTest* test,
     70                                    ModelType model_type)
     71     : callback_(base::Bind(&CreateRootHelper::CreateRootCallback,
     72                            base::Unretained(this))),
     73       test_(test),
     74       model_type_(model_type),
     75       success_(false) {
     76 }
     77 
     78 CreateRootHelper::~CreateRootHelper() {
     79 }
     80 
     81 const base::Closure& CreateRootHelper::callback() const {
     82   return callback_;
     83 }
     84 
     85 bool CreateRootHelper::success() {
     86   return success_;
     87 }
     88 
     89 void CreateRootHelper::CreateRootCallback() {
     90   success_ = test_->CreateRoot(model_type_);
     91 }
     92