| OLD | NEW |
| 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/network_state.h" | 5 #include "chromeos/network/network_state.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/i18n/streaming_utf8_validator.h" | 8 #include "base/i18n/streaming_utf8_validator.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 private: | 47 private: |
| 48 std::string value_; | 48 std::string value_; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 class NetworkStateTest : public testing::Test { | 51 class NetworkStateTest : public testing::Test { |
| 52 public: | 52 public: |
| 53 NetworkStateTest() : network_state_("test_path") { | 53 NetworkStateTest() : network_state_("test_path") { |
| 54 } | 54 } |
| 55 | 55 |
| 56 protected: | 56 protected: |
| 57 bool SetProperty(const std::string& key, scoped_ptr<base::Value> value) { |
| 58 const bool result = network_state_.PropertyChanged(key, *value); |
| 59 properties_.SetWithoutPathExpansion(key, value.release()); |
| 60 return result; |
| 61 } |
| 62 |
| 57 bool SetStringProperty(const std::string& key, const std::string& value) { | 63 bool SetStringProperty(const std::string& key, const std::string& value) { |
| 58 TestStringValue* string_value = new TestStringValue(value); | 64 return SetProperty(key, make_scoped_ptr(new TestStringValue(value))); |
| 59 bool res = network_state_.PropertyChanged(key, *string_value); | |
| 60 properties_.SetWithoutPathExpansion(key, string_value); | |
| 61 return res; | |
| 62 } | 65 } |
| 63 | 66 |
| 64 bool SignalInitialPropertiesReceived() { | 67 bool SignalInitialPropertiesReceived() { |
| 65 return network_state_.InitialPropertiesReceived(properties_); | 68 return network_state_.InitialPropertiesReceived(properties_); |
| 66 } | 69 } |
| 67 | 70 |
| 68 NetworkState network_state_; | 71 NetworkState network_state_; |
| 69 | 72 |
| 70 private: | 73 private: |
| 71 base::DictionaryValue properties_; | 74 base::DictionaryValue properties_; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 EXPECT_FALSE(network_state_.is_captive_portal()); | 209 EXPECT_FALSE(network_state_.is_captive_portal()); |
| 207 | 210 |
| 208 // Set the status property to the expected captive portal state property. | 211 // Set the status property to the expected captive portal state property. |
| 209 // is_captive_portal should now be true. | 212 // is_captive_portal should now be true. |
| 210 SetStringProperty(shill::kPortalDetectionFailedStatusProperty, | 213 SetStringProperty(shill::kPortalDetectionFailedStatusProperty, |
| 211 shill::kPortalDetectionStatusFailure); | 214 shill::kPortalDetectionStatusFailure); |
| 212 SignalInitialPropertiesReceived(); | 215 SignalInitialPropertiesReceived(); |
| 213 EXPECT_TRUE(network_state_.is_captive_portal()); | 216 EXPECT_TRUE(network_state_.is_captive_portal()); |
| 214 } | 217 } |
| 215 | 218 |
| 219 // Third-party VPN provider. |
| 220 TEST_F(NetworkStateTest, VPNThirdPartyProvider) { |
| 221 EXPECT_TRUE(SetStringProperty(shill::kTypeProperty, shill::kTypeVPN)); |
| 222 EXPECT_TRUE(SetStringProperty(shill::kNameProperty, "VPN")); |
| 223 |
| 224 scoped_ptr<base::DictionaryValue> provider(new base::DictionaryValue); |
| 225 provider->SetStringWithoutPathExpansion(shill::kTypeProperty, |
| 226 shill::kProviderThirdPartyVpn); |
| 227 provider->SetStringWithoutPathExpansion( |
| 228 shill::kHostProperty, "third-party-vpn-provider-extension-id"); |
| 229 EXPECT_TRUE(SetProperty(shill::kProviderProperty, provider.Pass())); |
| 230 SignalInitialPropertiesReceived(); |
| 231 EXPECT_EQ(network_state_.vpn_provider_type(), shill::kProviderThirdPartyVpn); |
| 232 EXPECT_EQ(network_state_.third_party_vpn_provider_extension_id(), |
| 233 "third-party-vpn-provider-extension-id"); |
| 234 } |
| 235 |
| 216 } // namespace chromeos | 236 } // namespace chromeos |
| OLD | NEW |