| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 EXPECT_EQ(&main_message_loop_, base::MessageLoop::current()); | 139 EXPECT_EQ(&main_message_loop_, base::MessageLoop::current()); |
| 140 EXPECT_TRUE(NULL != provider_.get()); | 140 EXPECT_TRUE(NULL != provider_.get()); |
| 141 EXPECT_TRUE(NULL != wlan_api_); | 141 EXPECT_TRUE(NULL != wlan_api_); |
| 142 } | 142 } |
| 143 | 143 |
| 144 TEST_F(GeolocationWifiDataProviderCommonTest, StartThread) { | 144 TEST_F(GeolocationWifiDataProviderCommonTest, StartThread) { |
| 145 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) | 145 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) |
| 146 .Times(AtLeast(1)); | 146 .Times(AtLeast(1)); |
| 147 EXPECT_CALL(*polling_policy_, PollingInterval()) | 147 EXPECT_CALL(*polling_policy_, PollingInterval()) |
| 148 .Times(AtLeast(1)); | 148 .Times(AtLeast(1)); |
| 149 EXPECT_TRUE(provider_->StartDataProvider()); | 149 provider_->StartDataProvider(); |
| 150 main_message_loop_.Run(); | 150 main_message_loop_.Run(); |
| 151 SUCCEED(); | 151 SUCCEED(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 TEST_F(GeolocationWifiDataProviderCommonTest, NoWifi){ | 154 TEST_F(GeolocationWifiDataProviderCommonTest, NoWifi){ |
| 155 EXPECT_CALL(*polling_policy_, NoWifiInterval()) | 155 EXPECT_CALL(*polling_policy_, NoWifiInterval()) |
| 156 .Times(AtLeast(1)); | 156 .Times(AtLeast(1)); |
| 157 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) | 157 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) |
| 158 .WillRepeatedly(Return(false)); | 158 .WillRepeatedly(Return(false)); |
| 159 provider_->StartDataProvider(); | 159 provider_->StartDataProvider(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 181 provider_->StartDataProvider(); | 181 provider_->StartDataProvider(); |
| 182 main_message_loop_.Run(); | 182 main_message_loop_.Run(); |
| 183 main_message_loop_.Run(); | 183 main_message_loop_.Run(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 TEST_F(GeolocationWifiDataProviderCommonTest, DoAnEmptyScan) { | 186 TEST_F(GeolocationWifiDataProviderCommonTest, DoAnEmptyScan) { |
| 187 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) | 187 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) |
| 188 .Times(AtLeast(1)); | 188 .Times(AtLeast(1)); |
| 189 EXPECT_CALL(*polling_policy_, PollingInterval()) | 189 EXPECT_CALL(*polling_policy_, PollingInterval()) |
| 190 .Times(AtLeast(1)); | 190 .Times(AtLeast(1)); |
| 191 EXPECT_TRUE(provider_->StartDataProvider()); | 191 provider_->StartDataProvider(); |
| 192 main_message_loop_.Run(); | 192 main_message_loop_.Run(); |
| 193 // Check we had at least one call. The worker thread may have raced ahead | 193 // Check we had at least one call. The worker thread may have raced ahead |
| 194 // and made multiple calls. | 194 // and made multiple calls. |
| 195 EXPECT_GT(wlan_api_->calls_, 0); | 195 EXPECT_GT(wlan_api_->calls_, 0); |
| 196 WifiData data; | 196 WifiData data; |
| 197 EXPECT_TRUE(provider_->GetData(&data)); | 197 EXPECT_TRUE(provider_->GetData(&data)); |
| 198 EXPECT_EQ(0, static_cast<int>(data.access_point_data.size())); | 198 EXPECT_EQ(0, static_cast<int>(data.access_point_data.size())); |
| 199 } | 199 } |
| 200 | 200 |
| 201 TEST_F(GeolocationWifiDataProviderCommonTest, DoScanWithResults) { | 201 TEST_F(GeolocationWifiDataProviderCommonTest, DoScanWithResults) { |
| 202 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) | 202 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) |
| 203 .Times(AtLeast(1)); | 203 .Times(AtLeast(1)); |
| 204 EXPECT_CALL(*polling_policy_, PollingInterval()) | 204 EXPECT_CALL(*polling_policy_, PollingInterval()) |
| 205 .Times(AtLeast(1)); | 205 .Times(AtLeast(1)); |
| 206 AccessPointData single_access_point; | 206 AccessPointData single_access_point; |
| 207 single_access_point.channel = 2; | 207 single_access_point.channel = 2; |
| 208 single_access_point.mac_address = 3; | 208 single_access_point.mac_address = 3; |
| 209 single_access_point.radio_signal_strength = 4; | 209 single_access_point.radio_signal_strength = 4; |
| 210 single_access_point.signal_to_noise = 5; | 210 single_access_point.signal_to_noise = 5; |
| 211 single_access_point.ssid = ASCIIToUTF16("foossid"); | 211 single_access_point.ssid = ASCIIToUTF16("foossid"); |
| 212 wlan_api_->data_out_.insert(single_access_point); | 212 wlan_api_->data_out_.insert(single_access_point); |
| 213 | 213 |
| 214 EXPECT_TRUE(provider_->StartDataProvider()); | 214 provider_->StartDataProvider(); |
| 215 main_message_loop_.Run(); | 215 main_message_loop_.Run(); |
| 216 EXPECT_GT(wlan_api_->calls_, 0); | 216 EXPECT_GT(wlan_api_->calls_, 0); |
| 217 WifiData data; | 217 WifiData data; |
| 218 EXPECT_TRUE(provider_->GetData(&data)); | 218 EXPECT_TRUE(provider_->GetData(&data)); |
| 219 EXPECT_EQ(1, static_cast<int>(data.access_point_data.size())); | 219 EXPECT_EQ(1, static_cast<int>(data.access_point_data.size())); |
| 220 EXPECT_EQ(single_access_point.ssid, data.access_point_data.begin()->ssid); | 220 EXPECT_EQ(single_access_point.ssid, data.access_point_data.begin()->ssid); |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST_F(GeolocationWifiDataProviderCommonTest, | 223 TEST_F(GeolocationWifiDataProviderCommonTest, |
| 224 StartThreadViaDeviceDataProvider) { | 224 StartThreadViaDeviceDataProvider) { |
| 225 MessageLoopQuitListener quit_listener(&main_message_loop_); | 225 MessageLoopQuitListener quit_listener(&main_message_loop_); |
| 226 WifiDataProvider::SetFactory(CreateWifiDataProviderCommonWithMock); | 226 WifiDataProvider::SetFactory(CreateWifiDataProviderCommonWithMock); |
| 227 DeviceDataProvider<WifiData>::Register(&quit_listener); | 227 DeviceDataProvider<WifiData>::Register(&quit_listener); |
| 228 main_message_loop_.Run(); | 228 main_message_loop_.Run(); |
| 229 DeviceDataProvider<WifiData>::Unregister(&quit_listener); | 229 DeviceDataProvider<WifiData>::Unregister(&quit_listener); |
| 230 DeviceDataProvider<WifiData>::ResetFactory(); | 230 DeviceDataProvider<WifiData>::ResetFactory(); |
| 231 } | 231 } |
| 232 | 232 |
| 233 } // namespace content | 233 } // namespace content |
| OLD | NEW |