summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authorskym <skym@chromium.org>2016-02-09 09:05:28 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-09 17:06:39 +0000
commit73cba5ad25bdfab281e570d0656a5e9c793c43cc (patch)
treea620d7a89b0f4db217774d2a3f2639f1c8dcd5f9 /sync
parent3bc3a1597398bc28771a6ef136e2e2ab8f0ccfd6 (diff)
downloadchromium_src-73cba5ad25bdfab281e570d0656a5e9c793c43cc.zip
chromium_src-73cba5ad25bdfab281e570d0656a5e9c793c43cc.tar.gz
chromium_src-73cba5ad25bdfab281e570d0656a5e9c793c43cc.tar.bz2
[Sync] Initial integration between DeviceInfoService and ModelTypeStore.
BUG=582460, 543405, 543404 Review URL: https://codereview.chromium.org/1662593002 Cr-Commit-Position: refs/heads/master@{#374398}
Diffstat (limited to 'sync')
-rw-r--r--sync/BUILD.gn2
-rw-r--r--sync/internal_api/public/test/model_type_store_test_util.h29
-rw-r--r--sync/internal_api/test/model_type_store_test_util.cc50
-rw-r--r--sync/sync_tests.gypi2
4 files changed, 83 insertions, 0 deletions
diff --git a/sync/BUILD.gn b/sync/BUILD.gn
index 8c9788c..9cd103d 100644
--- a/sync/BUILD.gn
+++ b/sync/BUILD.gn
@@ -557,6 +557,7 @@ static_library("test_support_sync_internal_api") {
"internal_api/public/test/fake_metadata_change_list.h",
"internal_api/public/test/fake_model_type_service.h",
"internal_api/public/test/fake_sync_manager.h",
+ "internal_api/public/test/model_type_store_test_util.h",
"internal_api/public/test/null_sync_context_proxy.h",
"internal_api/public/test/sync_manager_factory_for_profile_sync_test.h",
"internal_api/public/test/test_entry_factory.h",
@@ -565,6 +566,7 @@ static_library("test_support_sync_internal_api") {
"internal_api/test/fake_metadata_change_list.cc",
"internal_api/test/fake_model_type_service.cc",
"internal_api/test/fake_sync_manager.cc",
+ "internal_api/test/model_type_store_test_util.cc",
"internal_api/test/null_sync_context_proxy.cc",
"internal_api/test/sync_manager_factory_for_profile_sync_test.cc",
"internal_api/test/sync_manager_for_profile_sync_test.cc",
diff --git a/sync/internal_api/public/test/model_type_store_test_util.h b/sync/internal_api/public/test/model_type_store_test_util.h
new file mode 100644
index 0000000..53d010b
--- /dev/null
+++ b/sync/internal_api/public/test/model_type_store_test_util.h
@@ -0,0 +1,29 @@
+// 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.
+
+#ifndef SYNC_INTERNAL_API_PUBLIC_TEST_MODEL_TYPE_STORE_TEST_UTIL_H_
+#define SYNC_INTERNAL_API_PUBLIC_TEST_MODEL_TYPE_STORE_TEST_UTIL_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "sync/api/model_type_store.h"
+
+namespace syncer_v2 {
+
+// Util class with several static methods to facilitate writing unit tests for
+// classes that use ModelTypeStore objects.
+class ModelTypeStoreTestUtil {
+ public:
+ // Creates an in memory store syncronously. Be aware that to do this all
+ // outstanding tasks will be run as the current message loop is pumped.
+ static scoped_ptr<ModelTypeStore> CreateInMemoryStoreForTest();
+
+ // Can be curried with an owned store object to allow passing an already
+ // created store to a service constructor in a unit test.
+ static void MoveStoreToCallback(scoped_ptr<ModelTypeStore> store,
+ ModelTypeStore::InitCallback callback);
+};
+
+} // namespace syncer_v2
+
+#endif // SYNC_INTERNAL_API_PUBLIC_TEST_MODEL_TYPE_STORE_TEST_UTIL_H_
diff --git a/sync/internal_api/test/model_type_store_test_util.cc b/sync/internal_api/test/model_type_store_test_util.cc
new file mode 100644
index 0000000..13990d8
--- /dev/null
+++ b/sync/internal_api/test/model_type_store_test_util.cc
@@ -0,0 +1,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
diff --git a/sync/sync_tests.gypi b/sync/sync_tests.gypi
index 1c0b7ac..6f3231a 100644
--- a/sync/sync_tests.gypi
+++ b/sync/sync_tests.gypi
@@ -186,6 +186,7 @@
'internal_api/public/test/fake_metadata_change_list.h',
'internal_api/public/test/fake_model_type_service.h',
'internal_api/public/test/fake_sync_manager.h',
+ 'internal_api/public/test/model_type_store_test_util.h',
'internal_api/public/test/null_sync_context_proxy.h',
'internal_api/public/test/sync_manager_factory_for_profile_sync_test.h',
'internal_api/public/test/test_entry_factory.h',
@@ -194,6 +195,7 @@
'internal_api/test/fake_metadata_change_list.cc',
'internal_api/test/fake_model_type_service.cc',
'internal_api/test/fake_sync_manager.cc',
+ 'internal_api/test/model_type_store_test_util.cc',
'internal_api/test/null_sync_context_proxy.cc',
'internal_api/test/sync_manager_factory_for_profile_sync_test.cc',
'internal_api/test/sync_manager_for_profile_sync_test.cc',