Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Side by Side Diff: chromeos/network/network_device_handler_unittest.cc

Issue 11743006: Add NetworkDeviceHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "chromeos/network/network_device_handler.h"
6
7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h"
10 #include "base/values.h"
11 #include "chromeos/dbus/dbus_thread_manager.h"
12 #include "chromeos/dbus/shill_device_client.h"
13 #include "chromeos/dbus/shill_manager_client.h"
14 #include "dbus/object_path.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h"
17
18 namespace chromeos {
19
20 namespace {
21
22 class TestObserver : public NetworkDeviceHandler::Observer {
23 public:
24 TestObserver() : device_updates_(0) {}
25
26 virtual void NetworkDevicesUpdated(const DeviceMap& devices) {
27 ++device_updates_;
28 }
29
30 int device_updates() { return device_updates_; }
31
32 private:
33 int device_updates_;
34 };
35
36 } // namespace
37
38 class NetworkDeviceHandlerTest : public testing::Test {
39 public:
40 NetworkDeviceHandlerTest()
41 : manager_test_(NULL),
42 device_test_(NULL) {
43 }
44 virtual ~NetworkDeviceHandlerTest() {
45 }
46
47 virtual void SetUp() OVERRIDE {
48 // Initialize DBusThreadManager with a stub implementation.
49 DBusThreadManager::InitializeWithStub();
50 // Get the test interface for manager / device / service and clear the
Greg Spencer (Chromium) 2013/01/04 23:57:26 I don't see you clearing the default properties.
stevenjb 2013/01/07 15:56:22 Comment was copy/pasted from another test; fixed.
51 // default stub properties.
52 manager_test_ =
53 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface();
54 ASSERT_TRUE(manager_test_);
55 device_test_ =
56 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
57 ASSERT_TRUE(device_test_);
58 }
59
60 virtual void TearDown() OVERRIDE {
61 device_handler_->RemoveObserver(observer_.get());
62 observer_.reset();
63 device_handler_.reset();
64 DBusThreadManager::Shutdown();
65 }
66
67 void AddDevice(const std::string& type, const std::string& id) {
68 manager_test_->AddDevice(id);
69 device_test_->AddDevice(id, type, std::string("/device/" + id), "/stub");
70 }
71
72 void RemoveDevice(const std::string& id) {
73 manager_test_->RemoveDevice(id);
74 device_test_->RemoveDevice(id);
75 }
76
77 // Call this after any initial Shill client setup
78 void SetupNetworkDeviceHandler() {
79 device_handler_.reset(new NetworkDeviceHandler());
80 device_handler_->Init();
81 observer_.reset(new TestObserver());
82 device_handler_->AddObserver(observer_.get());
83 }
84
85 protected:
86 MessageLoopForUI message_loop_;
87 scoped_ptr<TestObserver> observer_;
88 scoped_ptr<NetworkDeviceHandler> device_handler_;
89 ShillManagerClient::TestInterface* manager_test_;
90 ShillDeviceClient::TestInterface* device_test_;
91
92 private:
93 DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandlerTest);
94 };
95
96 TEST_F(NetworkDeviceHandlerTest, NetworkDeviceHandlerStub) {
97 SetupNetworkDeviceHandler();
98 EXPECT_FALSE(device_handler_->devices_ready());
99
100 message_loop_.RunUntilIdle();
101 EXPECT_EQ(1, observer_->device_updates());
102 EXPECT_TRUE(device_handler_->devices_ready());
103 // ShillManagerClient default stub entries are in shill_manager_client.cc.
104 // TODO(stevenjb): Eliminate default stub entries and add them explicitly.
105 const size_t kNumShillManagerClientStubImplDevices = 2;
106 EXPECT_EQ(kNumShillManagerClientStubImplDevices,
107 device_handler_->devices().size());
108 }
109
110 // TEST_F(ShillPropertyHandlerTest, ShillPropertyHandlerDevicePropertyChanged) {
Greg Spencer (Chromium) 2013/01/04 23:57:26 Don't check in commented out code.
stevenjb 2013/01/07 15:56:22 Oops, juggling too many CLs. Implemented this test
111 // // This relies on the stub dbus implementations for ShillManagerClient,
112 // SetupShillPropertyHandler();
113 // message_loop_.RunUntilIdle();
114 // EXPECT_EQ(1, listener_->manager_updates());
115 // EXPECT_EQ(1, listener_->list_updates(flimflam::kDevicesProperty));
116 // const size_t kNumShillManagerClientStubImplDevices = 2;
117 // EXPECT_EQ(kNumShillManagerClientStubImplDevices,
118 // listener_->entries(flimflam::kDevicesProperty).size());
119 // // Add a device.
120 // const std::string kTestDevicePath("test_wifi_device1");
121 // AddDevice(flimflam::kTypeWifi, kTestDevicePath);
122 // message_loop_.RunUntilIdle();
123 // EXPECT_EQ(1, listener_->manager_updates()); // No new manager updates.
124 // EXPECT_EQ(2, listener_->list_updates(flimflam::kDevicesProperty));
125 // EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1,
126 // listener_->entries(flimflam::kDevicesProperty).size());
127 // // Device changes are not observed.
128 // // Remove a device
129 // RemoveDevice(kTestDevicePath);
130 // message_loop_.RunUntilIdle();
131 // EXPECT_EQ(3, listener_->list_updates(flimflam::kDevicesProperty));
132 // EXPECT_EQ(kNumShillManagerClientStubImplDevices,
133 // listener_->entries(flimflam::kDevicesProperty).size());
134
135 // EXPECT_EQ(0, listener_->errors());
136 // }
137
138 } // namespace chromeos
OLDNEW
« chromeos/network/network_device_handler.cc ('K') | « chromeos/network/network_device_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698