Chromium Code Reviews| Index: chromeos/network/geolocation_handler_unittest.cc |
| diff --git a/chromeos/network/geolocation_handler_unittest.cc b/chromeos/network/geolocation_handler_unittest.cc |
| index 49a98464e0395faa8acd6eba2f412537d6f2e152..17dea62b9272e9ed117e247fc4d7a8e3e92cb37f 100644 |
| --- a/chromeos/network/geolocation_handler_unittest.cc |
| +++ b/chromeos/network/geolocation_handler_unittest.cc |
| @@ -48,6 +48,11 @@ class GeolocationHandlerTest : public testing::Test { |
| &wifi_access_points_, NULL); |
| } |
| + bool GetCellTowers() { |
| + return geolocation_handler_->GetCellTowers(&cell_towers_, NULL); |
|
Ben Chan
2017/02/02 20:49:25
nullptr
can Skylar cook
2017/02/03 00:15:20
Done.
|
| + } |
| + |
| + // This should remain in sync with the format of shill (chromeos) dict entries |
| void AddAccessPoint(int idx) { |
| base::DictionaryValue properties; |
| std::string mac_address = |
| @@ -55,13 +60,34 @@ class GeolocationHandlerTest : public testing::Test { |
| idx, 0, 0, 0, 0, 0); |
| std::string channel = base::IntToString(idx); |
| std::string strength = base::IntToString(idx * 10); |
| + properties.SetStringWithoutPathExpansion(shill::kGeoMacAddressProperty, |
| + mac_address); |
| + properties.SetStringWithoutPathExpansion(shill::kGeoChannelProperty, |
| + channel); |
| + properties.SetStringWithoutPathExpansion(shill::kGeoSignalStrengthProperty, |
| + strength); |
| + manager_test_->AddGeoNetwork(shill::kGeoWifiAccessPointsProperty, |
| + properties); |
| + base::RunLoop().RunUntilIdle(); |
| + } |
| + |
| + // This should remain in sync with the format of shill (chromeos) dict entries |
| + void AddCellTower(int idx) { |
| + base::DictionaryValue properties; |
| + std::string ci = base::IntToString(idx); |
| + std::string lac = base::IntToString(idx * 10); |
|
Ben Chan
2017/02/02 20:49:25
these magic multiplications seem cryptic enough th
can Skylar cook
2017/02/03 00:15:20
Solely to differentiate the fields in a predictabl
|
| + std::string mcc = base::IntToString(idx * 100); |
| + std::string mnc = base::IntToString(idx * 100 + 1); |
| + |
| + properties.SetStringWithoutPathExpansion(shill::kGeoCellIdProperty, ci); |
| properties.SetStringWithoutPathExpansion( |
| - shill::kGeoMacAddressProperty, mac_address); |
| + shill::kGeoLocationAreaCodeProperty, lac); |
| properties.SetStringWithoutPathExpansion( |
| - shill::kGeoChannelProperty, channel); |
| + shill::kGeoMobileCountryCodeProperty, mcc); |
| properties.SetStringWithoutPathExpansion( |
| - shill::kGeoSignalStrengthProperty, strength); |
| - manager_test_->AddGeoNetwork(shill::kTypeWifi, properties); |
| + shill::kGeoMobileNetworkCodeProperty, mnc); |
| + |
| + manager_test_->AddGeoNetwork(shill::kGeoCellTowersProperty, properties); |
| base::RunLoop().RunUntilIdle(); |
| } |
| @@ -70,6 +96,7 @@ class GeolocationHandlerTest : public testing::Test { |
| std::unique_ptr<GeolocationHandler> geolocation_handler_; |
| ShillManagerClient::TestInterface* manager_test_; |
| WifiAccessPointVector wifi_access_points_; |
| + CellTowerVector cell_towers_; |
| private: |
| DISALLOW_COPY_AND_ASSIGN(GeolocationHandlerTest); |
| @@ -78,39 +105,106 @@ class GeolocationHandlerTest : public testing::Test { |
| TEST_F(GeolocationHandlerTest, NoAccessPoints) { |
| // Inititial call should return false. |
| EXPECT_FALSE(GetWifiAccessPoints()); |
| + EXPECT_FALSE(GetCellTowers()); |
| base::RunLoop().RunUntilIdle(); |
| // Second call should return false since there are no devices. |
| EXPECT_FALSE(GetWifiAccessPoints()); |
| + EXPECT_FALSE(GetCellTowers()); |
| } |
| TEST_F(GeolocationHandlerTest, OneAccessPoint) { |
| - // Add an acces point. |
| + // Add an access point. |
| AddAccessPoint(1); |
| base::RunLoop().RunUntilIdle(); |
| // Inititial call should return false and request access points. |
| EXPECT_FALSE(GetWifiAccessPoints()); |
| + EXPECT_FALSE(GetCellTowers()); |
| base::RunLoop().RunUntilIdle(); |
| // Second call should return true since we have an access point. |
| EXPECT_TRUE(GetWifiAccessPoints()); |
| + EXPECT_FALSE(GetCellTowers()); |
| ASSERT_EQ(1u, wifi_access_points_.size()); |
| EXPECT_EQ("01:00:00:00:00:00", wifi_access_points_[0].mac_address); |
| EXPECT_EQ(1, wifi_access_points_[0].channel); |
| } |
| TEST_F(GeolocationHandlerTest, MultipleAccessPoints) { |
| - // Add several acces points. |
| + // Add several access points. |
| AddAccessPoint(1); |
| AddAccessPoint(2); |
| AddAccessPoint(3); |
| base::RunLoop().RunUntilIdle(); |
| // Inititial call should return false and request access points. |
| EXPECT_FALSE(GetWifiAccessPoints()); |
| + EXPECT_FALSE(GetCellTowers()); |
| base::RunLoop().RunUntilIdle(); |
| // Second call should return true since we have an access point. |
| EXPECT_TRUE(GetWifiAccessPoints()); |
| + EXPECT_FALSE(GetCellTowers()); |
| ASSERT_EQ(3u, wifi_access_points_.size()); |
| EXPECT_EQ("02:00:00:00:00:00", wifi_access_points_[1].mac_address); |
| EXPECT_EQ(3, wifi_access_points_[2].channel); |
| } |
| +TEST_F(GeolocationHandlerTest, OneCellTower) { |
| + // Add a cell tower. |
| + AddCellTower(1); |
| + base::RunLoop().RunUntilIdle(); |
| + // Inititial call should return false and request towers. |
| + EXPECT_FALSE(GetCellTowers()); |
| + EXPECT_FALSE(GetWifiAccessPoints()); |
| + base::RunLoop().RunUntilIdle(); |
| + // Second call should return true since we have a cell tower. |
| + EXPECT_TRUE(GetCellTowers()); |
| + EXPECT_FALSE(GetWifiAccessPoints()); |
| + ASSERT_EQ(1u, cell_towers_.size()); |
| + EXPECT_EQ("1", cell_towers_[0].ci); |
| + EXPECT_EQ("10", cell_towers_[0].lac); |
| + EXPECT_EQ("100", cell_towers_[0].mcc); |
| + EXPECT_EQ("101", cell_towers_[0].mnc); |
| +} |
| + |
| +TEST_F(GeolocationHandlerTest, MultipleCellTowers) { |
| + // Add several cell towers. |
| + AddCellTower(1); |
| + AddCellTower(2); |
| + AddCellTower(3); |
| + base::RunLoop().RunUntilIdle(); |
| + // Inititial call should return false and request cell towers. |
| + EXPECT_FALSE(GetWifiAccessPoints()); |
| + EXPECT_FALSE(GetCellTowers()); |
| + base::RunLoop().RunUntilIdle(); |
| + // Second call should return true since we have a cell tower. |
| + EXPECT_FALSE(GetWifiAccessPoints()); |
| + EXPECT_TRUE(GetCellTowers()); |
| + ASSERT_EQ(3u, cell_towers_.size()); |
| + EXPECT_EQ("20", cell_towers_[1].lac); |
| + EXPECT_EQ("301", cell_towers_[2].mnc); |
| +} |
| + |
| +TEST_F(GeolocationHandlerTest, MultipleGeolocations) { |
| + // Add both a cell tower and wifi AP. |
| + AddCellTower(1); |
| + AddCellTower(2); |
| + AddAccessPoint(1); |
| + AddAccessPoint(2); |
| + base::RunLoop().RunUntilIdle(); |
| + // Inititial call should return false and request towers. |
| + EXPECT_FALSE(GetCellTowers()); |
| + EXPECT_FALSE(GetWifiAccessPoints()); |
| + base::RunLoop().RunUntilIdle(); |
| + // Second call should return true since we have a cell tower. |
| + EXPECT_TRUE(GetCellTowers()); |
| + EXPECT_TRUE(GetWifiAccessPoints()); |
| + ASSERT_EQ(2u, wifi_access_points_.size()); |
| + EXPECT_EQ("02:00:00:00:00:00", wifi_access_points_[1].mac_address); |
| + EXPECT_EQ(1, wifi_access_points_[0].channel); |
| + |
| + ASSERT_EQ(2u, cell_towers_.size()); |
| + EXPECT_EQ("2", cell_towers_[1].ci); |
| + EXPECT_EQ("10", cell_towers_[0].lac); |
| + EXPECT_EQ("200", cell_towers_[1].mcc); |
| + EXPECT_EQ("101", cell_towers_[0].mnc); |
| +} |
| + |
| } // namespace chromeos |