Commit b9d88681 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

network-config.mojom: Use real types for read-only properties

Bug: 853953
Change-Id: If221bdeaa048f3d94cc375f87f81af2f10e2b5f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1697430
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682294}
parent 8522e889
...@@ -108,16 +108,16 @@ mojom::ConnectionStateType GetConnectionState(const NetworkState* network, ...@@ -108,16 +108,16 @@ mojom::ConnectionStateType GetConnectionState(const NetworkState* network,
: mojom::ConnectionStateType::kNotConnected; : mojom::ConnectionStateType::kNotConnected;
} }
mojom::VPNType ShillVpnTypeToMojo(const std::string& shill_vpn_type) { mojom::VPNType OncVpnTypeToMojo(const std::string& onc_vpn_type) {
if (shill_vpn_type == shill::kProviderL2tpIpsec) if (onc_vpn_type == ::onc::vpn::kTypeL2TP_IPsec)
return mojom::VPNType::kL2TPIPsec; return mojom::VPNType::kL2TPIPsec;
if (shill_vpn_type == shill::kProviderOpenVpn) if (onc_vpn_type == ::onc::vpn::kOpenVPN)
return mojom::VPNType::kOpenVPN; return mojom::VPNType::kOpenVPN;
if (shill_vpn_type == shill::kProviderThirdPartyVpn) if (onc_vpn_type == ::onc::vpn::kThirdPartyVpn)
return mojom::VPNType::kThirdPartyVPN; return mojom::VPNType::kThirdPartyVPN;
if (shill_vpn_type == shill::kProviderArcVpn) if (onc_vpn_type == ::onc::vpn::kArcVpn)
return mojom::VPNType::kArcVPN; return mojom::VPNType::kArcVPN;
NOTREACHED() << "Unsupported shill VPN type: " << shill_vpn_type; NOTREACHED() << "Unsupported ONC VPN type: " << onc_vpn_type;
return mojom::VPNType::kOpenVPN; return mojom::VPNType::kOpenVPN;
} }
...@@ -236,7 +236,8 @@ mojom::NetworkStatePropertiesPtr NetworkStateToMojo(const NetworkState* network, ...@@ -236,7 +236,8 @@ mojom::NetworkStatePropertiesPtr NetworkStateToMojo(const NetworkState* network,
const NetworkState::VpnProviderInfo* vpn_provider = const NetworkState::VpnProviderInfo* vpn_provider =
network->vpn_provider(); network->vpn_provider();
if (vpn_provider) { if (vpn_provider) {
vpn->type = ShillVpnTypeToMojo(vpn_provider->type); vpn->type = OncVpnTypeToMojo(
ShillToOnc(vpn_provider->type, onc::kVPNTypeTable));
vpn->provider_id = vpn_provider->id; vpn->provider_id = vpn_provider->id;
// TODO(stevenjb): Set the provider name in network state. // TODO(stevenjb): Set the provider name in network state.
// vpn->provider_name = vpn_provider->name; // vpn->provider_name = vpn_provider->name;
...@@ -1081,6 +1082,8 @@ mojom::ManagedPropertiesPtr ManagedPropertiesToMojo( ...@@ -1081,6 +1082,8 @@ mojom::ManagedPropertiesPtr ManagedPropertiesToMojo(
switch (type) { switch (type) {
case mojom::NetworkType::kCellular: { case mojom::NetworkType::kCellular: {
auto cellular = mojom::ManagedCellularProperties::New(); auto cellular = mojom::ManagedCellularProperties::New();
cellular->activation_state = network_state->GetMojoActivationState();
const base::Value* cellular_dict = const base::Value* cellular_dict =
GetDictionary(properties, ::onc::network_config::kCellular); GetDictionary(properties, ::onc::network_config::kCellular);
if (!cellular_dict) { if (!cellular_dict) {
...@@ -1093,8 +1096,6 @@ mojom::ManagedPropertiesPtr ManagedPropertiesToMojo( ...@@ -1093,8 +1096,6 @@ mojom::ManagedPropertiesPtr ManagedPropertiesToMojo(
GetManagedApnProperties(cellular_dict, ::onc::cellular::kAPN); GetManagedApnProperties(cellular_dict, ::onc::cellular::kAPN);
cellular->apn_list = cellular->apn_list =
GetManagedApnList(cellular_dict->FindKey(::onc::cellular::kAPNList)); GetManagedApnList(cellular_dict->FindKey(::onc::cellular::kAPNList));
cellular->activation_state =
GetString(cellular_dict, ::onc::cellular::kActivationState);
cellular->allow_roaming = cellular->allow_roaming =
GetBoolean(properties, ::onc::cellular::kAllowRoaming); GetBoolean(properties, ::onc::cellular::kAllowRoaming);
cellular->esn = GetString(cellular_dict, ::onc::cellular::kESN); cellular->esn = GetString(cellular_dict, ::onc::cellular::kESN);
...@@ -1178,13 +1179,17 @@ mojom::ManagedPropertiesPtr ManagedPropertiesToMojo( ...@@ -1178,13 +1179,17 @@ mojom::ManagedPropertiesPtr ManagedPropertiesToMojo(
GetManagedOpenVPNProperties(vpn_dict, ::onc::vpn::kOpenVPN); GetManagedOpenVPNProperties(vpn_dict, ::onc::vpn::kOpenVPN);
vpn->third_party_vpn = GetManagedThirdPartyVPNProperties( vpn->third_party_vpn = GetManagedThirdPartyVPNProperties(
vpn_dict, ::onc::vpn::kThirdPartyVpn); vpn_dict, ::onc::vpn::kThirdPartyVpn);
vpn->type = GetManagedString(vpn_dict, ::onc::vpn::kType); mojom::ManagedStringPtr managed_type =
CHECK(vpn->type); GetManagedString(vpn_dict, ::onc::vpn::kType);
CHECK(managed_type);
vpn->type = OncVpnTypeToMojo(managed_type->active_value);
result->vpn = std::move(vpn); result->vpn = std::move(vpn);
break; break;
} }
case mojom::NetworkType::kWiFi: { case mojom::NetworkType::kWiFi: {
auto wifi = mojom::ManagedWiFiProperties::New(); auto wifi = mojom::ManagedWiFiProperties::New();
wifi->security = network_state->GetMojoSecurity();
const base::Value* wifi_dict = const base::Value* wifi_dict =
GetDictionary(properties, ::onc::network_config::kWiFi); GetDictionary(properties, ::onc::network_config::kWiFi);
if (!wifi_dict) { if (!wifi_dict) {
...@@ -1208,8 +1213,6 @@ mojom::ManagedPropertiesPtr ManagedPropertiesToMojo( ...@@ -1208,8 +1213,6 @@ mojom::ManagedPropertiesPtr ManagedPropertiesToMojo(
GetManagedInt32(wifi_dict, ::onc::wifi::kRoamThreshold); GetManagedInt32(wifi_dict, ::onc::wifi::kRoamThreshold);
wifi->ssid = GetManagedString(wifi_dict, ::onc::wifi::kSSID); wifi->ssid = GetManagedString(wifi_dict, ::onc::wifi::kSSID);
CHECK(wifi->ssid); CHECK(wifi->ssid);
wifi->security = GetManagedString(wifi_dict, ::onc::wifi::kSecurity);
CHECK(wifi->security);
wifi->signal_strength = GetInt32(wifi_dict, ::onc::wifi::kSignalStrength); wifi->signal_strength = GetInt32(wifi_dict, ::onc::wifi::kSignalStrength);
wifi->tethering_state = wifi->tethering_state =
GetString(wifi_dict, ::onc::wifi::kTetheringState); GetString(wifi_dict, ::onc::wifi::kTetheringState);
......
...@@ -82,7 +82,7 @@ class CrosNetworkConfigTest : public testing::Test { ...@@ -82,7 +82,7 @@ class CrosNetworkConfigTest : public testing::Test {
R"({"GUID": "wifi2_guid", "Type": "WiFi", R"({"GUID": "wifi2_guid", "Type": "WiFi",
"Name": "wifi2", "Priority": 0, "Name": "wifi2", "Priority": 0,
"WiFi": { "Passphrase": "fake", "SSID": "%s", "HexSSID": "%s", "WiFi": { "Passphrase": "fake", "SSID": "%s", "HexSSID": "%s",
"Security": "WPA-PSK"}})", "Security": "WPA-PSK", "AutoConnect": true}})",
user_policy_ssid.c_str(), user_policy_ssid.c_str(),
base::HexEncode(user_policy_ssid.c_str(), user_policy_ssid.size()) base::HexEncode(user_policy_ssid.c_str(), user_policy_ssid.size())
.c_str()))); .c_str())));
...@@ -111,11 +111,12 @@ class CrosNetworkConfigTest : public testing::Test { ...@@ -111,11 +111,12 @@ class CrosNetworkConfigTest : public testing::Test {
kCellularDevicePath, shill::kSIMLockStatusProperty, sim_value, kCellularDevicePath, shill::kSIMLockStatusProperty, sim_value,
/*notify_changed=*/false); /*notify_changed=*/false);
// Note: These are Shill dictionaries, not ONC.
helper().ConfigureService( helper().ConfigureService(
R"({"GUID": "eth_guid", "Type": "ethernet", "State": "online"})"); R"({"GUID": "eth_guid", "Type": "ethernet", "State": "online"})");
wifi1_path_ = helper().ConfigureService( wifi1_path_ = helper().ConfigureService(
R"({"GUID": "wifi1_guid", "Type": "wifi", "State": "ready", R"({"GUID": "wifi1_guid", "Type": "wifi", "State": "ready",
"Strength": 50})"); "Strength": 50, "AutoConnect": true})");
helper().ConfigureService( helper().ConfigureService(
R"({"GUID": "wifi2_guid", "Type": "wifi", "SSID": "wifi2", R"({"GUID": "wifi2_guid", "Type": "wifi", "SSID": "wifi2",
"State": "idle", "SecurityClass": "psk", "Strength": 100, "State": "idle", "SecurityClass": "psk", "Strength": 100,
...@@ -431,7 +432,7 @@ TEST_F(CrosNetworkConfigTest, GetManagedProperties) { ...@@ -431,7 +432,7 @@ TEST_F(CrosNetworkConfigTest, GetManagedProperties) {
EXPECT_EQ(mojom::ConnectionStateType::kNotConnected, EXPECT_EQ(mojom::ConnectionStateType::kNotConnected,
properties->connection_state); properties->connection_state);
ASSERT_TRUE(properties->wifi); ASSERT_TRUE(properties->wifi);
EXPECT_EQ(::onc::wifi::kWPA_PSK, properties->wifi->security->active_value); EXPECT_EQ(mojom::SecurityType::kWpaPsk, properties->wifi->security);
EXPECT_EQ(100, properties->wifi->signal_strength); EXPECT_EQ(100, properties->wifi->signal_strength);
properties = GetManagedProperties("cellular_guid"); properties = GetManagedProperties("cellular_guid");
...@@ -443,7 +444,7 @@ TEST_F(CrosNetworkConfigTest, GetManagedProperties) { ...@@ -443,7 +444,7 @@ TEST_F(CrosNetworkConfigTest, GetManagedProperties) {
ASSERT_TRUE(properties->cellular); ASSERT_TRUE(properties->cellular);
EXPECT_EQ(0, properties->cellular->signal_strength); EXPECT_EQ(0, properties->cellular->signal_strength);
EXPECT_EQ("LTE", properties->cellular->network_technology); EXPECT_EQ("LTE", properties->cellular->network_technology);
EXPECT_EQ(::onc::cellular::kActivated, EXPECT_EQ(mojom::ActivationStateType::kActivated,
properties->cellular->activation_state); properties->cellular->activation_state);
properties = GetManagedProperties("vpn_guid"); properties = GetManagedProperties("vpn_guid");
...@@ -453,14 +454,28 @@ TEST_F(CrosNetworkConfigTest, GetManagedProperties) { ...@@ -453,14 +454,28 @@ TEST_F(CrosNetworkConfigTest, GetManagedProperties) {
EXPECT_EQ(mojom::ConnectionStateType::kConnecting, EXPECT_EQ(mojom::ConnectionStateType::kConnecting,
properties->connection_state); properties->connection_state);
ASSERT_TRUE(properties->vpn); ASSERT_TRUE(properties->vpn);
EXPECT_EQ(::onc::vpn::kTypeL2TP_IPsec, properties->vpn->type->active_value); EXPECT_EQ(mojom::VPNType::kL2TPIPsec, properties->vpn->type);
} }
// Test managed property policy values. // Test managed property policy values.
TEST_F(CrosNetworkConfigTest, GetManagedPropertiesPolicy) { TEST_F(CrosNetworkConfigTest, GetManagedPropertiesPolicy) {
mojom::ManagedPropertiesPtr properties = GetManagedProperties("wifi2_guid"); mojom::ManagedPropertiesPtr properties = GetManagedProperties("wifi1_guid");
ASSERT_TRUE(properties);
ASSERT_EQ("wifi1_guid", properties->guid);
ASSERT_TRUE(properties->wifi);
ASSERT_TRUE(properties->wifi->auto_connect);
EXPECT_TRUE(properties->wifi->auto_connect->active_value);
EXPECT_EQ(mojom::PolicySource::kNone,
properties->wifi->auto_connect->policy_source);
properties = GetManagedProperties("wifi2_guid");
ASSERT_TRUE(properties); ASSERT_TRUE(properties);
ASSERT_EQ("wifi2_guid", properties->guid); ASSERT_EQ("wifi2_guid", properties->guid);
ASSERT_TRUE(properties->wifi->auto_connect);
EXPECT_TRUE(properties->wifi->auto_connect->active_value);
EXPECT_EQ(mojom::PolicySource::kUserPolicyEnforced,
properties->wifi->auto_connect->policy_source);
EXPECT_TRUE(properties->wifi->auto_connect->policy_value);
ASSERT_TRUE(properties->name); ASSERT_TRUE(properties->name);
EXPECT_EQ("wifi2", properties->name->active_value); EXPECT_EQ("wifi2", properties->name->active_value);
EXPECT_EQ(mojom::PolicySource::kUserPolicyEnforced, EXPECT_EQ(mojom::PolicySource::kUserPolicyEnforced,
...@@ -471,21 +486,6 @@ TEST_F(CrosNetworkConfigTest, GetManagedPropertiesPolicy) { ...@@ -471,21 +486,6 @@ TEST_F(CrosNetworkConfigTest, GetManagedPropertiesPolicy) {
EXPECT_EQ(mojom::PolicySource::kUserPolicyEnforced, EXPECT_EQ(mojom::PolicySource::kUserPolicyEnforced,
properties->priority->policy_source); properties->priority->policy_source);
EXPECT_EQ(0, properties->priority->policy_value); EXPECT_EQ(0, properties->priority->policy_value);
ASSERT_EQ(mojom::NetworkType::kWiFi, properties->type);
ASSERT_TRUE(properties->wifi);
EXPECT_EQ(::onc::wifi::kWPA_PSK, properties->wifi->security->active_value);
EXPECT_EQ(mojom::PolicySource::kUserPolicyEnforced,
properties->wifi->security->policy_source);
EXPECT_EQ(::onc::wifi::kWPA_PSK, *properties->wifi->security->policy_value);
properties = GetManagedProperties("vpn_guid");
ASSERT_TRUE(properties);
ASSERT_EQ("vpn_guid", properties->guid);
ASSERT_EQ(mojom::NetworkType::kVPN, properties->type);
ASSERT_TRUE(properties->vpn);
EXPECT_EQ(::onc::vpn::kTypeL2TP_IPsec, properties->vpn->type->active_value);
EXPECT_EQ(mojom::PolicySource::kNone, properties->vpn->type->policy_source);
} }
TEST_F(CrosNetworkConfigTest, SetNetworkTypeEnabledState) { TEST_F(CrosNetworkConfigTest, SetNetworkTypeEnabledState) {
......
...@@ -510,7 +510,7 @@ struct ManagedCellularProperties { ...@@ -510,7 +510,7 @@ struct ManagedCellularProperties {
ManagedBoolean? auto_connect; ManagedBoolean? auto_connect;
ManagedApnProperties? apn; ManagedApnProperties? apn;
ManagedApnList? apn_list; ManagedApnList? apn_list;
string? activation_state; ActivationStateType activation_state;
bool allow_roaming = false; bool allow_roaming = false;
string? esn; string? esn;
string? family; string? family;
...@@ -547,7 +547,7 @@ struct ManagedVPNProperties { ...@@ -547,7 +547,7 @@ struct ManagedVPNProperties {
ManagedL2TPProperties? l2tp; ManagedL2TPProperties? l2tp;
ManagedOpenVPNProperties? open_vpn; ManagedOpenVPNProperties? open_vpn;
ManagedThirdPartyVPNProperties? third_party_vpn; ManagedThirdPartyVPNProperties? third_party_vpn;
ManagedString type; VPNType type;
}; };
struct ManagedWiFiProperties { struct ManagedWiFiProperties {
...@@ -562,7 +562,7 @@ struct ManagedWiFiProperties { ...@@ -562,7 +562,7 @@ struct ManagedWiFiProperties {
ManagedBoolean? hidden_ssid; ManagedBoolean? hidden_ssid;
ManagedInt32? roam_threshold; ManagedInt32? roam_threshold;
ManagedString ssid; ManagedString ssid;
ManagedString security; SecurityType security;
int32 signal_strength = 0; int32 signal_strength = 0;
string? tethering_state; string? tethering_state;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment