diff options
Diffstat (limited to 'chrome/browser/geolocation')
3 files changed, 40 insertions, 37 deletions
diff --git a/chrome/browser/geolocation/libgps_wrapper_linux.cc b/chrome/browser/geolocation/libgps_wrapper_linux.cc index 141ad2f..f1c3728 100644 --- a/chrome/browser/geolocation/libgps_wrapper_linux.cc +++ b/chrome/browser/geolocation/libgps_wrapper_linux.cc @@ -84,11 +84,13 @@ bool LibGps::Start() { if (library().is_open()) return true; errno = 0; + static int fail_count = 0; if (!library().open(NULL, NULL)) { // See gps.h NL_NOxxx for definition of gps_open() error numbers. - LOG(INFO) << "gps_open() failed: " << errno; + LOG_IF(WARNING, 0 == fail_count++) << "gps_open() failed: " << errno; return false; } + fail_count = 0; if (!StartStreaming()) { LOG(INFO) << "StartStreaming failed"; library().close(); diff --git a/chrome/browser/geolocation/wifi_data_provider_chromeos.cc b/chrome/browser/geolocation/wifi_data_provider_chromeos.cc index 41097d3..1a0343c 100644 --- a/chrome/browser/geolocation/wifi_data_provider_chromeos.cc +++ b/chrome/browser/geolocation/wifi_data_provider_chromeos.cc @@ -45,22 +45,21 @@ NetworkLibraryWlanApi::~NetworkLibraryWlanApi() { } bool NetworkLibraryWlanApi::GetAccessPointData( - WifiData::AccessPointDataSet* data) { - const WifiNetworkVector& networks = network_library_->wifi_networks(); - for (WifiNetworkVector::const_iterator i = networks.begin(); - i != networks.end(); ++i) { - for (WifiNetwork::AccessPointVector::const_iterator j = - i->access_points().begin(); j != i->access_points().end(); ++j) { - AccessPointData ap_data; - ap_data.mac_address = ASCIIToUTF16(j->mac_address); - ap_data.radio_signal_strength = j->signal_strength; - ap_data.channel = j->channel; - ap_data.signal_to_noise = j->signal_to_noise; - ap_data.ssid = UTF8ToUTF16(i->name()); - data->insert(ap_data); - } + WifiData::AccessPointDataSet* result) { + WifiAccessPointVector access_points; + if (!network_library_->GetWifiAccessPoints(&access_points)) + return false; + for (WifiAccessPointVector::const_iterator i = access_points.begin(); + i != access_points.end(); ++i) { + AccessPointData ap_data; + ap_data.mac_address = ASCIIToUTF16(i->mac_address); + ap_data.radio_signal_strength = i->signal_strength; + ap_data.channel = i->channel; + ap_data.signal_to_noise = i->signal_to_noise; + ap_data.ssid = UTF8ToUTF16(i->name); + result->insert(ap_data); } - return !data->empty() || network_library_->wifi_available(); + return !result->empty() || network_library_->wifi_enabled(); } } // namespace diff --git a/chrome/browser/geolocation/wifi_data_provider_unittest_chromeos.cc b/chrome/browser/geolocation/wifi_data_provider_unittest_chromeos.cc index ca31a21..acd4f3a 100644 --- a/chrome/browser/geolocation/wifi_data_provider_unittest_chromeos.cc +++ b/chrome/browser/geolocation/wifi_data_provider_unittest_chromeos.cc @@ -8,70 +8,72 @@ #include "chrome/browser/chromeos/cros/mock_network_library.h" #include "testing/gtest/include/gtest/gtest.h" +using ::testing::DoAll; +using ::testing::NotNull; using ::testing::Return; using ::testing::ReturnRef; +using ::testing::SetArgumentPointee; namespace chromeos { class GeolocationChromeOsWifiDataProviderTest : public testing::Test { protected: GeolocationChromeOsWifiDataProviderTest() - : api_(WifiDataProviderChromeOs::NewWlanApi(&net_lib_)){} - virtual void SetUp() { - EXPECT_CALL(net_lib_, wifi_networks()) - .WillOnce(ReturnRef(wifi_network_data_)); + : api_(WifiDataProviderChromeOs::NewWlanApi(&net_lib_)) { } - void AddWifiAps(int ssids, int aps_per_ssid) { + + static WifiAccessPointVector MakeWifiAps(int ssids, int aps_per_ssid) { + WifiAccessPointVector ret; for (int i = 0; i < ssids; ++i) { - WifiNetwork network; - network.set_name(StringPrintf("SSID %d", i)); - std::vector<WifiNetwork::AccessPoint> aps; for (int j = 0; j < aps_per_ssid; ++j) { - WifiNetwork::AccessPoint ap; + WifiAccessPoint ap; + ap.name = StringPrintf("SSID %d", i); ap.channel = i * 10 + j; ap.mac_address = StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X", i, j, 3, 4, 5, 6); ap.signal_strength = j; ap.signal_to_noise = i; - aps.push_back(ap); + ret.push_back(ap); } - network.set_access_points(aps); - wifi_network_data_.push_back(network); } + return ret; } chromeos::MockNetworkLibrary net_lib_; scoped_ptr<WifiDataProviderCommon::WlanApiInterface> api_; - WifiNetworkVector wifi_network_data_; WifiData::AccessPointDataSet ap_data_; }; -TEST_F(GeolocationChromeOsWifiDataProviderTest, NoWifiAvailable) { - EXPECT_CALL(net_lib_, wifi_available()) - .WillRepeatedly(Return(false)); +TEST_F(GeolocationChromeOsWifiDataProviderTest, WifiPoweredOff) { + EXPECT_CALL(net_lib_, GetWifiAccessPoints(NotNull())) + .WillOnce(Return(false)); EXPECT_FALSE(api_->GetAccessPointData(&ap_data_)); EXPECT_EQ(0u, ap_data_.size()); } TEST_F(GeolocationChromeOsWifiDataProviderTest, NoAccessPointsInRange) { - EXPECT_CALL(net_lib_, wifi_available()) + EXPECT_CALL(net_lib_, GetWifiAccessPoints(NotNull())) + .WillOnce(Return(true)); + EXPECT_CALL(net_lib_, wifi_enabled()) .WillRepeatedly(Return(true)); EXPECT_TRUE(api_->GetAccessPointData(&ap_data_)); EXPECT_EQ(0u, ap_data_.size()); } TEST_F(GeolocationChromeOsWifiDataProviderTest, GetOneAccessPoint) { - AddWifiAps(1, 1); + EXPECT_CALL(net_lib_, GetWifiAccessPoints(NotNull())) + .WillOnce(DoAll(SetArgumentPointee<0>(MakeWifiAps(1, 1)), Return(true))); EXPECT_TRUE(api_->GetAccessPointData(&ap_data_)); - EXPECT_EQ(1u, ap_data_.size()); + ASSERT_EQ(1u, ap_data_.size()); EXPECT_EQ("00:00:03:04:05:06", UTF16ToUTF8(ap_data_.begin()->mac_address)); EXPECT_EQ("SSID 0", UTF16ToUTF8(ap_data_.begin()->ssid)); } TEST_F(GeolocationChromeOsWifiDataProviderTest, GetManyAccessPoints) { - AddWifiAps(3, 4); + EXPECT_CALL(net_lib_, GetWifiAccessPoints(NotNull())) + .WillOnce(DoAll(SetArgumentPointee<0>(MakeWifiAps(3, 4)), Return(true))); EXPECT_TRUE(api_->GetAccessPointData(&ap_data_)); - EXPECT_EQ(12u, ap_data_.size()); + ASSERT_EQ(12u, ap_data_.size()); } } // namespace chromeos |