Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/bind.h" | |
| 7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/values.h" | 9 #include "base/values.h" |
| 9 #include "chromeos/network/onc/onc_constants.h" | 10 #include "chromeos/network/onc/onc_constants.h" |
| 10 #include "chromeos/network/onc/onc_signature.h" | 11 #include "chromeos/network/onc/onc_signature.h" |
| 11 #include "chromeos/network/onc/onc_test_utils.h" | 12 #include "chromeos/network/onc/onc_test_utils.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace chromeos { | 15 namespace chromeos { |
| 15 namespace onc { | 16 namespace onc { |
| 16 | 17 |
| 18 namespace { | |
| 19 | |
|
Mattias Nissler (ping if slow)
2013/06/24 12:45:09
remove :)
pneubeck (no reviews)
2013/06/24 15:35:41
Done.
| |
| 20 } // namespace | |
| 21 | |
| 17 // First parameter: Filename of source ONC. | 22 // First parameter: Filename of source ONC. |
| 18 // Second parameter: Filename of expected translated Shill json. | 23 // Second parameter: Filename of expected translated Shill json. |
| 19 class ONCTranslatorOncToShillTest | 24 class ONCTranslatorOncToShillTest |
| 20 : public ::testing::TestWithParam<std::pair<std::string, std::string> > { | 25 : public ::testing::TestWithParam<std::pair<std::string, std::string> > { |
| 21 }; | 26 }; |
| 22 | 27 |
| 23 // Test the translation from ONC to Shill json. | 28 // Test the translation from ONC to Shill json. |
| 24 TEST_P(ONCTranslatorOncToShillTest, Translate) { | 29 TEST_P(ONCTranslatorOncToShillTest, Translate) { |
| 25 std::string source_onc_filename = GetParam().first; | 30 std::string source_onc_filename = GetParam().first; |
| 26 scoped_ptr<const base::DictionaryValue> onc_network( | 31 scoped_ptr<const base::DictionaryValue> onc_network( |
| 27 test_utils::ReadTestDictionary(source_onc_filename)); | 32 test_utils::ReadTestDictionary(source_onc_filename)); |
| 28 std::string result_shill_filename = GetParam().second; | 33 std::string result_shill_filename = GetParam().second; |
| 29 scoped_ptr<const base::DictionaryValue> expected_shill_network( | 34 scoped_ptr<const base::DictionaryValue> expected_shill_network( |
| 30 test_utils::ReadTestDictionary(result_shill_filename)); | 35 test_utils::ReadTestDictionary(result_shill_filename)); |
| 31 | 36 |
| 32 scoped_ptr<base::DictionaryValue> translation(TranslateONCObjectToShill( | 37 scoped_ptr<base::DictionaryValue> translation(TranslateONCObjectToShill( |
| 33 &kNetworkConfigurationSignature, *onc_network)); | 38 &kNetworkConfigurationSignature, *onc_network, |
| 39 base::Bind(&test_utils::FakeFingerprintToPEM))); | |
| 34 | 40 |
| 35 EXPECT_TRUE(test_utils::Equals(expected_shill_network.get(), | 41 EXPECT_TRUE(test_utils::Equals(expected_shill_network.get(), |
| 36 translation.get())); | 42 translation.get())); |
| 37 } | 43 } |
| 38 | 44 |
| 39 // Test different network types, such that each ONC object type is tested at | 45 // Test different network types, such that each ONC object type is tested at |
| 40 // least once. | 46 // least once. |
| 41 INSTANTIATE_TEST_CASE_P( | 47 INSTANTIATE_TEST_CASE_P( |
| 42 ONCTranslatorOncToShillTest, | 48 ONCTranslatorOncToShillTest, |
| 43 ONCTranslatorOncToShillTest, | 49 ONCTranslatorOncToShillTest, |
| 44 ::testing::Values( | 50 ::testing::Values( |
| 45 std::make_pair("managed_ethernet.onc", "shill_ethernet.json"), | 51 std::make_pair("managed_ethernet.onc", "shill_ethernet.json"), |
| 46 std::make_pair("valid_wifi_psk.onc", "shill_wifi_psk.json"), | 52 std::make_pair("valid_wifi_psk.onc", "shill_wifi_psk.json"), |
| 47 std::make_pair("valid_wifi_clientcert.onc", | 53 std::make_pair("valid_wifi_clientcert.onc", |
| 48 "shill_wifi_clientcert.json"), | 54 "shill_wifi_clientcert.json"), |
| 49 std::make_pair("valid_wifi_clientref.onc", | 55 std::make_pair("valid_wifi_clientref.onc", |
| 50 "shill_wifi_clientref.json"), | 56 "shill_wifi_clientref.json"), |
| 51 std::make_pair("valid_l2tpipsec.onc", "shill_l2tpipsec.json"), | 57 std::make_pair("valid_l2tpipsec.onc", "shill_l2tpipsec.json"), |
| 52 std::make_pair("valid_l2tpipsec_clientcert.onc", | 58 std::make_pair("valid_l2tpipsec_clientcert.onc", |
| 53 "shill_l2tpipsec_clientcert.json"), | 59 "shill_l2tpipsec_clientcert.json"), |
| 54 std::make_pair("valid_openvpn.onc", "shill_openvpn.json"), | 60 std::make_pair("valid_openvpn_with_cert_fingerprints.onc", |
| 61 "shill_openvpn.json"), | |
| 55 std::make_pair("valid_openvpn_clientcert.onc", | 62 std::make_pair("valid_openvpn_clientcert.onc", |
| 56 "shill_openvpn_clientcert.json"))); | 63 "shill_openvpn_clientcert.json"))); |
| 57 | 64 |
| 58 // First parameter: Filename of source Shill json. | 65 // First parameter: Filename of source Shill json. |
| 59 // Second parameter: Filename of expected translated ONC network part. | 66 // Second parameter: Filename of expected translated ONC network part. |
| 60 // | 67 // |
| 61 // Note: This translation direction doesn't have to reconstruct all of the ONC | 68 // Note: This translation direction doesn't have to reconstruct all of the ONC |
| 62 // fields, as Chrome doesn't need all of a Service's properties. | 69 // fields, as Chrome doesn't need all of a Service's properties. |
| 63 class ONCTranslatorShillToOncTest | 70 class ONCTranslatorShillToOncTest |
| 64 : public ::testing::TestWithParam<std::pair<std::string, std::string> > { | 71 : public ::testing::TestWithParam<std::pair<std::string, std::string> > { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 80 translation.get())); | 87 translation.get())); |
| 81 } | 88 } |
| 82 | 89 |
| 83 INSTANTIATE_TEST_CASE_P( | 90 INSTANTIATE_TEST_CASE_P( |
| 84 ONCTranslatorShillToOncTest, | 91 ONCTranslatorShillToOncTest, |
| 85 ONCTranslatorShillToOncTest, | 92 ONCTranslatorShillToOncTest, |
| 86 ::testing::Values( | 93 ::testing::Values( |
| 87 std::make_pair("shill_l2tpipsec.json", | 94 std::make_pair("shill_l2tpipsec.json", |
| 88 "translation_of_shill_l2tpipsec.onc"), | 95 "translation_of_shill_l2tpipsec.onc"), |
| 89 std::make_pair("shill_openvpn.json", | 96 std::make_pair("shill_openvpn.json", |
| 90 "valid_openvpn.onc"), | 97 "translation_of_shill_openvpn.onc"), |
| 91 std::make_pair("shill_openvpn_with_errors.json", | 98 std::make_pair("shill_openvpn_with_errors.json", |
| 92 "translation_of_shill_openvpn_with_errors.onc"), | 99 "translation_of_shill_openvpn_with_errors.onc"), |
| 93 std::make_pair("shill_wifi_with_state.json", | 100 std::make_pair("shill_wifi_with_state.json", |
| 94 "translation_of_shill_wifi_with_state.onc"))); | 101 "translation_of_shill_wifi_with_state.onc"))); |
| 95 | 102 |
| 96 } // namespace onc | 103 } // namespace onc |
| 97 } // namespace chromeos | 104 } // namespace chromeos |
| OLD | NEW |