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

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

Issue 10949030: This converts the Shill clients to allow propagation of shill errors (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/values.h" 6 #include "base/values.h"
7 #include "chromeos/dbus/shill_client_unittest_base.h" 7 #include "chromeos/dbus/shill_client_unittest_base.h"
8 #include "chromeos/dbus/shill_profile_client.h" 8 #include "chromeos/dbus/shill_profile_client.h"
9 #include "dbus/message.h" 9 #include "dbus/message.h"
10 #include "dbus/object_path.h" 10 #include "dbus/object_path.h"
11 #include "dbus/values_util.h" 11 #include "dbus/values_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h" 13 #include "third_party/cros_system_api/dbus/service_constants.h"
14 14
15 using testing::_;
16
15 namespace chromeos { 17 namespace chromeos {
16 18
17 namespace { 19 namespace {
18 20
19 const char kDefaultProfilePath[] = "/profile/default"; 21 const char kDefaultProfilePath[] = "/profile/default";
20 const char kExampleEntryPath[] = "example_entry_path"; 22 const char kExampleEntryPath[] = "example_entry_path";
21 23
22 void AppendVariantOfArrayOfStrings(dbus::MessageWriter* writer, 24 void AppendVariantOfArrayOfStrings(dbus::MessageWriter* writer,
23 const std::vector<std::string>& strings) { 25 const std::vector<std::string>& strings) {
24 dbus::MessageWriter variant_writer(NULL); 26 dbus::MessageWriter variant_writer(NULL);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 dbus::Signal signal(flimflam::kFlimflamProfileInterface, 60 dbus::Signal signal(flimflam::kFlimflamProfileInterface,
59 flimflam::kMonitorPropertyChanged); 61 flimflam::kMonitorPropertyChanged);
60 dbus::MessageWriter writer(&signal); 62 dbus::MessageWriter writer(&signal);
61 writer.AppendString(flimflam::kEntriesProperty); 63 writer.AppendString(flimflam::kEntriesProperty);
62 AppendVariantOfArrayOfStrings(&writer, 64 AppendVariantOfArrayOfStrings(&writer,
63 std::vector<std::string>(1, kExampleEntryPath)); 65 std::vector<std::string>(1, kExampleEntryPath));
64 66
65 // Set expectations. 67 // Set expectations.
66 base::ListValue value; 68 base::ListValue value;
67 value.Append(base::Value::CreateStringValue(kExampleEntryPath)); 69 value.Append(base::Value::CreateStringValue(kExampleEntryPath));
70 MockPropertyChangeObserver observer;
71 EXPECT_CALL(observer,
72 OnPropertyChanged(
73 flimflam::kEntriesProperty,
74 ValueEq(value))).Times(1);
68 75
69 client_->SetPropertyChangedHandler(dbus::ObjectPath(kDefaultProfilePath), 76 // Add the observer
70 base::Bind(&ExpectPropertyChanged, 77 client_->AddPropertyChangedObserver(
71 flimflam::kEntriesProperty, 78 dbus::ObjectPath(kDefaultProfilePath),
72 &value)); 79 &observer);
80
73 // Run the signal callback. 81 // Run the signal callback.
74 SendPropertyChangedSignal(&signal); 82 SendPropertyChangedSignal(&signal);
75 83
76 // Reset the handler. 84 // Remove the observer.
77 client_->ResetPropertyChangedHandler(dbus::ObjectPath(kDefaultProfilePath)); 85 client_->RemovePropertyChangedObserver(
86 dbus::ObjectPath(kDefaultProfilePath),
87 &observer);
88
89 EXPECT_CALL(observer, OnPropertyChanged(_, _)).Times(0);
90
91 // Run the signal callback again and make sure the observer isn't called.
92 SendPropertyChangedSignal(&signal);
78 } 93 }
79 94
80 TEST_F(ShillProfileClientTest, GetProperties) { 95 TEST_F(ShillProfileClientTest, GetProperties) {
81 // Create response. 96 // Create response.
82 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 97 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
83 dbus::MessageWriter writer(response.get()); 98 dbus::MessageWriter writer(response.get());
84 dbus::MessageWriter array_writer(NULL); 99 dbus::MessageWriter array_writer(NULL);
85 writer.OpenArray("{sv}", &array_writer); 100 writer.OpenArray("{sv}", &array_writer);
86 dbus::MessageWriter entry_writer(NULL); 101 dbus::MessageWriter entry_writer(NULL);
87 array_writer.OpenDictEntry(&entry_writer); 102 array_writer.OpenDictEntry(&entry_writer);
88 entry_writer.AppendString(flimflam::kEntriesProperty); 103 entry_writer.AppendString(flimflam::kEntriesProperty);
89 AppendVariantOfArrayOfStrings(&entry_writer, 104 AppendVariantOfArrayOfStrings(&entry_writer,
90 std::vector<std::string>(1, kExampleEntryPath)); 105 std::vector<std::string>(1, kExampleEntryPath));
91 array_writer.CloseContainer(&entry_writer); 106 array_writer.CloseContainer(&entry_writer);
92 writer.CloseContainer(&array_writer); 107 writer.CloseContainer(&array_writer);
93 108
94 // Create the expected value. 109 // Create the expected value.
95 base::ListValue* entries = new base::ListValue; 110 base::ListValue* entries = new base::ListValue;
96 entries->Append(base::Value::CreateStringValue(kExampleEntryPath)); 111 entries->Append(base::Value::CreateStringValue(kExampleEntryPath));
97 base::DictionaryValue value; 112 base::DictionaryValue value;
98 value.SetWithoutPathExpansion(flimflam::kEntriesProperty, entries); 113 value.SetWithoutPathExpansion(flimflam::kEntriesProperty, entries);
99 // Set expectations. 114 // Set expectations.
100 PrepareForMethodCall(flimflam::kGetPropertiesFunction, 115 PrepareForMethodCall(flimflam::kGetPropertiesFunction,
101 base::Bind(&ExpectNoArgument), 116 base::Bind(&ExpectNoArgument),
102 response.get()); 117 response.get());
103 // Call method. 118 // Call method.
119 MockErrorCallback error_callback;
104 client_->GetProperties(dbus::ObjectPath(kDefaultProfilePath), 120 client_->GetProperties(dbus::ObjectPath(kDefaultProfilePath),
105 base::Bind(&ExpectDictionaryValueResult, &value)); 121 base::Bind(&ExpectDictionaryValueResultWithoutStatus,
122 &value),
123 error_callback.GetCallback());
106 // Run the message loop. 124 // Run the message loop.
107 message_loop_.RunAllPending(); 125 message_loop_.RunAllPending();
108 } 126 }
109 127
110 TEST_F(ShillProfileClientTest, GetEntry) { 128 TEST_F(ShillProfileClientTest, GetEntry) {
111 // Create response. 129 // Create response.
112 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 130 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
113 dbus::MessageWriter writer(response.get()); 131 dbus::MessageWriter writer(response.get());
114 dbus::MessageWriter array_writer(NULL); 132 dbus::MessageWriter array_writer(NULL);
115 writer.OpenArray("{sv}", &array_writer); 133 writer.OpenArray("{sv}", &array_writer);
116 dbus::MessageWriter entry_writer(NULL); 134 dbus::MessageWriter entry_writer(NULL);
117 array_writer.OpenDictEntry(&entry_writer); 135 array_writer.OpenDictEntry(&entry_writer);
118 entry_writer.AppendString(flimflam::kTypeProperty); 136 entry_writer.AppendString(flimflam::kTypeProperty);
119 entry_writer.AppendVariantOfString(flimflam::kTypeWifi); 137 entry_writer.AppendVariantOfString(flimflam::kTypeWifi);
120 array_writer.CloseContainer(&entry_writer); 138 array_writer.CloseContainer(&entry_writer);
121 writer.CloseContainer(&array_writer); 139 writer.CloseContainer(&array_writer);
122 140
123 // Create the expected value. 141 // Create the expected value.
124 base::DictionaryValue value; 142 base::DictionaryValue value;
125 value.SetWithoutPathExpansion( 143 value.SetWithoutPathExpansion(
126 flimflam::kTypeProperty, 144 flimflam::kTypeProperty,
127 base::Value::CreateStringValue(flimflam::kTypeWifi)); 145 base::Value::CreateStringValue(flimflam::kTypeWifi));
128 // Set expectations. 146 // Set expectations.
129 PrepareForMethodCall(flimflam::kGetEntryFunction, 147 PrepareForMethodCall(flimflam::kGetEntryFunction,
130 base::Bind(&ExpectStringArgument, kExampleEntryPath), 148 base::Bind(&ExpectStringArgument, kExampleEntryPath),
131 response.get()); 149 response.get());
132 // Call method. 150 // Call method.
151 MockErrorCallback error_callback;
133 client_->GetEntry(dbus::ObjectPath(kDefaultProfilePath), 152 client_->GetEntry(dbus::ObjectPath(kDefaultProfilePath),
134 kExampleEntryPath, 153 kExampleEntryPath,
135 base::Bind(&ExpectDictionaryValueResult, &value)); 154 base::Bind(&ExpectDictionaryValueResultWithoutStatus,
155 &value),
156 error_callback.GetCallback());
157 EXPECT_CALL(error_callback, Run(_, _)).Times(0);
136 // Run the message loop. 158 // Run the message loop.
137 message_loop_.RunAllPending(); 159 message_loop_.RunAllPending();
138 } 160 }
139 161
140 TEST_F(ShillProfileClientTest, DeleteEntry) { 162 TEST_F(ShillProfileClientTest, DeleteEntry) {
141 // Create response. 163 // Create response.
142 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 164 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
143 165
144 // Create the expected value. 166 // Create the expected value.
145 base::DictionaryValue value; 167 base::DictionaryValue value;
146 value.SetWithoutPathExpansion(flimflam::kOfflineModeProperty, 168 value.SetWithoutPathExpansion(flimflam::kOfflineModeProperty,
147 base::Value::CreateBooleanValue(true)); 169 base::Value::CreateBooleanValue(true));
148 // Set expectations. 170 // Set expectations.
149 PrepareForMethodCall(flimflam::kDeleteEntryFunction, 171 PrepareForMethodCall(flimflam::kDeleteEntryFunction,
150 base::Bind(&ExpectStringArgument, kExampleEntryPath), 172 base::Bind(&ExpectStringArgument, kExampleEntryPath),
151 response.get()); 173 response.get());
152 // Call method. 174 // Call method.
175 MockClosure mock_closure;
176 MockErrorCallback mock_error_callback;
153 client_->DeleteEntry(dbus::ObjectPath(kDefaultProfilePath), 177 client_->DeleteEntry(dbus::ObjectPath(kDefaultProfilePath),
154 kExampleEntryPath, 178 kExampleEntryPath,
155 base::Bind(&ExpectNoResultValue)); 179 mock_closure.GetCallback(),
180 mock_error_callback.GetCallback());
181 EXPECT_CALL(mock_closure, Run()).Times(1);
182 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0);
183
156 // Run the message loop. 184 // Run the message loop.
157 message_loop_.RunAllPending(); 185 message_loop_.RunAllPending();
158 } 186 }
159 187
160 } // namespace chromeos 188 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698