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/cros/network_property_ui_data.h" 6 7 #include "base/values.h" 8 #include "chromeos/network/onc/onc_constants.h" 9 #include "testing/gtest/include/gtest/gtest.h" 10 11 namespace chromeos { 12 13 class NetworkPropertyUIDataTest : public testing::Test { 14 protected: 15 NetworkPropertyUIDataTest() {} 16 virtual ~NetworkPropertyUIDataTest() {} 17 18 void CheckProperty(const NetworkPropertyUIData& property, 19 const base::Value* expected_default_value, 20 bool expected_managed, 21 bool expected_editable) { 22 if (expected_default_value) { 23 EXPECT_TRUE(base::Value::Equals(expected_default_value, 24 property.default_value())); 25 } else { 26 EXPECT_FALSE(property.default_value()); 27 } 28 EXPECT_EQ(expected_managed, property.IsManaged()); 29 EXPECT_EQ(expected_editable, property.IsEditable()); 30 } 31 }; 32 33 TEST_F(NetworkPropertyUIDataTest, PropertyInit) { 34 NetworkPropertyUIData empty_prop; 35 CheckProperty(empty_prop, NULL, false, true); 36 37 NetworkPropertyUIData null_prop(onc::ONC_SOURCE_NONE); 38 CheckProperty(null_prop, NULL, false, true); 39 } 40 41 TEST_F(NetworkPropertyUIDataTest, ParseOncProperty) { 42 base::DictionaryValue onc; 43 44 base::StringValue val_a("a"); 45 base::StringValue val_b("b"); 46 base::StringValue val_a_a("a_a"); 47 base::StringValue val_a_b("a_b"); 48 49 onc.Set("a", val_a.DeepCopy()); 50 onc.Set("b", val_b.DeepCopy()); 51 onc.Set("a.a", val_a_a.DeepCopy()); 52 onc.Set("a.b", val_a_b.DeepCopy()); 53 base::ListValue recommended; 54 recommended.AppendString("b"); 55 recommended.AppendString("c"); 56 recommended.AppendString("a.a"); 57 onc.Set("Recommended", recommended.DeepCopy()); 58 onc.Set("a.Recommended", recommended.DeepCopy()); 59 60 NetworkPropertyUIData prop; 61 62 prop.ParseOncProperty(onc::ONC_SOURCE_NONE, &onc, "a"); 63 CheckProperty(prop, NULL, false, true); 64 65 onc::ONCSource source = onc::ONC_SOURCE_USER_IMPORT; 66 67 prop.ParseOncProperty(source, &onc, "a"); 68 CheckProperty(prop, NULL, false, true); 69 70 prop.ParseOncProperty(source, &onc, "a.b"); 71 CheckProperty(prop, NULL, false, true); 72 73 prop.ParseOncProperty(source, &onc, "c"); 74 CheckProperty(prop, NULL, false, true); 75 76 source = onc::ONC_SOURCE_USER_POLICY; 77 78 prop.ParseOncProperty(source, &onc, "a"); 79 CheckProperty(prop, NULL, true, false); 80 81 prop.ParseOncProperty(source, &onc, "b"); 82 CheckProperty(prop, &val_b, false, true); 83 84 prop.ParseOncProperty(source, &onc, "c"); 85 CheckProperty(prop, NULL, false, true); 86 87 prop.ParseOncProperty(source, &onc, "d"); 88 CheckProperty(prop, NULL, true, false); 89 90 prop.ParseOncProperty(source, &onc, "a.a"); 91 CheckProperty(prop, NULL, true, false); 92 93 prop.ParseOncProperty(source, &onc, "a.b"); 94 CheckProperty(prop, &val_a_b, false, true); 95 96 prop.ParseOncProperty(source, &onc, "a.c"); 97 CheckProperty(prop, NULL, false, true); 98 99 prop.ParseOncProperty(source, &onc, "a.d"); 100 CheckProperty(prop, NULL, true, false); 101 102 prop.ParseOncProperty(source, NULL, "a.e"); 103 CheckProperty(prop, NULL, true, false); 104 } 105 106 } // namespace chromeos 107