Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(850)

Side by Side Diff: extensions/browser/api/bluetooth/bluetooth_event_router_unittest.cc

Issue 2801403002: MD Settings: Bluetooth: Fix adapter state and discovery (Closed)
Patch Set: Use CHECK instead of early exit Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "content/public/test/test_browser_context.h" 13 #include "content/public/test/test_browser_context.h"
14 #include "content/public/test/test_browser_thread_bundle.h" 14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "device/bluetooth/bluetooth_common.h" 15 #include "device/bluetooth/bluetooth_common.h"
16 #include "device/bluetooth/bluetooth_uuid.h" 16 #include "device/bluetooth/bluetooth_uuid.h"
17 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 17 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
18 #include "extensions/browser/event_router.h"
18 #include "extensions/browser/extension_registry.h" 19 #include "extensions/browser/extension_registry.h"
19 #include "extensions/browser/extensions_test.h" 20 #include "extensions/browser/extensions_test.h"
20 #include "extensions/common/api/bluetooth.h" 21 #include "extensions/common/api/bluetooth.h"
21 #include "extensions/common/extension_builder.h" 22 #include "extensions/common/extension_builder.h"
22 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 namespace { 26 namespace {
26 27
27 const char kTestExtensionId[] = "test extension id"; 28 const char kTestExtensionId[] = "test extension id";
(...skipping 24 matching lines...) Expand all
52 ExtensionsTest::TearDown(); 53 ExtensionsTest::TearDown();
53 } 54 }
54 55
55 protected: 56 protected:
56 content::TestBrowserThreadBundle test_browser_thread_bundle_; 57 content::TestBrowserThreadBundle test_browser_thread_bundle_;
57 testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_; 58 testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_;
58 std::unique_ptr<BluetoothEventRouter> router_; 59 std::unique_ptr<BluetoothEventRouter> router_;
59 }; 60 };
60 61
61 TEST_F(BluetoothEventRouterTest, BluetoothEventListener) { 62 TEST_F(BluetoothEventRouterTest, BluetoothEventListener) {
62 router_->OnListenerAdded(); 63 EventListenerInfo info("", "", GURL(), nullptr);
64 router_->OnListenerAdded(info);
63 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); 65 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
64 router_->OnListenerRemoved(); 66 router_->OnListenerRemoved(info);
65 } 67 }
66 68
67 TEST_F(BluetoothEventRouterTest, MultipleBluetoothEventListeners) { 69 TEST_F(BluetoothEventRouterTest, MultipleBluetoothEventListeners) {
68 router_->OnListenerAdded(); 70 // TODO(rkc/stevenjb): Test multiple extensions and WebUI.
69 router_->OnListenerAdded(); 71 EventListenerInfo info("", "", GURL(), nullptr);
70 router_->OnListenerAdded(); 72 router_->OnListenerAdded(info);
71 router_->OnListenerRemoved(); 73 router_->OnListenerAdded(info);
72 router_->OnListenerRemoved(); 74 router_->OnListenerAdded(info);
75 router_->OnListenerRemoved(info);
76 router_->OnListenerRemoved(info);
73 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); 77 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
74 router_->OnListenerRemoved(); 78 router_->OnListenerRemoved(info);
75 } 79 }
76 80
77 TEST_F(BluetoothEventRouterTest, UnloadExtension) { 81 TEST_F(BluetoothEventRouterTest, UnloadExtension) {
78 scoped_refptr<const Extension> extension = 82 scoped_refptr<const Extension> extension =
79 ExtensionBuilder() 83 ExtensionBuilder()
80 .SetManifest(DictionaryBuilder() 84 .SetManifest(DictionaryBuilder()
81 .Set("name", "BT event router test") 85 .Set("name", "BT event router test")
82 .Set("version", "1.0") 86 .Set("version", "1.0")
83 .Set("manifest_version", 2) 87 .Set("manifest_version", 2)
84 .Build()) 88 .Build())
(...skipping 27 matching lines...) Expand all
112 testing::_, testing::_)).Times(1); 116 testing::_, testing::_)).Times(1);
113 117
114 router_->StartDiscoverySession(mock_adapter_, kTestExtensionId, 118 router_->StartDiscoverySession(mock_adapter_, kTestExtensionId,
115 base::Bind(&base::DoNothing), 119 base::Bind(&base::DoNothing),
116 base::Bind(&base::DoNothing)); 120 base::Bind(&base::DoNothing));
117 121
118 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); 122 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
119 } 123 }
120 124
121 } // namespace extensions 125 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/bluetooth/bluetooth_event_router.cc ('k') | extensions/browser/api/bluetooth/bluetooth_private_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698