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 "components/sync/device_info/device_info_data_type_controller.h" | 5 #include "components/sync/device_info/device_info_data_type_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/test/scoped_task_environment.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
13 #include "components/sync/base/model_type.h" | 14 #include "components/sync/base/model_type.h" |
14 #include "components/sync/device_info/local_device_info_provider_mock.h" | 15 #include "components/sync/device_info/local_device_info_provider_mock.h" |
15 #include "components/sync/driver/fake_sync_client.h" | 16 #include "components/sync/driver/fake_sync_client.h" |
16 #include "components/sync/driver/sync_api_component_factory.h" | 17 #include "components/sync/driver/sync_api_component_factory.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 namespace syncer { | 20 namespace syncer { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 class DeviceInfoDataTypeControllerTest : public testing::Test { | 24 class DeviceInfoDataTypeControllerTest : public testing::Test { |
24 public: | 25 public: |
25 DeviceInfoDataTypeControllerTest() | 26 DeviceInfoDataTypeControllerTest() |
26 : load_finished_(false), | 27 : scoped_task_environment_( |
| 28 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 29 load_finished_(false), |
27 last_type_(UNSPECIFIED), | 30 last_type_(UNSPECIFIED), |
28 weak_ptr_factory_(this) {} | 31 weak_ptr_factory_(this) {} |
29 ~DeviceInfoDataTypeControllerTest() override {} | 32 ~DeviceInfoDataTypeControllerTest() override {} |
30 | 33 |
31 void SetUp() override { | 34 void SetUp() override { |
32 local_device_ = base::MakeUnique<LocalDeviceInfoProviderMock>( | 35 local_device_ = base::MakeUnique<LocalDeviceInfoProviderMock>( |
33 "cache_guid", "Wayne Gretzky's Hacking Box", "Chromium 10k", | 36 "cache_guid", "Wayne Gretzky's Hacking Box", "Chromium 10k", |
34 "Chrome 10k", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id"); | 37 "Chrome 10k", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id"); |
35 | 38 |
36 controller_ = base::MakeUnique<DeviceInfoDataTypeController>( | 39 controller_ = base::MakeUnique<DeviceInfoDataTypeController>( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 74 |
72 if (last_type_ != DEVICE_INFO) { | 75 if (last_type_ != DEVICE_INFO) { |
73 return testing::AssertionFailure() | 76 return testing::AssertionFailure() |
74 << "OnLoadFinished was called with a wrong sync type: " | 77 << "OnLoadFinished was called with a wrong sync type: " |
75 << last_type_; | 78 << last_type_; |
76 } | 79 } |
77 | 80 |
78 return testing::AssertionSuccess(); | 81 return testing::AssertionSuccess(); |
79 } | 82 } |
80 | 83 |
| 84 private: |
| 85 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 86 |
81 protected: | 87 protected: |
82 std::unique_ptr<DeviceInfoDataTypeController> controller_; | 88 std::unique_ptr<DeviceInfoDataTypeController> controller_; |
83 std::unique_ptr<LocalDeviceInfoProviderMock> local_device_; | 89 std::unique_ptr<LocalDeviceInfoProviderMock> local_device_; |
84 bool load_finished_; | 90 bool load_finished_; |
85 | 91 |
86 private: | 92 private: |
87 base::MessageLoopForUI message_loop_; | |
88 ModelType last_type_; | 93 ModelType last_type_; |
89 SyncError last_error_; | 94 SyncError last_error_; |
90 FakeSyncClient sync_client_; | 95 FakeSyncClient sync_client_; |
91 base::WeakPtrFactory<DeviceInfoDataTypeControllerTest> weak_ptr_factory_; | 96 base::WeakPtrFactory<DeviceInfoDataTypeControllerTest> weak_ptr_factory_; |
92 }; | 97 }; |
93 | 98 |
94 TEST_F(DeviceInfoDataTypeControllerTest, StartModels) { | 99 TEST_F(DeviceInfoDataTypeControllerTest, StartModels) { |
95 Start(); | 100 Start(); |
96 EXPECT_EQ(DataTypeController::MODEL_LOADED, controller_->state()); | 101 EXPECT_EQ(DataTypeController::MODEL_LOADED, controller_->state()); |
97 EXPECT_TRUE(LoadResult()); | 102 EXPECT_TRUE(LoadResult()); |
(...skipping 19 matching lines...) Expand all Loading... |
117 controller_->Stop(); | 122 controller_->Stop(); |
118 // Destroy |local_device_| and |controller_| out of order | 123 // Destroy |local_device_| and |controller_| out of order |
119 // to verify that the controller doesn't crash in the destructor. | 124 // to verify that the controller doesn't crash in the destructor. |
120 local_device_.reset(); | 125 local_device_.reset(); |
121 controller_ = nullptr; | 126 controller_ = nullptr; |
122 } | 127 } |
123 | 128 |
124 } // namespace | 129 } // namespace |
125 | 130 |
126 } // namespace syncer | 131 } // namespace syncer |
OLD | NEW |