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

Unified Diff: chrome/browser/chromeos/cros/network_ui_data_unittest.cc

Issue 8728030: Infrastructure for accessing and manipulating network UI data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make clang happy. Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/cros/network_ui_data.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/cros/network_ui_data_unittest.cc
diff --git a/chrome/browser/chromeos/cros/network_ui_data_unittest.cc b/chrome/browser/chromeos/cros/network_ui_data_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..53f56f42bcd64ce463f18f4ac877668d9f2b77e2
--- /dev/null
+++ b/chrome/browser/chromeos/cros/network_ui_data_unittest.cc
@@ -0,0 +1,163 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/stringprintf.h"
+#include "chrome/browser/chromeos/cros/network_library.h"
+#include "chrome/browser/chromeos/cros/network_ui_data.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+
+namespace {
+
+// A mock network for testing. We really only need the ui_data() member.
+class TestNetwork : public Network {
+ public:
+ TestNetwork()
+ : Network("wifi-network", TYPE_WIFI) {}
+};
+
+} // namespace
+
+class NetworkUIDataTest : public testing::Test {
+ protected:
+ NetworkUIDataTest() {}
+
+ static void SetProperty(DictionaryValue* dict,
+ const char* property_key,
+ const char* controller,
+ base::Value* default_value) {
+ DictionaryValue* property_dict = new DictionaryValue();
+ if (controller) {
+ property_dict->SetString(NetworkPropertyUIData::kKeyController,
+ controller);
+ }
+ if (default_value) {
+ property_dict->Set(NetworkPropertyUIData::kKeyDefaultValue,
+ default_value);
+ }
+ dict->Set(base::StringPrintf("%s.%s",
+ NetworkUIData::kKeyProperties,
+ property_key),
+ property_dict);
+ }
+
+ static void CheckProperty(const DictionaryValue* dict,
+ const char* property_key,
+ const char* controller,
+ base::Value* default_value) {
+ DictionaryValue* property_dict;
+ std::string key = base::StringPrintf("%s.%s",
+ NetworkUIData::kKeyProperties,
+ property_key);
+ EXPECT_TRUE(dict->GetDictionary(key, &property_dict));
+ ASSERT_TRUE(property_dict);
+ std::string actual_controller;
+ EXPECT_TRUE(property_dict->GetString(NetworkPropertyUIData::kKeyController,
+ &actual_controller));
+ EXPECT_EQ(controller, actual_controller);
+ if (default_value) {
+ base::Value* actual_value = NULL;
+ EXPECT_TRUE(property_dict->Get(NetworkPropertyUIData::kKeyDefaultValue,
+ &actual_value));
+ EXPECT_TRUE(base::Value::Equals(default_value, actual_value));
+ }
+ }
+
+ TestNetwork network_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkUIDataTest);
+};
+
+TEST_F(NetworkUIDataTest, ONCSource) {
+ network_.ui_data()->SetString(NetworkUIData::kKeyONCSource, "user_import");
+ EXPECT_EQ(NetworkUIData::ONC_SOURCE_USER_IMPORT,
+ NetworkUIData::GetONCSource(&network_));
+ EXPECT_FALSE(NetworkUIData::IsManaged(&network_));
+
+ network_.ui_data()->SetString(NetworkUIData::kKeyONCSource, "device_policy");
+ EXPECT_EQ(NetworkUIData::ONC_SOURCE_DEVICE_POLICY,
+ NetworkUIData::GetONCSource(&network_));
+ EXPECT_TRUE(NetworkUIData::IsManaged(&network_));
+
+ network_.ui_data()->SetString(NetworkUIData::kKeyONCSource, "user_policy");
+ EXPECT_EQ(NetworkUIData::ONC_SOURCE_USER_POLICY,
+ NetworkUIData::GetONCSource(&network_));
+ EXPECT_TRUE(NetworkUIData::IsManaged(&network_));
+}
+
+TEST_F(NetworkUIDataTest, ReadProperties) {
+ SetProperty(network_.ui_data(), NetworkUIData::kPropertyAutoConnect,
+ "policy", NULL);
+ SetProperty(network_.ui_data(), NetworkUIData::kPropertyPreferred,
+ "user", Value::CreateBooleanValue(true));
+ SetProperty(network_.ui_data(), NetworkUIData::kPropertyPassphrase,
+ NULL, Value::CreateIntegerValue(42));
+
+ NetworkPropertyUIData property_ui_data(&network_,
+ NetworkUIData::kPropertyAutoConnect);
+ EXPECT_TRUE(property_ui_data.managed());
+ EXPECT_FALSE(property_ui_data.recommended());
+ EXPECT_FALSE(property_ui_data.editable());
+ EXPECT_FALSE(property_ui_data.default_value());
+
+ property_ui_data.UpdateFromNetwork(&network_,
+ NetworkUIData::kPropertyPreferred);
+ EXPECT_FALSE(property_ui_data.managed());
+ EXPECT_TRUE(property_ui_data.recommended());
+ EXPECT_TRUE(property_ui_data.editable());
+ base::FundamentalValue expected_preferred(true);
+ EXPECT_TRUE(base::Value::Equals(&expected_preferred,
+ property_ui_data.default_value()));
+
+ property_ui_data.UpdateFromNetwork(&network_,
+ NetworkUIData::kPropertyPassphrase);
+ EXPECT_FALSE(property_ui_data.managed());
+ EXPECT_TRUE(property_ui_data.recommended());
+ EXPECT_TRUE(property_ui_data.editable());
+ base::FundamentalValue expected_passphrase(42);
+ EXPECT_TRUE(base::Value::Equals(&expected_passphrase,
+ property_ui_data.default_value()));
+
+ property_ui_data.UpdateFromNetwork(&network_,
+ NetworkUIData::kPropertySaveCredentials);
+ EXPECT_FALSE(property_ui_data.managed());
+ EXPECT_FALSE(property_ui_data.recommended());
+ EXPECT_TRUE(property_ui_data.editable());
+ EXPECT_FALSE(property_ui_data.default_value());
+}
+
+TEST_F(NetworkUIDataTest, WriteProperties) {
+ NetworkUIData ui_data_builder;
+ ui_data_builder.set_onc_source(NetworkUIData::ONC_SOURCE_USER_POLICY);
+ NetworkPropertyUIData auto_connect_ui_data(
+ NetworkPropertyUIData::CONTROLLER_USER,
+ base::Value::CreateBooleanValue(true));
+ ui_data_builder.SetProperty(NetworkUIData::kPropertyAutoConnect,
+ auto_connect_ui_data);
+ NetworkPropertyUIData preferred_ui_data(
+ NetworkPropertyUIData::CONTROLLER_POLICY,
+ base::Value::CreateBooleanValue(42));
+ ui_data_builder.SetProperty(NetworkUIData::kPropertyPreferred,
+ preferred_ui_data);
+ NetworkPropertyUIData passphrase_ui_data(
+ NetworkPropertyUIData::CONTROLLER_USER, NULL);
+ ui_data_builder.SetProperty(NetworkUIData::kPropertyPassphrase,
+ passphrase_ui_data);
+
+ DictionaryValue dict;
+ ui_data_builder.FillDictionary(&dict);
+
+ std::string onc_source;
+ EXPECT_TRUE(dict.GetString(NetworkUIData::kKeyONCSource, &onc_source));
+ EXPECT_EQ("user_policy", onc_source);
+ CheckProperty(&dict, NetworkUIData::kPropertyAutoConnect,
+ "user", base::Value::CreateBooleanValue(true));
+ CheckProperty(&dict, NetworkUIData::kPropertyPreferred,
+ "policy", base::Value::CreateBooleanValue(42));
+ CheckProperty(&dict, NetworkUIData::kPropertyPassphrase,
+ "user", NULL);
+}
+
+} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/cros/network_ui_data.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698