OLD | NEW |
(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 "chromeos/dbus/flimflam_client_unittest_base.h" |
| 7 #include "chromeos/dbus/flimflam_profile_client.h" |
| 8 #include "dbus/message.h" |
| 9 #include "dbus/object_path.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 namespace chromeos { |
| 15 |
| 16 namespace { |
| 17 |
| 18 const char kDefaultProfilePath[] = "/profile/default"; |
| 19 const char kExampleEntryPath[] = "example_entry_path"; |
| 20 |
| 21 void AppendVariantOfArrayOfStrings(dbus::MessageWriter* writer, |
| 22 const std::vector<std::string>& strings) { |
| 23 dbus::MessageWriter variant_writer(NULL); |
| 24 writer->OpenVariant("as", &variant_writer); |
| 25 variant_writer.AppendArrayOfStrings(strings); |
| 26 writer->CloseContainer(&variant_writer); |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
| 31 class FlimflamProfileClientTest : public FlimflamClientUnittestBase { |
| 32 public: |
| 33 FlimflamProfileClientTest() |
| 34 : FlimflamClientUnittestBase(flimflam::kFlimflamProfileInterface, |
| 35 dbus::ObjectPath(kDefaultProfilePath)) { |
| 36 } |
| 37 |
| 38 virtual void SetUp() { |
| 39 FlimflamClientUnittestBase::SetUp(); |
| 40 // Create a client with the mock bus. |
| 41 client_.reset(FlimflamProfileClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, |
| 42 mock_bus_)); |
| 43 // Run the message loop to run the signal connection result callback. |
| 44 message_loop_.RunAllPending(); |
| 45 } |
| 46 |
| 47 virtual void TearDown() { |
| 48 FlimflamClientUnittestBase::TearDown(); |
| 49 } |
| 50 |
| 51 protected: |
| 52 scoped_ptr<FlimflamProfileClient> client_; |
| 53 }; |
| 54 |
| 55 TEST_F(FlimflamProfileClientTest, PropertyChanged) { |
| 56 // Create a signal. |
| 57 dbus::Signal signal(flimflam::kFlimflamProfileInterface, |
| 58 flimflam::kMonitorPropertyChanged); |
| 59 dbus::MessageWriter writer(&signal); |
| 60 writer.AppendString(flimflam::kEntriesProperty); |
| 61 AppendVariantOfArrayOfStrings(&writer, |
| 62 std::vector<std::string>(1, kExampleEntryPath)); |
| 63 |
| 64 // Set expectations. |
| 65 base::ListValue* value = new base::ListValue; |
| 66 value->Append(base::Value::CreateStringValue(kExampleEntryPath)); |
| 67 |
| 68 client_->SetPropertyChangedHandler(dbus::ObjectPath(kDefaultProfilePath), |
| 69 base::Bind(&ExpectPropertyChanged, |
| 70 flimflam::kEntriesProperty, |
| 71 value)); |
| 72 // Run the signal callback. |
| 73 SendPropertyChangedSignal(&signal); |
| 74 |
| 75 // Reset the handler. |
| 76 client_->ResetPropertyChangedHandler(dbus::ObjectPath(kDefaultProfilePath)); |
| 77 } |
| 78 |
| 79 TEST_F(FlimflamProfileClientTest, GetProperties) { |
| 80 // Create response. |
| 81 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 82 dbus::MessageWriter writer(response.get()); |
| 83 dbus::MessageWriter array_writer(NULL); |
| 84 writer.OpenArray("{sv}", &array_writer); |
| 85 dbus::MessageWriter entry_writer(NULL); |
| 86 array_writer.OpenDictEntry(&entry_writer); |
| 87 entry_writer.AppendString(flimflam::kEntriesProperty); |
| 88 AppendVariantOfArrayOfStrings(&entry_writer, |
| 89 std::vector<std::string>(1, kExampleEntryPath)); |
| 90 array_writer.CloseContainer(&entry_writer); |
| 91 writer.CloseContainer(&array_writer); |
| 92 |
| 93 // Create the expected value. |
| 94 base::ListValue* entries = new base::ListValue; |
| 95 entries->Append(base::Value::CreateStringValue(kExampleEntryPath)); |
| 96 base::DictionaryValue value; |
| 97 value.SetWithoutPathExpansion(flimflam::kEntriesProperty, entries); |
| 98 // Set expectations. |
| 99 PrepareForMethodCall(flimflam::kGetPropertiesFunction, |
| 100 base::Bind(&ExpectNoArgument), |
| 101 response.get()); |
| 102 // Call method. |
| 103 client_->GetProperties(dbus::ObjectPath(kDefaultProfilePath), |
| 104 base::Bind(&ExpectDictionaryValueResult, &value)); |
| 105 // Run the message loop. |
| 106 message_loop_.RunAllPending(); |
| 107 } |
| 108 |
| 109 TEST_F(FlimflamProfileClientTest, GetEntry) { |
| 110 // Create response. |
| 111 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 112 dbus::MessageWriter writer(response.get()); |
| 113 dbus::MessageWriter array_writer(NULL); |
| 114 writer.OpenArray("{sv}", &array_writer); |
| 115 dbus::MessageWriter entry_writer(NULL); |
| 116 array_writer.OpenDictEntry(&entry_writer); |
| 117 entry_writer.AppendString(flimflam::kTypeProperty); |
| 118 entry_writer.AppendVariantOfString(flimflam::kTypeWifi); |
| 119 array_writer.CloseContainer(&entry_writer); |
| 120 writer.CloseContainer(&array_writer); |
| 121 |
| 122 // Create the expected value. |
| 123 base::DictionaryValue value; |
| 124 value.SetWithoutPathExpansion( |
| 125 flimflam::kTypeProperty, |
| 126 base::Value::CreateStringValue(flimflam::kTypeWifi)); |
| 127 // Set expectations. |
| 128 PrepareForMethodCall(flimflam::kGetEntryFunction, |
| 129 base::Bind(&ExpectStringArgument, kExampleEntryPath), |
| 130 response.get()); |
| 131 // Call method. |
| 132 client_->GetEntry(dbus::ObjectPath(kDefaultProfilePath), |
| 133 kExampleEntryPath, |
| 134 base::Bind(&ExpectDictionaryValueResult, &value)); |
| 135 // Run the message loop. |
| 136 message_loop_.RunAllPending(); |
| 137 } |
| 138 |
| 139 TEST_F(FlimflamProfileClientTest, DeleteEntry) { |
| 140 // Create response. |
| 141 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 142 |
| 143 // Create the expected value. |
| 144 base::DictionaryValue value; |
| 145 value.SetWithoutPathExpansion(flimflam::kOfflineModeProperty, |
| 146 base::Value::CreateBooleanValue(true)); |
| 147 // Set expectations. |
| 148 PrepareForMethodCall(flimflam::kDeleteEntryFunction, |
| 149 base::Bind(&ExpectStringArgument, kExampleEntryPath), |
| 150 response.get()); |
| 151 // Call method. |
| 152 client_->DeleteEntry(dbus::ObjectPath(kDefaultProfilePath), |
| 153 kExampleEntryPath, |
| 154 base::Bind(&ExpectNoResultValue)); |
| 155 // Run the message loop. |
| 156 message_loop_.RunAllPending(); |
| 157 } |
| 158 |
| 159 } // namespace chromeos |
OLD | NEW |