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

Side by Side Diff: device/bluetooth/test/bluetooth_test_mac.mm

Issue 2244693002: bluetooth: Refactor how we update based on Advertising Data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix arc Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "device/bluetooth/test/bluetooth_test_mac.h" 5 #include "device/bluetooth/test/bluetooth_test_mac.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 MockCentralManager* get() { return mock_central_manager_.get(); }; 50 MockCentralManager* get() { return mock_central_manager_.get(); };
51 51
52 private: 52 private:
53 scoped_nsobject<MockCentralManager> mock_central_manager_; 53 scoped_nsobject<MockCentralManager> mock_central_manager_;
54 54
55 DISALLOW_COPY_AND_ASSIGN(ScopedMockCentralManager); 55 DISALLOW_COPY_AND_ASSIGN(ScopedMockCentralManager);
56 }; 56 };
57 57
58 namespace { 58 namespace {
59 59
60 scoped_nsobject<NSDictionary> CreateAdvertisementData(NSString* name, 60 scoped_nsobject<NSDictionary> CreateAdvertisementData(
61 NSArray* uuids) { 61 NSString* name,
62 NSArray* uuids,
63 NSDictionary* service_data) {
62 NSMutableDictionary* advertisement_data( 64 NSMutableDictionary* advertisement_data(
63 [NSMutableDictionary dictionaryWithDictionary:@{ 65 [NSMutableDictionary dictionaryWithDictionary:@{
64 CBAdvertisementDataServiceDataKey : @{}, 66 CBAdvertisementDataIsConnectable : @(YES)
65 CBAdvertisementDataIsConnectable : @(YES),
66 }]); 67 }]);
68
67 if (name) { 69 if (name) {
68 [advertisement_data setObject:name forKey:CBAdvertisementDataLocalNameKey]; 70 [advertisement_data setObject:name forKey:CBAdvertisementDataLocalNameKey];
69 } 71 }
72
70 if (uuids) { 73 if (uuids) {
71 [advertisement_data setObject:uuids 74 [advertisement_data setObject:uuids
72 forKey:CBAdvertisementDataServiceUUIDsKey]; 75 forKey:CBAdvertisementDataServiceUUIDsKey];
73 } 76 }
77
78 if (service_data) {
79 [advertisement_data setObject:service_data
80 forKey:CBAdvertisementDataServiceDataKey];
81 }
82
74 return scoped_nsobject<NSDictionary>(advertisement_data, 83 return scoped_nsobject<NSDictionary>(advertisement_data,
75 base::scoped_policy::RETAIN); 84 base::scoped_policy::RETAIN);
76 } 85 }
77 86
78 } // namespace 87 } // namespace
79 88
80 // UUID1 hashes to kTestDeviceAddress1, and UUID2 to kTestDeviceAddress2. 89 // UUID1 hashes to kTestDeviceAddress1, and UUID2 to kTestDeviceAddress2.
81 const std::string BluetoothTestMac::kTestPeripheralUUID1 = 90 const std::string BluetoothTestMac::kTestPeripheralUUID1 =
82 "34045B00-0000-0000-0000-000000000000"; 91 "34045B00-0000-0000-0000-000000000000";
83 const std::string BluetoothTestMac::kTestPeripheralUUID2 = 92 const std::string BluetoothTestMac::kTestPeripheralUUID2 =
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 140
132 BluetoothDevice* BluetoothTestMac::SimulateLowEnergyDevice(int device_ordinal) { 141 BluetoothDevice* BluetoothTestMac::SimulateLowEnergyDevice(int device_ordinal) {
133 TestBluetoothAdapterObserver observer(adapter_); 142 TestBluetoothAdapterObserver observer(adapter_);
134 CBCentralManager* central_manager = adapter_mac_->low_energy_central_manager_; 143 CBCentralManager* central_manager = adapter_mac_->low_energy_central_manager_;
135 BluetoothLowEnergyCentralManagerDelegate* central_manager_delegate = 144 BluetoothLowEnergyCentralManagerDelegate* central_manager_delegate =
136 adapter_mac_->low_energy_central_manager_delegate_; 145 adapter_mac_->low_energy_central_manager_delegate_;
137 146
138 const char* identifier; 147 const char* identifier;
139 NSString* name; 148 NSString* name;
140 NSArray* uuids; 149 NSArray* uuids;
150 NSDictionary* service_data;
141 151
142 switch (device_ordinal) { 152 switch (device_ordinal) {
143 case 1: 153 case 1:
144 identifier = kTestPeripheralUUID1.c_str(); 154 identifier = kTestPeripheralUUID1.c_str();
145 name = @(kTestDeviceName.c_str()); 155 name = @(kTestDeviceName.c_str());
146 uuids = @[ 156 uuids = @[
147 [CBUUID UUIDWithString:@(kTestUUIDGenericAccess.c_str())], 157 [CBUUID UUIDWithString:@(kTestUUIDGenericAccess.c_str())],
148 [CBUUID UUIDWithString:@(kTestUUIDGenericAttribute.c_str())] 158 [CBUUID UUIDWithString:@(kTestUUIDGenericAttribute.c_str())]
149 ]; 159 ];
160 service_data = @{
161 [CBUUID UUIDWithString:@(kTestUUIDHeartRate.c_str())] :
162 [NSData dataWithBytes:(unsigned char[]){1} length:1]
163 };
150 break; 164 break;
151 case 2: 165 case 2:
152 identifier = kTestPeripheralUUID1.c_str(); 166 identifier = kTestPeripheralUUID1.c_str();
153 name = @(kTestDeviceName.c_str()); 167 name = @(kTestDeviceName.c_str());
154 uuids = @[ 168 uuids = @[
155 [CBUUID UUIDWithString:@(kTestUUIDImmediateAlert.c_str())], 169 [CBUUID UUIDWithString:@(kTestUUIDImmediateAlert.c_str())],
156 [CBUUID UUIDWithString:@(kTestUUIDLinkLoss.c_str())] 170 [CBUUID UUIDWithString:@(kTestUUIDLinkLoss.c_str())]
157 ]; 171 ];
172 service_data = @{
173 [CBUUID UUIDWithString:@(kTestUUIDHeartRate.c_str())] :
174 [NSData dataWithBytes:(unsigned char[]){2} length:1],
175 [CBUUID UUIDWithString:@(kTestUUIDImmediateAlert.c_str())] :
176 [NSData dataWithBytes:(unsigned char[]){0} length:1]
177 };
158 break; 178 break;
159 case 3: 179 case 3:
160 identifier = kTestPeripheralUUID1.c_str(); 180 identifier = kTestPeripheralUUID1.c_str();
161 name = @(kTestDeviceNameEmpty.c_str()); 181 name = @(kTestDeviceNameEmpty.c_str());
162 uuids = nil; 182 uuids = nil;
183 service_data = nil;
163 break; 184 break;
164 case 4: 185 case 4:
165 identifier = kTestPeripheralUUID2.c_str(); 186 identifier = kTestPeripheralUUID2.c_str();
166 name = @(kTestDeviceNameEmpty.c_str()); 187 name = @(kTestDeviceNameEmpty.c_str());
167 uuids = nil; 188 uuids = nil;
189 service_data = nil;
168 break; 190 break;
169 case 5: 191 case 5:
170 identifier = kTestPeripheralUUID1.c_str(); 192 identifier = kTestPeripheralUUID1.c_str();
171 name = nil; 193 name = nil;
172 uuids = nil; 194 uuids = nil;
195 service_data = nil;
173 break; 196 break;
174 default: 197 default:
175 NOTREACHED() << "SimulateLowEnergyDevice not implemented for " 198 NOTREACHED() << "SimulateLowEnergyDevice not implemented for "
176 << device_ordinal; 199 << device_ordinal;
177 identifier = nil; 200 identifier = nil;
178 name = nil; 201 name = nil;
179 uuids = nil; 202 uuids = nil;
203 service_data = nil;
180 } 204 }
181 scoped_nsobject<MockCBPeripheral> mock_peripheral([[MockCBPeripheral alloc] 205 scoped_nsobject<MockCBPeripheral> mock_peripheral([[MockCBPeripheral alloc]
182 initWithUTF8StringIdentifier:identifier 206 initWithUTF8StringIdentifier:identifier
183 name:name]); 207 name:name]);
184 mock_peripheral.get().bluetoothTestMac = this; 208 mock_peripheral.get().bluetoothTestMac = this;
185 [central_manager_delegate centralManager:central_manager 209 [central_manager_delegate
186 didDiscoverPeripheral:mock_peripheral.get().peripheral 210 centralManager:central_manager
187 advertisementData:CreateAdvertisementData(name, uuids) 211 didDiscoverPeripheral:mock_peripheral.get().peripheral
188 RSSI:@(0)]; 212 advertisementData:CreateAdvertisementData(name, uuids, service_data)
213 RSSI:@(0)];
189 return observer.last_device(); 214 return observer.last_device();
190 } 215 }
191 216
192 void BluetoothTestMac::SimulateGattConnection(BluetoothDevice* device) { 217 void BluetoothTestMac::SimulateGattConnection(BluetoothDevice* device) {
193 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = 218 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac =
194 static_cast<BluetoothLowEnergyDeviceMac*>(device); 219 static_cast<BluetoothLowEnergyDeviceMac*>(device);
195 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); 220 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral();
196 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; 221 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral;
197 [mockPeripheral setState:CBPeripheralStateConnected]; 222 [mockPeripheral setState:CBPeripheralStateConnected];
198 CBCentralManager* centralManager = 223 CBCentralManager* centralManager =
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); 467 // crypto::SHA256HashString(input_str, raw, sizeof(raw));
443 // if (base::HexEncode(raw, sizeof(raw)) == target) { 468 // if (base::HexEncode(raw, sizeof(raw)) == target) {
444 // return input_str; 469 // return input_str;
445 // } 470 // }
446 // ++input[0]; 471 // ++input[0];
447 // } 472 // }
448 // return ""; 473 // return "";
449 // } 474 // }
450 475
451 } // namespace device 476 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698