| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "device/geolocation/wifi_data_provider_common.h" | 5 #include "content/browser/geolocation/wifi_data_provider_common.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 13 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "device/geolocation/wifi_data_provider_manager.h" | 15 #include "content/browser/geolocation/wifi_data_provider_manager.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using testing::_; | 20 using testing::_; |
| 20 using testing::AtLeast; | 21 using testing::AtLeast; |
| 21 using testing::DoDefault; | 22 using testing::DoDefault; |
| 22 using testing::Invoke; | 23 using testing::Invoke; |
| 23 using testing::Return; | 24 using testing::Return; |
| 24 | 25 |
| 25 namespace device { | 26 namespace content { |
| 26 | 27 |
| 27 class MockWlanApi : public WifiDataProviderCommon::WlanApiInterface { | 28 class MockWlanApi : public WifiDataProviderCommon::WlanApiInterface { |
| 28 public: | 29 public: |
| 29 MockWlanApi() : calls_(0), bool_return_(true) { | 30 MockWlanApi() : calls_(0), bool_return_(true) { |
| 30 ANNOTATE_BENIGN_RACE(&calls_, "This is a test-only data race on a counter"); | 31 ANNOTATE_BENIGN_RACE(&calls_, "This is a test-only data race on a counter"); |
| 31 ON_CALL(*this, GetAccessPointData(_)) | 32 ON_CALL(*this, GetAccessPointData(_)) |
| 32 .WillByDefault(Invoke(this, &MockWlanApi::GetAccessPointDataInternal)); | 33 .WillByDefault(Invoke(this, &MockWlanApi::GetAccessPointDataInternal)); |
| 33 } | 34 } |
| 34 | 35 |
| 35 MOCK_METHOD1(GetAccessPointData, bool(WifiData::AccessPointDataSet* data)); | 36 MOCK_METHOD1(GetAccessPointData, bool(WifiData::AccessPointDataSet* data)); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 EXPECT_TRUE(main_task_runner_->BelongsToCurrentThread()); | 118 EXPECT_TRUE(main_task_runner_->BelongsToCurrentThread()); |
| 118 run_loop_->Quit(); | 119 run_loop_->Quit(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 void RunLoop() { | 122 void RunLoop() { |
| 122 run_loop_.reset(new base::RunLoop()); | 123 run_loop_.reset(new base::RunLoop()); |
| 123 run_loop_->Run(); | 124 run_loop_->Run(); |
| 124 } | 125 } |
| 125 | 126 |
| 126 protected: | 127 protected: |
| 127 base::MessageLoopForUI message_loop_; | 128 TestBrowserThreadBundle thread_bundle_; |
| 128 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 129 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 129 std::unique_ptr<base::RunLoop> run_loop_; | 130 std::unique_ptr<base::RunLoop> run_loop_; |
| 130 WifiDataProviderManager::WifiDataUpdateCallback wifi_data_callback_; | 131 WifiDataProviderManager::WifiDataUpdateCallback wifi_data_callback_; |
| 131 scoped_refptr<WifiDataProviderCommonWithMock> provider_; | 132 scoped_refptr<WifiDataProviderCommonWithMock> provider_; |
| 132 MockWlanApi* wlan_api_; | 133 MockWlanApi* wlan_api_; |
| 133 MockPollingPolicy* polling_policy_; | 134 MockPollingPolicy* polling_policy_; |
| 134 }; | 135 }; |
| 135 | 136 |
| 136 TEST_F(GeolocationWifiDataProviderCommonTest, CreateDestroy) { | 137 TEST_F(GeolocationWifiDataProviderCommonTest, CreateDestroy) { |
| 137 // Test fixture members were SetUp correctly. | 138 // Test fixture members were SetUp correctly. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 230 |
| 230 TEST_F(GeolocationWifiDataProviderCommonTest, RegisterUnregister) { | 231 TEST_F(GeolocationWifiDataProviderCommonTest, RegisterUnregister) { |
| 231 WifiDataProviderManager::SetFactoryForTesting( | 232 WifiDataProviderManager::SetFactoryForTesting( |
| 232 CreateWifiDataProviderCommonWithMock); | 233 CreateWifiDataProviderCommonWithMock); |
| 233 WifiDataProviderManager::Register(&wifi_data_callback_); | 234 WifiDataProviderManager::Register(&wifi_data_callback_); |
| 234 RunLoop(); | 235 RunLoop(); |
| 235 WifiDataProviderManager::Unregister(&wifi_data_callback_); | 236 WifiDataProviderManager::Unregister(&wifi_data_callback_); |
| 236 WifiDataProviderManager::ResetFactoryForTesting(); | 237 WifiDataProviderManager::ResetFactoryForTesting(); |
| 237 } | 238 } |
| 238 | 239 |
| 239 } // namespace device | 240 } // namespace content |
| OLD | NEW |