Service workers: Allow HTTPS pages arrived at via HTTP redirect to use SW
[chromium-blink-merge.git] / chromeos / network / onc / onc_translator_unittest.cc
blob72ceae167c37992ccd0c341f2503ea9b2189a770
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"
7 #include <string>
8 #include <utility>
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"
17 namespace chromeos {
18 namespace onc {
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(),
39 translation.get()));
42 // Test different network types, such that each ONC object type is tested at
43 // least once.
44 INSTANTIATE_TEST_CASE_P(
45 ONCTranslatorOncToShillTest,
46 ONCTranslatorOncToShillTest,
47 ::testing::Values(
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("wifi_proxy.onc", "shill_wifi_proxy.json"),
58 std::make_pair("wifi_proxy_pac.onc", "shill_wifi_proxy_pac.json"),
59 std::make_pair("l2tpipsec_clientcert_with_cert_pems.onc",
60 "shill_l2tpipsec_clientcert.json"),
61 std::make_pair("valid_openvpn_with_cert_pems.onc",
62 "shill_openvpn.json"),
63 std::make_pair("openvpn_clientcert_with_cert_pems.onc",
64 "shill_openvpn_clientcert.json"),
65 std::make_pair("cellular.onc", "shill_cellular.json"),
66 std::make_pair("wimax.onc", "shill_wimax.json"),
67 std::make_pair("third_party_vpn.onc", "shill_third_party_vpn.json")));
69 // First parameter: Filename of source Shill json.
70 // Second parameter: Filename of expected translated ONC network part.
72 // Note: This translation direction doesn't have to reconstruct all of the ONC
73 // fields, as Chrome doesn't need all of a Service's properties.
74 class ONCTranslatorShillToOncTest
75 : public ::testing::TestWithParam<std::pair<std::string, std::string> > {
78 TEST_P(ONCTranslatorShillToOncTest, Translate) {
79 std::string source_shill_filename = GetParam().first;
80 scoped_ptr<const base::DictionaryValue> shill_network(
81 test_utils::ReadTestDictionary(source_shill_filename));
83 std::string result_onc_filename = GetParam().second;
84 scoped_ptr<base::DictionaryValue> expected_onc_network(
85 test_utils::ReadTestDictionary(result_onc_filename));
87 scoped_ptr<base::DictionaryValue> translation(TranslateShillServiceToONCPart(
88 *shill_network, ::onc::ONC_SOURCE_NONE, &kNetworkWithStateSignature,
89 nullptr /* network_state */));
91 EXPECT_TRUE(test_utils::Equals(expected_onc_network.get(),
92 translation.get()));
95 INSTANTIATE_TEST_CASE_P(
96 ONCTranslatorShillToOncTest,
97 ONCTranslatorShillToOncTest,
98 ::testing::Values(
99 std::make_pair("shill_ethernet.json",
100 "translation_of_shill_ethernet.onc"),
101 std::make_pair("shill_ethernet_with_eap.json",
102 "translation_of_shill_ethernet_with_eap.onc"),
103 std::make_pair("shill_ethernet_with_ipconfig.json",
104 "translation_of_shill_ethernet_with_ipconfig.onc"),
105 std::make_pair("shill_wifi_clientcert.json",
106 "translation_of_shill_wifi_clientcert.onc"),
107 std::make_pair("shill_wifi_non_utf8_ssid.json",
108 "translation_of_shill_wifi_non_utf8_ssid.onc"),
109 std::make_pair("shill_output_l2tpipsec.json",
110 "translation_of_shill_l2tpipsec.onc"),
111 std::make_pair("shill_output_openvpn.json",
112 "translation_of_shill_openvpn.onc"),
113 std::make_pair("shill_output_openvpn_with_errors.json",
114 "translation_of_shill_openvpn_with_errors.onc"),
115 std::make_pair("shill_wifi_with_state.json",
116 "translation_of_shill_wifi_with_state.onc"),
117 std::make_pair("shill_wifi_proxy.json",
118 "translation_of_shill_wifi_proxy.onc"),
119 std::make_pair("shill_wifi_proxy_pac.json",
120 "translation_of_shill_wifi_proxy_pac.onc"),
121 std::make_pair("shill_cellular_with_state.json",
122 "translation_of_shill_cellular_with_state.onc"),
123 std::make_pair("shill_wimax_with_state.json",
124 "translation_of_shill_wimax_with_state.onc"),
125 std::make_pair("shill_output_third_party_vpn.json",
126 "third_party_vpn.onc")));
128 } // namespace onc
129 } // namespace chromeos