| 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 <string.h> | 5 #include <string.h> |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
| 10 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 10 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
| 11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
| 12 #include "chrome/browser/extensions/extension_function_test_utils.h" | 12 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_test_message_listener.h" | 14 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "device/bluetooth/bluetooth_adapter.h" | 17 #include "device/bluetooth/bluetooth_adapter.h" |
| 18 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | 18 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
| 19 #include "device/bluetooth/bluetooth_uuid.h" | |
| 20 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 19 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 21 #include "device/bluetooth/test/mock_bluetooth_device.h" | 20 #include "device/bluetooth/test/mock_bluetooth_device.h" |
| 22 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" | 21 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" |
| 23 #include "device/bluetooth/test/mock_bluetooth_profile.h" | 22 #include "device/bluetooth/test/mock_bluetooth_profile.h" |
| 24 #include "device/bluetooth/test/mock_bluetooth_socket.h" | 23 #include "device/bluetooth/test/mock_bluetooth_socket.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 26 | 25 |
| 27 using device::BluetoothAdapter; | 26 using device::BluetoothAdapter; |
| 28 using device::BluetoothDevice; | 27 using device::BluetoothDevice; |
| 29 using device::BluetoothDiscoverySession; | 28 using device::BluetoothDiscoverySession; |
| 30 using device::BluetoothOutOfBandPairingData; | 29 using device::BluetoothOutOfBandPairingData; |
| 31 using device::BluetoothProfile; | 30 using device::BluetoothProfile; |
| 32 using device::BluetoothUUID; | |
| 33 using device::MockBluetoothAdapter; | 31 using device::MockBluetoothAdapter; |
| 34 using device::MockBluetoothDevice; | 32 using device::MockBluetoothDevice; |
| 35 using device::MockBluetoothDiscoverySession; | 33 using device::MockBluetoothDiscoverySession; |
| 36 using device::MockBluetoothProfile; | 34 using device::MockBluetoothProfile; |
| 37 using extensions::Extension; | 35 using extensions::Extension; |
| 38 | 36 |
| 39 namespace utils = extension_function_test_utils; | 37 namespace utils = extension_function_test_utils; |
| 40 namespace api = extensions::api; | 38 namespace api = extensions::api; |
| 41 | 39 |
| 42 namespace { | 40 namespace { |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 // Load and wait for setup | 553 // Load and wait for setup |
| 556 ExtensionTestMessageListener listener("ready", true); | 554 ExtensionTestMessageListener listener("ready", true); |
| 557 scoped_refptr<const Extension> extension( | 555 scoped_refptr<const Extension> extension( |
| 558 LoadExtension(test_data_dir_.AppendASCII("bluetooth/on_connection"))); | 556 LoadExtension(test_data_dir_.AppendASCII("bluetooth/on_connection"))); |
| 559 ASSERT_TRUE(extension.get()); | 557 ASSERT_TRUE(extension.get()); |
| 560 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 558 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 561 | 559 |
| 562 scoped_refptr<device::MockBluetoothSocket> socket = | 560 scoped_refptr<device::MockBluetoothSocket> socket = |
| 563 new device::MockBluetoothSocket(); | 561 new device::MockBluetoothSocket(); |
| 564 | 562 |
| 565 event_router()->AddProfile( | 563 event_router()->AddProfile("1234", extension->id(), profile1_.get()); |
| 566 BluetoothUUID("1234"), | |
| 567 extension->id(), profile1_.get()); | |
| 568 event_router()->DispatchConnectionEvent( | 564 event_router()->DispatchConnectionEvent( |
| 569 extension->id(), BluetoothUUID("1234"), device1_.get(), socket); | 565 extension->id(), "1234", device1_.get(), socket); |
| 570 | 566 |
| 571 listener.Reply("go"); | 567 listener.Reply("go"); |
| 572 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 568 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 573 event_router()->RemoveProfile(BluetoothUUID("1234")); | 569 event_router()->RemoveProfile("1234"); |
| 574 } | 570 } |
| 575 | 571 |
| 576 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { | 572 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { |
| 577 ResultCatcher catcher; | 573 ResultCatcher catcher; |
| 578 catcher.RestrictToProfile(browser()->profile()); | 574 catcher.RestrictToProfile(browser()->profile()); |
| 579 | 575 |
| 580 BluetoothAdapter::ConstDeviceList devices; | 576 BluetoothAdapter::ConstDeviceList devices; |
| 581 devices.push_back(device1_.get()); | 577 devices.push_back(device1_.get()); |
| 582 devices.push_back(device2_.get()); | 578 devices.push_back(device2_.get()); |
| 583 | 579 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 EXPECT_CALL(*device1_.get(), GetVendorIDSource()) | 633 EXPECT_CALL(*device1_.get(), GetVendorIDSource()) |
| 638 .WillRepeatedly(testing::Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); | 634 .WillRepeatedly(testing::Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); |
| 639 EXPECT_CALL(*device1_.get(), GetVendorID()) | 635 EXPECT_CALL(*device1_.get(), GetVendorID()) |
| 640 .WillRepeatedly(testing::Return(0x00E0)); | 636 .WillRepeatedly(testing::Return(0x00E0)); |
| 641 EXPECT_CALL(*device1_.get(), GetProductID()) | 637 EXPECT_CALL(*device1_.get(), GetProductID()) |
| 642 .WillRepeatedly(testing::Return(0x240A)); | 638 .WillRepeatedly(testing::Return(0x240A)); |
| 643 EXPECT_CALL(*device1_.get(), GetDeviceID()) | 639 EXPECT_CALL(*device1_.get(), GetDeviceID()) |
| 644 .WillRepeatedly(testing::Return(0x0400)); | 640 .WillRepeatedly(testing::Return(0x0400)); |
| 645 | 641 |
| 646 BluetoothDevice::UUIDList uuids; | 642 BluetoothDevice::UUIDList uuids; |
| 647 uuids.push_back(BluetoothUUID("1105")); | 643 uuids.push_back("00001105-0000-1000-8000-00805f9b34fb"); |
| 648 uuids.push_back(BluetoothUUID("1106")); | 644 uuids.push_back("00001106-0000-1000-8000-00805f9b34fb"); |
| 649 | 645 |
| 650 EXPECT_CALL(*device1_.get(), GetUUIDs()) | 646 EXPECT_CALL(*device1_.get(), GetUUIDs()) |
| 651 .WillOnce(testing::Return(uuids)); | 647 .WillOnce(testing::Return(uuids)); |
| 652 | 648 |
| 653 devices.push_back(device1_.get()); | 649 devices.push_back(device1_.get()); |
| 654 | 650 |
| 655 // Leave the second largely empty so we can check a device without | 651 // Leave the second largely empty so we can check a device without |
| 656 // available information. | 652 // available information. |
| 657 devices.push_back(device2_.get()); | 653 devices.push_back(device2_.get()); |
| 658 | 654 |
| 659 EXPECT_CALL(*mock_adapter_, GetDevices()) | 655 EXPECT_CALL(*mock_adapter_, GetDevices()) |
| 660 .Times(1) | 656 .Times(1) |
| 661 .WillRepeatedly(testing::Return(devices)); | 657 .WillRepeatedly(testing::Return(devices)); |
| 662 | 658 |
| 663 // Load and wait for setup | 659 // Load and wait for setup |
| 664 ExtensionTestMessageListener listener("ready", true); | 660 ExtensionTestMessageListener listener("ready", true); |
| 665 ASSERT_TRUE( | 661 ASSERT_TRUE( |
| 666 LoadExtension(test_data_dir_.AppendASCII("bluetooth/device_info"))); | 662 LoadExtension(test_data_dir_.AppendASCII("bluetooth/device_info"))); |
| 667 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 663 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 668 | 664 |
| 669 listener.Reply("go"); | 665 listener.Reply("go"); |
| 670 | 666 |
| 671 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 667 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 672 } | 668 } |
| OLD | NEW |