OLD | NEW |
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 "sync/internal_api/sync_context_proxy_impl.h" | 5 #include "sync/internal_api/sync_context_proxy_impl.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" |
(...skipping 30 matching lines...) Expand all Loading... |
41 void TearDown() override { | 41 void TearDown() override { |
42 context_proxy_.reset(); | 42 context_proxy_.reset(); |
43 registry_.reset(); | 43 registry_.reset(); |
44 dir_maker_.TearDown(); | 44 dir_maker_.TearDown(); |
45 } | 45 } |
46 | 46 |
47 // The sync thread could be shut down at any time without warning. This | 47 // The sync thread could be shut down at any time without warning. This |
48 // function simulates such an event. | 48 // function simulates such an event. |
49 void DisableSync() { registry_.reset(); } | 49 void DisableSync() { registry_.reset(); } |
50 | 50 |
51 void Start(SharedModelTypeProcessor* processor) { | 51 void OnSyncStarting(SharedModelTypeProcessor* processor) { |
52 processor->Start(base::Bind(&SyncContextProxyImplTest::StartDone, | 52 processor->OnSyncStarting(base::Bind( |
53 base::Unretained(this))); | 53 &SyncContextProxyImplTest::OnReadyToConnect, base::Unretained(this))); |
54 } | 54 } |
55 | 55 |
56 void StartDone(syncer::SyncError error, | 56 void OnReadyToConnect(syncer::SyncError error, |
57 scoped_ptr<ActivationContext> context) { | 57 scoped_ptr<ActivationContext> context) { |
58 context_proxy_->ConnectTypeToSync(syncer::THEMES, std::move(context)); | 58 context_proxy_->ConnectTypeToSync(syncer::THEMES, std::move(context)); |
59 } | 59 } |
60 | 60 |
61 scoped_ptr<SharedModelTypeProcessor> CreateModelTypeProcessor() { | 61 scoped_ptr<SharedModelTypeProcessor> CreateModelTypeProcessor() { |
62 scoped_ptr<SharedModelTypeProcessor> processor = | 62 scoped_ptr<SharedModelTypeProcessor> processor = |
63 make_scoped_ptr(new SharedModelTypeProcessor(syncer::THEMES, this)); | 63 make_scoped_ptr(new SharedModelTypeProcessor(syncer::THEMES, this)); |
64 processor->OnMetadataLoaded(make_scoped_ptr(new MetadataBatch())); | 64 processor->OnMetadataLoaded(make_scoped_ptr(new MetadataBatch())); |
65 return processor; | 65 return processor; |
66 } | 66 } |
67 | 67 |
68 private: | 68 private: |
69 base::MessageLoop loop_; | 69 base::MessageLoop loop_; |
70 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner_; | 70 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner_; |
71 scoped_refptr<base::SingleThreadTaskRunner> type_task_runner_; | 71 scoped_refptr<base::SingleThreadTaskRunner> type_task_runner_; |
72 | 72 |
73 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers_; | 73 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers_; |
74 syncer::TestDirectorySetterUpper dir_maker_; | 74 syncer::TestDirectorySetterUpper dir_maker_; |
75 syncer::MockNudgeHandler nudge_handler_; | 75 syncer::MockNudgeHandler nudge_handler_; |
76 scoped_ptr<syncer::ModelTypeRegistry> registry_; | 76 scoped_ptr<syncer::ModelTypeRegistry> registry_; |
77 | 77 |
78 scoped_ptr<SyncContextProxyImpl> context_proxy_; | 78 scoped_ptr<SyncContextProxyImpl> context_proxy_; |
79 }; | 79 }; |
80 | 80 |
81 // Try to connect a type to a SyncContext that has already shut down. | 81 // Try to connect a type to a SyncContext that has already shut down. |
82 TEST_F(SyncContextProxyImplTest, FailToConnect1) { | 82 TEST_F(SyncContextProxyImplTest, FailToConnect1) { |
83 scoped_ptr<SharedModelTypeProcessor> processor = CreateModelTypeProcessor(); | 83 scoped_ptr<SharedModelTypeProcessor> processor = CreateModelTypeProcessor(); |
84 DisableSync(); | 84 DisableSync(); |
85 Start(processor.get()); | 85 OnSyncStarting(processor.get()); |
86 | 86 |
87 base::RunLoop run_loop_; | 87 base::RunLoop run_loop_; |
88 run_loop_.RunUntilIdle(); | 88 run_loop_.RunUntilIdle(); |
89 EXPECT_FALSE(processor->IsConnected()); | 89 EXPECT_FALSE(processor->IsConnected()); |
90 } | 90 } |
91 | 91 |
92 // Try to connect a type to a SyncContext as it shuts down. | 92 // Try to connect a type to a SyncContext as it shuts down. |
93 TEST_F(SyncContextProxyImplTest, FailToConnect2) { | 93 TEST_F(SyncContextProxyImplTest, FailToConnect2) { |
94 scoped_ptr<SharedModelTypeProcessor> processor = CreateModelTypeProcessor(); | 94 scoped_ptr<SharedModelTypeProcessor> processor = CreateModelTypeProcessor(); |
95 Start(processor.get()); | 95 OnSyncStarting(processor.get()); |
96 DisableSync(); | 96 DisableSync(); |
97 | 97 |
98 base::RunLoop run_loop_; | 98 base::RunLoop run_loop_; |
99 run_loop_.RunUntilIdle(); | 99 run_loop_.RunUntilIdle(); |
100 EXPECT_FALSE(processor->IsConnected()); | 100 EXPECT_FALSE(processor->IsConnected()); |
101 } | 101 } |
102 | 102 |
103 // Tests the case where the type's sync proxy shuts down first. | 103 // Tests the case where the type's sync proxy shuts down first. |
104 TEST_F(SyncContextProxyImplTest, TypeDisconnectsFirst) { | 104 TEST_F(SyncContextProxyImplTest, TypeDisconnectsFirst) { |
105 scoped_ptr<SharedModelTypeProcessor> processor = CreateModelTypeProcessor(); | 105 scoped_ptr<SharedModelTypeProcessor> processor = CreateModelTypeProcessor(); |
106 Start(processor.get()); | 106 OnSyncStarting(processor.get()); |
107 | 107 |
108 base::RunLoop run_loop_; | 108 base::RunLoop run_loop_; |
109 run_loop_.RunUntilIdle(); | 109 run_loop_.RunUntilIdle(); |
110 | 110 |
111 EXPECT_TRUE(processor->IsConnected()); | 111 EXPECT_TRUE(processor->IsConnected()); |
112 processor.reset(); | 112 processor.reset(); |
113 } | 113 } |
114 | 114 |
115 // Tests the case where the sync thread shuts down first. | 115 // Tests the case where the sync thread shuts down first. |
116 TEST_F(SyncContextProxyImplTest, SyncDisconnectsFirst) { | 116 TEST_F(SyncContextProxyImplTest, SyncDisconnectsFirst) { |
117 scoped_ptr<SharedModelTypeProcessor> processor = CreateModelTypeProcessor(); | 117 scoped_ptr<SharedModelTypeProcessor> processor = CreateModelTypeProcessor(); |
118 Start(processor.get()); | 118 OnSyncStarting(processor.get()); |
119 | 119 |
120 base::RunLoop run_loop_; | 120 base::RunLoop run_loop_; |
121 run_loop_.RunUntilIdle(); | 121 run_loop_.RunUntilIdle(); |
122 | 122 |
123 EXPECT_TRUE(processor->IsConnected()); | 123 EXPECT_TRUE(processor->IsConnected()); |
124 DisableSync(); | 124 DisableSync(); |
125 } | 125 } |
126 | 126 |
127 } // namespace syncer_v2 | 127 } // namespace syncer_v2 |
OLD | NEW |