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

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

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: 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 { 27 namespace syncer_v2 {
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 ModelTypeRegistry(workers_, dir_maker_.directory(), 38 registry_.reset(new syncer::ModelTypeRegistry(
39 &nudge_handler_)); 39 workers_, dir_maker_.directory(), &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<DataTypeErrorHandlerMock>(), 56 base::MakeUnique<syncer::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(SyncError error, 61 void OnReadyToConnect(syncer::SyncError error,
62 std::unique_ptr<ActivationContext> context) { 62 std::unique_ptr<ActivationContext> context) {
63 connector_proxy_->ConnectType(THEMES, std::move(context)); 63 connector_proxy_->ConnectType(syncer::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(THEMES, this)); 68 base::WrapUnique(new SharedModelTypeProcessor(syncer::THEMES, this));
69 processor->OnMetadataLoaded(SyncError(), base::MakeUnique<MetadataBatch>()); 69 processor->OnMetadataLoaded(syncer::SyncError(),
70 base::MakeUnique<MetadataBatch>());
70 return processor; 71 return processor;
71 } 72 }
72 73
73 private: 74 private:
74 base::MessageLoop loop_; 75 base::MessageLoop loop_;
75 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner_; 76 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner_;
76 scoped_refptr<base::SingleThreadTaskRunner> type_task_runner_; 77 scoped_refptr<base::SingleThreadTaskRunner> type_task_runner_;
77 78
78 std::vector<scoped_refptr<ModelSafeWorker>> workers_; 79 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers_;
79 TestDirectorySetterUpper dir_maker_; 80 syncer::TestDirectorySetterUpper dir_maker_;
80 MockNudgeHandler nudge_handler_; 81 syncer::MockNudgeHandler nudge_handler_;
81 std::unique_ptr<ModelTypeRegistry> registry_; 82 std::unique_ptr<syncer::ModelTypeRegistry> registry_;
82 83
83 std::unique_ptr<ModelTypeConnectorProxy> connector_proxy_; 84 std::unique_ptr<ModelTypeConnectorProxy> connector_proxy_;
84 }; 85 };
85 86
86 // Try to connect a type to a ModelTypeConnector that has already shut down. 87 // Try to connect a type to a ModelTypeConnector that has already shut down.
87 TEST_F(ModelTypeConnectorProxyTest, FailToConnect1) { 88 TEST_F(ModelTypeConnectorProxyTest, FailToConnect1) {
88 std::unique_ptr<SharedModelTypeProcessor> processor = 89 std::unique_ptr<SharedModelTypeProcessor> processor =
89 CreateModelTypeProcessor(); 90 CreateModelTypeProcessor();
90 DisableSync(); 91 DisableSync();
91 OnSyncStarting(processor.get()); 92 OnSyncStarting(processor.get());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 CreateModelTypeProcessor(); 127 CreateModelTypeProcessor();
127 OnSyncStarting(processor.get()); 128 OnSyncStarting(processor.get());
128 129
129 base::RunLoop run_loop_; 130 base::RunLoop run_loop_;
130 run_loop_.RunUntilIdle(); 131 run_loop_.RunUntilIdle();
131 132
132 EXPECT_TRUE(processor->IsConnected()); 133 EXPECT_TRUE(processor->IsConnected());
133 DisableSync(); 134 DisableSync();
134 } 135 }
135 136
136 } // namespace syncer 137 } // namespace syncer_v2
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698