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

Side by Side Diff: extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc

Issue 569493003: Remove CreateEmptyExtension from extension_function_test_utils (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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
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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "chrome/browser/extensions/extension_apitest.h" 6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_function_test_utils.h"
8 #include "chrome/browser/extensions/extension_test_message_listener.h" 7 #include "chrome/browser/extensions/extension_test_message_listener.h"
9 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 8 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
10 #include "device/bluetooth/test/mock_bluetooth_device.h" 9 #include "device/bluetooth/test/mock_bluetooth_device.h"
11 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h" 10 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h"
12 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" 11 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h"
13 #include "device/bluetooth/test/mock_bluetooth_gatt_descriptor.h" 12 #include "device/bluetooth/test/mock_bluetooth_gatt_descriptor.h"
14 #include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h" 13 #include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h"
15 #include "device/bluetooth/test/mock_bluetooth_gatt_service.h" 14 #include "device/bluetooth/test/mock_bluetooth_gatt_service.h"
16 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.h " 15 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_api.h "
17 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event _router.h" 16 #include "extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event _router.h"
17 #include "extensions/common/test_util.h"
18 #include "extensions/test/result_catcher.h" 18 #include "extensions/test/result_catcher.h"
19 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
20 20
21 using device::BluetoothUUID; 21 using device::BluetoothUUID;
22 using device::BluetoothAdapter; 22 using device::BluetoothAdapter;
23 using device::BluetoothDevice; 23 using device::BluetoothDevice;
24 using device::BluetoothGattCharacteristic; 24 using device::BluetoothGattCharacteristic;
25 using device::BluetoothGattConnection; 25 using device::BluetoothGattConnection;
26 using device::BluetoothGattDescriptor; 26 using device::BluetoothGattDescriptor;
27 using device::BluetoothGattService; 27 using device::BluetoothGattService;
28 using device::BluetoothGattNotifySession; 28 using device::BluetoothGattNotifySession;
29 using device::MockBluetoothAdapter; 29 using device::MockBluetoothAdapter;
30 using device::MockBluetoothDevice; 30 using device::MockBluetoothDevice;
31 using device::MockBluetoothGattCharacteristic; 31 using device::MockBluetoothGattCharacteristic;
32 using device::MockBluetoothGattConnection; 32 using device::MockBluetoothGattConnection;
33 using device::MockBluetoothGattDescriptor; 33 using device::MockBluetoothGattDescriptor;
34 using device::MockBluetoothGattService; 34 using device::MockBluetoothGattService;
35 using device::MockBluetoothGattNotifySession; 35 using device::MockBluetoothGattNotifySession;
36 using extensions::BluetoothLowEnergyEventRouter; 36 using extensions::BluetoothLowEnergyEventRouter;
37 using extensions::ResultCatcher; 37 using extensions::ResultCatcher;
38 using testing::Invoke; 38 using testing::Invoke;
39 using testing::Return; 39 using testing::Return;
40 using testing::ReturnRef; 40 using testing::ReturnRef;
41 using testing::ReturnRefOfCopy; 41 using testing::ReturnRefOfCopy;
42 using testing::SaveArg; 42 using testing::SaveArg;
43 using testing::_; 43 using testing::_;
44 44
45 namespace utils = extension_function_test_utils;
46
47 namespace { 45 namespace {
48 46
49 // Test service constants. 47 // Test service constants.
50 const char kTestLeDeviceAddress0[] = "11:22:33:44:55:66"; 48 const char kTestLeDeviceAddress0[] = "11:22:33:44:55:66";
51 const char kTestLeDeviceName0[] = "Test LE Device 0"; 49 const char kTestLeDeviceName0[] = "Test LE Device 0";
52 50
53 const char kTestLeDeviceAddress1[] = "77:88:99:AA:BB:CC"; 51 const char kTestLeDeviceAddress1[] = "77:88:99:AA:BB:CC";
54 const char kTestLeDeviceName1[] = "Test LE Device 1"; 52 const char kTestLeDeviceName1[] = "Test LE Device 1";
55 53
56 const char kTestServiceId0[] = "service_id0"; 54 const char kTestServiceId0[] = "service_id0";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 const uint8 kTestDescriptorDefaultValue1[] = {0x04, 0x05}; 90 const uint8 kTestDescriptorDefaultValue1[] = {0x04, 0x05};
93 91
94 class BluetoothLowEnergyApiTest : public ExtensionApiTest { 92 class BluetoothLowEnergyApiTest : public ExtensionApiTest {
95 public: 93 public:
96 BluetoothLowEnergyApiTest() {} 94 BluetoothLowEnergyApiTest() {}
97 95
98 virtual ~BluetoothLowEnergyApiTest() {} 96 virtual ~BluetoothLowEnergyApiTest() {}
99 97
100 virtual void SetUpOnMainThread() OVERRIDE { 98 virtual void SetUpOnMainThread() OVERRIDE {
101 ExtensionApiTest::SetUpOnMainThread(); 99 ExtensionApiTest::SetUpOnMainThread();
102 empty_extension_ = utils::CreateEmptyExtension(); 100 empty_extension_ = extensions::test_util::CreateEmptyExtension();
103 SetUpMocks(); 101 SetUpMocks();
104 } 102 }
105 103
106 virtual void TearDownOnMainThread() OVERRIDE { 104 virtual void TearDownOnMainThread() OVERRIDE {
107 EXPECT_CALL(*mock_adapter_, RemoveObserver(_)); 105 EXPECT_CALL(*mock_adapter_, RemoveObserver(_));
108 } 106 }
109 107
110 void SetUpMocks() { 108 void SetUpMocks() {
111 mock_adapter_ = new testing::StrictMock<MockBluetoothAdapter>(); 109 mock_adapter_ = new testing::StrictMock<MockBluetoothAdapter>();
112 EXPECT_CALL(*mock_adapter_, GetDevices()) 110 EXPECT_CALL(*mock_adapter_, GetDevices())
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 .Times(2) 1153 .Times(2)
1156 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( 1154 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>(
1157 first_conn)) 1155 first_conn))
1158 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( 1156 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>(
1159 CreateGattConnection(kTestLeDeviceAddress0, 1157 CreateGattConnection(kTestLeDeviceAddress0,
1160 false /* expect_disconnect */))); 1158 false /* expect_disconnect */)));
1161 1159
1162 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 1160 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
1163 "bluetooth_low_energy/reconnect_after_disconnected"))); 1161 "bluetooth_low_energy/reconnect_after_disconnected")));
1164 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1162 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
1165
1166 } 1163 }
1167 1164
1168 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ConnectInProgress) { 1165 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ConnectInProgress) {
1169 ResultCatcher catcher; 1166 ResultCatcher catcher;
1170 catcher.RestrictToBrowserContext(browser()->profile()); 1167 catcher.RestrictToBrowserContext(browser()->profile());
1171 1168
1172 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) 1169 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0))
1173 .WillRepeatedly(Return(device0_.get())); 1170 .WillRepeatedly(Return(device0_.get()));
1174 1171
1175 BluetoothDevice::GattConnectionCallback connect_callback; 1172 BluetoothDevice::GattConnectionCallback connect_callback;
(...skipping 16 matching lines...) Expand all
1192 "bluetooth_low_energy/connect_in_progress"))); 1189 "bluetooth_low_energy/connect_in_progress")));
1193 1190
1194 listener.WaitUntilSatisfied(); 1191 listener.WaitUntilSatisfied();
1195 connect_callback.Run(conn_ptr.Pass()); 1192 connect_callback.Run(conn_ptr.Pass());
1196 1193
1197 listener.Reset(); 1194 listener.Reset();
1198 listener.WaitUntilSatisfied(); 1195 listener.WaitUntilSatisfied();
1199 disconnect_callback.Run(); 1196 disconnect_callback.Run();
1200 1197
1201 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1198 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
1202
1203 } 1199 }
1204 1200
1205 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, StartStopNotifications) { 1201 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, StartStopNotifications) {
1206 ResultCatcher catcher; 1202 ResultCatcher catcher;
1207 catcher.RestrictToBrowserContext(browser()->profile()); 1203 catcher.RestrictToBrowserContext(browser()->profile());
1208 1204
1209 event_router()->GattServiceAdded( 1205 event_router()->GattServiceAdded(
1210 mock_adapter_, device0_.get(), service0_.get()); 1206 mock_adapter_, device0_.get(), service0_.get());
1211 event_router()->GattServiceAdded( 1207 event_router()->GattServiceAdded(
1212 mock_adapter_, device0_.get(), service1_.get()); 1208 mock_adapter_, device0_.get(), service1_.get());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get()); 1269 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get());
1274 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc1_.get()); 1270 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc1_.get());
1275 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); 1271 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
1276 event_router()->GattServiceRemoved( 1272 event_router()->GattServiceRemoved(
1277 mock_adapter_, device0_.get(), service1_.get()); 1273 mock_adapter_, device0_.get(), service1_.get());
1278 event_router()->GattServiceRemoved( 1274 event_router()->GattServiceRemoved(
1279 mock_adapter_, device0_.get(), service0_.get()); 1275 mock_adapter_, device0_.get(), service0_.get());
1280 } 1276 }
1281 1277
1282 } // namespace 1278 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698