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

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

Issue 24348002: Migrate DBus service constants from flimflam namespace to shill namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased to ToT Created 7 years, 2 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) 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 "chromeos/network/network_change_notifier_chromeos.h" 5 #include "chromeos/network/network_change_notifier_chromeos.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 using net::NetworkChangeNotifier; 57 using net::NetworkChangeNotifier;
58 58
59 TEST(NetworkChangeNotifierChromeosTest, ConnectionTypeFromShill) { 59 TEST(NetworkChangeNotifierChromeosTest, ConnectionTypeFromShill) {
60 struct TypeMapping { 60 struct TypeMapping {
61 const char* shill_type; 61 const char* shill_type;
62 const char* technology; 62 const char* technology;
63 NetworkChangeNotifier::ConnectionType connection_type; 63 NetworkChangeNotifier::ConnectionType connection_type;
64 }; 64 };
65 TypeMapping type_mappings[] = { 65 TypeMapping type_mappings[] = {
66 { flimflam::kTypeEthernet, "", NetworkChangeNotifier::CONNECTION_ETHERNET }, 66 { shill::kTypeEthernet, "", NetworkChangeNotifier::CONNECTION_ETHERNET },
67 { flimflam::kTypeWifi, "", NetworkChangeNotifier::CONNECTION_WIFI }, 67 { shill::kTypeWifi, "", NetworkChangeNotifier::CONNECTION_WIFI },
68 { flimflam::kTypeWimax, "", NetworkChangeNotifier::CONNECTION_4G }, 68 { shill::kTypeWimax, "", NetworkChangeNotifier::CONNECTION_4G },
69 { "unknown type", "unknown technology", 69 { "unknown type", "unknown technology",
70 NetworkChangeNotifier::CONNECTION_UNKNOWN }, 70 NetworkChangeNotifier::CONNECTION_UNKNOWN },
71 { flimflam::kTypeCellular, flimflam::kNetworkTechnology1Xrtt, 71 { shill::kTypeCellular, shill::kNetworkTechnology1Xrtt,
72 NetworkChangeNotifier::CONNECTION_2G }, 72 NetworkChangeNotifier::CONNECTION_2G },
73 { flimflam::kTypeCellular, flimflam::kNetworkTechnologyGprs, 73 { shill::kTypeCellular, shill::kNetworkTechnologyGprs,
74 NetworkChangeNotifier::CONNECTION_2G }, 74 NetworkChangeNotifier::CONNECTION_2G },
75 { flimflam::kTypeCellular, flimflam::kNetworkTechnologyEdge, 75 { shill::kTypeCellular, shill::kNetworkTechnologyEdge,
76 NetworkChangeNotifier::CONNECTION_2G }, 76 NetworkChangeNotifier::CONNECTION_2G },
77 { flimflam::kTypeCellular, flimflam::kNetworkTechnologyEvdo, 77 { shill::kTypeCellular, shill::kNetworkTechnologyEvdo,
78 NetworkChangeNotifier::CONNECTION_3G }, 78 NetworkChangeNotifier::CONNECTION_3G },
79 { flimflam::kTypeCellular, flimflam::kNetworkTechnologyGsm, 79 { shill::kTypeCellular, shill::kNetworkTechnologyGsm,
80 NetworkChangeNotifier::CONNECTION_3G }, 80 NetworkChangeNotifier::CONNECTION_3G },
81 { flimflam::kTypeCellular, flimflam::kNetworkTechnologyUmts, 81 { shill::kTypeCellular, shill::kNetworkTechnologyUmts,
82 NetworkChangeNotifier::CONNECTION_3G }, 82 NetworkChangeNotifier::CONNECTION_3G },
83 { flimflam::kTypeCellular, flimflam::kNetworkTechnologyHspa, 83 { shill::kTypeCellular, shill::kNetworkTechnologyHspa,
84 NetworkChangeNotifier::CONNECTION_3G }, 84 NetworkChangeNotifier::CONNECTION_3G },
85 { flimflam::kTypeCellular, flimflam::kNetworkTechnologyHspaPlus, 85 { shill::kTypeCellular, shill::kNetworkTechnologyHspaPlus,
86 NetworkChangeNotifier::CONNECTION_4G }, 86 NetworkChangeNotifier::CONNECTION_4G },
87 { flimflam::kTypeCellular, flimflam::kNetworkTechnologyLte, 87 { shill::kTypeCellular, shill::kNetworkTechnologyLte,
88 NetworkChangeNotifier::CONNECTION_4G }, 88 NetworkChangeNotifier::CONNECTION_4G },
89 { flimflam::kTypeCellular, flimflam::kNetworkTechnologyLteAdvanced, 89 { shill::kTypeCellular, shill::kNetworkTechnologyLteAdvanced,
90 NetworkChangeNotifier::CONNECTION_4G }, 90 NetworkChangeNotifier::CONNECTION_4G },
91 { flimflam::kTypeCellular, "unknown technology", 91 { shill::kTypeCellular, "unknown technology",
92 NetworkChangeNotifier::CONNECTION_2G } 92 NetworkChangeNotifier::CONNECTION_2G }
93 }; 93 };
94 94
95 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(type_mappings); ++i) { 95 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(type_mappings); ++i) {
96 NetworkChangeNotifier::ConnectionType type = 96 NetworkChangeNotifier::ConnectionType type =
97 NetworkChangeNotifierChromeos::ConnectionTypeFromShill( 97 NetworkChangeNotifierChromeos::ConnectionTypeFromShill(
98 type_mappings[i].shill_type, type_mappings[i].technology); 98 type_mappings[i].shill_type, type_mappings[i].technology);
99 EXPECT_EQ(type_mappings[i].connection_type, type); 99 EXPECT_EQ(type_mappings[i].connection_type, type);
100 } 100 }
101 } 101 }
(...skipping 19 matching lines...) Expand all
121 EXPECT_EQ(notifier_state.ip_address, notifier_.ip_address_); 121 EXPECT_EQ(notifier_state.ip_address, notifier_.ip_address_);
122 std::vector<std::string> dns_servers; 122 std::vector<std::string> dns_servers;
123 base::SplitString(notifier_state.dns_servers, ',', &dns_servers); 123 base::SplitString(notifier_state.dns_servers, ',', &dns_servers);
124 EXPECT_EQ(dns_servers, notifier_.dns_servers_); 124 EXPECT_EQ(dns_servers, notifier_.dns_servers_);
125 } 125 }
126 126
127 // Sets the default network state used for notifier updates. 127 // Sets the default network state used for notifier updates.
128 void SetDefaultNetworkState( 128 void SetDefaultNetworkState(
129 const DefaultNetworkState& default_network_state) { 129 const DefaultNetworkState& default_network_state) {
130 if (default_network_state.is_connected) 130 if (default_network_state.is_connected)
131 default_network_.connection_state_ = flimflam::kStateOnline; 131 default_network_.connection_state_ = shill::kStateOnline;
132 else 132 else
133 default_network_.connection_state_ = flimflam::kStateConfiguration; 133 default_network_.connection_state_ = shill::kStateConfiguration;
134 default_network_.type_ = default_network_state.type; 134 default_network_.type_ = default_network_state.type;
135 default_network_.network_technology_ = 135 default_network_.network_technology_ =
136 default_network_state.network_technology; 136 default_network_state.network_technology;
137 default_network_.path_ = default_network_state.service_path; 137 default_network_.path_ = default_network_state.service_path;
138 default_network_.ip_address_ = default_network_state.ip_address; 138 default_network_.ip_address_ = default_network_state.ip_address;
139 std::vector<std::string> dns_servers; 139 std::vector<std::string> dns_servers;
140 base::SplitString(default_network_state.dns_servers, ',', &dns_servers); 140 base::SplitString(default_network_state.dns_servers, ',', &dns_servers);
141 default_network_.dns_servers_ = dns_servers; 141 default_network_.dns_servers_ = dns_servers;
142 } 142 }
143 143
144 // Process an default network update based on the state of |default_network_|. 144 // Process an default network update based on the state of |default_network_|.
145 void ProcessDefaultNetworkUpdate(bool* type_changed, 145 void ProcessDefaultNetworkUpdate(bool* type_changed,
146 bool* ip_changed, 146 bool* ip_changed,
147 bool* dns_changed) { 147 bool* dns_changed) {
148 notifier_.UpdateState(&default_network_, type_changed, ip_changed, 148 notifier_.UpdateState(&default_network_, type_changed, ip_changed,
149 dns_changed); 149 dns_changed);
150 } 150 }
151 151
152 private: 152 private:
153 NetworkState default_network_; 153 NetworkState default_network_;
154 NetworkChangeNotifierChromeos notifier_; 154 NetworkChangeNotifierChromeos notifier_;
155 }; 155 };
156 156
157 NotifierUpdateTestCase test_cases[] = { 157 NotifierUpdateTestCase test_cases[] = {
158 { "Online -> Offline", 158 { "Online -> Offline",
159 { NetworkChangeNotifier::CONNECTION_ETHERNET, kService1, kIpAddress1, 159 { NetworkChangeNotifier::CONNECTION_ETHERNET, kService1, kIpAddress1,
160 kDnsServers1 }, 160 kDnsServers1 },
161 { false, flimflam::kTypeEthernet, "", kService1, "", "" }, 161 { false, shill::kTypeEthernet, "", kService1, "", "" },
162 { NetworkChangeNotifier::CONNECTION_NONE, "", "", "" }, 162 { NetworkChangeNotifier::CONNECTION_NONE, "", "", "" },
163 true, true, true 163 true, true, true
164 }, 164 },
165 { "Offline -> Offline", 165 { "Offline -> Offline",
166 { NetworkChangeNotifier::CONNECTION_NONE, "", "", "" }, 166 { NetworkChangeNotifier::CONNECTION_NONE, "", "", "" },
167 { false, flimflam::kTypeEthernet, "", kService1, kIpAddress1, 167 { false, shill::kTypeEthernet, "", kService1, kIpAddress1,
168 kDnsServers1 }, 168 kDnsServers1 },
169 { NetworkChangeNotifier::CONNECTION_NONE, "", "", "" }, 169 { NetworkChangeNotifier::CONNECTION_NONE, "", "", "" },
170 false, false, false 170 false, false, false
171 }, 171 },
172 { "Offline -> Online", 172 { "Offline -> Online",
173 { NetworkChangeNotifier::CONNECTION_NONE, "", "", "" }, 173 { NetworkChangeNotifier::CONNECTION_NONE, "", "", "" },
174 { true, flimflam::kTypeEthernet, "", kService1, kIpAddress1, kDnsServers1 }, 174 { true, shill::kTypeEthernet, "", kService1, kIpAddress1, kDnsServers1 },
175 { NetworkChangeNotifier::CONNECTION_ETHERNET, kService1, kIpAddress1, 175 { NetworkChangeNotifier::CONNECTION_ETHERNET, kService1, kIpAddress1,
176 kDnsServers1 }, 176 kDnsServers1 },
177 true, true, true 177 true, true, true
178 }, 178 },
179 { "Online -> Online (new default service, different connection type)", 179 { "Online -> Online (new default service, different connection type)",
180 { NetworkChangeNotifier::CONNECTION_ETHERNET, kService1, kIpAddress1, 180 { NetworkChangeNotifier::CONNECTION_ETHERNET, kService1, kIpAddress1,
181 kDnsServers1 }, 181 kDnsServers1 },
182 { true, flimflam::kTypeWifi, "", kService2, kIpAddress1, kDnsServers1 }, 182 { true, shill::kTypeWifi, "", kService2, kIpAddress1, kDnsServers1 },
183 { NetworkChangeNotifier::CONNECTION_WIFI, kService2, kIpAddress1, 183 { NetworkChangeNotifier::CONNECTION_WIFI, kService2, kIpAddress1,
184 kDnsServers1 }, 184 kDnsServers1 },
185 true, true, true 185 true, true, true
186 }, 186 },
187 { "Online -> Online (new default service, same connection type)", 187 { "Online -> Online (new default service, same connection type)",
188 { NetworkChangeNotifier::CONNECTION_WIFI, kService2, kIpAddress1, 188 { NetworkChangeNotifier::CONNECTION_WIFI, kService2, kIpAddress1,
189 kDnsServers1 }, 189 kDnsServers1 },
190 { true, flimflam::kTypeWifi, "", kService3, kIpAddress1, kDnsServers1 }, 190 { true, shill::kTypeWifi, "", kService3, kIpAddress1, kDnsServers1 },
191 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, kIpAddress1, 191 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, kIpAddress1,
192 kDnsServers1 }, 192 kDnsServers1 },
193 false, true, true 193 false, true, true
194 }, 194 },
195 { "Online -> Online (same default service, first IP address update)", 195 { "Online -> Online (same default service, first IP address update)",
196 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, "", kDnsServers1 }, 196 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, "", kDnsServers1 },
197 { true, flimflam::kTypeWifi, "", kService3, kIpAddress2, kDnsServers1 }, 197 { true, shill::kTypeWifi, "", kService3, kIpAddress2, kDnsServers1 },
198 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, kIpAddress2, 198 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, kIpAddress2,
199 kDnsServers1 }, 199 kDnsServers1 },
200 false, false, false 200 false, false, false
201 }, 201 },
202 { "Online -> Online (same default service, new IP address, same DNS)", 202 { "Online -> Online (same default service, new IP address, same DNS)",
203 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, kIpAddress1, 203 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, kIpAddress1,
204 kDnsServers1 }, 204 kDnsServers1 },
205 { true, flimflam::kTypeWifi, "", kService3, kIpAddress2, kDnsServers1 }, 205 { true, shill::kTypeWifi, "", kService3, kIpAddress2, kDnsServers1 },
206 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, kIpAddress2, 206 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, kIpAddress2,
207 kDnsServers1 }, 207 kDnsServers1 },
208 false, true, false 208 false, true, false
209 }, 209 },
210 { "Online -> Online (same default service, same IP address, new DNS)", 210 { "Online -> Online (same default service, same IP address, new DNS)",
211 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, kIpAddress2, 211 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, kIpAddress2,
212 kDnsServers1 }, 212 kDnsServers1 },
213 { true, flimflam::kTypeWifi, "", kService3, kIpAddress2, kDnsServers2 }, 213 { true, shill::kTypeWifi, "", kService3, kIpAddress2, kDnsServers2 },
214 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, kIpAddress2, 214 { NetworkChangeNotifier::CONNECTION_WIFI, kService3, kIpAddress2,
215 kDnsServers2 }, 215 kDnsServers2 },
216 false, false, true 216 false, false, true
217 } 217 }
218 }; 218 };
219 219
220 TEST_F(NetworkChangeNotifierChromeosUpdateTest, UpdateDefaultNetwork) { 220 TEST_F(NetworkChangeNotifierChromeosUpdateTest, UpdateDefaultNetwork) {
221 for (size_t i = 0; i < arraysize(test_cases); ++i) { 221 for (size_t i = 0; i < arraysize(test_cases); ++i) {
222 SCOPED_TRACE(test_cases[i].test_description); 222 SCOPED_TRACE(test_cases[i].test_description);
223 SetNotifierState(test_cases[i].initial_state); 223 SetNotifierState(test_cases[i].initial_state);
224 SetDefaultNetworkState(test_cases[i].default_network_state); 224 SetDefaultNetworkState(test_cases[i].default_network_state);
225 bool type_changed = false, ip_changed = false, dns_changed = false; 225 bool type_changed = false, ip_changed = false, dns_changed = false;
226 ProcessDefaultNetworkUpdate(&type_changed, &ip_changed, &dns_changed); 226 ProcessDefaultNetworkUpdate(&type_changed, &ip_changed, &dns_changed);
227 VerifyNotifierState(test_cases[i].expected_state); 227 VerifyNotifierState(test_cases[i].expected_state);
228 EXPECT_TRUE(type_changed == test_cases[i].expected_type_changed); 228 EXPECT_TRUE(type_changed == test_cases[i].expected_type_changed);
229 EXPECT_TRUE(ip_changed == test_cases[i].expected_ip_changed); 229 EXPECT_TRUE(ip_changed == test_cases[i].expected_ip_changed);
230 EXPECT_TRUE(dns_changed == test_cases[i].expected_dns_changed); 230 EXPECT_TRUE(dns_changed == test_cases[i].expected_dns_changed);
231 } 231 }
232 } 232 }
233 233
234 } // namespace chromeos 234 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_change_notifier_chromeos.cc ('k') | chromeos/network/network_configuration_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698