OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "device/bluetooth/bluetooth_adapter.h" | 5 #include "device/bluetooth/bluetooth_adapter.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "device/bluetooth/bluetooth_device.h" | 15 #include "device/bluetooth/bluetooth_device.h" |
16 #include "device/bluetooth/bluetooth_discovery_session.h" | 16 #include "device/bluetooth/bluetooth_discovery_session.h" |
17 #include "device/bluetooth/test/bluetooth_test.h" | 17 #include "device/bluetooth/test/bluetooth_test.h" |
18 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 18 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
22 #include "device/bluetooth/test/bluetooth_test_android.h" | 22 #include "device/bluetooth/test/bluetooth_test_android.h" |
23 #elif defined(OS_MACOSX) | 23 #elif defined(OS_MACOSX) |
24 #include "device/bluetooth/test/bluetooth_test_mac.h" | 24 #include "device/bluetooth/test/bluetooth_test_mac.h" |
| 25 #elif defined(OS_WIN) |
| 26 #include "device/bluetooth/test/bluetooth_test_win.h" |
25 #endif | 27 #endif |
26 | 28 |
27 using device::BluetoothDevice; | 29 using device::BluetoothDevice; |
28 | 30 |
29 namespace device { | 31 namespace device { |
30 | 32 |
31 class TestBluetoothAdapter : public BluetoothAdapter { | 33 class TestBluetoothAdapter : public BluetoothAdapter { |
32 public: | 34 public: |
33 TestBluetoothAdapter() { | 35 TestBluetoothAdapter() { |
34 } | 36 } |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 resulting_uuids.end()); | 406 resulting_uuids.end()); |
405 | 407 |
406 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(df); | 408 resulting_filter = adapter->GetMergedDiscoveryFilterMasked(df); |
407 EXPECT_EQ(BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL, | 409 EXPECT_EQ(BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL, |
408 resulting_filter->GetTransport()); | 410 resulting_filter->GetTransport()); |
409 | 411 |
410 adapter->CleanupSessions(); | 412 adapter->CleanupSessions(); |
411 } | 413 } |
412 | 414 |
413 // TODO(scheib): Enable BluetoothTest fixture tests on all platforms. | 415 // TODO(scheib): Enable BluetoothTest fixture tests on all platforms. |
414 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 416 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
415 TEST_F(BluetoothTest, ConstructDefaultAdapter) { | 417 TEST_F(BluetoothTest, ConstructDefaultAdapter) { |
416 InitWithDefaultAdapter(); | 418 InitWithDefaultAdapter(); |
417 if (!adapter_->IsPresent()) { | 419 if (!adapter_->IsPresent()) { |
418 LOG(WARNING) << "Bluetooth adapter not present; skipping unit test."; | 420 LOG(WARNING) << "Bluetooth adapter not present; skipping unit test."; |
419 return; | 421 return; |
420 } | 422 } |
421 EXPECT_GT(adapter_->GetAddress().length(), 0u); | 423 EXPECT_GT(adapter_->GetAddress().length(), 0u); |
422 EXPECT_GT(adapter_->GetName().length(), 0u); | 424 EXPECT_GT(adapter_->GetName().length(), 0u); |
423 EXPECT_TRUE(adapter_->IsPresent()); | 425 EXPECT_TRUE(adapter_->IsPresent()); |
424 // Don't know on test machines if adapter will be powered or not, but | 426 // Don't know on test machines if adapter will be powered or not, but |
425 // the call should be safe to make and consistent. | 427 // the call should be safe to make and consistent. |
426 EXPECT_EQ(adapter_->IsPowered(), adapter_->IsPowered()); | 428 EXPECT_EQ(adapter_->IsPowered(), adapter_->IsPowered()); |
427 EXPECT_FALSE(adapter_->IsDiscoverable()); | 429 EXPECT_FALSE(adapter_->IsDiscoverable()); |
428 EXPECT_FALSE(adapter_->IsDiscovering()); | 430 EXPECT_FALSE(adapter_->IsDiscovering()); |
429 } | 431 } |
430 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 432 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
431 | 433 |
432 // TODO(scheib): Enable BluetoothTest fixture tests on all platforms. | 434 // TODO(scheib): Enable BluetoothTest fixture tests on all platforms. |
433 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 435 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
434 TEST_F(BluetoothTest, ConstructWithoutDefaultAdapter) { | 436 TEST_F(BluetoothTest, ConstructWithoutDefaultAdapter) { |
435 InitWithoutDefaultAdapter(); | 437 InitWithoutDefaultAdapter(); |
436 EXPECT_EQ(adapter_->GetAddress(), ""); | 438 EXPECT_EQ(adapter_->GetAddress(), ""); |
437 EXPECT_EQ(adapter_->GetName(), ""); | 439 EXPECT_EQ(adapter_->GetName(), ""); |
438 EXPECT_FALSE(adapter_->IsPresent()); | 440 EXPECT_FALSE(adapter_->IsPresent()); |
439 EXPECT_FALSE(adapter_->IsPowered()); | 441 EXPECT_FALSE(adapter_->IsPowered()); |
440 EXPECT_FALSE(adapter_->IsDiscoverable()); | 442 EXPECT_FALSE(adapter_->IsDiscoverable()); |
441 EXPECT_FALSE(adapter_->IsDiscovering()); | 443 EXPECT_FALSE(adapter_->IsDiscovering()); |
442 } | 444 } |
443 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 445 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
444 | 446 |
445 // TODO(scheib): Enable BluetoothTest fixture tests on all platforms. | 447 // TODO(scheib): Enable BluetoothTest fixture tests on all platforms. |
446 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 448 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
447 TEST_F(BluetoothTest, ConstructFakeAdapter) { | 449 TEST_F(BluetoothTest, ConstructFakeAdapter) { |
448 InitWithFakeAdapter(); | 450 InitWithFakeAdapter(); |
449 EXPECT_EQ(adapter_->GetAddress(), kTestAdapterAddress); | 451 EXPECT_EQ(adapter_->GetAddress(), kTestAdapterAddress); |
450 EXPECT_EQ(adapter_->GetName(), kTestAdapterName); | 452 EXPECT_EQ(adapter_->GetName(), kTestAdapterName); |
451 EXPECT_TRUE(adapter_->IsPresent()); | 453 EXPECT_TRUE(adapter_->IsPresent()); |
452 EXPECT_TRUE(adapter_->IsPowered()); | 454 EXPECT_TRUE(adapter_->IsPowered()); |
453 EXPECT_FALSE(adapter_->IsDiscoverable()); | 455 EXPECT_FALSE(adapter_->IsDiscoverable()); |
454 EXPECT_FALSE(adapter_->IsDiscovering()); | 456 EXPECT_FALSE(adapter_->IsDiscovering()); |
455 } | 457 } |
456 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 458 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
457 | 459 |
458 // TODO(scheib): Enable BluetoothTest fixture tests on all platforms. | 460 // TODO(scheib): Enable BluetoothTest fixture tests on all platforms. |
459 #if defined(OS_ANDROID) | 461 #if defined(OS_ANDROID) |
460 // Starts and Stops a discovery session. | 462 // Starts and Stops a discovery session. |
461 TEST_F(BluetoothTest, DiscoverySession) { | 463 TEST_F(BluetoothTest, DiscoverySession) { |
462 InitWithFakeAdapter(); | 464 InitWithFakeAdapter(); |
463 EXPECT_FALSE(adapter_->IsDiscovering()); | 465 EXPECT_FALSE(adapter_->IsDiscovering()); |
464 | 466 |
465 StartLowEnergyDiscoverySession(); | 467 StartLowEnergyDiscoverySession(); |
466 EXPECT_EQ(1, callback_count_); | 468 EXPECT_EQ(1, callback_count_); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 // Start discovery and find a device. | 610 // Start discovery and find a device. |
609 StartLowEnergyDiscoverySession(); | 611 StartLowEnergyDiscoverySession(); |
610 DiscoverLowEnergyDevice(1); | 612 DiscoverLowEnergyDevice(1); |
611 DiscoverLowEnergyDevice(4); | 613 DiscoverLowEnergyDevice(4); |
612 EXPECT_EQ(2, observer.device_added_count()); | 614 EXPECT_EQ(2, observer.device_added_count()); |
613 EXPECT_EQ(2u, adapter_->GetDevices().size()); | 615 EXPECT_EQ(2u, adapter_->GetDevices().size()); |
614 } | 616 } |
615 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 617 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
616 | 618 |
617 } // namespace device | 619 } // namespace device |
OLD | NEW |