summaryrefslogtreecommitdiffstats
path: root/sync/internal_api/test/model_type_store_test_util.cc
blob: 13990d8efa93b956c915e43f1545a86fee794690 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2016 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 "sync/internal_api/public/test/model_type_store_test_util.h"

#include <utility>

#include "base/bind.h"
#include "base/run_loop.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace syncer_v2 {

using Result = ModelTypeStore::Result;

namespace {

void MoveStoreToScopedPtr(scoped_ptr<ModelTypeStore>* out_store,
                          Result result,
                          scoped_ptr<ModelTypeStore> in_store) {
  ASSERT_EQ(Result::SUCCESS, result);
  std::swap(*out_store, in_store);
}

}  // namespace

// static
scoped_ptr<ModelTypeStore>
ModelTypeStoreTestUtil::CreateInMemoryStoreForTest() {
  scoped_ptr<ModelTypeStore> store;
  ModelTypeStore::CreateInMemoryStoreForTest(
      base::Bind(&MoveStoreToScopedPtr, &store));

  // Force the initialization to run now, synchronously.
  base::RunLoop().RunUntilIdle();

  EXPECT_TRUE(store);
  return store;
}

// static
void ModelTypeStoreTestUtil::MoveStoreToCallback(
    scoped_ptr<ModelTypeStore> store,
    ModelTypeStore::InitCallback callback) {
  ASSERT_TRUE(store);
  callback.Run(Result::SUCCESS, std::move(store));
}

}  // namespace syncer_v2