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