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

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

Issue 420663003: Extensions: Move bluetooth APIs to extensions/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android, gn Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/common/extensions/api/bluetooth_private.h"
12 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 9 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
13 #include "device/bluetooth/test/mock_bluetooth_device.h" 10 #include "device/bluetooth/test/mock_bluetooth_device.h"
11 #include "extensions/browser/api/bluetooth/bluetooth_api.h"
12 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h"
14 #include "extensions/browser/event_router.h" 13 #include "extensions/browser/event_router.h"
14 #include "extensions/common/api/bluetooth_private.h"
15 #include "extensions/common/switches.h" 15 #include "extensions/common/switches.h"
16 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
17 17
18 using device::MockBluetoothAdapter; 18 using device::MockBluetoothAdapter;
19 using device::MockBluetoothDevice; 19 using device::MockBluetoothDevice;
20 using testing::_; 20 using testing::_;
21 using testing::InSequence; 21 using testing::InSequence;
22 using testing::NiceMock; 22 using testing::NiceMock;
23 using testing::Return; 23 using testing::Return;
24 using testing::ReturnPointee; 24 using testing::ReturnPointee;
25 using testing::WithArgs; 25 using testing::WithArgs;
26 using testing::WithoutArgs; 26 using testing::WithoutArgs;
27 27
28 namespace bt = extensions::api::bluetooth; 28 namespace bt = extensions::core_api::bluetooth;
29 namespace bt_private = extensions::api::bluetooth_private; 29 namespace bt_private = extensions::core_api::bluetooth_private;
30
31 namespace extensions {
30 32
31 namespace { 33 namespace {
32 34
33 const char kTestExtensionId[] = "jofgjdphhceggjecimellaapdjjadibj"; 35 const char kTestExtensionId[] = "jofgjdphhceggjecimellaapdjjadibj";
34 const char kAdapterName[] = "Helix"; 36 const char kAdapterName[] = "Helix";
35 const char kDeviceName[] = "Red"; 37 const char kDeviceName[] = "Red";
36 } 38 }
37 39
38 class BluetoothPrivateApiTest : public ExtensionApiTest { 40 class BluetoothPrivateApiTest : public ExtensionApiTest {
39 public: 41 public:
40 BluetoothPrivateApiTest() 42 BluetoothPrivateApiTest()
41 : adapter_name_(kAdapterName), 43 : adapter_name_(kAdapterName),
42 adapter_powered_(false), 44 adapter_powered_(false),
43 adapter_discoverable_(false) {} 45 adapter_discoverable_(false) {}
44 46
45 virtual ~BluetoothPrivateApiTest() {} 47 virtual ~BluetoothPrivateApiTest() {}
46 48
47 virtual void SetUpOnMainThread() OVERRIDE { 49 virtual void SetUpOnMainThread() OVERRIDE {
48 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 50 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
49 extensions::switches::kWhitelistedExtensionID, kTestExtensionId); 51 switches::kWhitelistedExtensionID, kTestExtensionId);
50 mock_adapter_ = new NiceMock<MockBluetoothAdapter>(); 52 mock_adapter_ = new NiceMock<MockBluetoothAdapter>();
51 event_router()->SetAdapterForTest(mock_adapter_.get()); 53 event_router()->SetAdapterForTest(mock_adapter_.get());
52 mock_device_.reset(new NiceMock<MockBluetoothDevice>(mock_adapter_.get(), 54 mock_device_.reset(new NiceMock<MockBluetoothDevice>(mock_adapter_.get(),
53 0, 55 0,
54 kDeviceName, 56 kDeviceName,
55 "11:12:13:14:15:16", 57 "11:12:13:14:15:16",
56 false, 58 false,
57 false)); 59 false));
58 ON_CALL(*mock_adapter_.get(), GetDevice(mock_device_->GetAddress())) 60 ON_CALL(*mock_adapter_.get(), GetDevice(mock_device_->GetAddress()))
59 .WillByDefault(Return(mock_device_.get())); 61 .WillByDefault(Return(mock_device_.get()));
60 ON_CALL(*mock_adapter_.get(), IsPresent()).WillByDefault(Return(true)); 62 ON_CALL(*mock_adapter_.get(), IsPresent()).WillByDefault(Return(true));
61 } 63 }
62 64
63 virtual void TearDownOnMainThread() OVERRIDE {} 65 virtual void TearDownOnMainThread() OVERRIDE {}
64 66
65 extensions::BluetoothEventRouter* event_router() { 67 BluetoothEventRouter* event_router() {
66 return extensions::BluetoothAPI::Get(browser()->profile()) 68 return BluetoothAPI::Get(browser()->profile())->event_router();
67 ->event_router();
68 } 69 }
69 70
70 void SetName(const std::string& name, const base::Closure& callback) { 71 void SetName(const std::string& name, const base::Closure& callback) {
71 adapter_name_ = name; 72 adapter_name_ = name;
72 callback.Run(); 73 callback.Run();
73 } 74 }
74 75
75 void SetPowered(bool powered, const base::Closure& callback) { 76 void SetPowered(bool powered, const base::Closure& callback) {
76 adapter_powered_ = powered; 77 adapter_powered_ = powered;
77 callback.Run(); 78 callback.Run();
78 } 79 }
79 80
80 void SetDiscoverable(bool discoverable, const base::Closure& callback) { 81 void SetDiscoverable(bool discoverable, const base::Closure& callback) {
81 adapter_discoverable_ = discoverable; 82 adapter_discoverable_ = discoverable;
82 callback.Run(); 83 callback.Run();
83 } 84 }
84 85
85 void DispatchPairingEvent(bt_private::PairingEventType pairing_event_type) { 86 void DispatchPairingEvent(bt_private::PairingEventType pairing_event_type) {
86 bt_private::PairingEvent pairing_event; 87 bt_private::PairingEvent pairing_event;
87 pairing_event.pairing = pairing_event_type; 88 pairing_event.pairing = pairing_event_type;
88 pairing_event.device.name.reset(new std::string(kDeviceName)); 89 pairing_event.device.name.reset(new std::string(kDeviceName));
89 pairing_event.device.address = mock_device_->GetAddress(); 90 pairing_event.device.address = mock_device_->GetAddress();
90 pairing_event.device.vendor_id_source = bt::VENDOR_ID_SOURCE_USB; 91 pairing_event.device.vendor_id_source = bt::VENDOR_ID_SOURCE_USB;
91 pairing_event.device.type = bt::DEVICE_TYPE_PHONE; 92 pairing_event.device.type = bt::DEVICE_TYPE_PHONE;
92 93
93 scoped_ptr<base::ListValue> args = 94 scoped_ptr<base::ListValue> args =
94 bt_private::OnPairing::Create(pairing_event); 95 bt_private::OnPairing::Create(pairing_event);
95 scoped_ptr<extensions::Event> event( 96 scoped_ptr<Event> event(
96 new extensions::Event(bt_private::OnPairing::kEventName, args.Pass())); 97 new Event(bt_private::OnPairing::kEventName, args.Pass()));
97 extensions::EventRouter::Get(browser()->profile()) 98 EventRouter::Get(browser()->profile())->DispatchEventToExtension(
98 ->DispatchEventToExtension(kTestExtensionId, event.Pass()); 99 kTestExtensionId, event.Pass());
99 } 100 }
100 101
101 void DispatchAuthorizePairingEvent() { 102 void DispatchAuthorizePairingEvent() {
102 DispatchPairingEvent(bt_private::PAIRING_EVENT_TYPE_REQUESTAUTHORIZATION); 103 DispatchPairingEvent(bt_private::PAIRING_EVENT_TYPE_REQUESTAUTHORIZATION);
103 } 104 }
104 105
105 void DispatchPincodePairingEvent() { 106 void DispatchPincodePairingEvent() {
106 DispatchPairingEvent(bt_private::PAIRING_EVENT_TYPE_REQUESTPINCODE); 107 DispatchPairingEvent(bt_private::PAIRING_EVENT_TYPE_REQUESTPINCODE);
107 } 108 }
108 109
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 EXPECT_CALL(*mock_adapter_.get(), 175 EXPECT_CALL(*mock_adapter_.get(),
175 AddPairingDelegate( 176 AddPairingDelegate(
176 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH)) 177 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH))
177 .WillOnce(WithoutArgs( 178 .WillOnce(WithoutArgs(
178 Invoke(this, &BluetoothPrivateApiTest::DispatchPasskeyPairingEvent))); 179 Invoke(this, &BluetoothPrivateApiTest::DispatchPasskeyPairingEvent)));
179 EXPECT_CALL(*mock_device_, ExpectingPasskey()).WillRepeatedly(Return(true)); 180 EXPECT_CALL(*mock_device_, ExpectingPasskey()).WillRepeatedly(Return(true));
180 EXPECT_CALL(*mock_device_, SetPasskey(900531)); 181 EXPECT_CALL(*mock_device_, SetPasskey(900531));
181 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/passkey_pairing")) 182 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/passkey_pairing"))
182 << message_; 183 << message_;
183 } 184 }
185
186 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/bluetooth/bluetooth_private_api.cc ('k') | extensions/browser/api/bluetooth_low_energy/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698