OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chromeos/chromeos_switches.h" | 8 #include "chromeos/chromeos_switches.h" |
9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
10 #include "chromeos/dbus/fake_bluetooth_device_client.h" | 10 #include "chromeos/dbus/fake_bluetooth_device_client.h" |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 EXPECT_EQ(0, error_callback_count_); | 874 EXPECT_EQ(0, error_callback_count_); |
875 | 875 |
876 EXPECT_EQ(1, observer.device_removed_count_); | 876 EXPECT_EQ(1, observer.device_removed_count_); |
877 EXPECT_EQ(address, observer.last_device_address_); | 877 EXPECT_EQ(address, observer.last_device_address_); |
878 | 878 |
879 // GetDevices shouldn't return the device either. | 879 // GetDevices shouldn't return the device either. |
880 devices = adapter_->GetDevices(); | 880 devices = adapter_->GetDevices(); |
881 ASSERT_EQ(0U, devices.size()); | 881 ASSERT_EQ(0U, devices.size()); |
882 } | 882 } |
883 | 883 |
| 884 TEST_F(BluetoothExperimentalChromeOSTest, ForgetUnpairedDevice) { |
| 885 GetAdapter(); |
| 886 DiscoverDevices(); |
| 887 |
| 888 BluetoothDevice* device = adapter_->GetDevice( |
| 889 FakeBluetoothDeviceClient::kMicrosoftMouseAddress); |
| 890 ASSERT_TRUE(device != NULL); |
| 891 ASSERT_FALSE(device->IsPaired()); |
| 892 |
| 893 // Connect the device so it becomes trusted and remembered. |
| 894 device->Connect( |
| 895 NULL, |
| 896 base::Bind(&BluetoothExperimentalChromeOSTest::Callback, |
| 897 base::Unretained(this)), |
| 898 base::Bind(&BluetoothExperimentalChromeOSTest::ConnectErrorCallback, |
| 899 base::Unretained(this))); |
| 900 |
| 901 ASSERT_EQ(1, callback_count_); |
| 902 ASSERT_EQ(0, error_callback_count_); |
| 903 callback_count_ = 0; |
| 904 |
| 905 ASSERT_TRUE(device->IsConnected()); |
| 906 ASSERT_FALSE(device->IsConnecting()); |
| 907 |
| 908 // Make sure the trusted property has been set to true. |
| 909 FakeBluetoothDeviceClient::Properties* properties = |
| 910 fake_bluetooth_device_client_->GetProperties( |
| 911 dbus::ObjectPath(FakeBluetoothDeviceClient::kMicrosoftMousePath)); |
| 912 ASSERT_TRUE(properties->trusted.value()); |
| 913 |
| 914 // Install an observer; expect the DeviceRemoved method to be called |
| 915 // with the device we remove. |
| 916 TestObserver observer(adapter_); |
| 917 adapter_->AddObserver(&observer); |
| 918 |
| 919 device->Forget( |
| 920 base::Bind(&BluetoothExperimentalChromeOSTest::ErrorCallback, |
| 921 base::Unretained(this))); |
| 922 EXPECT_EQ(0, error_callback_count_); |
| 923 |
| 924 EXPECT_EQ(1, observer.device_removed_count_); |
| 925 EXPECT_EQ(FakeBluetoothDeviceClient::kMicrosoftMouseAddress, |
| 926 observer.last_device_address_); |
| 927 |
| 928 // GetDevices shouldn't return the device either. |
| 929 device = adapter_->GetDevice( |
| 930 FakeBluetoothDeviceClient::kMicrosoftMouseAddress); |
| 931 EXPECT_FALSE(device != NULL); |
| 932 } |
| 933 |
884 TEST_F(BluetoothExperimentalChromeOSTest, ConnectPairedDevice) { | 934 TEST_F(BluetoothExperimentalChromeOSTest, ConnectPairedDevice) { |
885 GetAdapter(); | 935 GetAdapter(); |
886 | 936 |
887 BluetoothDevice* device = adapter_->GetDevice( | 937 BluetoothDevice* device = adapter_->GetDevice( |
888 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 938 FakeBluetoothDeviceClient::kPairedDeviceAddress); |
889 ASSERT_TRUE(device != NULL); | 939 ASSERT_TRUE(device != NULL); |
890 ASSERT_TRUE(device->IsPaired()); | 940 ASSERT_TRUE(device->IsPaired()); |
891 | 941 |
892 TestObserver observer(adapter_); | 942 TestObserver observer(adapter_); |
893 adapter_->AddObserver(&observer); | 943 adapter_->AddObserver(&observer); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 base::Unretained(this))); | 983 base::Unretained(this))); |
934 | 984 |
935 EXPECT_EQ(1, callback_count_); | 985 EXPECT_EQ(1, callback_count_); |
936 EXPECT_EQ(0, error_callback_count_); | 986 EXPECT_EQ(0, error_callback_count_); |
937 | 987 |
938 EXPECT_EQ(1, observer.device_changed_count_); | 988 EXPECT_EQ(1, observer.device_changed_count_); |
939 EXPECT_EQ(device, observer.last_device_); | 989 EXPECT_EQ(device, observer.last_device_); |
940 | 990 |
941 EXPECT_TRUE(device->IsConnected()); | 991 EXPECT_TRUE(device->IsConnected()); |
942 EXPECT_FALSE(device->IsConnecting()); | 992 EXPECT_FALSE(device->IsConnecting()); |
| 993 |
| 994 // Make sure the trusted property has been set to true. |
| 995 FakeBluetoothDeviceClient::Properties* properties = |
| 996 fake_bluetooth_device_client_->GetProperties( |
| 997 dbus::ObjectPath(FakeBluetoothDeviceClient::kMicrosoftMousePath)); |
| 998 EXPECT_TRUE(properties->trusted.value()); |
943 } | 999 } |
944 | 1000 |
945 TEST_F(BluetoothExperimentalChromeOSTest, ConnectConnectedDevice) { | 1001 TEST_F(BluetoothExperimentalChromeOSTest, ConnectConnectedDevice) { |
946 GetAdapter(); | 1002 GetAdapter(); |
947 | 1003 |
948 BluetoothDevice* device = adapter_->GetDevice( | 1004 BluetoothDevice* device = adapter_->GetDevice( |
949 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 1005 FakeBluetoothDeviceClient::kPairedDeviceAddress); |
950 ASSERT_TRUE(device != NULL); | 1006 ASSERT_TRUE(device != NULL); |
951 ASSERT_TRUE(device->IsPaired()); | 1007 ASSERT_TRUE(device->IsPaired()); |
952 | 1008 |
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1839 EXPECT_FALSE(device->IsConnected()); | 1895 EXPECT_FALSE(device->IsConnected()); |
1840 EXPECT_FALSE(device->IsConnecting()); | 1896 EXPECT_FALSE(device->IsConnecting()); |
1841 EXPECT_FALSE(device->IsPaired()); | 1897 EXPECT_FALSE(device->IsPaired()); |
1842 | 1898 |
1843 // Pairing dialog should be dismissed | 1899 // Pairing dialog should be dismissed |
1844 EXPECT_EQ(1, pairing_delegate.call_count_); | 1900 EXPECT_EQ(1, pairing_delegate.call_count_); |
1845 EXPECT_EQ(1, pairing_delegate.dismiss_count_); | 1901 EXPECT_EQ(1, pairing_delegate.dismiss_count_); |
1846 } | 1902 } |
1847 | 1903 |
1848 } // namespace chromeos | 1904 } // namespace chromeos |
OLD | NEW |