| 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "base/sequenced_task_runner.h" | 7 #include "base/sequenced_task_runner.h" |
| 8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
| 9 #include "sync/engine/model_type_sync_proxy_impl.h" | 9 #include "sync/engine/model_type_processor_impl.h" |
| 10 #include "sync/internal_api/public/base/model_type.h" | 10 #include "sync/internal_api/public/base/model_type.h" |
| 11 #include "sync/internal_api/public/sync_context.h" | 11 #include "sync/internal_api/public/sync_context.h" |
| 12 #include "sync/internal_api/sync_context_proxy_impl.h" | 12 #include "sync/internal_api/sync_context_proxy_impl.h" |
| 13 #include "sync/sessions/model_type_registry.h" | 13 #include "sync/sessions/model_type_registry.h" |
| 14 #include "sync/test/engine/mock_nudge_handler.h" | 14 #include "sync/test/engine/mock_nudge_handler.h" |
| 15 #include "sync/test/engine/test_directory_setter_upper.h" | 15 #include "sync/test/engine/test_directory_setter_upper.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace syncer_v2 { | 18 namespace syncer_v2 { |
| 19 | 19 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers_; | 51 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers_; |
| 52 syncer::TestDirectorySetterUpper dir_maker_; | 52 syncer::TestDirectorySetterUpper dir_maker_; |
| 53 syncer::MockNudgeHandler nudge_handler_; | 53 syncer::MockNudgeHandler nudge_handler_; |
| 54 scoped_ptr<syncer::ModelTypeRegistry> registry_; | 54 scoped_ptr<syncer::ModelTypeRegistry> registry_; |
| 55 | 55 |
| 56 scoped_ptr<SyncContextProxyImpl> context_proxy_; | 56 scoped_ptr<SyncContextProxyImpl> context_proxy_; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 // Try to connect a type to a SyncContext that has already shut down. | 59 // Try to connect a type to a SyncContext that has already shut down. |
| 60 TEST_F(SyncContextProxyImplTest, FailToConnect1) { | 60 TEST_F(SyncContextProxyImplTest, FailToConnect1) { |
| 61 ModelTypeSyncProxyImpl themes_sync_proxy(syncer::THEMES); | 61 ModelTypeProcessorImpl themes_sync_proxy(syncer::THEMES); |
| 62 DisableSync(); | 62 DisableSync(); |
| 63 themes_sync_proxy.Enable(GetProxy()); | 63 themes_sync_proxy.Enable(GetProxy()); |
| 64 | 64 |
| 65 base::RunLoop run_loop_; | 65 base::RunLoop run_loop_; |
| 66 run_loop_.RunUntilIdle(); | 66 run_loop_.RunUntilIdle(); |
| 67 EXPECT_FALSE(themes_sync_proxy.IsConnected()); | 67 EXPECT_FALSE(themes_sync_proxy.IsConnected()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Try to connect a type to a SyncContext as it shuts down. | 70 // Try to connect a type to a SyncContext as it shuts down. |
| 71 TEST_F(SyncContextProxyImplTest, FailToConnect2) { | 71 TEST_F(SyncContextProxyImplTest, FailToConnect2) { |
| 72 ModelTypeSyncProxyImpl themes_sync_proxy(syncer::THEMES); | 72 ModelTypeProcessorImpl themes_sync_proxy(syncer::THEMES); |
| 73 themes_sync_proxy.Enable(GetProxy()); | 73 themes_sync_proxy.Enable(GetProxy()); |
| 74 DisableSync(); | 74 DisableSync(); |
| 75 | 75 |
| 76 base::RunLoop run_loop_; | 76 base::RunLoop run_loop_; |
| 77 run_loop_.RunUntilIdle(); | 77 run_loop_.RunUntilIdle(); |
| 78 EXPECT_FALSE(themes_sync_proxy.IsConnected()); | 78 EXPECT_FALSE(themes_sync_proxy.IsConnected()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Tests the case where the type's sync proxy shuts down first. | 81 // Tests the case where the type's sync proxy shuts down first. |
| 82 TEST_F(SyncContextProxyImplTest, TypeDisconnectsFirst) { | 82 TEST_F(SyncContextProxyImplTest, TypeDisconnectsFirst) { |
| 83 scoped_ptr<ModelTypeSyncProxyImpl> themes_sync_proxy( | 83 scoped_ptr<ModelTypeProcessorImpl> themes_sync_proxy( |
| 84 new ModelTypeSyncProxyImpl(syncer::THEMES)); | 84 new ModelTypeProcessorImpl(syncer::THEMES)); |
| 85 themes_sync_proxy->Enable(GetProxy()); | 85 themes_sync_proxy->Enable(GetProxy()); |
| 86 | 86 |
| 87 base::RunLoop run_loop_; | 87 base::RunLoop run_loop_; |
| 88 run_loop_.RunUntilIdle(); | 88 run_loop_.RunUntilIdle(); |
| 89 | 89 |
| 90 EXPECT_TRUE(themes_sync_proxy->IsConnected()); | 90 EXPECT_TRUE(themes_sync_proxy->IsConnected()); |
| 91 themes_sync_proxy.reset(); | 91 themes_sync_proxy.reset(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Tests the case where the sync thread shuts down first. | 94 // Tests the case where the sync thread shuts down first. |
| 95 TEST_F(SyncContextProxyImplTest, SyncDisconnectsFirst) { | 95 TEST_F(SyncContextProxyImplTest, SyncDisconnectsFirst) { |
| 96 scoped_ptr<ModelTypeSyncProxyImpl> themes_sync_proxy( | 96 scoped_ptr<ModelTypeProcessorImpl> themes_sync_proxy( |
| 97 new ModelTypeSyncProxyImpl(syncer::THEMES)); | 97 new ModelTypeProcessorImpl(syncer::THEMES)); |
| 98 themes_sync_proxy->Enable(GetProxy()); | 98 themes_sync_proxy->Enable(GetProxy()); |
| 99 | 99 |
| 100 base::RunLoop run_loop_; | 100 base::RunLoop run_loop_; |
| 101 run_loop_.RunUntilIdle(); | 101 run_loop_.RunUntilIdle(); |
| 102 | 102 |
| 103 EXPECT_TRUE(themes_sync_proxy->IsConnected()); | 103 EXPECT_TRUE(themes_sync_proxy->IsConnected()); |
| 104 DisableSync(); | 104 DisableSync(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace syncer | 107 } // namespace syncer |
| OLD | NEW |