Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Side by Side Diff: chromeos/network/onc/onc_translator_unittest.cc

Issue 12390017: Separating ONC<->Shill translation from the ONC signature. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed browser tests. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/onc/onc_translator.h" 5 #include "chromeos/network/onc/onc_translator.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chromeos/network/onc/onc_constants.h" 9 #include "chromeos/network/onc/onc_constants.h"
10 #include "chromeos/network/onc/onc_signature.h" 10 #include "chromeos/network/onc/onc_signature.h"
11 #include "chromeos/network/onc/onc_test_utils.h" 11 #include "chromeos/network/onc/onc_test_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace chromeos { 14 namespace chromeos {
15 namespace onc { 15 namespace onc {
16 16
17 // First parameter: Filename of source ONC. 17 // First parameter: Filename of source ONC.
18 // Second parameter: Filename of expected translated Shill json. 18 // Second parameter: Filename of expected translated Shill json.
19 class ONCTranslatorOncToShillTest 19 class ONCTranslatorOncToShillTest
20 : public ::testing::TestWithParam<std::pair<std::string, std::string> > { 20 : public ::testing::TestWithParam<std::pair<std::string, std::string> > {
21 }; 21 };
22 22
23 // Test the translation from ONC to Shill json. 23 // Test the translation from ONC to Shill json.
24 TEST_P(ONCTranslatorOncToShillTest, Translate) { 24 TEST_P(ONCTranslatorOncToShillTest, Translate) {
25 std::string source_onc_filename = GetParam().first; 25 std::string source_onc_filename = GetParam().first;
26 scoped_ptr<const base::DictionaryValue> onc_network( 26 scoped_ptr<const base::DictionaryValue> onc_network(
27 test_utils::ReadTestDictionary(source_onc_filename)); 27 test_utils::ReadTestDictionary(source_onc_filename));
28 std::string result_json_filename = GetParam().second; 28 std::string result_shill_filename = GetParam().second;
29 scoped_ptr<const base::DictionaryValue> shill_network( 29 scoped_ptr<const base::DictionaryValue> expected_shill_network(
30 test_utils::ReadTestDictionary(result_json_filename)); 30 test_utils::ReadTestDictionary(result_shill_filename));
31 31
32 scoped_ptr<base::DictionaryValue> translation(TranslateONCObjectToShill( 32 scoped_ptr<base::DictionaryValue> translation(TranslateONCObjectToShill(
33 &kNetworkConfigurationSignature, *onc_network)); 33 &kNetworkConfigurationSignature, *onc_network));
34 34
35 EXPECT_TRUE(test_utils::Equals(shill_network.get(), translation.get())); 35 EXPECT_TRUE(test_utils::Equals(expected_shill_network.get(),
36 translation.get()));
36 } 37 }
37 38
38 // Test different network types, such that each ONC object type is tested at 39 // Test different network types, such that each ONC object type is tested at
39 // least once. 40 // least once.
40 INSTANTIATE_TEST_CASE_P( 41 INSTANTIATE_TEST_CASE_P(
41 ONCTranslatorOncToShillTest, 42 ONCTranslatorOncToShillTest,
42 ONCTranslatorOncToShillTest, 43 ONCTranslatorOncToShillTest,
43 ::testing::Values( 44 ::testing::Values(
44 std::make_pair("managed_ethernet.onc", "shill_ethernet.json"), 45 std::make_pair("managed_ethernet.onc", "shill_ethernet.json"),
45 std::make_pair("valid_wifi_psk.onc", "shill_wifi_psk.json"), 46 std::make_pair("valid_wifi_psk.onc", "shill_wifi_psk.json"),
46 std::make_pair("valid_wifi_clientcert.onc", 47 std::make_pair("valid_wifi_clientcert.onc",
47 "shill_wifi_clientcert.json"), 48 "shill_wifi_clientcert.json"),
48 std::make_pair("valid_wifi_clientref.onc", 49 std::make_pair("valid_wifi_clientref.onc",
49 "shill_wifi_clientref.json"), 50 "shill_wifi_clientref.json"),
50 std::make_pair("valid_l2tpipsec.onc", "shill_l2tpipsec.json"), 51 std::make_pair("valid_l2tpipsec.onc", "shill_l2tpipsec.json"),
51 std::make_pair("valid_l2tpipsec_clientcert.onc", 52 std::make_pair("valid_l2tpipsec_clientcert.onc",
52 "shill_l2tpipsec_clientcert.json"), 53 "shill_l2tpipsec_clientcert.json"),
53 std::make_pair("valid_openvpn.onc", "shill_openvpn.json"), 54 std::make_pair("valid_openvpn.onc", "shill_openvpn.json"),
54 std::make_pair("valid_openvpn_clientcert.onc", 55 std::make_pair("valid_openvpn_clientcert.onc",
55 "shill_openvpn_clientcert.json"))); 56 "shill_openvpn_clientcert.json")));
56 57
57 // Test the translation from Shill json to ONC. 58 // First parameter: Filename of source Shill json.
59 // Second parameter: Filename of expected translated ONC network part.
58 // 60 //
59 // Note: This translation direction doesn't have to reconstruct all of the ONC 61 // Note: This translation direction doesn't have to reconstruct all of the ONC
60 // fields, as Chrome doesn't need all of a Service's properties. 62 // fields, as Chrome doesn't need all of a Service's properties.
61 TEST(ONCTranslatorShillToOncTest, L2TPIPsec) { 63 class ONCTranslatorShillToOncTest
62 scoped_ptr<base::DictionaryValue> onc_network( 64 : public ::testing::TestWithParam<std::pair<std::string, std::string> > {
63 test_utils::ReadTestDictionary("valid_l2tpipsec.onc")); 65 };
64 66
65 // These two fields are part of the ONC (and are required). However, they 67 TEST_P(ONCTranslatorShillToOncTest, Translate) {
66 // don't exist explicitly in the Shill dictionary. As there is no use-case 68 std::string source_shill_filename = GetParam().first;
67 // yet, that requires to reconstruct these fields from a Shill dictionary, we 69 scoped_ptr<const base::DictionaryValue> shill_network(
68 // don't require their translation. 70 test_utils::ReadTestDictionary(source_shill_filename));
69 onc_network->Remove("VPN.IPsec.AuthenticationType", NULL);
70 onc_network->Remove("VPN.IPsec.IKEVersion", NULL);
71 71
72 scoped_ptr<const base::DictionaryValue> shill_network( 72 std::string result_onc_filename = GetParam().second;
73 test_utils::ReadTestDictionary("shill_l2tpipsec.json")); 73 scoped_ptr<base::DictionaryValue> expected_onc_network(
74 test_utils::ReadTestDictionary(result_onc_filename));
74 75
75 scoped_ptr<base::DictionaryValue> translation(TranslateShillServiceToONCPart( 76 scoped_ptr<base::DictionaryValue> translation(TranslateShillServiceToONCPart(
76 *shill_network, &kNetworkConfigurationSignature)); 77 *shill_network, &kNetworkWithStateSignature));
77 78
78 EXPECT_TRUE(test_utils::Equals(onc_network.get(), translation.get())); 79 EXPECT_TRUE(test_utils::Equals(expected_onc_network.get(),
80 translation.get()));
79 } 81 }
80 82
81 TEST(ONCTranslatorShillToOncTest, OpenVPN) { 83 INSTANTIATE_TEST_CASE_P(
82 scoped_ptr<const base::DictionaryValue> onc_network( 84 ONCTranslatorShillToOncTest,
83 test_utils::ReadTestDictionary("valid_openvpn.onc")); 85 ONCTranslatorShillToOncTest,
84 86 ::testing::Values(
85 scoped_ptr<const base::DictionaryValue> shill_network( 87 std::make_pair("shill_l2tpipsec.json",
86 test_utils::ReadTestDictionary("shill_openvpn.json")); 88 "translation_of_shill_l2tpipsec.onc"),
87 89 std::make_pair("shill_openvpn.json",
88 scoped_ptr<base::DictionaryValue> translation(TranslateShillServiceToONCPart( 90 "valid_openvpn.onc"),
89 *shill_network, &kNetworkConfigurationSignature)); 91 std::make_pair("shill_openvpn_with_errors.json",
90 92 "translation_of_shill_openvpn_with_errors.onc"),
91 EXPECT_TRUE(test_utils::Equals(onc_network.get(), translation.get())); 93 std::make_pair("shill_wifi_with_state.json",
92 } 94 "translation_of_shill_wifi_with_state.onc")));
93
94 TEST(ONCTranslatorShillToOncTest, OpenVPN_with_errors) {
95 scoped_ptr<const base::DictionaryValue> onc_network(
96 test_utils::ReadTestDictionary(
97 "translation_of_shill_openvpn_with_errors.onc"));
98
99 scoped_ptr<const base::DictionaryValue> shill_network(
100 test_utils::ReadTestDictionary("shill_openvpn_with_errors.json"));
101
102 scoped_ptr<base::DictionaryValue> translation(TranslateShillServiceToONCPart(
103 *shill_network, &kNetworkConfigurationSignature));
104
105 EXPECT_TRUE(test_utils::Equals(onc_network.get(), translation.get()));
106 }
107 95
108 } // namespace onc 96 } // namespace onc
109 } // namespace chromeos 97 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_translator_shill_to_onc.cc ('k') | chromeos/network/onc/onc_validator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698