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

Side by Side Diff: chrome/browser/chromeos/network_settings/onc_translator_unittest.cc

Issue 11299236: This moves the ONC parsing code into chromeos/network/onc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit tests Created 8 years 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
(Empty)
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.
4
5 #include "chrome/browser/chromeos/network_settings/onc_translator.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h"
9 #include "chrome/browser/chromeos/cros/onc_constants.h"
10 #include "chrome/browser/chromeos/network_settings/onc_signature.h"
11 #include "chrome/browser/chromeos/network_settings/onc_test_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace chromeos {
15 namespace onc {
16
17 // First parameter: Filename of source ONC.
18 // Second parameter: Filename of expected translated Shill json.
19 class ONCTranslatorOncToShillTest
20 : public ::testing::TestWithParam<std::pair<std::string, std::string> > {
21 };
22
23 // Test the translation from ONC to Shill json.
24 TEST_P(ONCTranslatorOncToShillTest, Translate) {
25 std::string source_onc_filename = GetParam().first;
26 scoped_ptr<const base::DictionaryValue> onc_network(
27 test_utils::ReadTestDictionary(source_onc_filename));
28 std::string result_json_filename = GetParam().second;
29 scoped_ptr<const base::DictionaryValue> shill_network(
30 test_utils::ReadTestDictionary(result_json_filename));
31
32 scoped_ptr<base::DictionaryValue> translation(TranslateONCObjectToShill(
33 &kNetworkConfigurationSignature, *onc_network));
34
35 EXPECT_TRUE(test_utils::Equals(shill_network.get(), translation.get()));
36 }
37
38 // Test different network types, such that each ONC object type is tested at
39 // least once.
40 INSTANTIATE_TEST_CASE_P(
41 ONCTranslatorOncToShillTest,
42 ONCTranslatorOncToShillTest,
43 ::testing::Values(
44 std::make_pair("valid.onc", "shill_ethernet.json"),
45 std::make_pair("valid_l2tpipsec.onc", "shill_l2tpipsec.json"),
46 std::make_pair("valid_openvpn.onc", "shill_openvpn.json")));
47
48 // Test the translation from Shill json to ONC.
49 //
50 // Note: This translation direction doesn't have to reconstruct all of the ONC
51 // fields, as Chrome doesn't need all of a Service's properties.
52 TEST(ONCTranslatorShillToOncTest, L2TPIPsec) {
53 scoped_ptr<base::DictionaryValue> onc_network(
54 test_utils::ReadTestDictionary("valid_l2tpipsec.onc"));
55
56 // These two fields are part of the ONC (and are required). However, they
57 // don't exist explicitly in the Shill dictionary. As there is no use-case
58 // yet, that requires to reconstruct these fields from a Shill dictionary, we
59 // don't require their translation.
60 onc_network->Remove("VPN.IPsec.AuthenticationType", NULL);
61 onc_network->Remove("VPN.IPsec.IKEVersion", NULL);
62
63 scoped_ptr<const base::DictionaryValue> shill_network(
64 test_utils::ReadTestDictionary("shill_l2tpipsec.json"));
65
66 scoped_ptr<base::DictionaryValue> translation(TranslateShillServiceToONCPart(
67 *shill_network, &kNetworkConfigurationSignature));
68
69 EXPECT_TRUE(test_utils::Equals(onc_network.get(), translation.get()));
70 }
71
72 TEST(ONCTranslatorShillToOncTest, OpenVPN) {
73 scoped_ptr<const base::DictionaryValue> onc_network(
74 test_utils::ReadTestDictionary("valid_openvpn.onc"));
75
76 scoped_ptr<const base::DictionaryValue> shill_network(
77 test_utils::ReadTestDictionary("shill_openvpn.json"));
78
79 scoped_ptr<base::DictionaryValue> translation(TranslateShillServiceToONCPart(
80 *shill_network, &kNetworkConfigurationSignature));
81
82 EXPECT_TRUE(test_utils::Equals(onc_network.get(), translation.get()));
83 }
84
85 } // namespace onc
86 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698