Index: chromeos/network/network_device_handler_unittest.cc |
diff --git a/chromeos/network/network_device_handler_unittest.cc b/chromeos/network/network_device_handler_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..011a7dc938a2c510f87c2912e4e7bebe996c19ba |
--- /dev/null |
+++ b/chromeos/network/network_device_handler_unittest.cc |
@@ -0,0 +1,138 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chromeos/network/network_device_handler.h" |
+ |
+#include "base/bind.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/message_loop.h" |
+#include "base/values.h" |
+#include "chromeos/dbus/dbus_thread_manager.h" |
+#include "chromeos/dbus/shill_device_client.h" |
+#include "chromeos/dbus/shill_manager_client.h" |
+#include "dbus/object_path.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "third_party/cros_system_api/dbus/service_constants.h" |
+ |
+namespace chromeos { |
+ |
+namespace { |
+ |
+class TestObserver : public NetworkDeviceHandler::Observer { |
+ public: |
+ TestObserver() : device_updates_(0) {} |
+ |
+ virtual void NetworkDevicesUpdated(const DeviceMap& devices) { |
+ ++device_updates_; |
+ } |
+ |
+ int device_updates() { return device_updates_; } |
+ |
+ private: |
+ int device_updates_; |
+}; |
+ |
+} // namespace |
+ |
+class NetworkDeviceHandlerTest : public testing::Test { |
+ public: |
+ NetworkDeviceHandlerTest() |
+ : manager_test_(NULL), |
+ device_test_(NULL) { |
+ } |
+ virtual ~NetworkDeviceHandlerTest() { |
+ } |
+ |
+ virtual void SetUp() OVERRIDE { |
+ // Initialize DBusThreadManager with a stub implementation. |
+ DBusThreadManager::InitializeWithStub(); |
+ // 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.
|
+ // default stub properties. |
+ manager_test_ = |
+ DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); |
+ ASSERT_TRUE(manager_test_); |
+ device_test_ = |
+ DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
+ ASSERT_TRUE(device_test_); |
+ } |
+ |
+ virtual void TearDown() OVERRIDE { |
+ device_handler_->RemoveObserver(observer_.get()); |
+ observer_.reset(); |
+ device_handler_.reset(); |
+ DBusThreadManager::Shutdown(); |
+ } |
+ |
+ void AddDevice(const std::string& type, const std::string& id) { |
+ manager_test_->AddDevice(id); |
+ device_test_->AddDevice(id, type, std::string("/device/" + id), "/stub"); |
+ } |
+ |
+ void RemoveDevice(const std::string& id) { |
+ manager_test_->RemoveDevice(id); |
+ device_test_->RemoveDevice(id); |
+ } |
+ |
+ // Call this after any initial Shill client setup |
+ void SetupNetworkDeviceHandler() { |
+ device_handler_.reset(new NetworkDeviceHandler()); |
+ device_handler_->Init(); |
+ observer_.reset(new TestObserver()); |
+ device_handler_->AddObserver(observer_.get()); |
+ } |
+ |
+ protected: |
+ MessageLoopForUI message_loop_; |
+ scoped_ptr<TestObserver> observer_; |
+ scoped_ptr<NetworkDeviceHandler> device_handler_; |
+ ShillManagerClient::TestInterface* manager_test_; |
+ ShillDeviceClient::TestInterface* device_test_; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandlerTest); |
+}; |
+ |
+TEST_F(NetworkDeviceHandlerTest, NetworkDeviceHandlerStub) { |
+ SetupNetworkDeviceHandler(); |
+ EXPECT_FALSE(device_handler_->devices_ready()); |
+ |
+ message_loop_.RunUntilIdle(); |
+ EXPECT_EQ(1, observer_->device_updates()); |
+ EXPECT_TRUE(device_handler_->devices_ready()); |
+ // ShillManagerClient default stub entries are in shill_manager_client.cc. |
+ // TODO(stevenjb): Eliminate default stub entries and add them explicitly. |
+ const size_t kNumShillManagerClientStubImplDevices = 2; |
+ EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
+ device_handler_->devices().size()); |
+} |
+ |
+// 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
|
+// // This relies on the stub dbus implementations for ShillManagerClient, |
+// SetupShillPropertyHandler(); |
+// message_loop_.RunUntilIdle(); |
+// EXPECT_EQ(1, listener_->manager_updates()); |
+// EXPECT_EQ(1, listener_->list_updates(flimflam::kDevicesProperty)); |
+// const size_t kNumShillManagerClientStubImplDevices = 2; |
+// EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
+// listener_->entries(flimflam::kDevicesProperty).size()); |
+// // Add a device. |
+// const std::string kTestDevicePath("test_wifi_device1"); |
+// AddDevice(flimflam::kTypeWifi, kTestDevicePath); |
+// message_loop_.RunUntilIdle(); |
+// EXPECT_EQ(1, listener_->manager_updates()); // No new manager updates. |
+// EXPECT_EQ(2, listener_->list_updates(flimflam::kDevicesProperty)); |
+// EXPECT_EQ(kNumShillManagerClientStubImplDevices + 1, |
+// listener_->entries(flimflam::kDevicesProperty).size()); |
+// // Device changes are not observed. |
+// // Remove a device |
+// RemoveDevice(kTestDevicePath); |
+// message_loop_.RunUntilIdle(); |
+// EXPECT_EQ(3, listener_->list_updates(flimflam::kDevicesProperty)); |
+// EXPECT_EQ(kNumShillManagerClientStubImplDevices, |
+// listener_->entries(flimflam::kDevicesProperty).size()); |
+ |
+// EXPECT_EQ(0, listener_->errors()); |
+// } |
+ |
+} // namespace chromeos |