Simple Cache: transactional index in subdirectory
[chromium-blink-merge.git] / chromeos / dbus / shill_ipconfig_client_unittest.cc
blob6c15b15b293caa240392d0f4cfd5a259d9f0484e
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 "base/bind.h"
6 #include "base/values.h"
7 #include "chromeos/dbus/shill_client_unittest_base.h"
8 #include "chromeos/dbus/shill_ipconfig_client.h"
9 #include "dbus/message.h"
10 #include "dbus/values_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/cros_system_api/dbus/service_constants.h"
14 using testing::_;
15 using testing::ByRef;
17 namespace chromeos {
19 namespace {
21 const char kExampleIPConfigPath[] = "/foo/bar";
23 } // namespace
25 class ShillIPConfigClientTest : public ShillClientUnittestBase {
26 public:
27 ShillIPConfigClientTest()
28 : ShillClientUnittestBase(
29 flimflam::kFlimflamIPConfigInterface,
30 dbus::ObjectPath(kExampleIPConfigPath)) {
33 virtual void SetUp() {
34 ShillClientUnittestBase::SetUp();
35 // Create a client with the mock bus.
36 client_.reset(ShillIPConfigClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION));
37 client_->Init(mock_bus_.get());
38 // Run the message loop to run the signal connection result callback.
39 message_loop_.RunUntilIdle();
42 virtual void TearDown() {
43 ShillClientUnittestBase::TearDown();
46 protected:
47 scoped_ptr<ShillIPConfigClient> client_;
50 TEST_F(ShillIPConfigClientTest, PropertyChanged) {
51 // Create a signal.
52 const base::FundamentalValue kConnected(true);
53 dbus::Signal signal(flimflam::kFlimflamIPConfigInterface,
54 flimflam::kMonitorPropertyChanged);
55 dbus::MessageWriter writer(&signal);
56 writer.AppendString(flimflam::kConnectedProperty);
57 dbus::AppendBasicTypeValueDataAsVariant(&writer, kConnected);
59 // Set expectations.
60 MockPropertyChangeObserver observer;
61 EXPECT_CALL(observer, OnPropertyChanged(flimflam::kConnectedProperty,
62 ValueEq(ByRef(kConnected)))).Times(1);
64 // Add the observer
65 client_->AddPropertyChangedObserver(
66 dbus::ObjectPath(kExampleIPConfigPath),
67 &observer);
69 // Run the signal callback.
70 SendPropertyChangedSignal(&signal);
72 // Remove the observer.
73 client_->RemovePropertyChangedObserver(
74 dbus::ObjectPath(kExampleIPConfigPath),
75 &observer);
77 EXPECT_CALL(observer, OnPropertyChanged(_, _)).Times(0);
79 // Run the signal callback again and make sure the observer isn't called.
80 SendPropertyChangedSignal(&signal);
83 TEST_F(ShillIPConfigClientTest, GetProperties) {
84 const char kAddress[] = "address";
85 const int32 kMtu = 68;
87 // Create response.
88 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
89 dbus::MessageWriter writer(response.get());
90 dbus::MessageWriter array_writer(NULL);
91 writer.OpenArray("{sv}", &array_writer);
92 dbus::MessageWriter entry_writer(NULL);
93 // Append address.
94 array_writer.OpenDictEntry(&entry_writer);
95 entry_writer.AppendString(flimflam::kAddressProperty);
96 entry_writer.AppendVariantOfString(kAddress);
97 array_writer.CloseContainer(&entry_writer);
98 // Append MTU.
99 array_writer.OpenDictEntry(&entry_writer);
100 entry_writer.AppendString(flimflam::kMtuProperty);
101 entry_writer.AppendVariantOfInt32(kMtu);
102 array_writer.CloseContainer(&entry_writer);
103 writer.CloseContainer(&array_writer);
105 // Create the expected value.
106 base::DictionaryValue value;
107 value.SetWithoutPathExpansion(flimflam::kAddressProperty,
108 base::Value::CreateStringValue(kAddress));
109 value.SetWithoutPathExpansion(flimflam::kMtuProperty,
110 base::Value::CreateIntegerValue(kMtu));
112 // Set expectations.
113 PrepareForMethodCall(flimflam::kGetPropertiesFunction,
114 base::Bind(&ExpectNoArgument),
115 response.get());
116 // Call method.
117 client_->GetProperties(dbus::ObjectPath(kExampleIPConfigPath),
118 base::Bind(&ExpectDictionaryValueResult, &value));
119 // Run the message loop.
120 message_loop_.RunUntilIdle();
123 TEST_F(ShillIPConfigClientTest, SetProperty) {
124 const char kAddress[] = "address";
126 // Create response.
127 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
129 // Set expectations.
130 base::StringValue value(kAddress);
131 PrepareForMethodCall(flimflam::kSetPropertyFunction,
132 base::Bind(&ExpectStringAndValueArguments,
133 flimflam::kAddressProperty,
134 &value),
135 response.get());
136 // Call method.
137 client_->SetProperty(dbus::ObjectPath(kExampleIPConfigPath),
138 flimflam::kAddressProperty,
139 value,
140 base::Bind(&ExpectNoResultValue));
141 // Run the message loop.
142 message_loop_.RunUntilIdle();
145 TEST_F(ShillIPConfigClientTest, ClearProperty) {
146 // Create response.
147 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
149 // Set expectations.
150 PrepareForMethodCall(flimflam::kClearPropertyFunction,
151 base::Bind(&ExpectStringArgument,
152 flimflam::kAddressProperty),
153 response.get());
154 // Call method.
155 client_->ClearProperty(dbus::ObjectPath(kExampleIPConfigPath),
156 flimflam::kAddressProperty,
157 base::Bind(&ExpectNoResultValue));
158 // Run the message loop.
159 message_loop_.RunUntilIdle();
162 TEST_F(ShillIPConfigClientTest, Remove) {
163 // Create response.
164 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
166 // Set expectations.
167 PrepareForMethodCall(flimflam::kRemoveConfigFunction,
168 base::Bind(&ExpectNoArgument),
169 response.get());
170 // Call method.
171 client_->Remove(dbus::ObjectPath(kExampleIPConfigPath),
172 base::Bind(&ExpectNoResultValue));
174 // Run the message loop.
175 message_loop_.RunUntilIdle();
178 } // namespace chromeos