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

Side by Side Diff: chrome/browser/chromeos/cros/network_property_ui_data_unittest.cc

Issue 13454006: Moving ManagedNetworkConfigurationHandler to chromeos/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up parsing of NetworkUIData. Created 7 years, 8 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 "chrome/browser/chromeos/cros/network_ui_data.h" 5 #include "chrome/browser/chromeos/cros/network_property_ui_data.h"
6
7 #include "base/values.h"
8 #include "chromeos/network/network_ui_data.h"
6 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
7 10
8 namespace chromeos { 11 namespace chromeos {
9 12
10 class NetworkUIDataTest : public testing::Test { 13 class NetworkUIDataTest : public testing::Test {
11 protected: 14 protected:
12 NetworkUIDataTest() {} 15 NetworkUIDataTest() {}
13 virtual ~NetworkUIDataTest() {} 16 virtual ~NetworkUIDataTest() {}
14 17
15 void CheckProperty(const NetworkPropertyUIData& property, 18 void CheckProperty(const NetworkPropertyUIData& property,
16 const base::Value* expected_default_value, 19 const base::Value* expected_default_value,
17 bool expected_managed, 20 bool expected_managed,
18 bool expected_recommended, 21 bool expected_recommended,
19 bool expected_editable) { 22 bool expected_editable) {
20 if (expected_default_value) { 23 if (expected_default_value) {
21 EXPECT_TRUE(base::Value::Equals(expected_default_value, 24 EXPECT_TRUE(base::Value::Equals(expected_default_value,
22 property.default_value())); 25 property.default_value()));
23 } else { 26 } else {
24 EXPECT_FALSE(property.default_value()); 27 EXPECT_FALSE(property.default_value());
25 } 28 }
26 EXPECT_EQ(expected_managed, property.managed()); 29 EXPECT_EQ(expected_managed, property.managed());
27 EXPECT_EQ(expected_recommended, property.recommended()); 30 EXPECT_EQ(expected_recommended, property.recommended());
28 EXPECT_EQ(expected_editable, property.editable()); 31 EXPECT_EQ(expected_editable, property.editable());
29 } 32 }
30 }; 33 };
31 34
32 TEST_F(NetworkUIDataTest, ONCSource) {
33 base::DictionaryValue ui_data_dict;
34
35 ui_data_dict.SetString(NetworkUIData::kKeyONCSource, "user_import");
36 {
37 NetworkUIData ui_data(ui_data_dict);
38 EXPECT_EQ(onc::ONC_SOURCE_USER_IMPORT, ui_data.onc_source());
39 EXPECT_FALSE(ui_data.is_managed());
40 }
41
42 ui_data_dict.SetString(NetworkUIData::kKeyONCSource, "device_policy");
43 {
44 NetworkUIData ui_data(ui_data_dict);
45 EXPECT_EQ(onc::ONC_SOURCE_DEVICE_POLICY, ui_data.onc_source());
46 EXPECT_TRUE(ui_data.is_managed());
47 }
48 ui_data_dict.SetString(NetworkUIData::kKeyONCSource, "user_policy");
49 {
50 NetworkUIData ui_data(ui_data_dict);
51 EXPECT_EQ(onc::ONC_SOURCE_USER_POLICY, ui_data.onc_source());
52 EXPECT_TRUE(ui_data.is_managed());
53 }
54 }
55
56 TEST_F(NetworkUIDataTest, CertificateType) {
57 {
58 base::DictionaryValue ui_data_dict;
59 ui_data_dict.SetString(NetworkUIData::kKeyCertificateType, "none");
60 NetworkUIData ui_data(ui_data_dict);
61 EXPECT_EQ(CLIENT_CERT_TYPE_NONE, ui_data.certificate_type());
62 }
63 {
64 base::DictionaryValue ui_data_dict;
65 ui_data_dict.SetString(NetworkUIData::kKeyCertificateType, "ref");
66 NetworkUIData ui_data(ui_data_dict);
67 EXPECT_EQ(CLIENT_CERT_TYPE_REF, ui_data.certificate_type());
68 }
69 {
70 // for type pattern we need to have some kind of pattern
71 std::string organization("Little If Any, Inc.");
72 base::DictionaryValue ui_data_dict;
73 base::DictionaryValue* pattern_dict = new base::DictionaryValue;
74 base::DictionaryValue* issuer_dict = new base::DictionaryValue;
75 issuer_dict->SetString("Organization", organization);
76 pattern_dict->Set("Issuer", issuer_dict);
77 ui_data_dict.Set("certificate_pattern", pattern_dict);
78 ui_data_dict.SetString(NetworkUIData::kKeyCertificateType, "pattern");
79 NetworkUIData ui_data(ui_data_dict);
80 EXPECT_EQ(CLIENT_CERT_TYPE_PATTERN, ui_data.certificate_type());
81 }
82 }
83
84 TEST_F(NetworkUIDataTest, CertificatePattern) {
85 std::string organization("Little If Any, Inc.");
86 base::DictionaryValue ui_data_dict;
87 base::DictionaryValue* pattern_dict = new base::DictionaryValue;
88 base::DictionaryValue* issuer_dict = new base::DictionaryValue;
89 issuer_dict->SetString("Organization", organization);
90 pattern_dict->Set("Issuer", issuer_dict);
91 ui_data_dict.Set("certificate_pattern", pattern_dict);
92 NetworkUIData ui_data(ui_data_dict);
93 EXPECT_FALSE(ui_data.certificate_pattern().Empty());
94 EXPECT_EQ(organization,
95 ui_data.certificate_pattern().issuer().organization());
96 }
97
98 TEST_F(NetworkUIDataTest, PropertyInit) { 35 TEST_F(NetworkUIDataTest, PropertyInit) {
99 NetworkPropertyUIData empty_prop; 36 NetworkPropertyUIData empty_prop;
100 CheckProperty(empty_prop, NULL, false, false, true); 37 CheckProperty(empty_prop, NULL, false, false, true);
101 38
102 NetworkUIData empty_data; 39 NetworkUIData empty_data;
103 NetworkPropertyUIData null_prop(empty_data); 40 NetworkPropertyUIData null_prop(empty_data);
104 CheckProperty(null_prop, NULL, false, false, true); 41 CheckProperty(null_prop, NULL, false, false, true);
105 42
106 base::DictionaryValue empty_dict; 43 base::DictionaryValue empty_dict;
107 NetworkUIData empty_data_2(empty_dict); 44 NetworkUIData empty_data_2(empty_dict);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 CheckProperty(prop, NULL, false, false, true); 112 CheckProperty(prop, NULL, false, false, true);
176 113
177 prop.ParseOncProperty(ui_data, &onc, "a.d"); 114 prop.ParseOncProperty(ui_data, &onc, "a.d");
178 CheckProperty(prop, NULL, true, false, false); 115 CheckProperty(prop, NULL, true, false, false);
179 116
180 prop.ParseOncProperty(ui_data, NULL, "a.e"); 117 prop.ParseOncProperty(ui_data, NULL, "a.e");
181 CheckProperty(prop, NULL, true, false, false); 118 CheckProperty(prop, NULL, true, false, false);
182 } 119 }
183 120
184 } // namespace chromeos 121 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_property_ui_data.cc ('k') | chrome/browser/chromeos/cros/network_ui_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698