OLD | NEW |
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // Create the expected value. | 96 // Create the expected value. |
95 base::ListValue* entries = new base::ListValue; | 97 base::ListValue* entries = new base::ListValue; |
96 entries->Append(base::Value::CreateStringValue(kExampleEntryPath)); | 98 entries->Append(base::Value::CreateStringValue(kExampleEntryPath)); |
97 base::DictionaryValue value; | 99 base::DictionaryValue value; |
98 value.SetWithoutPathExpansion(flimflam::kEntriesProperty, entries); | 100 value.SetWithoutPathExpansion(flimflam::kEntriesProperty, entries); |
99 // Set expectations. | 101 // Set expectations. |
100 PrepareForMethodCall(flimflam::kGetPropertiesFunction, | 102 PrepareForMethodCall(flimflam::kGetPropertiesFunction, |
101 base::Bind(&ExpectNoArgument), | 103 base::Bind(&ExpectNoArgument), |
102 response.get()); | 104 response.get()); |
103 // Call method. | 105 // Call method. |
| 106 MockErrorCallback error_callback; |
104 client_->GetProperties(dbus::ObjectPath(kDefaultProfilePath), | 107 client_->GetProperties(dbus::ObjectPath(kDefaultProfilePath), |
105 base::Bind(&ExpectDictionaryValueResult, &value)); | 108 base::Bind(&ExpectDictionaryValueResultWithoutStatus, |
| 109 &value), |
| 110 error_callback.GetCallback()); |
| 111 EXPECT_CALL(error_callback, Run(_, _)).Times(0); |
| 112 |
106 // Run the message loop. | 113 // Run the message loop. |
107 message_loop_.RunAllPending(); | 114 message_loop_.RunAllPending(); |
108 } | 115 } |
109 | 116 |
110 TEST_F(ShillProfileClientTest, GetEntry) { | 117 TEST_F(ShillProfileClientTest, GetEntry) { |
111 // Create response. | 118 // Create response. |
112 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 119 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
113 dbus::MessageWriter writer(response.get()); | 120 dbus::MessageWriter writer(response.get()); |
114 dbus::MessageWriter array_writer(NULL); | 121 dbus::MessageWriter array_writer(NULL); |
115 writer.OpenArray("{sv}", &array_writer); | 122 writer.OpenArray("{sv}", &array_writer); |
116 dbus::MessageWriter entry_writer(NULL); | 123 dbus::MessageWriter entry_writer(NULL); |
117 array_writer.OpenDictEntry(&entry_writer); | 124 array_writer.OpenDictEntry(&entry_writer); |
118 entry_writer.AppendString(flimflam::kTypeProperty); | 125 entry_writer.AppendString(flimflam::kTypeProperty); |
119 entry_writer.AppendVariantOfString(flimflam::kTypeWifi); | 126 entry_writer.AppendVariantOfString(flimflam::kTypeWifi); |
120 array_writer.CloseContainer(&entry_writer); | 127 array_writer.CloseContainer(&entry_writer); |
121 writer.CloseContainer(&array_writer); | 128 writer.CloseContainer(&array_writer); |
122 | 129 |
123 // Create the expected value. | 130 // Create the expected value. |
124 base::DictionaryValue value; | 131 base::DictionaryValue value; |
125 value.SetWithoutPathExpansion( | 132 value.SetWithoutPathExpansion( |
126 flimflam::kTypeProperty, | 133 flimflam::kTypeProperty, |
127 base::Value::CreateStringValue(flimflam::kTypeWifi)); | 134 base::Value::CreateStringValue(flimflam::kTypeWifi)); |
128 // Set expectations. | 135 // Set expectations. |
129 PrepareForMethodCall(flimflam::kGetEntryFunction, | 136 PrepareForMethodCall(flimflam::kGetEntryFunction, |
130 base::Bind(&ExpectStringArgument, kExampleEntryPath), | 137 base::Bind(&ExpectStringArgument, kExampleEntryPath), |
131 response.get()); | 138 response.get()); |
132 // Call method. | 139 // Call method. |
| 140 MockErrorCallback error_callback; |
133 client_->GetEntry(dbus::ObjectPath(kDefaultProfilePath), | 141 client_->GetEntry(dbus::ObjectPath(kDefaultProfilePath), |
134 kExampleEntryPath, | 142 kExampleEntryPath, |
135 base::Bind(&ExpectDictionaryValueResult, &value)); | 143 base::Bind(&ExpectDictionaryValueResultWithoutStatus, |
| 144 &value), |
| 145 error_callback.GetCallback()); |
| 146 EXPECT_CALL(error_callback, Run(_, _)).Times(0); |
136 // Run the message loop. | 147 // Run the message loop. |
137 message_loop_.RunAllPending(); | 148 message_loop_.RunAllPending(); |
138 } | 149 } |
139 | 150 |
140 TEST_F(ShillProfileClientTest, DeleteEntry) { | 151 TEST_F(ShillProfileClientTest, DeleteEntry) { |
141 // Create response. | 152 // Create response. |
142 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 153 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
143 | 154 |
144 // Create the expected value. | 155 // Create the expected value. |
145 base::DictionaryValue value; | 156 base::DictionaryValue value; |
146 value.SetWithoutPathExpansion(flimflam::kOfflineModeProperty, | 157 value.SetWithoutPathExpansion(flimflam::kOfflineModeProperty, |
147 base::Value::CreateBooleanValue(true)); | 158 base::Value::CreateBooleanValue(true)); |
148 // Set expectations. | 159 // Set expectations. |
149 PrepareForMethodCall(flimflam::kDeleteEntryFunction, | 160 PrepareForMethodCall(flimflam::kDeleteEntryFunction, |
150 base::Bind(&ExpectStringArgument, kExampleEntryPath), | 161 base::Bind(&ExpectStringArgument, kExampleEntryPath), |
151 response.get()); | 162 response.get()); |
152 // Call method. | 163 // Call method. |
| 164 MockClosure mock_closure; |
| 165 MockErrorCallback mock_error_callback; |
153 client_->DeleteEntry(dbus::ObjectPath(kDefaultProfilePath), | 166 client_->DeleteEntry(dbus::ObjectPath(kDefaultProfilePath), |
154 kExampleEntryPath, | 167 kExampleEntryPath, |
155 base::Bind(&ExpectNoResultValue)); | 168 mock_closure.GetCallback(), |
| 169 mock_error_callback.GetCallback()); |
| 170 EXPECT_CALL(mock_closure, Run()).Times(1); |
| 171 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); |
| 172 |
156 // Run the message loop. | 173 // Run the message loop. |
157 message_loop_.RunAllPending(); | 174 message_loop_.RunAllPending(); |
158 } | 175 } |
159 | 176 |
160 } // namespace chromeos | 177 } // namespace chromeos |
OLD | NEW |