Don't kill key events even when it's VKEY_UNKNOWN.
[chromium-blink-merge.git] / chromeos / network / network_ui_data_unittest.cc
blobff07b0c5867101af04a10262888eee14cbb3b937
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/network_ui_data.h"
7 #include "base/values.h"
8 #include "chromeos/network/onc/onc_test_utils.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace chromeos {
13 TEST(NetworkUIDataTest, ONCSource) {
14 base::DictionaryValue ui_data_dict;
16 ui_data_dict.SetString(NetworkUIData::kKeyONCSource, "user_import");
18 NetworkUIData ui_data(ui_data_dict);
19 EXPECT_EQ(::onc::ONC_SOURCE_USER_IMPORT, ui_data.onc_source());
20 EXPECT_FALSE(ui_data.is_managed());
23 ui_data_dict.SetString(NetworkUIData::kKeyONCSource, "device_policy");
25 NetworkUIData ui_data(ui_data_dict);
26 EXPECT_EQ(::onc::ONC_SOURCE_DEVICE_POLICY, ui_data.onc_source());
27 EXPECT_TRUE(ui_data.is_managed());
29 ui_data_dict.SetString(NetworkUIData::kKeyONCSource, "user_policy");
31 NetworkUIData ui_data(ui_data_dict);
32 EXPECT_EQ(::onc::ONC_SOURCE_USER_POLICY, ui_data.onc_source());
33 EXPECT_TRUE(ui_data.is_managed());
37 TEST(NetworkUIDataTest, CertificateType) {
39 base::DictionaryValue ui_data_dict;
40 ui_data_dict.SetString(NetworkUIData::kKeyCertificateType, "none");
41 NetworkUIData ui_data(ui_data_dict);
42 EXPECT_EQ(CLIENT_CERT_TYPE_NONE, ui_data.certificate_type());
45 base::DictionaryValue ui_data_dict;
46 ui_data_dict.SetString(NetworkUIData::kKeyCertificateType, "ref");
47 NetworkUIData ui_data(ui_data_dict);
48 EXPECT_EQ(CLIENT_CERT_TYPE_REF, ui_data.certificate_type());
51 // for type pattern we need to have some kind of pattern
52 std::string organization("Little If Any, Inc.");
53 base::DictionaryValue ui_data_dict;
54 base::DictionaryValue* pattern_dict = new base::DictionaryValue;
55 base::DictionaryValue* issuer_dict = new base::DictionaryValue;
56 issuer_dict->SetString("Organization", organization);
57 pattern_dict->Set("Issuer", issuer_dict);
58 ui_data_dict.Set("certificate_pattern", pattern_dict);
59 ui_data_dict.SetString(NetworkUIData::kKeyCertificateType, "pattern");
60 NetworkUIData ui_data(ui_data_dict);
61 EXPECT_EQ(CLIENT_CERT_TYPE_PATTERN, ui_data.certificate_type());
65 TEST(NetworkUIDataTest, CertificatePattern) {
66 std::string organization("Little If Any, Inc.");
67 base::DictionaryValue ui_data_dict;
68 base::DictionaryValue* pattern_dict = new base::DictionaryValue;
69 base::DictionaryValue* issuer_dict = new base::DictionaryValue;
70 issuer_dict->SetString("Organization", organization);
71 pattern_dict->Set("Issuer", issuer_dict);
72 ui_data_dict.SetString("certificate_type", "pattern");
73 ui_data_dict.Set("certificate_pattern", pattern_dict);
74 NetworkUIData ui_data(ui_data_dict);
75 EXPECT_FALSE(ui_data.certificate_pattern().Empty());
76 EXPECT_EQ(organization,
77 ui_data.certificate_pattern().issuer().organization());
80 class CreateUIDataTest
81 : public ::testing::TestWithParam<std::pair<std::string, std::string> > {
84 TEST_P(CreateUIDataTest, CreateUIDataFromONC) {
85 namespace test_utils = onc::test_utils;
86 scoped_ptr<base::DictionaryValue> onc_network =
87 test_utils::ReadTestDictionary(GetParam().first);
89 scoped_ptr<base::DictionaryValue> expected_uidata =
90 test_utils::ReadTestDictionary(GetParam().second);
92 scoped_ptr<NetworkUIData> actual_uidata =
93 NetworkUIData::CreateFromONC(
94 ::onc::ONC_SOURCE_USER_POLICY, *onc_network);
95 EXPECT_TRUE(actual_uidata != NULL);
97 base::DictionaryValue actual_uidata_dict;
98 actual_uidata->FillDictionary(&actual_uidata_dict);
99 EXPECT_TRUE(test_utils::Equals(&actual_uidata_dict, expected_uidata.get()));
102 INSTANTIATE_TEST_CASE_P(
103 CreateUIDataTest,
104 CreateUIDataTest,
105 ::testing::Values(
106 std::make_pair("wifi_clientcert_with_cert_pems.onc",
107 "uidata_for_wifi_clientcert.json"),
108 std::make_pair("valid_wifi_clientref.onc",
109 "uidata_for_wifi_clientref.json"),
110 std::make_pair("valid_wifi_psk.onc",
111 "uidata_for_wifi_psk.json"),
112 std::make_pair("openvpn_clientcert_with_cert_pems.onc",
113 "uidata_for_openvpn_clientcert.json"),
114 std::make_pair("l2tpipsec_clientcert_with_cert_pems.onc",
115 "uidata_for_l2tpipsec_clientcert.json")));
117 } // namespace chromeos