Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: components/sync/core_impl/model_type_connector_proxy_unittest.cc

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Rebase. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/sync/core_impl/model_type_connector_proxy.h" 5 #include "components/sync/core_impl/model_type_connector_proxy.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "components/sync/api/data_type_error_handler_mock.h" 16 #include "components/sync/api/data_type_error_handler_mock.h"
17 #include "components/sync/api/stub_model_type_service.h" 17 #include "components/sync/api/stub_model_type_service.h"
18 #include "components/sync/base/model_type.h" 18 #include "components/sync/base/model_type.h"
19 #include "components/sync/core/activation_context.h" 19 #include "components/sync/core/activation_context.h"
20 #include "components/sync/core/model_type_connector.h" 20 #include "components/sync/core/model_type_connector.h"
21 #include "components/sync/core/shared_model_type_processor.h" 21 #include "components/sync/core/shared_model_type_processor.h"
22 #include "components/sync/engine_impl/model_type_registry.h" 22 #include "components/sync/engine_impl/model_type_registry.h"
23 #include "components/sync/test/engine/mock_nudge_handler.h" 23 #include "components/sync/test/engine/mock_nudge_handler.h"
24 #include "components/sync/test/engine/test_directory_setter_upper.h" 24 #include "components/sync/test/engine/test_directory_setter_upper.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 namespace syncer_v2 { 27 namespace syncer {
28 28
29 class ModelTypeConnectorProxyTest : public ::testing::Test, 29 class ModelTypeConnectorProxyTest : public ::testing::Test,
30 StubModelTypeService { 30 StubModelTypeService {
31 public: 31 public:
32 ModelTypeConnectorProxyTest() 32 ModelTypeConnectorProxyTest()
33 : sync_task_runner_(base::ThreadTaskRunnerHandle::Get()), 33 : sync_task_runner_(base::ThreadTaskRunnerHandle::Get()),
34 type_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 34 type_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
35 35
36 void SetUp() override { 36 void SetUp() override {
37 dir_maker_.SetUp(); 37 dir_maker_.SetUp();
38 registry_.reset(new syncer::ModelTypeRegistry( 38 registry_.reset(new ModelTypeRegistry(workers_, dir_maker_.directory(),
39 workers_, dir_maker_.directory(), &nudge_handler_)); 39 &nudge_handler_));
40 connector_proxy_.reset( 40 connector_proxy_.reset(
41 new ModelTypeConnectorProxy(sync_task_runner_, registry_->AsWeakPtr())); 41 new ModelTypeConnectorProxy(sync_task_runner_, registry_->AsWeakPtr()));
42 } 42 }
43 43
44 void TearDown() override { 44 void TearDown() override {
45 connector_proxy_.reset(); 45 connector_proxy_.reset();
46 registry_.reset(); 46 registry_.reset();
47 dir_maker_.TearDown(); 47 dir_maker_.TearDown();
48 } 48 }
49 49
50 // The sync thread could be shut down at any time without warning. This 50 // The sync thread could be shut down at any time without warning. This
51 // function simulates such an event. 51 // function simulates such an event.
52 void DisableSync() { registry_.reset(); } 52 void DisableSync() { registry_.reset(); }
53 53
54 void OnSyncStarting(SharedModelTypeProcessor* processor) { 54 void OnSyncStarting(SharedModelTypeProcessor* processor) {
55 processor->OnSyncStarting( 55 processor->OnSyncStarting(
56 base::MakeUnique<syncer::DataTypeErrorHandlerMock>(), 56 base::MakeUnique<DataTypeErrorHandlerMock>(),
57 base::Bind(&ModelTypeConnectorProxyTest::OnReadyToConnect, 57 base::Bind(&ModelTypeConnectorProxyTest::OnReadyToConnect,
58 base::Unretained(this))); 58 base::Unretained(this)));
59 } 59 }
60 60
61 void OnReadyToConnect(syncer::SyncError error, 61 void OnReadyToConnect(SyncError error,
62 std::unique_ptr<ActivationContext> context) { 62 std::unique_ptr<ActivationContext> context) {
63 connector_proxy_->ConnectType(syncer::THEMES, std::move(context)); 63 connector_proxy_->ConnectType(THEMES, std::move(context));
64 } 64 }
65 65
66 std::unique_ptr<SharedModelTypeProcessor> CreateModelTypeProcessor() { 66 std::unique_ptr<SharedModelTypeProcessor> CreateModelTypeProcessor() {
67 std::unique_ptr<SharedModelTypeProcessor> processor = 67 std::unique_ptr<SharedModelTypeProcessor> processor =
68 base::WrapUnique(new SharedModelTypeProcessor(syncer::THEMES, this)); 68 base::WrapUnique(new SharedModelTypeProcessor(THEMES, this));
69 processor->OnMetadataLoaded(syncer::SyncError(), 69 processor->OnMetadataLoaded(SyncError(), base::MakeUnique<MetadataBatch>());
70 base::MakeUnique<MetadataBatch>());
71 return processor; 70 return processor;
72 } 71 }
73 72
74 private: 73 private:
75 base::MessageLoop loop_; 74 base::MessageLoop loop_;
76 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner_; 75 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner_;
77 scoped_refptr<base::SingleThreadTaskRunner> type_task_runner_; 76 scoped_refptr<base::SingleThreadTaskRunner> type_task_runner_;
78 77
79 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers_; 78 std::vector<scoped_refptr<ModelSafeWorker>> workers_;
80 syncer::TestDirectorySetterUpper dir_maker_; 79 TestDirectorySetterUpper dir_maker_;
81 syncer::MockNudgeHandler nudge_handler_; 80 MockNudgeHandler nudge_handler_;
82 std::unique_ptr<syncer::ModelTypeRegistry> registry_; 81 std::unique_ptr<ModelTypeRegistry> registry_;
83 82
84 std::unique_ptr<ModelTypeConnectorProxy> connector_proxy_; 83 std::unique_ptr<ModelTypeConnectorProxy> connector_proxy_;
85 }; 84 };
86 85
87 // Try to connect a type to a ModelTypeConnector that has already shut down. 86 // Try to connect a type to a ModelTypeConnector that has already shut down.
88 TEST_F(ModelTypeConnectorProxyTest, FailToConnect1) { 87 TEST_F(ModelTypeConnectorProxyTest, FailToConnect1) {
89 std::unique_ptr<SharedModelTypeProcessor> processor = 88 std::unique_ptr<SharedModelTypeProcessor> processor =
90 CreateModelTypeProcessor(); 89 CreateModelTypeProcessor();
91 DisableSync(); 90 DisableSync();
92 OnSyncStarting(processor.get()); 91 OnSyncStarting(processor.get());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 CreateModelTypeProcessor(); 126 CreateModelTypeProcessor();
128 OnSyncStarting(processor.get()); 127 OnSyncStarting(processor.get());
129 128
130 base::RunLoop run_loop_; 129 base::RunLoop run_loop_;
131 run_loop_.RunUntilIdle(); 130 run_loop_.RunUntilIdle();
132 131
133 EXPECT_TRUE(processor->IsConnected()); 132 EXPECT_TRUE(processor->IsConnected());
134 DisableSync(); 133 DisableSync();
135 } 134 }
136 135
137 } // namespace syncer_v2 136 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698