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

Side by Side Diff: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc

Issue 1945823003: bluetooth: Remove BluetoothAdvertisementData (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Fix test Created 4 years, 7 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 "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h" 5 #include "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 const char kTxPowerServiceUUID[] = "1804"; 72 const char kTxPowerServiceUUID[] = "1804";
73 // Characteristics: 73 // Characteristics:
74 const char kBlacklistExcludeReadsCharacteristicUUID[] = 74 const char kBlacklistExcludeReadsCharacteristicUUID[] =
75 "bad1c9a2-9a5b-4015-8b60-1579bbbf2135"; 75 "bad1c9a2-9a5b-4015-8b60-1579bbbf2135";
76 const char kBodySensorLocation[] = "2a38"; 76 const char kBodySensorLocation[] = "2a38";
77 const char kDeviceNameUUID[] = "2a00"; 77 const char kDeviceNameUUID[] = "2a00";
78 const char kHeartRateMeasurementUUID[] = "2a37"; 78 const char kHeartRateMeasurementUUID[] = "2a37";
79 const char kSerialNumberStringUUID[] = "2a25"; 79 const char kSerialNumberStringUUID[] = "2a25";
80 const char kPeripheralPrivacyFlagUUID[] = "2a02"; 80 const char kPeripheralPrivacyFlagUUID[] = "2a02";
81 81
82 const int kDefaultTxPower = -10; // TxPower of a device broadcasting at 0.1mW.
83 const int kDefaultRssi = -51; // RSSI at 1m from a device broadcasting at
84 // 0.1mW.
85
86 // Invokes Run() on the k-th argument of the function with no arguments. 82 // Invokes Run() on the k-th argument of the function with no arguments.
87 ACTION_TEMPLATE(RunCallback, 83 ACTION_TEMPLATE(RunCallback,
88 HAS_1_TEMPLATE_PARAMS(int, k), 84 HAS_1_TEMPLATE_PARAMS(int, k),
89 AND_0_VALUE_PARAMS()) { 85 AND_0_VALUE_PARAMS()) {
90 return ::testing::get<k>(args).Run(); 86 return ::testing::get<k>(args).Run();
91 } 87 }
92 88
93 // Invokes Run() on the k-th argument of the function with 1 argument. 89 // Invokes Run() on the k-th argument of the function with 1 argument.
94 ACTION_TEMPLATE(RunCallback, 90 ACTION_TEMPLATE(RunCallback,
95 HAS_1_TEMPLATE_PARAMS(int, k), 91 HAS_1_TEMPLATE_PARAMS(int, k),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return GetFailingConnectionsAdapter(); 162 return GetFailingConnectionsAdapter();
167 if (fake_adapter_name == "FailingGATTOperationsAdapter") 163 if (fake_adapter_name == "FailingGATTOperationsAdapter")
168 return GetFailingGATTOperationsAdapter(); 164 return GetFailingGATTOperationsAdapter();
169 if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter") 165 if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter")
170 return GetSecondDiscoveryFindsHeartRateAdapter(); 166 return GetSecondDiscoveryFindsHeartRateAdapter();
171 if (fake_adapter_name == "DelayedServicesDiscoveryAdapter") 167 if (fake_adapter_name == "DelayedServicesDiscoveryAdapter")
172 return GetDelayedServicesDiscoveryAdapter(); 168 return GetDelayedServicesDiscoveryAdapter();
173 if (fake_adapter_name.empty()) 169 if (fake_adapter_name.empty())
174 return nullptr; 170 return nullptr;
175 171
176 if (base::StartsWith(fake_adapter_name, "PowerValueAdapter",
177 base::CompareCase::SENSITIVE)) {
178 std::vector<StringPiece> args =
179 base::SplitStringPiece(fake_adapter_name, ":", base::KEEP_WHITESPACE,
180 base::SPLIT_WANT_NONEMPTY);
181 DCHECK(args[0] == "PowerValueAdapter");
182 DCHECK(args.size() == 3) << "Should contain AdapterName:TxPower:RSSI";
183
184 int tx_power;
185 base::StringToInt(args[1], &tx_power);
186 DCHECK(tx_power >= INT8_MIN && tx_power <= INT8_MAX)
187 << "Must be between [-128, 127]";
188 int rssi;
189 base::StringToInt(args[2], &rssi);
190 DCHECK(rssi >= INT8_MIN && rssi <= INT8_MAX)
191 << "Must be between [-128, 127]";
192 return GetPowerValueAdapter(tx_power, rssi);
193 }
194
195 if (base::StartsWith(fake_adapter_name, "PowerPresenceAdapter",
196 base::CompareCase::SENSITIVE)) {
197 std::vector<StringPiece> args =
198 base::SplitStringPiece(fake_adapter_name, ":", base::KEEP_WHITESPACE,
199 base::SPLIT_WANT_NONEMPTY);
200 DCHECK(args[0] == "PowerPresenceAdapter");
201 DCHECK(args.size() == 3)
202 << "Should contain AdapterName:TxPowerPresent:RSSIPResent";
203 DCHECK(args[1] == "true" || args[1] == "false");
204 DCHECK(args[2] == "true" || args[2] == "false");
205
206 return GetPowerPresenceAdapter(args[1] == "true" /* tx_power_present */,
207 args[2] == "true" /* rssi_present */);
208 }
209
210 NOTREACHED() << fake_adapter_name; 172 NOTREACHED() << fake_adapter_name;
211 return nullptr; 173 return nullptr;
212 } 174 }
213 175
214 // Adapters 176 // Adapters
215 177
216 // static 178 // static
217 scoped_refptr<NiceMockBluetoothAdapter> 179 scoped_refptr<NiceMockBluetoothAdapter>
218 LayoutTestBluetoothAdapterProvider::GetBaseAdapter() { 180 LayoutTestBluetoothAdapterProvider::GetBaseAdapter() {
219 scoped_refptr<NiceMockBluetoothAdapter> adapter( 181 scoped_refptr<NiceMockBluetoothAdapter> adapter(
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 276
315 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) 277 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _))
316 .WillByDefault(RunCallbackWithResult<1 /* success_callback */>( 278 .WillByDefault(RunCallbackWithResult<1 /* success_callback */>(
317 []() { return GetDiscoverySession(); })); 279 []() { return GetDiscoverySession(); }));
318 280
319 return adapter; 281 return adapter;
320 } 282 }
321 283
322 // static 284 // static
323 scoped_refptr<NiceMockBluetoothAdapter> 285 scoped_refptr<NiceMockBluetoothAdapter>
324 LayoutTestBluetoothAdapterProvider::GetPowerValueAdapter(int8_t tx_power,
325 int8_t rssi) {
326 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
327 std::unique_ptr<NiceMockBluetoothDevice> device(
328 GetHeartRateDevice(adapter.get()));
329
330 ON_CALL(*device, GetInquiryTxPower()).WillByDefault(Return(tx_power));
331 ON_CALL(*device, GetInquiryRSSI()).WillByDefault(Return(rssi));
332
333 adapter->AddMockDevice(std::move(device));
334
335 return adapter;
336 }
337
338 // static
339 scoped_refptr<NiceMockBluetoothAdapter>
340 LayoutTestBluetoothAdapterProvider::GetPowerPresenceAdapter(
341 bool tx_power_present,
342 bool rssi_present) {
343 // TODO(ortuno): RSSI Unknown and Tx Power Unknown should have different
344 // values. Add kUnknownTxPower when implemented: http://crbug.com/551572
345 int tx_power =
346 tx_power_present ? kDefaultTxPower : BluetoothDevice::kUnknownPower;
347 int rssi = rssi_present ? kDefaultRssi : BluetoothDevice::kUnknownPower;
348
349 return GetPowerValueAdapter(tx_power, rssi);
350 }
351
352 // static
353 scoped_refptr<NiceMockBluetoothAdapter>
354 LayoutTestBluetoothAdapterProvider::GetGlucoseHeartRateAdapter() { 286 LayoutTestBluetoothAdapterProvider::GetGlucoseHeartRateAdapter() {
355 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 287 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
356 288
357 adapter->AddMockDevice(GetHeartRateDevice(adapter.get())); 289 adapter->AddMockDevice(GetHeartRateDevice(adapter.get()));
358 adapter->AddMockDevice(GetGlucoseDevice(adapter.get())); 290 adapter->AddMockDevice(GetGlucoseDevice(adapter.get()));
359 291
360 return adapter; 292 return adapter;
361 } 293 }
362 294
363 // static 295 // static
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 return BluetoothUUID(); 962 return BluetoothUUID();
1031 } 963 }
1032 964
1033 // static 965 // static
1034 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 966 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
1035 return BluetoothDevice::CanonicalizeAddress( 967 return BluetoothDevice::CanonicalizeAddress(
1036 base::StringPrintf("%012" PRIx64, addr)); 968 base::StringPrintf("%012" PRIx64, addr));
1037 } 969 }
1038 970
1039 } // namespace content 971 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698