| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | |
| 6 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h" | |
| 7 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h" | |
| 8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" | |
| 9 #include "chromeos/dbus/mock_bluetooth_adapter_client.h" | 5 #include "chromeos/dbus/mock_bluetooth_adapter_client.h" |
| 10 #include "chromeos/dbus/mock_bluetooth_device_client.h" | 6 #include "chromeos/dbus/mock_bluetooth_device_client.h" |
| 11 #include "chromeos/dbus/mock_bluetooth_manager_client.h" | 7 #include "chromeos/dbus/mock_bluetooth_manager_client.h" |
| 12 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 8 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
| 13 #include "dbus/object_path.h" | 9 #include "dbus/object_path.h" |
| 10 #include "device/bluetooth/bluetooth_adapter.h" |
| 11 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
| 12 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 13 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using device::BluetoothAdapter; |
| 17 using device::BluetoothAdapterFactory; |
| 18 using device::BluetoothDevice; |
| 19 using device::MockBluetoothAdapter; |
| 16 using ::testing::_; | 20 using ::testing::_; |
| 17 using ::testing::Mock; | 21 using ::testing::Mock; |
| 18 using ::testing::Return; | 22 using ::testing::Return; |
| 19 using ::testing::SaveArg; | 23 using ::testing::SaveArg; |
| 20 | 24 |
| 21 namespace chromeos { | 25 namespace chromeos { |
| 22 | 26 |
| 23 class BluetoothAdapterDevicesChromeOsTest : public testing::Test { | 27 class BluetoothAdapterChromeOsDevicesTest : public testing::Test { |
| 24 public: | 28 public: |
| 25 virtual void SetUp() { | 29 virtual void SetUp() { |
| 26 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; | 30 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager; |
| 27 | 31 |
| 28 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) | 32 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) |
| 29 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); | 33 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); |
| 30 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | 34 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); |
| 31 | 35 |
| 32 mock_manager_client_ = | 36 mock_manager_client_ = |
| 33 mock_dbus_thread_manager->mock_bluetooth_manager_client(); | 37 mock_dbus_thread_manager->mock_bluetooth_manager_client(); |
| 34 mock_adapter_client_ = | 38 mock_adapter_client_ = |
| 35 mock_dbus_thread_manager->mock_bluetooth_adapter_client(); | 39 mock_dbus_thread_manager->mock_bluetooth_adapter_client(); |
| 36 mock_device_client_ = | 40 mock_device_client_ = |
| 37 mock_dbus_thread_manager->mock_bluetooth_device_client(); | 41 mock_dbus_thread_manager->mock_bluetooth_device_client(); |
| 38 | 42 |
| 39 // Create the default adapter instance; | 43 // Create the default adapter instance; |
| 40 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 44 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 41 // a callback to obtain the adapter path. | 45 // a callback to obtain the adapter path. |
| 42 BluetoothManagerClient::AdapterCallback adapter_callback; | 46 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 43 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 47 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 44 .WillOnce(SaveArg<0>(&adapter_callback)); | 48 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 45 | 49 |
| 46 EXPECT_CALL(*mock_manager_client_, AddObserver(_)) | 50 EXPECT_CALL(*mock_manager_client_, AddObserver(_)) |
| 47 .Times(1); | 51 .Times(1); |
| 48 EXPECT_CALL(*mock_adapter_client_, AddObserver(_)) | 52 EXPECT_CALL(*mock_adapter_client_, AddObserver(_)) |
| 49 .Times(1); | 53 .Times(1); |
| 50 | 54 |
| 51 adapter_ = BluetoothAdapterFactory::DefaultAdapter(); | 55 adapter_ = BluetoothAdapterFactory::DefaultAdapter(); |
| 56 ASSERT_TRUE(adapter_.get() != NULL); |
| 52 | 57 |
| 53 // Call the adapter callback; | 58 // Call the adapter callback; |
| 54 // BluetoothAdapterClient::GetProperties will be called once to obtain | 59 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 55 // the property set. | 60 // the property set. |
| 56 MockBluetoothAdapterClient::Properties adapter_properties; | 61 MockBluetoothAdapterClient::Properties adapter_properties; |
| 57 adapter_properties.address.ReplaceValue(adapter_address_); | 62 adapter_properties.address.ReplaceValue(adapter_address_); |
| 58 adapter_properties.powered.ReplaceValue(true); | 63 adapter_properties.powered.ReplaceValue(true); |
| 59 | 64 |
| 60 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path_)) | 65 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path_)) |
| 61 .WillRepeatedly(Return(&adapter_properties)); | 66 .WillRepeatedly(Return(&adapter_properties)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 MockBluetoothAdapterClient* mock_adapter_client_; | 101 MockBluetoothAdapterClient* mock_adapter_client_; |
| 97 MockBluetoothDeviceClient* mock_device_client_; | 102 MockBluetoothDeviceClient* mock_device_client_; |
| 98 | 103 |
| 99 static const dbus::ObjectPath adapter_path_; | 104 static const dbus::ObjectPath adapter_path_; |
| 100 static const std::string adapter_address_; | 105 static const std::string adapter_address_; |
| 101 scoped_refptr<BluetoothAdapter> adapter_; | 106 scoped_refptr<BluetoothAdapter> adapter_; |
| 102 | 107 |
| 103 MockBluetoothAdapter::Observer adapter_observer_; | 108 MockBluetoothAdapter::Observer adapter_observer_; |
| 104 }; | 109 }; |
| 105 | 110 |
| 106 const dbus::ObjectPath BluetoothAdapterDevicesChromeOsTest::adapter_path_( | 111 const dbus::ObjectPath BluetoothAdapterChromeOsDevicesTest::adapter_path_( |
| 107 "/fake/hci0"); | 112 "/fake/hci0"); |
| 108 const std::string BluetoothAdapterDevicesChromeOsTest::adapter_address_ = | 113 const std::string BluetoothAdapterChromeOsDevicesTest::adapter_address_ = |
| 109 "CA:FE:4A:C0:FE:FE"; | 114 "CA:FE:4A:C0:FE:FE"; |
| 110 | 115 |
| 111 TEST_F(BluetoothAdapterDevicesChromeOsTest, DeviceRemovedAfterFound) { | 116 TEST_F(BluetoothAdapterChromeOsDevicesTest, DeviceRemovedAfterFound) { |
| 112 const dbus::ObjectPath device_path("/fake/hci0/dev_ba_c0_11_00_00_01"); | 117 const dbus::ObjectPath device_path("/fake/hci0/dev_ba_c0_11_00_00_01"); |
| 113 const std::string device_address = "BA:C0:11:00:00:01"; | 118 const std::string device_address = "BA:C0:11:00:00:01"; |
| 114 | 119 |
| 115 MockBluetoothDeviceClient::Properties device_properties; | 120 MockBluetoothDeviceClient::Properties device_properties; |
| 116 device_properties.address.ReplaceValue(device_address); | 121 device_properties.address.ReplaceValue(device_address); |
| 117 device_properties.name.ReplaceValue("Fake Keyboard"); | 122 device_properties.name.ReplaceValue("Fake Keyboard"); |
| 118 device_properties.bluetooth_class.ReplaceValue(0x2540); | 123 device_properties.bluetooth_class.ReplaceValue(0x2540); |
| 119 | 124 |
| 120 // Inform the adapter that the device has been found; | 125 // Inform the adapter that the device has been found; |
| 121 // BluetoothAdapterClient::Observer::DeviceAdded will be called, passing | 126 // BluetoothAdapterClient::Observer::DeviceAdded will be called, passing |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 159 |
| 155 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 160 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 156 ->DeviceRemoved(adapter_path_, device_path); | 161 ->DeviceRemoved(adapter_path_, device_path); |
| 157 | 162 |
| 158 // Verify that the device is still visible, just no longer paired. | 163 // Verify that the device is still visible, just no longer paired. |
| 159 EXPECT_TRUE(device->IsVisible()); | 164 EXPECT_TRUE(device->IsVisible()); |
| 160 EXPECT_FALSE(device->IsPaired()); | 165 EXPECT_FALSE(device->IsPaired()); |
| 161 } | 166 } |
| 162 | 167 |
| 163 } // namespace chromeos | 168 } // namespace chromeos |
| OLD | NEW |