| 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/fake_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 FakeWiFiService::FakeWiFiService() { | 14 FakeWiFiService::FakeWiFiService() { |
| 15 // Populate data expected by unit test. | 15 // Populate data expected by unit test. |
| 16 { | 16 { |
| 17 WiFiService::NetworkProperties network_properties; | 17 WiFiService::NetworkProperties network_properties; |
| 18 network_properties.connection_state = onc::connection_state::kConnected; | 18 network_properties.connection_state = onc::connection_state::kConnected; |
| 19 network_properties.guid = "stub_ethernet"; | |
| 20 network_properties.name = "eth0"; | |
| 21 network_properties.type = onc::network_type::kEthernet; | |
| 22 network_properties.json_extra = | |
| 23 " {" | |
| 24 " \"Authentication\": \"None\"" | |
| 25 " }"; | |
| 26 networks_.push_back(network_properties); | |
| 27 } | |
| 28 { | |
| 29 WiFiService::NetworkProperties network_properties; | |
| 30 network_properties.connection_state = onc::connection_state::kConnected; | |
| 31 network_properties.guid = "stub_wifi1"; | 19 network_properties.guid = "stub_wifi1"; |
| 32 network_properties.name = "wifi1"; | 20 network_properties.name = "wifi1"; |
| 33 network_properties.type = onc::network_type::kWiFi; | 21 network_properties.type = onc::network_type::kWiFi; |
| 34 network_properties.frequency = 0; | 22 network_properties.frequency = 0; |
| 35 network_properties.ssid = "stub_wifi1"; | 23 network_properties.ssid = "wifi1"; |
| 36 network_properties.security = onc::wifi::kWEP_PSK; | 24 network_properties.security = onc::wifi::kWEP_PSK; |
| 37 network_properties.signal_strength = 0; | 25 network_properties.signal_strength = 40; |
| 26 network_properties.json_extra = |
| 27 "{" |
| 28 " \"IPConfigs\": [{" |
| 29 " \"Gateway\": \"0.0.0.1\"," |
| 30 " \"IPAddress\": \"0.0.0.0\"," |
| 31 " \"RoutingPrefix\": 0," |
| 32 " \"Type\": \"IPv4\"" |
| 33 " }]," |
| 34 " \"WiFi\": {" |
| 35 " \"Frequency\": 2400," |
| 36 " \"FrequencyList\": [2400]" |
| 37 " }" |
| 38 "}"; |
| 38 networks_.push_back(network_properties); | 39 networks_.push_back(network_properties); |
| 39 } | 40 } |
| 40 { | 41 { |
| 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; | 42 WiFiService::NetworkProperties network_properties; |
| 50 network_properties.connection_state = onc::connection_state::kNotConnected; | 43 network_properties.connection_state = onc::connection_state::kNotConnected; |
| 51 network_properties.guid = "stub_wifi2"; | 44 network_properties.guid = "stub_wifi2"; |
| 52 network_properties.name = "wifi2_PSK"; | 45 network_properties.name = "wifi2_PSK"; |
| 53 network_properties.type = onc::network_type::kWiFi; | 46 network_properties.type = onc::network_type::kWiFi; |
| 54 network_properties.frequency = 5000; | 47 network_properties.frequency = 5000; |
| 55 network_properties.frequency_set.insert(2400); | 48 network_properties.frequency_set.insert(2400); |
| 56 network_properties.frequency_set.insert(5000); | 49 network_properties.frequency_set.insert(5000); |
| 57 network_properties.ssid = "wifi2_PSK"; | 50 network_properties.ssid = "wifi2_PSK"; |
| 58 network_properties.security = onc::wifi::kWPA_PSK; | 51 network_properties.security = onc::wifi::kWPA_PSK; |
| 59 network_properties.signal_strength = 80; | 52 network_properties.signal_strength = 80; |
| 60 networks_.push_back(network_properties); | 53 networks_.push_back(network_properties); |
| 61 } | 54 } |
| 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 } | 55 } |
| 77 | 56 |
| 78 FakeWiFiService::~FakeWiFiService() { | 57 FakeWiFiService::~FakeWiFiService() { |
| 79 } | 58 } |
| 80 | 59 |
| 81 void FakeWiFiService::Initialize( | 60 void FakeWiFiService::Initialize( |
| 82 scoped_refptr<base::SequencedTaskRunner> task_runner) { | 61 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
| 83 } | 62 } |
| 84 | 63 |
| 85 void FakeWiFiService::UnInitialize() { | 64 void FakeWiFiService::UnInitialize() { |
| 86 } | 65 } |
| 87 | 66 |
| 88 void FakeWiFiService::GetProperties(const std::string& network_guid, | 67 void FakeWiFiService::GetProperties(const std::string& network_guid, |
| 89 base::DictionaryValue* properties, | 68 base::DictionaryValue* properties, |
| 90 std::string* error) { | 69 std::string* error) { |
| 91 WiFiService::NetworkList::iterator network_properties = | 70 WiFiService::NetworkList::iterator network_properties = |
| 92 FindNetwork(network_guid); | 71 FindNetwork(network_guid); |
| 93 if (network_properties != networks_.end()) { | 72 if (network_properties != networks_.end()) { |
| 94 properties->Swap(network_properties->ToValue(false).get()); | 73 properties->Swap(network_properties->ToValue(false).get()); |
| 95 } else { | 74 } else { |
| 96 *error = "Error.DBusFailed"; | 75 *error = "Error.DBusFailed"; |
| 97 } | 76 } |
| 98 } | 77 } |
| 99 | 78 |
| 100 void FakeWiFiService::GetManagedProperties( | 79 void FakeWiFiService::GetManagedProperties( |
| 101 const std::string& network_guid, | 80 const std::string& network_guid, |
| 102 base::DictionaryValue* managed_properties, | 81 base::DictionaryValue* managed_properties, |
| 103 std::string* error) { | 82 std::string* error) { |
| 104 const std::string network_properties = | 83 // Not implemented |
| 105 "{" | 84 *error = kErrorWiFiService; |
| 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 } | 85 } |
| 160 | 86 |
| 161 void FakeWiFiService::GetState(const std::string& network_guid, | 87 void FakeWiFiService::GetState(const std::string& network_guid, |
| 162 base::DictionaryValue* properties, | 88 base::DictionaryValue* properties, |
| 163 std::string* error) { | 89 std::string* error) { |
| 164 WiFiService::NetworkList::iterator network_properties = | 90 WiFiService::NetworkList::iterator network_properties = |
| 165 FindNetwork(network_guid); | 91 FindNetwork(network_guid); |
| 166 if (network_properties == networks_.end()) { | 92 if (network_properties == networks_.end()) { |
| 167 *error = "Error.InvalidParameter"; | 93 *error = "Error.InvalidParameter"; |
| 168 return; | 94 return; |
| 169 } | 95 } |
| 170 | 96 properties->Swap(network_properties->ToValue(true).get()); |
| 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 } | 97 } |
| 187 | 98 |
| 188 void FakeWiFiService::SetProperties( | 99 void FakeWiFiService::SetProperties( |
| 189 const std::string& network_guid, | 100 const std::string& network_guid, |
| 190 scoped_ptr<base::DictionaryValue> properties, | 101 scoped_ptr<base::DictionaryValue> properties, |
| 191 std::string* error) { | 102 std::string* error) { |
| 192 WiFiService::NetworkList::iterator network_properties = | 103 WiFiService::NetworkList::iterator network_properties = |
| 193 FindNetwork(network_guid); | 104 FindNetwork(network_guid); |
| 194 if (network_properties == networks_.end() || | 105 if (network_properties == networks_.end() || |
| 195 !network_properties->UpdateFromValue(*properties)) { | 106 !network_properties->UpdateFromValue(*properties)) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 FROM_HERE, base::Bind(network_list_changed_observer_, current_networks)); | 225 FROM_HERE, base::Bind(network_list_changed_observer_, current_networks)); |
| 315 } | 226 } |
| 316 | 227 |
| 317 void FakeWiFiService::NotifyNetworkChanged(const std::string& network_guid) { | 228 void FakeWiFiService::NotifyNetworkChanged(const std::string& network_guid) { |
| 318 WiFiService::NetworkGuidList changed_networks(1, network_guid); | 229 WiFiService::NetworkGuidList changed_networks(1, network_guid); |
| 319 message_loop_proxy_->PostTask( | 230 message_loop_proxy_->PostTask( |
| 320 FROM_HERE, base::Bind(networks_changed_observer_, changed_networks)); | 231 FROM_HERE, base::Bind(networks_changed_observer_, changed_networks)); |
| 321 } | 232 } |
| 322 | 233 |
| 323 } // namespace wifi | 234 } // namespace wifi |
| OLD | NEW |