| 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 "device/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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 bool GetAccessPointDataInternal(WifiData::AccessPointDataSet* data) { | 42 bool GetAccessPointDataInternal(WifiData::AccessPointDataSet* data) { |
| 43 ++calls_; | 43 ++calls_; |
| 44 *data = data_out_; | 44 *data = data_out_; |
| 45 return bool_return_; | 45 return bool_return_; |
| 46 } | 46 } |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 class MockPollingPolicy : public WifiPollingPolicy { | 49 class MockPollingPolicy : public WifiPollingPolicy { |
| 50 public: | 50 public: |
| 51 MockPollingPolicy() { | 51 MockPollingPolicy() { |
| 52 ON_CALL(*this,PollingInterval()) | 52 ON_CALL(*this, PollingInterval()).WillByDefault(Return(1)); |
| 53 .WillByDefault(Return(1)); | 53 ON_CALL(*this, NoWifiInterval()).WillByDefault(Return(1)); |
| 54 ON_CALL(*this,NoWifiInterval()) | |
| 55 .WillByDefault(Return(1)); | |
| 56 } | 54 } |
| 57 | 55 |
| 58 MOCK_METHOD0(PollingInterval, int()); | 56 MOCK_METHOD0(PollingInterval, int()); |
| 59 MOCK_METHOD0(NoWifiInterval, int()); | 57 MOCK_METHOD0(NoWifiInterval, int()); |
| 60 | 58 |
| 61 virtual void UpdatePollingInterval(bool) {} | 59 virtual void UpdatePollingInterval(bool) {} |
| 62 }; | 60 }; |
| 63 | 61 |
| 64 class WifiDataProviderCommonWithMock : public WifiDataProviderCommon { | 62 class WifiDataProviderCommonWithMock : public WifiDataProviderCommon { |
| 65 public: | 63 public: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 }; | 132 }; |
| 135 | 133 |
| 136 TEST_F(GeolocationWifiDataProviderCommonTest, CreateDestroy) { | 134 TEST_F(GeolocationWifiDataProviderCommonTest, CreateDestroy) { |
| 137 // Test fixture members were SetUp correctly. | 135 // Test fixture members were SetUp correctly. |
| 138 EXPECT_TRUE(main_task_runner_->BelongsToCurrentThread()); | 136 EXPECT_TRUE(main_task_runner_->BelongsToCurrentThread()); |
| 139 EXPECT_TRUE(NULL != provider_.get()); | 137 EXPECT_TRUE(NULL != provider_.get()); |
| 140 EXPECT_TRUE(NULL != wlan_api_); | 138 EXPECT_TRUE(NULL != wlan_api_); |
| 141 } | 139 } |
| 142 | 140 |
| 143 TEST_F(GeolocationWifiDataProviderCommonTest, RunNormal) { | 141 TEST_F(GeolocationWifiDataProviderCommonTest, RunNormal) { |
| 144 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) | 142 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)).Times(AtLeast(1)); |
| 145 .Times(AtLeast(1)); | 143 EXPECT_CALL(*polling_policy_, PollingInterval()).Times(AtLeast(1)); |
| 146 EXPECT_CALL(*polling_policy_, PollingInterval()) | |
| 147 .Times(AtLeast(1)); | |
| 148 provider_->StartDataProvider(); | 144 provider_->StartDataProvider(); |
| 149 RunLoop(); | 145 RunLoop(); |
| 150 SUCCEED(); | 146 SUCCEED(); |
| 151 } | 147 } |
| 152 | 148 |
| 153 TEST_F(GeolocationWifiDataProviderCommonTest, NoWifi) { | 149 TEST_F(GeolocationWifiDataProviderCommonTest, NoWifi) { |
| 154 EXPECT_CALL(*polling_policy_, NoWifiInterval()) | 150 EXPECT_CALL(*polling_policy_, NoWifiInterval()).Times(AtLeast(1)); |
| 155 .Times(AtLeast(1)); | 151 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)).WillRepeatedly(Return(false)); |
| 156 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) | |
| 157 .WillRepeatedly(Return(false)); | |
| 158 provider_->StartDataProvider(); | 152 provider_->StartDataProvider(); |
| 159 RunLoop(); | 153 RunLoop(); |
| 160 } | 154 } |
| 161 | 155 |
| 162 TEST_F(GeolocationWifiDataProviderCommonTest, IntermittentWifi) { | 156 TEST_F(GeolocationWifiDataProviderCommonTest, IntermittentWifi) { |
| 163 EXPECT_CALL(*polling_policy_, PollingInterval()) | 157 EXPECT_CALL(*polling_policy_, PollingInterval()).Times(AtLeast(1)); |
| 164 .Times(AtLeast(1)); | 158 EXPECT_CALL(*polling_policy_, NoWifiInterval()).Times(1); |
| 165 EXPECT_CALL(*polling_policy_, NoWifiInterval()) | |
| 166 .Times(1); | |
| 167 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) | 159 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) |
| 168 .WillOnce(Return(true)) | 160 .WillOnce(Return(true)) |
| 169 .WillOnce(Return(false)) | 161 .WillOnce(Return(false)) |
| 170 .WillRepeatedly(DoDefault()); | 162 .WillRepeatedly(DoDefault()); |
| 171 | 163 |
| 172 AccessPointData single_access_point; | 164 AccessPointData single_access_point; |
| 173 single_access_point.channel = 2; | 165 single_access_point.channel = 2; |
| 174 single_access_point.mac_address = 3; | 166 single_access_point.mac_address = 3; |
| 175 single_access_point.radio_signal_strength = 4; | 167 single_access_point.radio_signal_strength = 4; |
| 176 single_access_point.signal_to_noise = 5; | 168 single_access_point.signal_to_noise = 5; |
| 177 single_access_point.ssid = base::ASCIIToUTF16("foossid"); | 169 single_access_point.ssid = base::ASCIIToUTF16("foossid"); |
| 178 wlan_api_->data_out_.insert(single_access_point); | 170 wlan_api_->data_out_.insert(single_access_point); |
| 179 | 171 |
| 180 provider_->StartDataProvider(); | 172 provider_->StartDataProvider(); |
| 181 RunLoop(); | 173 RunLoop(); |
| 182 RunLoop(); | 174 RunLoop(); |
| 183 } | 175 } |
| 184 | 176 |
| 185 #if defined(OS_MACOSX) | 177 #if defined(OS_MACOSX) |
| 186 #define MAYBE_DoAnEmptyScan DISABLED_DoAnEmptyScan | 178 #define MAYBE_DoAnEmptyScan DISABLED_DoAnEmptyScan |
| 187 #else | 179 #else |
| 188 #define MAYBE_DoAnEmptyScan DoAnEmptyScan | 180 #define MAYBE_DoAnEmptyScan DoAnEmptyScan |
| 189 #endif | 181 #endif |
| 190 TEST_F(GeolocationWifiDataProviderCommonTest, MAYBE_DoAnEmptyScan) { | 182 TEST_F(GeolocationWifiDataProviderCommonTest, MAYBE_DoAnEmptyScan) { |
| 191 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) | 183 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)).Times(AtLeast(1)); |
| 192 .Times(AtLeast(1)); | 184 EXPECT_CALL(*polling_policy_, PollingInterval()).Times(AtLeast(1)); |
| 193 EXPECT_CALL(*polling_policy_, PollingInterval()) | |
| 194 .Times(AtLeast(1)); | |
| 195 provider_->StartDataProvider(); | 185 provider_->StartDataProvider(); |
| 196 RunLoop(); | 186 RunLoop(); |
| 197 EXPECT_EQ(wlan_api_->calls_, 1); | 187 EXPECT_EQ(wlan_api_->calls_, 1); |
| 198 WifiData data; | 188 WifiData data; |
| 199 EXPECT_TRUE(provider_->GetData(&data)); | 189 EXPECT_TRUE(provider_->GetData(&data)); |
| 200 EXPECT_EQ(0, static_cast<int>(data.access_point_data.size())); | 190 EXPECT_EQ(0, static_cast<int>(data.access_point_data.size())); |
| 201 } | 191 } |
| 202 | 192 |
| 203 #if defined(OS_MACOSX) | 193 #if defined(OS_MACOSX) |
| 204 #define MAYBE_DoScanWithResults DISABLED_DoScanWithResults | 194 #define MAYBE_DoScanWithResults DISABLED_DoScanWithResults |
| 205 #else | 195 #else |
| 206 #define MAYBE_DoScanWithResults DoScanWithResults | 196 #define MAYBE_DoScanWithResults DoScanWithResults |
| 207 #endif | 197 #endif |
| 208 TEST_F(GeolocationWifiDataProviderCommonTest, MAYBE_DoScanWithResults) { | 198 TEST_F(GeolocationWifiDataProviderCommonTest, MAYBE_DoScanWithResults) { |
| 209 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) | 199 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)).Times(AtLeast(1)); |
| 210 .Times(AtLeast(1)); | 200 EXPECT_CALL(*polling_policy_, PollingInterval()).Times(AtLeast(1)); |
| 211 EXPECT_CALL(*polling_policy_, PollingInterval()) | |
| 212 .Times(AtLeast(1)); | |
| 213 AccessPointData single_access_point; | 201 AccessPointData single_access_point; |
| 214 single_access_point.channel = 2; | 202 single_access_point.channel = 2; |
| 215 single_access_point.mac_address = 3; | 203 single_access_point.mac_address = 3; |
| 216 single_access_point.radio_signal_strength = 4; | 204 single_access_point.radio_signal_strength = 4; |
| 217 single_access_point.signal_to_noise = 5; | 205 single_access_point.signal_to_noise = 5; |
| 218 single_access_point.ssid = base::ASCIIToUTF16("foossid"); | 206 single_access_point.ssid = base::ASCIIToUTF16("foossid"); |
| 219 wlan_api_->data_out_.insert(single_access_point); | 207 wlan_api_->data_out_.insert(single_access_point); |
| 220 | 208 |
| 221 provider_->StartDataProvider(); | 209 provider_->StartDataProvider(); |
| 222 RunLoop(); | 210 RunLoop(); |
| 223 EXPECT_EQ(wlan_api_->calls_, 1); | 211 EXPECT_EQ(wlan_api_->calls_, 1); |
| 224 WifiData data; | 212 WifiData data; |
| 225 EXPECT_TRUE(provider_->GetData(&data)); | 213 EXPECT_TRUE(provider_->GetData(&data)); |
| 226 EXPECT_EQ(1, static_cast<int>(data.access_point_data.size())); | 214 EXPECT_EQ(1, static_cast<int>(data.access_point_data.size())); |
| 227 EXPECT_EQ(single_access_point.ssid, data.access_point_data.begin()->ssid); | 215 EXPECT_EQ(single_access_point.ssid, data.access_point_data.begin()->ssid); |
| 228 } | 216 } |
| 229 | 217 |
| 230 TEST_F(GeolocationWifiDataProviderCommonTest, RegisterUnregister) { | 218 TEST_F(GeolocationWifiDataProviderCommonTest, RegisterUnregister) { |
| 231 WifiDataProviderManager::SetFactoryForTesting( | 219 WifiDataProviderManager::SetFactoryForTesting( |
| 232 CreateWifiDataProviderCommonWithMock); | 220 CreateWifiDataProviderCommonWithMock); |
| 233 WifiDataProviderManager::Register(&wifi_data_callback_); | 221 WifiDataProviderManager::Register(&wifi_data_callback_); |
| 234 RunLoop(); | 222 RunLoop(); |
| 235 WifiDataProviderManager::Unregister(&wifi_data_callback_); | 223 WifiDataProviderManager::Unregister(&wifi_data_callback_); |
| 236 WifiDataProviderManager::ResetFactoryForTesting(); | 224 WifiDataProviderManager::ResetFactoryForTesting(); |
| 237 } | 225 } |
| 238 | 226 |
| 239 } // namespace device | 227 } // namespace device |
| OLD | NEW |