Chromium Code Reviews| 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; | |
|
hashimoto
2012/09/25 08:08:19
Add expectation
Greg Spencer (Chromium)
2012/09/25 18:40:08
Done.
| |
| 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()); | |
| 106 // Run the message loop. | 111 // Run the message loop. |
| 107 message_loop_.RunAllPending(); | 112 message_loop_.RunAllPending(); |
| 108 } | 113 } |
| 109 | 114 |
| 110 TEST_F(ShillProfileClientTest, GetEntry) { | 115 TEST_F(ShillProfileClientTest, GetEntry) { |
| 111 // Create response. | 116 // Create response. |
| 112 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 117 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 113 dbus::MessageWriter writer(response.get()); | 118 dbus::MessageWriter writer(response.get()); |
| 114 dbus::MessageWriter array_writer(NULL); | 119 dbus::MessageWriter array_writer(NULL); |
| 115 writer.OpenArray("{sv}", &array_writer); | 120 writer.OpenArray("{sv}", &array_writer); |
| 116 dbus::MessageWriter entry_writer(NULL); | 121 dbus::MessageWriter entry_writer(NULL); |
| 117 array_writer.OpenDictEntry(&entry_writer); | 122 array_writer.OpenDictEntry(&entry_writer); |
| 118 entry_writer.AppendString(flimflam::kTypeProperty); | 123 entry_writer.AppendString(flimflam::kTypeProperty); |
| 119 entry_writer.AppendVariantOfString(flimflam::kTypeWifi); | 124 entry_writer.AppendVariantOfString(flimflam::kTypeWifi); |
| 120 array_writer.CloseContainer(&entry_writer); | 125 array_writer.CloseContainer(&entry_writer); |
| 121 writer.CloseContainer(&array_writer); | 126 writer.CloseContainer(&array_writer); |
| 122 | 127 |
| 123 // Create the expected value. | 128 // Create the expected value. |
| 124 base::DictionaryValue value; | 129 base::DictionaryValue value; |
| 125 value.SetWithoutPathExpansion( | 130 value.SetWithoutPathExpansion( |
| 126 flimflam::kTypeProperty, | 131 flimflam::kTypeProperty, |
| 127 base::Value::CreateStringValue(flimflam::kTypeWifi)); | 132 base::Value::CreateStringValue(flimflam::kTypeWifi)); |
| 128 // Set expectations. | 133 // Set expectations. |
| 129 PrepareForMethodCall(flimflam::kGetEntryFunction, | 134 PrepareForMethodCall(flimflam::kGetEntryFunction, |
| 130 base::Bind(&ExpectStringArgument, kExampleEntryPath), | 135 base::Bind(&ExpectStringArgument, kExampleEntryPath), |
| 131 response.get()); | 136 response.get()); |
| 132 // Call method. | 137 // Call method. |
| 138 MockErrorCallback error_callback; | |
| 133 client_->GetEntry(dbus::ObjectPath(kDefaultProfilePath), | 139 client_->GetEntry(dbus::ObjectPath(kDefaultProfilePath), |
| 134 kExampleEntryPath, | 140 kExampleEntryPath, |
| 135 base::Bind(&ExpectDictionaryValueResult, &value)); | 141 base::Bind(&ExpectDictionaryValueResultWithoutStatus, |
| 142 &value), | |
| 143 error_callback.GetCallback()); | |
| 144 EXPECT_CALL(error_callback, Run(_, _)).Times(0); | |
| 136 // Run the message loop. | 145 // Run the message loop. |
| 137 message_loop_.RunAllPending(); | 146 message_loop_.RunAllPending(); |
| 138 } | 147 } |
| 139 | 148 |
| 140 TEST_F(ShillProfileClientTest, DeleteEntry) { | 149 TEST_F(ShillProfileClientTest, DeleteEntry) { |
| 141 // Create response. | 150 // Create response. |
| 142 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 151 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 143 | 152 |
| 144 // Create the expected value. | 153 // Create the expected value. |
| 145 base::DictionaryValue value; | 154 base::DictionaryValue value; |
| 146 value.SetWithoutPathExpansion(flimflam::kOfflineModeProperty, | 155 value.SetWithoutPathExpansion(flimflam::kOfflineModeProperty, |
| 147 base::Value::CreateBooleanValue(true)); | 156 base::Value::CreateBooleanValue(true)); |
| 148 // Set expectations. | 157 // Set expectations. |
| 149 PrepareForMethodCall(flimflam::kDeleteEntryFunction, | 158 PrepareForMethodCall(flimflam::kDeleteEntryFunction, |
| 150 base::Bind(&ExpectStringArgument, kExampleEntryPath), | 159 base::Bind(&ExpectStringArgument, kExampleEntryPath), |
| 151 response.get()); | 160 response.get()); |
| 152 // Call method. | 161 // Call method. |
| 162 MockClosure mock_closure; | |
| 163 MockErrorCallback mock_error_callback; | |
| 153 client_->DeleteEntry(dbus::ObjectPath(kDefaultProfilePath), | 164 client_->DeleteEntry(dbus::ObjectPath(kDefaultProfilePath), |
| 154 kExampleEntryPath, | 165 kExampleEntryPath, |
| 155 base::Bind(&ExpectNoResultValue)); | 166 mock_closure.GetCallback(), |
| 167 mock_error_callback.GetCallback()); | |
| 168 EXPECT_CALL(mock_closure, Run()).Times(1); | |
| 169 EXPECT_CALL(mock_error_callback, Run(_, _)).Times(0); | |
| 170 | |
| 156 // Run the message loop. | 171 // Run the message loop. |
| 157 message_loop_.RunAllPending(); | 172 message_loop_.RunAllPending(); |
| 158 } | 173 } |
| 159 | 174 |
| 160 } // namespace chromeos | 175 } // namespace chromeos |
| OLD | NEW |