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

Side by Side Diff: chromeos/dbus/shill_network_client_unittest.cc

Issue 11887008: Deprecate ShillNetworkClient and add GeolocationHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unittest Created 7 years, 11 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
(Empty)
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 "base/bind.h"
6 #include "base/values.h"
7 #include "chromeos/dbus/shill_client_unittest_base.h"
8 #include "chromeos/dbus/shill_network_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"
13
14 using testing::_;
15 using testing::ByRef;
16
17 namespace chromeos {
18
19 namespace {
20
21 const char kExampleNetworkPath[] = "/foo/bar";
22
23 } // namespace
24
25 class ShillNetworkClientTest : public ShillClientUnittestBase {
26 public:
27 ShillNetworkClientTest()
28 : ShillClientUnittestBase(
29 flimflam::kFlimflamNetworkInterface,
30 dbus::ObjectPath(kExampleNetworkPath)) {
31 }
32
33 virtual void SetUp() {
34 ShillClientUnittestBase::SetUp();
35 // Create a client with the mock bus.
36 client_.reset(ShillNetworkClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION,
37 mock_bus_));
38 // Run the message loop to run the signal connection result callback.
39 message_loop_.RunUntilIdle();
40 }
41
42 virtual void TearDown() {
43 ShillClientUnittestBase::TearDown();
44 }
45
46 protected:
47 scoped_ptr<ShillNetworkClient> client_;
48 };
49
50 TEST_F(ShillNetworkClientTest, PropertyChanged) {
51 // Create a signal.
52 const base::FundamentalValue kConnected(true);
53 dbus::Signal signal(flimflam::kFlimflamNetworkInterface,
54 flimflam::kMonitorPropertyChanged);
55 dbus::MessageWriter writer(&signal);
56 writer.AppendString(flimflam::kConnectedProperty);
57 dbus::AppendBasicTypeValueDataAsVariant(&writer, kConnected);
58
59 // Set expectations.
60 MockPropertyChangeObserver observer;
61 EXPECT_CALL(observer,
62 OnPropertyChanged(
63 flimflam::kConnectedProperty,
64 ValueEq(ByRef(kConnected)))).Times(1);
65
66 // Add the observer
67 client_->AddPropertyChangedObserver(
68 dbus::ObjectPath(kExampleNetworkPath),
69 &observer);
70
71 // Run the signal callback.
72 SendPropertyChangedSignal(&signal);
73
74 // Remove the observer.
75 client_->RemovePropertyChangedObserver(
76 dbus::ObjectPath(kExampleNetworkPath),
77 &observer);
78
79 EXPECT_CALL(observer, OnPropertyChanged(_, _)).Times(0);
80
81 // Run the signal callback again and make sure the observer isn't called.
82 SendPropertyChangedSignal(&signal);
83 }
84
85 TEST_F(ShillNetworkClientTest, GetProperties) {
86 const char kAddress[] = "address";
87 const char kName[] = "name";
88 const uint8 kSignalStrength = 1;
89 const uint32 kWifiChannel = 1;
90 const bool kConnected = true;
91
92 // Create response.
93 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
94 dbus::MessageWriter writer(response.get());
95 dbus::MessageWriter array_writer(NULL);
96 writer.OpenArray("{sv}", &array_writer);
97 dbus::MessageWriter entry_writer(NULL);
98 // Append address.
99 array_writer.OpenDictEntry(&entry_writer);
100 entry_writer.AppendString(flimflam::kAddressProperty);
101 entry_writer.AppendVariantOfString(kAddress);
102 array_writer.CloseContainer(&entry_writer);
103 // Append name.
104 array_writer.OpenDictEntry(&entry_writer);
105 entry_writer.AppendString(flimflam::kNameProperty);
106 entry_writer.AppendVariantOfString(kName);
107 array_writer.CloseContainer(&entry_writer);
108 // Append signal strength.
109 array_writer.OpenDictEntry(&entry_writer);
110 entry_writer.AppendString(flimflam::kSignalStrengthProperty);
111 entry_writer.AppendVariantOfByte(kSignalStrength);
112 array_writer.CloseContainer(&entry_writer);
113 // Append Wifi channel.
114 array_writer.OpenDictEntry(&entry_writer);
115 entry_writer.AppendString(flimflam::kWifiChannelProperty);
116 entry_writer.AppendVariantOfUint32(kWifiChannel);
117 array_writer.CloseContainer(&entry_writer);
118 // Append connected.
119 array_writer.OpenDictEntry(&entry_writer);
120 entry_writer.AppendString(flimflam::kConnectedProperty);
121 entry_writer.AppendVariantOfBool(kConnected);
122 array_writer.CloseContainer(&entry_writer);
123 writer.CloseContainer(&array_writer);
124
125 // Create the expected value.
126 base::DictionaryValue value;
127 value.SetWithoutPathExpansion(flimflam::kAddressProperty,
128 base::Value::CreateStringValue(kAddress));
129 value.SetWithoutPathExpansion(flimflam::kNameProperty,
130 base::Value::CreateStringValue(kName));
131 value.SetWithoutPathExpansion(
132 flimflam::kSignalStrengthProperty,
133 base::Value::CreateIntegerValue(kSignalStrength));
134 // WiFi.Channel is set as a double because uint32 is larger than int32.
135 value.SetWithoutPathExpansion(flimflam::kWifiChannelProperty,
136 base::Value::CreateDoubleValue(kWifiChannel));
137 value.SetWithoutPathExpansion(flimflam::kConnectedProperty,
138 base::Value::CreateBooleanValue(kConnected));
139
140 // Set expectations.
141 PrepareForMethodCall(flimflam::kGetPropertiesFunction,
142 base::Bind(&ExpectNoArgument),
143 response.get());
144 // Call method.
145 client_->GetProperties(dbus::ObjectPath(kExampleNetworkPath),
146 base::Bind(&ExpectDictionaryValueResult, &value));
147 // Run the message loop.
148 message_loop_.RunUntilIdle();
149 }
150
151 TEST_F(ShillNetworkClientTest, CallGetPropertiesAndBlock) {
152 const char kName[] = "name";
153
154 // Create response.
155 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
156 dbus::MessageWriter writer(response.get());
157 dbus::MessageWriter array_writer(NULL);
158 writer.OpenArray("{sv}", &array_writer);
159 dbus::MessageWriter entry_writer(NULL);
160 array_writer.OpenDictEntry(&entry_writer);
161 entry_writer.AppendString(flimflam::kNameProperty);
162 entry_writer.AppendVariantOfString(kName);
163 array_writer.CloseContainer(&entry_writer);
164 writer.CloseContainer(&array_writer);
165
166 // Create the expected value.
167 base::DictionaryValue value;
168 value.SetWithoutPathExpansion(flimflam::kNameProperty,
169 base::Value::CreateStringValue(kName));
170
171 // Set expectations.
172 PrepareForMethodCall(flimflam::kGetPropertiesFunction,
173 base::Bind(&ExpectNoArgument),
174 response.get());
175 // Call method.
176 scoped_ptr<base::DictionaryValue> result(
177 client_->CallGetPropertiesAndBlock(
178 dbus::ObjectPath(kExampleNetworkPath)));
179
180 ASSERT_TRUE(result.get());
181 EXPECT_TRUE(result->Equals(&value));
182 }
183
184 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698