Don't preload rarely seen large images
[chromium-blink-merge.git] / chromeos / dbus / shill_ipconfig_client_unittest.cc
blob68d6913167f5778eb15032850f87c735f219a5f0
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 shill::kFlimflamIPConfigInterface,
30 dbus::ObjectPath(kExampleIPConfigPath)) {
33 void SetUp() override {
34 ShillClientUnittestBase::SetUp();
35 // Create a client with the mock bus.
36 client_.reset(ShillIPConfigClient::Create());
37 client_->Init(mock_bus_.get());
38 // Run the message loop to run the signal connection result callback.
39 message_loop_.RunUntilIdle();
42 void TearDown() override { ShillClientUnittestBase::TearDown(); }
44 protected:
45 scoped_ptr<ShillIPConfigClient> client_;
48 TEST_F(ShillIPConfigClientTest, PropertyChanged) {
49 // Create a signal.
50 const base::FundamentalValue kConnected(true);
51 dbus::Signal signal(shill::kFlimflamIPConfigInterface,
52 shill::kMonitorPropertyChanged);
53 dbus::MessageWriter writer(&signal);
54 writer.AppendString(shill::kConnectedProperty);
55 dbus::AppendBasicTypeValueDataAsVariant(&writer, kConnected);
57 // Set expectations.
58 MockPropertyChangeObserver observer;
59 EXPECT_CALL(observer, OnPropertyChanged(shill::kConnectedProperty,
60 ValueEq(ByRef(kConnected)))).Times(1);
62 // Add the observer
63 client_->AddPropertyChangedObserver(
64 dbus::ObjectPath(kExampleIPConfigPath),
65 &observer);
67 // Run the signal callback.
68 SendPropertyChangedSignal(&signal);
70 // Remove the observer.
71 client_->RemovePropertyChangedObserver(
72 dbus::ObjectPath(kExampleIPConfigPath),
73 &observer);
75 EXPECT_CALL(observer, OnPropertyChanged(_, _)).Times(0);
77 // Run the signal callback again and make sure the observer isn't called.
78 SendPropertyChangedSignal(&signal);
81 TEST_F(ShillIPConfigClientTest, GetProperties) {
82 const char kAddress[] = "address";
83 const int32 kMtu = 68;
85 // Create response.
86 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
87 dbus::MessageWriter writer(response.get());
88 dbus::MessageWriter array_writer(NULL);
89 writer.OpenArray("{sv}", &array_writer);
90 dbus::MessageWriter entry_writer(NULL);
91 // Append address.
92 array_writer.OpenDictEntry(&entry_writer);
93 entry_writer.AppendString(shill::kAddressProperty);
94 entry_writer.AppendVariantOfString(kAddress);
95 array_writer.CloseContainer(&entry_writer);
96 // Append MTU.
97 array_writer.OpenDictEntry(&entry_writer);
98 entry_writer.AppendString(shill::kMtuProperty);
99 entry_writer.AppendVariantOfInt32(kMtu);
100 array_writer.CloseContainer(&entry_writer);
101 writer.CloseContainer(&array_writer);
103 // Create the expected value.
104 base::DictionaryValue value;
105 value.SetWithoutPathExpansion(shill::kAddressProperty,
106 new base::StringValue(kAddress));
107 value.SetWithoutPathExpansion(shill::kMtuProperty,
108 new base::FundamentalValue(kMtu));
110 // Set expectations.
111 PrepareForMethodCall(shill::kGetPropertiesFunction,
112 base::Bind(&ExpectNoArgument),
113 response.get());
114 // Call method.
115 client_->GetProperties(dbus::ObjectPath(kExampleIPConfigPath),
116 base::Bind(&ExpectDictionaryValueResult, &value));
117 // Run the message loop.
118 message_loop_.RunUntilIdle();
121 TEST_F(ShillIPConfigClientTest, SetProperty) {
122 const char kAddress[] = "address";
124 // Create response.
125 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
127 // Set expectations.
128 base::StringValue value(kAddress);
129 PrepareForMethodCall(shill::kSetPropertyFunction,
130 base::Bind(&ExpectStringAndValueArguments,
131 shill::kAddressProperty,
132 &value),
133 response.get());
134 // Call method.
135 client_->SetProperty(dbus::ObjectPath(kExampleIPConfigPath),
136 shill::kAddressProperty,
137 value,
138 base::Bind(&ExpectNoResultValue));
139 // Run the message loop.
140 message_loop_.RunUntilIdle();
143 TEST_F(ShillIPConfigClientTest, ClearProperty) {
144 // Create response.
145 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
147 // Set expectations.
148 PrepareForMethodCall(shill::kClearPropertyFunction,
149 base::Bind(&ExpectStringArgument,
150 shill::kAddressProperty),
151 response.get());
152 // Call method.
153 client_->ClearProperty(dbus::ObjectPath(kExampleIPConfigPath),
154 shill::kAddressProperty,
155 base::Bind(&ExpectNoResultValue));
156 // Run the message loop.
157 message_loop_.RunUntilIdle();
160 TEST_F(ShillIPConfigClientTest, Remove) {
161 // Create response.
162 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
164 // Set expectations.
165 PrepareForMethodCall(shill::kRemoveConfigFunction,
166 base::Bind(&ExpectNoArgument),
167 response.get());
168 // Call method.
169 client_->Remove(dbus::ObjectPath(kExampleIPConfigPath),
170 base::Bind(&ExpectNoResultValue));
172 // Run the message loop.
173 message_loop_.RunUntilIdle();
176 } // namespace chromeos