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 "chrome/browser/chromeos/dbus/flimflam_client_unittest_base.h" | |
7 #include "chrome/browser/chromeos/dbus/flimflam_network_client.h" | |
8 #include "dbus/message.h" | |
9 #include "dbus/values_util.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 #include "third_party/cros_system_api/dbus/service_constants.h" | |
12 | |
13 namespace chromeos { | |
14 | |
15 class FlimflamNetworkClientTest : public FlimflamClientUnittestBase { | |
16 public: | |
17 FlimflamNetworkClientTest() | |
18 : FlimflamClientUnittestBase(flimflam::kFlimflamNetworkInterface) { | |
19 } | |
20 | |
21 virtual void SetUp() { | |
22 FlimflamClientUnittestBase::SetUp(); | |
23 // Create a client with the mock bus. | |
24 client_.reset(FlimflamNetworkClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, | |
25 mock_bus_)); | |
26 // Run the message loop to run the signal connection result callback. | |
27 message_loop_.RunAllPending(); | |
28 } | |
29 | |
30 virtual void TearDown() { | |
31 FlimflamClientUnittestBase::TearDown(); | |
32 } | |
33 | |
34 protected: | |
35 scoped_ptr<FlimflamNetworkClient> client_; | |
36 }; | |
37 | |
38 TEST_F(FlimflamNetworkClientTest, PropertyChanged) { | |
39 // Create a signal. | |
40 const base::FundamentalValue kConnected(true); | |
41 dbus::Signal signal(flimflam::kFlimflamNetworkInterface, | |
42 flimflam::kMonitorPropertyChanged); | |
43 dbus::MessageWriter writer(&signal); | |
44 writer.AppendString(flimflam::kConnectedProperty); | |
45 dbus::AppendBasicTypeValueDataAsVariant(&writer, kConnected); | |
46 | |
47 // Set expectations. | |
48 client_->SetPropertyChangedHandler(base::Bind(&ExpectPropertyChanged, | |
49 flimflam::kConnectedProperty, | |
50 &kConnected)); | |
51 // Run the signal callback. | |
52 SendPropertyChangedSignal(&signal); | |
53 | |
54 // Reset the handler. | |
55 client_->ResetPropertyChangedHandler(); | |
56 } | |
57 | |
58 TEST_F(FlimflamNetworkClientTest, GetProperties) { | |
59 const char kAddress[] = "address"; | |
60 const char kName[] = "name"; | |
61 const uint8 kSignalStrength = 1; | |
62 const uint32 kWifiChannel = 1; | |
63 const bool kConnected = true; | |
64 | |
65 // Create response. | |
66 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
67 dbus::MessageWriter writer(response.get()); | |
68 dbus::MessageWriter array_writer(NULL); | |
69 writer.OpenArray("{sv}", &array_writer); | |
70 dbus::MessageWriter entry_writer(NULL); | |
71 // Append address. | |
72 array_writer.OpenDictEntry(&entry_writer); | |
73 entry_writer.AppendString(flimflam::kAddressProperty); | |
74 entry_writer.AppendVariantOfString(kAddress); | |
75 array_writer.CloseContainer(&entry_writer); | |
76 // Append name. | |
77 array_writer.OpenDictEntry(&entry_writer); | |
78 entry_writer.AppendString(flimflam::kNameProperty); | |
79 entry_writer.AppendVariantOfString(kName); | |
80 array_writer.CloseContainer(&entry_writer); | |
81 // Append signal strength. | |
82 array_writer.OpenDictEntry(&entry_writer); | |
83 entry_writer.AppendString(flimflam::kSignalStrengthProperty); | |
84 entry_writer.AppendVariantOfByte(kSignalStrength); | |
85 array_writer.CloseContainer(&entry_writer); | |
86 // Append Wifi channel. | |
87 array_writer.OpenDictEntry(&entry_writer); | |
88 entry_writer.AppendString(flimflam::kWifiChannelProperty); | |
89 entry_writer.AppendVariantOfUint32(kWifiChannel); | |
90 array_writer.CloseContainer(&entry_writer); | |
91 // Append connected. | |
92 array_writer.OpenDictEntry(&entry_writer); | |
93 entry_writer.AppendString(flimflam::kConnectedProperty); | |
94 entry_writer.AppendVariantOfBool(kConnected); | |
95 array_writer.CloseContainer(&entry_writer); | |
96 writer.CloseContainer(&array_writer); | |
97 | |
98 // Create the expected value. | |
99 base::DictionaryValue value; | |
100 value.SetWithoutPathExpansion(flimflam::kAddressProperty, | |
101 base::Value::CreateStringValue(kAddress)); | |
102 value.SetWithoutPathExpansion(flimflam::kNameProperty, | |
103 base::Value::CreateStringValue(kName)); | |
104 value.SetWithoutPathExpansion( | |
105 flimflam::kSignalStrengthProperty, | |
106 base::Value::CreateIntegerValue(kSignalStrength)); | |
107 // WiFi.Channel is set as a double because uint32 is larger than int32. | |
108 value.SetWithoutPathExpansion(flimflam::kWifiChannelProperty, | |
109 base::Value::CreateDoubleValue(kWifiChannel)); | |
110 value.SetWithoutPathExpansion(flimflam::kConnectedProperty, | |
111 base::Value::CreateBooleanValue(kConnected)); | |
112 | |
113 // Set expectations. | |
114 PrepareForMethodCall(flimflam::kGetPropertiesFunction, | |
115 base::Bind(&ExpectNoArgument), | |
116 response.get()); | |
117 // Call method. | |
118 client_->GetProperties(base::Bind(&ExpectDictionaryValueResult, | |
119 &value)); | |
120 // Run the message loop. | |
121 message_loop_.RunAllPending(); | |
122 } | |
123 | |
124 } // namespace chromeos | |
OLD | NEW |