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
3 // found in the LICENSE file.
5 #include "chromeos/network/onc/onc_translator.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/values.h"
12 #include "chromeos/network/onc/onc_signature.h"
13 #include "chromeos/network/onc/onc_test_utils.h"
14 #include "components/onc/onc_constants.h"
15 #include "testing/gtest/include/gtest/gtest.h"
20 // First parameter: Filename of source ONC.
21 // Second parameter: Filename of expected translated Shill json.
22 class ONCTranslatorOncToShillTest
23 : public ::testing::TestWithParam
<std::pair
<std::string
, std::string
> > {
26 // Test the translation from ONC to Shill json.
27 TEST_P(ONCTranslatorOncToShillTest
, Translate
) {
28 std::string source_onc_filename
= GetParam().first
;
29 scoped_ptr
<const base::DictionaryValue
> onc_network(
30 test_utils::ReadTestDictionary(source_onc_filename
));
31 std::string result_shill_filename
= GetParam().second
;
32 scoped_ptr
<const base::DictionaryValue
> expected_shill_network(
33 test_utils::ReadTestDictionary(result_shill_filename
));
35 scoped_ptr
<base::DictionaryValue
> translation(TranslateONCObjectToShill(
36 &kNetworkConfigurationSignature
, *onc_network
));
38 EXPECT_TRUE(test_utils::Equals(expected_shill_network
.get(),
42 // Test different network types, such that each ONC object type is tested at
44 INSTANTIATE_TEST_CASE_P(
45 ONCTranslatorOncToShillTest
,
46 ONCTranslatorOncToShillTest
,
48 std::make_pair("ethernet.onc", "shill_ethernet.json"),
49 std::make_pair("ethernet_with_eap_and_cert_pems.onc",
50 "shill_ethernet_with_eap.json"),
51 std::make_pair("valid_wifi_psk.onc", "shill_wifi_psk.json"),
52 std::make_pair("wifi_clientcert_with_cert_pems.onc",
53 "shill_wifi_clientcert.json"),
54 std::make_pair("valid_wifi_clientref.onc", "shill_wifi_clientref.json"),
55 std::make_pair("valid_l2tpipsec.onc", "shill_l2tpipsec.json"),
56 std::make_pair("wifi_dhcp.onc", "shill_wifi_dhcp.json"),
57 std::make_pair("l2tpipsec_clientcert_with_cert_pems.onc",
58 "shill_l2tpipsec_clientcert.json"),
59 std::make_pair("valid_openvpn_with_cert_pems.onc",
60 "shill_openvpn.json"),
61 std::make_pair("openvpn_clientcert_with_cert_pems.onc",
62 "shill_openvpn_clientcert.json"),
63 std::make_pair("cellular.onc", "shill_cellular.json"),
64 std::make_pair("wimax.onc", "shill_wimax.json"),
65 std::make_pair("third_party_vpn.onc", "shill_third_party_vpn.json")));
67 // First parameter: Filename of source Shill json.
68 // Second parameter: Filename of expected translated ONC network part.
70 // Note: This translation direction doesn't have to reconstruct all of the ONC
71 // fields, as Chrome doesn't need all of a Service's properties.
72 class ONCTranslatorShillToOncTest
73 : public ::testing::TestWithParam
<std::pair
<std::string
, std::string
> > {
76 TEST_P(ONCTranslatorShillToOncTest
, Translate
) {
77 std::string source_shill_filename
= GetParam().first
;
78 scoped_ptr
<const base::DictionaryValue
> shill_network(
79 test_utils::ReadTestDictionary(source_shill_filename
));
81 std::string result_onc_filename
= GetParam().second
;
82 scoped_ptr
<base::DictionaryValue
> expected_onc_network(
83 test_utils::ReadTestDictionary(result_onc_filename
));
85 scoped_ptr
<base::DictionaryValue
> translation(TranslateShillServiceToONCPart(
86 *shill_network
, ::onc::ONC_SOURCE_NONE
, &kNetworkWithStateSignature
));
88 EXPECT_TRUE(test_utils::Equals(expected_onc_network
.get(),
92 INSTANTIATE_TEST_CASE_P(
93 ONCTranslatorShillToOncTest
,
94 ONCTranslatorShillToOncTest
,
96 std::make_pair("shill_ethernet.json",
97 "translation_of_shill_ethernet.onc"),
98 std::make_pair("shill_ethernet_with_eap.json",
99 "translation_of_shill_ethernet_with_eap.onc"),
100 std::make_pair("shill_ethernet_with_ipconfig.json",
101 "translation_of_shill_ethernet_with_ipconfig.onc"),
102 std::make_pair("shill_wifi_clientcert.json",
103 "translation_of_shill_wifi_clientcert.onc"),
104 std::make_pair("shill_wifi_non_utf8_ssid.json",
105 "translation_of_shill_wifi_non_utf8_ssid.onc"),
106 std::make_pair("shill_output_l2tpipsec.json",
107 "translation_of_shill_l2tpipsec.onc"),
108 std::make_pair("shill_output_openvpn.json",
109 "translation_of_shill_openvpn.onc"),
110 std::make_pair("shill_output_openvpn_with_errors.json",
111 "translation_of_shill_openvpn_with_errors.onc"),
112 std::make_pair("shill_wifi_with_state.json",
113 "translation_of_shill_wifi_with_state.onc"),
114 std::make_pair("shill_cellular_with_state.json",
115 "translation_of_shill_cellular_with_state.onc"),
116 std::make_pair("shill_wimax_with_state.json",
117 "translation_of_shill_wimax_with_state.onc"),
118 std::make_pair("shill_output_third_party_vpn.json",
119 "third_party_vpn.onc")));
122 } // namespace chromeos