| 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 "extensions/browser/api/bluetooth/bluetooth_event_router.h" | 5 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <string> | 8 #include <string> |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 15 #include "content/public/test/test_browser_context.h" | 15 #include "content/public/test/test_browser_context.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
| 17 #include "device/bluetooth/bluetooth_uuid.h" | 17 #include "device/bluetooth/bluetooth_uuid.h" |
| 18 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 18 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 19 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 20 #include "extensions/browser/extensions_test.h" | 20 #include "extensions/browser/extensions_test.h" |
| 21 #include "extensions/common/api/bluetooth.h" | 21 #include "extensions/common/api/bluetooth.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // services so it removes itself as an ExtensionRegistry observer. | 53 // services so it removes itself as an ExtensionRegistry observer. |
| 54 router_.reset(NULL); | 54 router_.reset(NULL); |
| 55 ExtensionsTest::TearDown(); | 55 ExtensionsTest::TearDown(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 protected: | 58 protected: |
| 59 base::MessageLoopForUI message_loop_; | 59 base::MessageLoopForUI message_loop_; |
| 60 // Note: |ui_thread_| must be declared before |router_|. | 60 // Note: |ui_thread_| must be declared before |router_|. |
| 61 content::TestBrowserThread ui_thread_; | 61 content::TestBrowserThread ui_thread_; |
| 62 testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_; | 62 testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_; |
| 63 scoped_ptr<content::NotificationService> notification_service_; | 63 std::unique_ptr<content::NotificationService> notification_service_; |
| 64 scoped_ptr<BluetoothEventRouter> router_; | 64 std::unique_ptr<BluetoothEventRouter> router_; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 TEST_F(BluetoothEventRouterTest, BluetoothEventListener) { | 67 TEST_F(BluetoothEventRouterTest, BluetoothEventListener) { |
| 68 router_->OnListenerAdded(); | 68 router_->OnListenerAdded(); |
| 69 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); | 69 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 70 router_->OnListenerRemoved(); | 70 router_->OnListenerRemoved(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 TEST_F(BluetoothEventRouterTest, MultipleBluetoothEventListeners) { | 73 TEST_F(BluetoothEventRouterTest, MultipleBluetoothEventListeners) { |
| 74 router_->OnListenerAdded(); | 74 router_->OnListenerAdded(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 93 | 93 |
| 94 ExtensionRegistry::Get(browser_context())->TriggerOnUnloaded( | 94 ExtensionRegistry::Get(browser_context())->TriggerOnUnloaded( |
| 95 extension.get(), UnloadedExtensionInfo::REASON_DISABLE); | 95 extension.get(), UnloadedExtensionInfo::REASON_DISABLE); |
| 96 | 96 |
| 97 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); | 97 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // This test check that calling SetDiscoveryFilter before StartDiscoverySession | 100 // This test check that calling SetDiscoveryFilter before StartDiscoverySession |
| 101 // for given extension will start session with proper filter. | 101 // for given extension will start session with proper filter. |
| 102 TEST_F(BluetoothEventRouterTest, SetDiscoveryFilter) { | 102 TEST_F(BluetoothEventRouterTest, SetDiscoveryFilter) { |
| 103 scoped_ptr<device::BluetoothDiscoveryFilter> discovery_filter( | 103 std::unique_ptr<device::BluetoothDiscoveryFilter> discovery_filter( |
| 104 new device::BluetoothDiscoveryFilter( | 104 new device::BluetoothDiscoveryFilter( |
| 105 device::BluetoothDiscoveryFilter::Transport::TRANSPORT_LE)); | 105 device::BluetoothDiscoveryFilter::Transport::TRANSPORT_LE)); |
| 106 | 106 |
| 107 discovery_filter->SetRSSI(-80); | 107 discovery_filter->SetRSSI(-80); |
| 108 discovery_filter->AddUUID(device::BluetoothUUID("1000")); | 108 discovery_filter->AddUUID(device::BluetoothUUID("1000")); |
| 109 | 109 |
| 110 device::BluetoothDiscoveryFilter df( | 110 device::BluetoothDiscoveryFilter df( |
| 111 device::BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); | 111 device::BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); |
| 112 df.CopyFrom(*discovery_filter); | 112 df.CopyFrom(*discovery_filter); |
| 113 | 113 |
| 114 router_->SetDiscoveryFilter(std::move(discovery_filter), mock_adapter_, | 114 router_->SetDiscoveryFilter(std::move(discovery_filter), mock_adapter_, |
| 115 kTestExtensionId, base::Bind(&base::DoNothing), | 115 kTestExtensionId, base::Bind(&base::DoNothing), |
| 116 base::Bind(&base::DoNothing)); | 116 base::Bind(&base::DoNothing)); |
| 117 | 117 |
| 118 EXPECT_CALL(*mock_adapter_, StartDiscoverySessionWithFilterRaw( | 118 EXPECT_CALL(*mock_adapter_, StartDiscoverySessionWithFilterRaw( |
| 119 testing::Pointee(IsFilterEqual(&df)), | 119 testing::Pointee(IsFilterEqual(&df)), |
| 120 testing::_, testing::_)).Times(1); | 120 testing::_, testing::_)).Times(1); |
| 121 | 121 |
| 122 router_->StartDiscoverySession(mock_adapter_, kTestExtensionId, | 122 router_->StartDiscoverySession(mock_adapter_, kTestExtensionId, |
| 123 base::Bind(&base::DoNothing), | 123 base::Bind(&base::DoNothing), |
| 124 base::Bind(&base::DoNothing)); | 124 base::Bind(&base::DoNothing)); |
| 125 | 125 |
| 126 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); | 126 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 127 } | 127 } |
| 128 | 128 |
| 129 } // namespace extensions | 129 } // namespace extensions |
| OLD | NEW |