Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: chromeos/network/geolocation_handler_unittest.cc

Issue 2624843003: Add support for cellular geolocation (Closed)
Patch Set: Use cell tower info in SimpleGeolocationProvider. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chromeos/network/geolocation_handler.h" 5 #include "chromeos/network/geolocation_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 30 matching lines...) Expand all
41 void TearDown() override { 41 void TearDown() override {
42 geolocation_handler_.reset(); 42 geolocation_handler_.reset();
43 DBusThreadManager::Shutdown(); 43 DBusThreadManager::Shutdown();
44 } 44 }
45 45
46 bool GetWifiAccessPoints() { 46 bool GetWifiAccessPoints() {
47 return geolocation_handler_->GetWifiAccessPoints( 47 return geolocation_handler_->GetWifiAccessPoints(
48 &wifi_access_points_, NULL); 48 &wifi_access_points_, NULL);
49 } 49 }
50 50
51 bool GetCellTowers() {
52 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.
53 }
54
55 // This should remain in sync with the format of shill (chromeos) dict entries
51 void AddAccessPoint(int idx) { 56 void AddAccessPoint(int idx) {
52 base::DictionaryValue properties; 57 base::DictionaryValue properties;
53 std::string mac_address = 58 std::string mac_address =
54 base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X", 59 base::StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X",
55 idx, 0, 0, 0, 0, 0); 60 idx, 0, 0, 0, 0, 0);
56 std::string channel = base::IntToString(idx); 61 std::string channel = base::IntToString(idx);
57 std::string strength = base::IntToString(idx * 10); 62 std::string strength = base::IntToString(idx * 10);
58 properties.SetStringWithoutPathExpansion( 63 properties.SetStringWithoutPathExpansion(shill::kGeoMacAddressProperty,
59 shill::kGeoMacAddressProperty, mac_address); 64 mac_address);
60 properties.SetStringWithoutPathExpansion( 65 properties.SetStringWithoutPathExpansion(shill::kGeoChannelProperty,
61 shill::kGeoChannelProperty, channel); 66 channel);
62 properties.SetStringWithoutPathExpansion( 67 properties.SetStringWithoutPathExpansion(shill::kGeoSignalStrengthProperty,
63 shill::kGeoSignalStrengthProperty, strength); 68 strength);
64 manager_test_->AddGeoNetwork(shill::kTypeWifi, properties); 69 manager_test_->AddGeoNetwork(shill::kGeoWifiAccessPointsProperty,
70 properties);
65 base::RunLoop().RunUntilIdle(); 71 base::RunLoop().RunUntilIdle();
66 } 72 }
67 73
74 // This should remain in sync with the format of shill (chromeos) dict entries
75 void AddCellTower(int idx) {
76 base::DictionaryValue properties;
77 std::string ci = base::IntToString(idx);
78 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
79 std::string mcc = base::IntToString(idx * 100);
80 std::string mnc = base::IntToString(idx * 100 + 1);
81
82 properties.SetStringWithoutPathExpansion(shill::kGeoCellIdProperty, ci);
83 properties.SetStringWithoutPathExpansion(
84 shill::kGeoLocationAreaCodeProperty, lac);
85 properties.SetStringWithoutPathExpansion(
86 shill::kGeoMobileCountryCodeProperty, mcc);
87 properties.SetStringWithoutPathExpansion(
88 shill::kGeoMobileNetworkCodeProperty, mnc);
89
90 manager_test_->AddGeoNetwork(shill::kGeoCellTowersProperty, properties);
91 base::RunLoop().RunUntilIdle();
92 }
93
68 protected: 94 protected:
69 base::MessageLoopForUI message_loop_; 95 base::MessageLoopForUI message_loop_;
70 std::unique_ptr<GeolocationHandler> geolocation_handler_; 96 std::unique_ptr<GeolocationHandler> geolocation_handler_;
71 ShillManagerClient::TestInterface* manager_test_; 97 ShillManagerClient::TestInterface* manager_test_;
72 WifiAccessPointVector wifi_access_points_; 98 WifiAccessPointVector wifi_access_points_;
99 CellTowerVector cell_towers_;
73 100
74 private: 101 private:
75 DISALLOW_COPY_AND_ASSIGN(GeolocationHandlerTest); 102 DISALLOW_COPY_AND_ASSIGN(GeolocationHandlerTest);
76 }; 103 };
77 104
78 TEST_F(GeolocationHandlerTest, NoAccessPoints) { 105 TEST_F(GeolocationHandlerTest, NoAccessPoints) {
79 // Inititial call should return false. 106 // Inititial call should return false.
80 EXPECT_FALSE(GetWifiAccessPoints()); 107 EXPECT_FALSE(GetWifiAccessPoints());
108 EXPECT_FALSE(GetCellTowers());
81 base::RunLoop().RunUntilIdle(); 109 base::RunLoop().RunUntilIdle();
82 // Second call should return false since there are no devices. 110 // Second call should return false since there are no devices.
83 EXPECT_FALSE(GetWifiAccessPoints()); 111 EXPECT_FALSE(GetWifiAccessPoints());
112 EXPECT_FALSE(GetCellTowers());
84 } 113 }
85 114
86 TEST_F(GeolocationHandlerTest, OneAccessPoint) { 115 TEST_F(GeolocationHandlerTest, OneAccessPoint) {
87 // Add an acces point. 116 // Add an access point.
88 AddAccessPoint(1); 117 AddAccessPoint(1);
89 base::RunLoop().RunUntilIdle(); 118 base::RunLoop().RunUntilIdle();
90 // Inititial call should return false and request access points. 119 // Inititial call should return false and request access points.
91 EXPECT_FALSE(GetWifiAccessPoints()); 120 EXPECT_FALSE(GetWifiAccessPoints());
121 EXPECT_FALSE(GetCellTowers());
92 base::RunLoop().RunUntilIdle(); 122 base::RunLoop().RunUntilIdle();
93 // Second call should return true since we have an access point. 123 // Second call should return true since we have an access point.
94 EXPECT_TRUE(GetWifiAccessPoints()); 124 EXPECT_TRUE(GetWifiAccessPoints());
125 EXPECT_FALSE(GetCellTowers());
95 ASSERT_EQ(1u, wifi_access_points_.size()); 126 ASSERT_EQ(1u, wifi_access_points_.size());
96 EXPECT_EQ("01:00:00:00:00:00", wifi_access_points_[0].mac_address); 127 EXPECT_EQ("01:00:00:00:00:00", wifi_access_points_[0].mac_address);
97 EXPECT_EQ(1, wifi_access_points_[0].channel); 128 EXPECT_EQ(1, wifi_access_points_[0].channel);
98 } 129 }
99 130
100 TEST_F(GeolocationHandlerTest, MultipleAccessPoints) { 131 TEST_F(GeolocationHandlerTest, MultipleAccessPoints) {
101 // Add several acces points. 132 // Add several access points.
102 AddAccessPoint(1); 133 AddAccessPoint(1);
103 AddAccessPoint(2); 134 AddAccessPoint(2);
104 AddAccessPoint(3); 135 AddAccessPoint(3);
105 base::RunLoop().RunUntilIdle(); 136 base::RunLoop().RunUntilIdle();
106 // Inititial call should return false and request access points. 137 // Inititial call should return false and request access points.
107 EXPECT_FALSE(GetWifiAccessPoints()); 138 EXPECT_FALSE(GetWifiAccessPoints());
139 EXPECT_FALSE(GetCellTowers());
108 base::RunLoop().RunUntilIdle(); 140 base::RunLoop().RunUntilIdle();
109 // Second call should return true since we have an access point. 141 // Second call should return true since we have an access point.
110 EXPECT_TRUE(GetWifiAccessPoints()); 142 EXPECT_TRUE(GetWifiAccessPoints());
143 EXPECT_FALSE(GetCellTowers());
111 ASSERT_EQ(3u, wifi_access_points_.size()); 144 ASSERT_EQ(3u, wifi_access_points_.size());
112 EXPECT_EQ("02:00:00:00:00:00", wifi_access_points_[1].mac_address); 145 EXPECT_EQ("02:00:00:00:00:00", wifi_access_points_[1].mac_address);
113 EXPECT_EQ(3, wifi_access_points_[2].channel); 146 EXPECT_EQ(3, wifi_access_points_[2].channel);
114 } 147 }
115 148
149 TEST_F(GeolocationHandlerTest, OneCellTower) {
150 // Add a cell tower.
151 AddCellTower(1);
152 base::RunLoop().RunUntilIdle();
153 // Inititial call should return false and request towers.
154 EXPECT_FALSE(GetCellTowers());
155 EXPECT_FALSE(GetWifiAccessPoints());
156 base::RunLoop().RunUntilIdle();
157 // Second call should return true since we have a cell tower.
158 EXPECT_TRUE(GetCellTowers());
159 EXPECT_FALSE(GetWifiAccessPoints());
160 ASSERT_EQ(1u, cell_towers_.size());
161 EXPECT_EQ("1", cell_towers_[0].ci);
162 EXPECT_EQ("10", cell_towers_[0].lac);
163 EXPECT_EQ("100", cell_towers_[0].mcc);
164 EXPECT_EQ("101", cell_towers_[0].mnc);
165 }
166
167 TEST_F(GeolocationHandlerTest, MultipleCellTowers) {
168 // Add several cell towers.
169 AddCellTower(1);
170 AddCellTower(2);
171 AddCellTower(3);
172 base::RunLoop().RunUntilIdle();
173 // Inititial call should return false and request cell towers.
174 EXPECT_FALSE(GetWifiAccessPoints());
175 EXPECT_FALSE(GetCellTowers());
176 base::RunLoop().RunUntilIdle();
177 // Second call should return true since we have a cell tower.
178 EXPECT_FALSE(GetWifiAccessPoints());
179 EXPECT_TRUE(GetCellTowers());
180 ASSERT_EQ(3u, cell_towers_.size());
181 EXPECT_EQ("20", cell_towers_[1].lac);
182 EXPECT_EQ("301", cell_towers_[2].mnc);
183 }
184
185 TEST_F(GeolocationHandlerTest, MultipleGeolocations) {
186 // Add both a cell tower and wifi AP.
187 AddCellTower(1);
188 AddCellTower(2);
189 AddAccessPoint(1);
190 AddAccessPoint(2);
191 base::RunLoop().RunUntilIdle();
192 // Inititial call should return false and request towers.
193 EXPECT_FALSE(GetCellTowers());
194 EXPECT_FALSE(GetWifiAccessPoints());
195 base::RunLoop().RunUntilIdle();
196 // Second call should return true since we have a cell tower.
197 EXPECT_TRUE(GetCellTowers());
198 EXPECT_TRUE(GetWifiAccessPoints());
199 ASSERT_EQ(2u, wifi_access_points_.size());
200 EXPECT_EQ("02:00:00:00:00:00", wifi_access_points_[1].mac_address);
201 EXPECT_EQ(1, wifi_access_points_[0].channel);
202
203 ASSERT_EQ(2u, cell_towers_.size());
204 EXPECT_EQ("2", cell_towers_[1].ci);
205 EXPECT_EQ("10", cell_towers_[0].lac);
206 EXPECT_EQ("200", cell_towers_[1].mcc);
207 EXPECT_EQ("101", cell_towers_[0].mnc);
208 }
209
116 } // namespace chromeos 210 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698