OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/wifi/wifi_service.h" | 5 #include "components/wifi/fake_wifi_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "components/onc/onc_constants.h" | 10 #include "components/onc/onc_constants.h" |
11 | 11 |
12 namespace wifi { | 12 namespace wifi { |
13 | 13 |
14 // Fake implementation of WiFiService used to satisfy expectations of | 14 FakeWiFiService::FakeWiFiService() { |
15 // networkingPrivateApi browser test. | 15 // Populate data expected by unit test. |
16 class FakeWiFiService : public WiFiService { | 16 { |
17 public: | 17 WiFiService::NetworkProperties network_properties; |
18 FakeWiFiService() { | 18 network_properties.connection_state = onc::connection_state::kConnected; |
19 // Populate data expected by unit test. | 19 network_properties.guid = "stub_ethernet"; |
20 { | 20 network_properties.name = "eth0"; |
21 WiFiService::NetworkProperties network_properties; | 21 network_properties.type = onc::network_type::kEthernet; |
22 network_properties.connection_state = onc::connection_state::kConnected; | 22 network_properties.json_extra = |
23 network_properties.guid = "stub_ethernet"; | 23 " {" |
24 network_properties.name = "eth0"; | 24 " \"Authentication\": \"None\"" |
25 network_properties.type = onc::network_type::kEthernet; | 25 " }"; |
26 network_properties.json_extra = | 26 networks_.push_back(network_properties); |
27 " {" | 27 } |
28 " \"Authentication\": \"None\"" | 28 { |
29 " }"; | 29 WiFiService::NetworkProperties network_properties; |
30 networks_.push_back(network_properties); | 30 network_properties.connection_state = onc::connection_state::kConnected; |
| 31 network_properties.guid = "stub_wifi1"; |
| 32 network_properties.name = "wifi1"; |
| 33 network_properties.type = onc::network_type::kWiFi; |
| 34 network_properties.frequency = 0; |
| 35 network_properties.ssid = "stub_wifi1"; |
| 36 network_properties.security = onc::wifi::kWEP_PSK; |
| 37 network_properties.signal_strength = 0; |
| 38 networks_.push_back(network_properties); |
| 39 } |
| 40 { |
| 41 WiFiService::NetworkProperties network_properties; |
| 42 network_properties.connection_state = onc::connection_state::kConnected; |
| 43 network_properties.guid = "stub_vpn1"; |
| 44 network_properties.name = "vpn1"; |
| 45 network_properties.type = onc::network_type::kVPN; |
| 46 networks_.push_back(network_properties); |
| 47 } |
| 48 { |
| 49 WiFiService::NetworkProperties network_properties; |
| 50 network_properties.connection_state = onc::connection_state::kNotConnected; |
| 51 network_properties.guid = "stub_wifi2"; |
| 52 network_properties.name = "wifi2_PSK"; |
| 53 network_properties.type = onc::network_type::kWiFi; |
| 54 network_properties.frequency = 5000; |
| 55 network_properties.frequency_set.insert(2400); |
| 56 network_properties.frequency_set.insert(5000); |
| 57 network_properties.ssid = "wifi2_PSK"; |
| 58 network_properties.security = onc::wifi::kWPA_PSK; |
| 59 network_properties.signal_strength = 80; |
| 60 networks_.push_back(network_properties); |
| 61 } |
| 62 { |
| 63 WiFiService::NetworkProperties network_properties; |
| 64 network_properties.connection_state = onc::connection_state::kNotConnected; |
| 65 network_properties.guid = "stub_cellular1"; |
| 66 network_properties.name = "cellular1"; |
| 67 network_properties.type = onc::network_type::kCellular; |
| 68 network_properties.json_extra = |
| 69 " {" |
| 70 " \"ActivationState\": \"not-activated\"," |
| 71 " \"NetworkTechnology\": \"GSM\"," |
| 72 " \"RoamingState\": \"home\"" |
| 73 " }"; |
| 74 networks_.push_back(network_properties); |
| 75 } |
| 76 } |
| 77 |
| 78 FakeWiFiService::~FakeWiFiService() { |
| 79 } |
| 80 |
| 81 void FakeWiFiService::Initialize( |
| 82 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
| 83 } |
| 84 |
| 85 void FakeWiFiService::UnInitialize() { |
| 86 } |
| 87 |
| 88 void FakeWiFiService::GetProperties(const std::string& network_guid, |
| 89 base::DictionaryValue* properties, |
| 90 std::string* error) { |
| 91 WiFiService::NetworkList::iterator network_properties = |
| 92 FindNetwork(network_guid); |
| 93 if (network_properties != networks_.end()) { |
| 94 properties->Swap(network_properties->ToValue(false).get()); |
| 95 } else { |
| 96 *error = "Error.DBusFailed"; |
| 97 } |
| 98 } |
| 99 |
| 100 void FakeWiFiService::GetManagedProperties( |
| 101 const std::string& network_guid, |
| 102 base::DictionaryValue* managed_properties, |
| 103 std::string* error) { |
| 104 const std::string network_properties = |
| 105 "{" |
| 106 " \"ConnectionState\": {" |
| 107 " \"Active\": \"NotConnected\"," |
| 108 " \"Effective\": \"Unmanaged\"" |
| 109 " }," |
| 110 " \"GUID\": \"stub_wifi2\"," |
| 111 " \"Name\": {" |
| 112 " \"Active\": \"wifi2_PSK\"," |
| 113 " \"Effective\": \"UserPolicy\"," |
| 114 " \"UserPolicy\": \"My WiFi Network\"" |
| 115 " }," |
| 116 " \"Type\": {" |
| 117 " \"Active\": \"WiFi\"," |
| 118 " \"Effective\": \"UserPolicy\"," |
| 119 " \"UserPolicy\": \"WiFi\"" |
| 120 " }," |
| 121 " \"WiFi\": {" |
| 122 " \"AutoConnect\": {" |
| 123 " \"Active\": false," |
| 124 " \"UserEditable\": true" |
| 125 " }," |
| 126 " \"Frequency\" : {" |
| 127 " \"Active\": 5000," |
| 128 " \"Effective\": \"Unmanaged\"" |
| 129 " }," |
| 130 " \"FrequencyList\" : {" |
| 131 " \"Active\": [2400, 5000]," |
| 132 " \"Effective\": \"Unmanaged\"" |
| 133 " }," |
| 134 " \"Passphrase\": {" |
| 135 " \"Effective\": \"UserSetting\"," |
| 136 " \"UserEditable\": true," |
| 137 " \"UserSetting\": \"FAKE_CREDENTIAL_VPaJDV9x\"" |
| 138 " }," |
| 139 " \"SSID\": {" |
| 140 " \"Active\": \"wifi2_PSK\"," |
| 141 " \"Effective\": \"UserPolicy\"," |
| 142 " \"UserPolicy\": \"wifi2_PSK\"" |
| 143 " }," |
| 144 " \"Security\": {" |
| 145 " \"Active\": \"WPA-PSK\"," |
| 146 " \"Effective\": \"UserPolicy\"," |
| 147 " \"UserPolicy\": \"WPA-PSK\"" |
| 148 " }," |
| 149 " \"SignalStrength\": {" |
| 150 " \"Active\": 80," |
| 151 " \"Effective\": \"Unmanaged\"" |
| 152 " }" |
| 153 " }" |
| 154 "}"; |
| 155 scoped_ptr<base::DictionaryValue> properties_value( |
| 156 reinterpret_cast<base::DictionaryValue*>( |
| 157 base::JSONReader::Read(network_properties))); |
| 158 managed_properties->MergeDictionary(properties_value.get()); |
| 159 } |
| 160 |
| 161 void FakeWiFiService::GetState(const std::string& network_guid, |
| 162 base::DictionaryValue* properties, |
| 163 std::string* error) { |
| 164 WiFiService::NetworkList::iterator network_properties = |
| 165 FindNetwork(network_guid); |
| 166 if (network_properties == networks_.end()) { |
| 167 *error = "Error.InvalidParameter"; |
| 168 return; |
| 169 } |
| 170 |
| 171 const std::string network_state = |
| 172 "{" |
| 173 " \"ConnectionState\": \"NotConnected\"," |
| 174 " \"GUID\": \"stub_wifi2\"," |
| 175 " \"Name\": \"wifi2_PSK\"," |
| 176 " \"Type\": \"WiFi\"," |
| 177 " \"WiFi\": {" |
| 178 " \"Security\": \"WPA-PSK\"," |
| 179 " \"SignalStrength\": 80" |
| 180 " }" |
| 181 "}"; |
| 182 scoped_ptr<base::DictionaryValue> properties_value( |
| 183 reinterpret_cast<base::DictionaryValue*>( |
| 184 base::JSONReader::Read(network_state))); |
| 185 properties->MergeDictionary(properties_value.get()); |
| 186 } |
| 187 |
| 188 void FakeWiFiService::SetProperties( |
| 189 const std::string& network_guid, |
| 190 scoped_ptr<base::DictionaryValue> properties, |
| 191 std::string* error) { |
| 192 WiFiService::NetworkList::iterator network_properties = |
| 193 FindNetwork(network_guid); |
| 194 if (network_properties == networks_.end() || |
| 195 !network_properties->UpdateFromValue(*properties)) { |
| 196 *error = "Error.DBusFailed"; |
| 197 } |
| 198 } |
| 199 |
| 200 void FakeWiFiService::CreateNetwork( |
| 201 bool shared, |
| 202 scoped_ptr<base::DictionaryValue> properties, |
| 203 std::string* network_guid, |
| 204 std::string* error) { |
| 205 WiFiService::NetworkProperties network_properties; |
| 206 if (network_properties.UpdateFromValue(*properties)) { |
| 207 network_properties.guid = network_properties.ssid; |
| 208 networks_.push_back(network_properties); |
| 209 *network_guid = network_properties.guid; |
| 210 } else { |
| 211 *error = "Error.DBusFailed"; |
| 212 } |
| 213 } |
| 214 |
| 215 void FakeWiFiService::GetVisibleNetworks(const std::string& network_type, |
| 216 base::ListValue* network_list) { |
| 217 for (WiFiService::NetworkList::const_iterator it = networks_.begin(); |
| 218 it != networks_.end(); |
| 219 ++it) { |
| 220 if (network_type.empty() || network_type == onc::network_type::kAllTypes || |
| 221 it->type == network_type) { |
| 222 scoped_ptr<base::DictionaryValue> network(it->ToValue(true)); |
| 223 network_list->Append(network.release()); |
31 } | 224 } |
32 { | 225 } |
33 WiFiService::NetworkProperties network_properties; | 226 } |
34 network_properties.connection_state = onc::connection_state::kConnected; | 227 |
35 network_properties.guid = "stub_wifi1"; | 228 void FakeWiFiService::RequestNetworkScan() { |
36 network_properties.name = "wifi1"; | 229 NotifyNetworkListChanged(networks_); |
37 network_properties.type = onc::network_type::kWiFi; | 230 } |
38 network_properties.frequency = 0; | 231 |
39 network_properties.ssid = "stub_wifi1"; | 232 void FakeWiFiService::StartConnect(const std::string& network_guid, |
40 network_properties.security = onc::wifi::kWEP_PSK; | 233 std::string* error) { |
41 network_properties.signal_strength = 0; | 234 NetworkList::iterator network_properties = FindNetwork(network_guid); |
42 networks_.push_back(network_properties); | 235 if (network_properties != networks_.end()) { |
43 } | 236 DisconnectAllNetworksOfType(network_properties->type); |
44 { | 237 network_properties->connection_state = onc::connection_state::kConnected; |
45 WiFiService::NetworkProperties network_properties; | 238 SortNetworks(); |
46 network_properties.connection_state = onc::connection_state::kConnected; | |
47 network_properties.guid = "stub_vpn1"; | |
48 network_properties.name = "vpn1"; | |
49 network_properties.type = onc::network_type::kVPN; | |
50 networks_.push_back(network_properties); | |
51 } | |
52 { | |
53 WiFiService::NetworkProperties network_properties; | |
54 network_properties.connection_state = | |
55 onc::connection_state::kNotConnected; | |
56 network_properties.guid = "stub_wifi2"; | |
57 network_properties.name = "wifi2_PSK"; | |
58 network_properties.type = onc::network_type::kWiFi; | |
59 network_properties.frequency = 5000; | |
60 network_properties.frequency_set.insert(2400); | |
61 network_properties.frequency_set.insert(5000); | |
62 network_properties.ssid = "wifi2_PSK"; | |
63 network_properties.security = onc::wifi::kWPA_PSK; | |
64 network_properties.signal_strength = 80; | |
65 networks_.push_back(network_properties); | |
66 } | |
67 { | |
68 WiFiService::NetworkProperties network_properties; | |
69 network_properties.connection_state = | |
70 onc::connection_state::kNotConnected; | |
71 network_properties.guid = "stub_cellular1"; | |
72 network_properties.name = "cellular1"; | |
73 network_properties.type = onc::network_type::kCellular; | |
74 network_properties.json_extra = | |
75 " {" | |
76 " \"ActivationState\": \"not-activated\"," | |
77 " \"NetworkTechnology\": \"GSM\"," | |
78 " \"RoamingState\": \"home\"" | |
79 " }"; | |
80 networks_.push_back(network_properties); | |
81 } | |
82 } | |
83 | |
84 virtual void Initialize( | |
85 scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE {} | |
86 | |
87 virtual void UnInitialize() OVERRIDE {} | |
88 | |
89 virtual void GetProperties(const std::string& network_guid, | |
90 base::DictionaryValue* properties, | |
91 std::string* error) OVERRIDE { | |
92 NetworkList::iterator network_properties = FindNetwork(network_guid); | |
93 if (network_properties != networks_.end()) { | |
94 properties->Swap(network_properties->ToValue(false).get()); | |
95 } else { | |
96 *error = "Error.DBusFailed"; | |
97 } | |
98 } | |
99 | |
100 virtual void GetManagedProperties(const std::string& network_guid, | |
101 base::DictionaryValue* managed_properties, | |
102 std::string* error) OVERRIDE { | |
103 const std::string network_properties = | |
104 "{" | |
105 " \"ConnectionState\": {" | |
106 " \"Active\": \"NotConnected\"," | |
107 " \"Effective\": \"Unmanaged\"" | |
108 " }," | |
109 " \"GUID\": \"stub_wifi2\"," | |
110 " \"Name\": {" | |
111 " \"Active\": \"wifi2_PSK\"," | |
112 " \"Effective\": \"UserPolicy\"," | |
113 " \"UserPolicy\": \"My WiFi Network\"" | |
114 " }," | |
115 " \"Type\": {" | |
116 " \"Active\": \"WiFi\"," | |
117 " \"Effective\": \"UserPolicy\"," | |
118 " \"UserPolicy\": \"WiFi\"" | |
119 " }," | |
120 " \"WiFi\": {" | |
121 " \"AutoConnect\": {" | |
122 " \"Active\": false," | |
123 " \"UserEditable\": true" | |
124 " }," | |
125 " \"Frequency\" : {" | |
126 " \"Active\": 5000," | |
127 " \"Effective\": \"Unmanaged\"" | |
128 " }," | |
129 " \"FrequencyList\" : {" | |
130 " \"Active\": [2400, 5000]," | |
131 " \"Effective\": \"Unmanaged\"" | |
132 " }," | |
133 " \"Passphrase\": {" | |
134 " \"Effective\": \"UserSetting\"," | |
135 " \"UserEditable\": true," | |
136 " \"UserSetting\": \"FAKE_CREDENTIAL_VPaJDV9x\"" | |
137 " }," | |
138 " \"SSID\": {" | |
139 " \"Active\": \"wifi2_PSK\"," | |
140 " \"Effective\": \"UserPolicy\"," | |
141 " \"UserPolicy\": \"wifi2_PSK\"" | |
142 " }," | |
143 " \"Security\": {" | |
144 " \"Active\": \"WPA-PSK\"," | |
145 " \"Effective\": \"UserPolicy\"," | |
146 " \"UserPolicy\": \"WPA-PSK\"" | |
147 " }," | |
148 " \"SignalStrength\": {" | |
149 " \"Active\": 80," | |
150 " \"Effective\": \"Unmanaged\"" | |
151 " }" | |
152 " }" | |
153 "}"; | |
154 scoped_ptr<base::DictionaryValue> properties_value( | |
155 reinterpret_cast<base::DictionaryValue*>( | |
156 base::JSONReader::Read(network_properties))); | |
157 managed_properties->MergeDictionary(properties_value.get()); | |
158 } | |
159 | |
160 virtual void GetState(const std::string& network_guid, | |
161 base::DictionaryValue* properties, | |
162 std::string* error) OVERRIDE { | |
163 NetworkList::iterator network_properties = FindNetwork(network_guid); | |
164 if (network_properties == networks_.end()) { | |
165 *error = "Error.InvalidParameter"; | |
166 return; | |
167 } | |
168 | |
169 const std::string network_state = | |
170 "{" | |
171 " \"ConnectionState\": \"NotConnected\"," | |
172 " \"GUID\": \"stub_wifi2\"," | |
173 " \"Name\": \"wifi2_PSK\"," | |
174 " \"Type\": \"WiFi\"," | |
175 " \"WiFi\": {" | |
176 " \"Security\": \"WPA-PSK\"," | |
177 " \"SignalStrength\": 80" | |
178 " }" | |
179 "}"; | |
180 scoped_ptr<base::DictionaryValue> properties_value( | |
181 reinterpret_cast<base::DictionaryValue*>( | |
182 base::JSONReader::Read(network_state))); | |
183 properties->MergeDictionary(properties_value.get()); | |
184 } | |
185 | |
186 virtual void SetProperties(const std::string& network_guid, | |
187 scoped_ptr<base::DictionaryValue> properties, | |
188 std::string* error) OVERRIDE { | |
189 NetworkList::iterator network_properties = FindNetwork(network_guid); | |
190 if (network_properties == networks_.end() || | |
191 !network_properties->UpdateFromValue(*properties)) { | |
192 *error = "Error.DBusFailed"; | |
193 } | |
194 } | |
195 | |
196 virtual void CreateNetwork(bool shared, | |
197 scoped_ptr<base::DictionaryValue> properties, | |
198 std::string* network_guid, | |
199 std::string* error) OVERRIDE { | |
200 WiFiService::NetworkProperties network_properties; | |
201 if (network_properties.UpdateFromValue(*properties)) { | |
202 network_properties.guid = network_properties.ssid; | |
203 networks_.push_back(network_properties); | |
204 *network_guid = network_properties.guid; | |
205 } else { | |
206 *error = "Error.DBusFailed"; | |
207 } | |
208 } | |
209 | |
210 virtual void GetVisibleNetworks(const std::string& network_type, | |
211 base::ListValue* network_list) OVERRIDE { | |
212 for (WiFiService::NetworkList::const_iterator it = networks_.begin(); | |
213 it != networks_.end(); | |
214 ++it) { | |
215 if (network_type.empty() || | |
216 network_type == onc::network_type::kAllTypes || | |
217 it->type == network_type) { | |
218 scoped_ptr<base::DictionaryValue> network(it->ToValue(true)); | |
219 network_list->Append(network.release()); | |
220 } | |
221 } | |
222 } | |
223 | |
224 virtual void RequestNetworkScan() OVERRIDE { | |
225 NotifyNetworkListChanged(networks_); | 239 NotifyNetworkListChanged(networks_); |
226 } | 240 NotifyNetworkChanged(network_guid); |
227 | 241 } else { |
228 virtual void StartConnect(const std::string& network_guid, | 242 *error = "configure-failed"; |
229 std::string* error) OVERRIDE { | 243 } |
230 NetworkList::iterator network_properties = FindNetwork(network_guid); | 244 } |
231 if (network_properties != networks_.end()) { | 245 |
232 DisconnectAllNetworksOfType(network_properties->type); | 246 void FakeWiFiService::StartDisconnect(const std::string& network_guid, |
233 network_properties->connection_state = onc::connection_state::kConnected; | 247 std::string* error) { |
234 SortNetworks(); | 248 WiFiService::NetworkList::iterator network_properties = |
235 NotifyNetworkListChanged(networks_); | 249 FindNetwork(network_guid); |
236 NotifyNetworkChanged(network_guid); | 250 if (network_properties != networks_.end()) { |
237 } else { | 251 network_properties->connection_state = onc::connection_state::kNotConnected; |
238 *error = "configure-failed"; | 252 SortNetworks(); |
239 } | 253 NotifyNetworkListChanged(networks_); |
240 } | 254 NotifyNetworkChanged(network_guid); |
241 | 255 } else { |
242 virtual void StartDisconnect(const std::string& network_guid, | |
243 std::string* error) OVERRIDE { | |
244 NetworkList::iterator network_properties = FindNetwork(network_guid); | |
245 if (network_properties != networks_.end()) { | |
246 network_properties->connection_state = | |
247 onc::connection_state::kNotConnected; | |
248 SortNetworks(); | |
249 NotifyNetworkListChanged(networks_); | |
250 NotifyNetworkChanged(network_guid); | |
251 } else { | |
252 *error = "not-found"; | |
253 } | |
254 } | |
255 | |
256 virtual void GetKeyFromSystem(const std::string& network_guid, | |
257 std::string* key_data, | |
258 std::string* error) OVERRIDE { | |
259 *error = "not-found"; | 256 *error = "not-found"; |
260 } | 257 } |
261 | 258 } |
262 virtual void SetEventObservers( | 259 |
263 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 260 void FakeWiFiService::GetKeyFromSystem(const std::string& network_guid, |
264 const NetworkGuidListCallback& networks_changed_observer, | 261 std::string* key_data, |
265 const NetworkGuidListCallback& network_list_changed_observer) OVERRIDE { | 262 std::string* error) { |
266 message_loop_proxy_.swap(message_loop_proxy); | 263 *error = "not-found"; |
267 networks_changed_observer_ = networks_changed_observer; | 264 } |
268 network_list_changed_observer_ = network_list_changed_observer; | 265 |
269 } | 266 void FakeWiFiService::SetEventObservers( |
270 | 267 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
271 virtual void RequestConnectedNetworkUpdate() OVERRIDE { } | 268 const NetworkGuidListCallback& networks_changed_observer, |
272 | 269 const NetworkGuidListCallback& network_list_changed_observer) { |
273 private: | 270 message_loop_proxy_.swap(message_loop_proxy); |
274 NetworkList::iterator FindNetwork(const std::string& network_guid) { | 271 networks_changed_observer_ = networks_changed_observer; |
275 for (NetworkList::iterator it = networks_.begin(); it != networks_.end(); | 272 network_list_changed_observer_ = network_list_changed_observer; |
276 ++it) { | 273 } |
277 if (it->guid == network_guid) | 274 |
278 return it; | 275 void FakeWiFiService::RequestConnectedNetworkUpdate() { |
279 } | 276 } |
280 return networks_.end(); | 277 |
281 } | 278 WiFiService::NetworkList::iterator FakeWiFiService::FindNetwork( |
282 | 279 const std::string& network_guid) { |
283 void DisconnectAllNetworksOfType(const std::string& type) { | 280 for (WiFiService::NetworkList::iterator it = networks_.begin(); |
284 for (NetworkList::iterator it = networks_.begin(); it != networks_.end(); | 281 it != networks_.end(); |
285 ++it) { | 282 ++it) { |
286 if (it->type == type) | 283 if (it->guid == network_guid) |
287 it->connection_state = onc::connection_state::kNotConnected; | 284 return it; |
288 } | 285 } |
289 } | 286 return networks_.end(); |
290 | 287 } |
291 void SortNetworks() { | 288 |
292 // Sort networks, so connected/connecting is up front, then by type: | 289 void FakeWiFiService::DisconnectAllNetworksOfType(const std::string& type) { |
293 // Ethernet, WiFi, Cellular, VPN | 290 for (WiFiService::NetworkList::iterator it = networks_.begin(); |
294 networks_.sort(WiFiService::NetworkProperties::OrderByType); | 291 it != networks_.end(); |
295 } | 292 ++it) { |
296 | 293 if (it->type == type) |
297 void NotifyNetworkListChanged(const NetworkList& networks) { | 294 it->connection_state = onc::connection_state::kNotConnected; |
298 WiFiService::NetworkGuidList current_networks; | 295 } |
299 for (WiFiService::NetworkList::const_iterator it = networks.begin(); | 296 } |
300 it != networks.end(); | 297 |
301 ++it) { | 298 void FakeWiFiService::SortNetworks() { |
302 current_networks.push_back(it->guid); | 299 // Sort networks, so connected/connecting is up front, then by type: |
303 } | 300 // Ethernet, WiFi, Cellular, VPN |
304 | 301 networks_.sort(WiFiService::NetworkProperties::OrderByType); |
305 message_loop_proxy_->PostTask( | 302 } |
306 FROM_HERE, | 303 |
307 base::Bind(network_list_changed_observer_, current_networks)); | 304 void FakeWiFiService::NotifyNetworkListChanged( |
308 } | 305 const WiFiService::NetworkList& networks) { |
309 | 306 WiFiService::NetworkGuidList current_networks; |
310 void NotifyNetworkChanged(const std::string& network_guid) { | 307 for (WiFiService::NetworkList::const_iterator it = networks.begin(); |
311 WiFiService::NetworkGuidList changed_networks(1, network_guid); | 308 it != networks.end(); |
312 message_loop_proxy_->PostTask( | 309 ++it) { |
313 FROM_HERE, | 310 current_networks.push_back(it->guid); |
314 base::Bind(networks_changed_observer_, changed_networks)); | 311 } |
315 } | 312 |
316 | 313 message_loop_proxy_->PostTask( |
317 NetworkList networks_; | 314 FROM_HERE, base::Bind(network_list_changed_observer_, current_networks)); |
318 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 315 } |
319 NetworkGuidListCallback networks_changed_observer_; | 316 |
320 NetworkGuidListCallback network_list_changed_observer_; | 317 void FakeWiFiService::NotifyNetworkChanged(const std::string& network_guid) { |
321 }; | 318 WiFiService::NetworkGuidList changed_networks(1, network_guid); |
322 | 319 message_loop_proxy_->PostTask( |
323 WiFiService* WiFiService::CreateForTest() { return new FakeWiFiService(); } | 320 FROM_HERE, base::Bind(networks_changed_observer_, changed_networks)); |
| 321 } |
324 | 322 |
325 } // namespace wifi | 323 } // namespace wifi |
OLD | NEW |