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

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

Issue 1908523002: bluetooth: Make IsGattServicesDiscoveryComplete virtual (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Address scheib's comments Created 4 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
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_device.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 std::set<BluetoothUUID> GetUUIDs( 119 std::set<BluetoothUUID> GetUUIDs(
120 const device::BluetoothDiscoveryFilter* filter) { 120 const device::BluetoothDiscoveryFilter* filter) {
121 std::set<BluetoothUUID> result; 121 std::set<BluetoothUUID> result;
122 filter->GetUUIDs(result); 122 filter->GetUUIDs(result);
123 return result; 123 return result;
124 } 124 }
125 125
126 // Notifies the adapter's observers that the services have been discovered. 126 // Notifies the adapter's observers that the services have been discovered.
127 void NotifyServicesDiscovered(MockBluetoothAdapter* adapter, 127 void NotifyServicesDiscovered(MockBluetoothAdapter* adapter,
128 MockBluetoothDevice* device) { 128 MockBluetoothDevice* device) {
129 device->SetGattServicesDiscoveryComplete(true);
130 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter->GetObservers(), 129 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter->GetObservers(),
131 GattServicesDiscovered(adapter, device)); 130 GattServicesDiscovered(adapter, device));
132 } 131 }
133 132
134 } // namespace 133 } // namespace
135 134
136 namespace content { 135 namespace content {
137 136
138 // static 137 // static
139 scoped_refptr<BluetoothAdapter> 138 scoped_refptr<BluetoothAdapter>
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 // static 439 // static
441 scoped_refptr<NiceMockBluetoothAdapter> 440 scoped_refptr<NiceMockBluetoothAdapter>
442 LayoutTestBluetoothAdapterProvider::GetDelayedServicesDiscoveryAdapter() { 441 LayoutTestBluetoothAdapterProvider::GetDelayedServicesDiscoveryAdapter() {
443 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 442 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
444 std::unique_ptr<NiceMockBluetoothDevice> device( 443 std::unique_ptr<NiceMockBluetoothDevice> device(
445 GetHeartRateDevice(adapter.get())); 444 GetHeartRateDevice(adapter.get()));
446 445
447 MockBluetoothAdapter* adapter_ptr = adapter.get(); 446 MockBluetoothAdapter* adapter_ptr = adapter.get();
448 MockBluetoothDevice* device_ptr = device.get(); 447 MockBluetoothDevice* device_ptr = device.get();
449 448
450 // Override the previous mock implementation of CreateGattConnection that 449 // Override the previous mock implementation of
451 // this a NotifyServicesDiscovered task. Instead thsi adapter will not post 450 // IsGattServicesDiscoveryComplete so that the first time the function is
452 // that task until GetGattServices is called. 451 // called it returns false, adds a service and posts a task to notify
453 ON_CALL(*device, CreateGattConnection(_, _)) 452 // the services have been discovered. Subsequent calls to the function
454 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( 453 // will return true.
455 [adapter_ptr, device_ptr]() { 454 ON_CALL(*device, IsGattServicesDiscoveryComplete())
456 return base::WrapUnique(new NiceMockBluetoothGattConnection(
457 adapter_ptr, device_ptr->GetAddress()));
458 }));
459
460 ON_CALL(*device, GetGattServices())
461 .WillByDefault(Invoke([adapter_ptr, device_ptr] { 455 .WillByDefault(Invoke([adapter_ptr, device_ptr] {
462 std::vector<BluetoothGattService*> services = 456 std::vector<BluetoothGattService*> services =
463 device_ptr->GetMockServices(); 457 device_ptr->GetMockServices();
464 458
465 if (services.size() > 0) { 459 if (services.size() == 0) {
466 return services; 460 std::unique_ptr<NiceMockBluetoothGattService> heart_rate(
461 GetBaseGATTService(device_ptr, kHeartRateServiceUUID));
462
463 device_ptr->AddMockService(std::move(heart_rate));
464 base::ThreadTaskRunnerHandle::Get()->PostTask(
465 FROM_HERE,
466 base::Bind(&NotifyServicesDiscovered,
467 base::RetainedRef(adapter_ptr), device_ptr));
468
469 DCHECK(services.size() == 0);
470 return false;
467 } 471 }
468 472
469 std::unique_ptr<NiceMockBluetoothGattService> heart_rate( 473 return true;
470 GetBaseGATTService(device_ptr, kHeartRateServiceUUID));
471
472 device_ptr->AddMockService(std::move(heart_rate));
473 base::ThreadTaskRunnerHandle::Get()->PostTask(
474 FROM_HERE, base::Bind(&NotifyServicesDiscovered,
475 base::RetainedRef(adapter_ptr), device_ptr));
476
477 DCHECK(services.size() == 0);
478 return services;
479 })); 474 }));
480 475
481 adapter->AddMockDevice(std::move(device)); 476 adapter->AddMockDevice(std::move(device));
482 477
483 return adapter; 478 return adapter;
484 } 479 }
485 480
486 // static 481 // static
487 scoped_refptr<NiceMockBluetoothAdapter> 482 scoped_refptr<NiceMockBluetoothAdapter>
488 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { 483 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 BluetoothDevice::UUIDList uuids, 646 BluetoothDevice::UUIDList uuids,
652 const std::string& address) { 647 const std::string& address) {
653 std::unique_ptr<NiceMockBluetoothDevice> device( 648 std::unique_ptr<NiceMockBluetoothDevice> device(
654 GetBaseDevice(adapter, device_name, uuids, address)); 649 GetBaseDevice(adapter, device_name, uuids, address));
655 650
656 MockBluetoothDevice* device_ptr = device.get(); 651 MockBluetoothDevice* device_ptr = device.get();
657 652
658 ON_CALL(*device, CreateGattConnection(_, _)) 653 ON_CALL(*device, CreateGattConnection(_, _))
659 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( 654 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>(
660 [adapter, device_ptr]() { 655 [adapter, device_ptr]() {
661 base::ThreadTaskRunnerHandle::Get()->PostTask(
662 FROM_HERE, base::Bind(&NotifyServicesDiscovered,
663 base::RetainedRef(adapter), device_ptr));
664 return base::WrapUnique(new NiceMockBluetoothGattConnection( 656 return base::WrapUnique(new NiceMockBluetoothGattConnection(
665 adapter, device_ptr->GetAddress())); 657 adapter, device_ptr->GetAddress()));
666 })); 658 }));
667 659
660 ON_CALL(*device, IsGattServicesDiscoveryComplete())
661 .WillByDefault(Return(true));
662
668 return device; 663 return device;
669 } 664 }
670 665
671 // static 666 // static
672 std::unique_ptr<NiceMockBluetoothDevice> 667 std::unique_ptr<NiceMockBluetoothDevice>
673 LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice( 668 LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice(
674 MockBluetoothAdapter* adapter, 669 MockBluetoothAdapter* adapter,
675 BluetoothDevice::ConnectErrorCode error_code, 670 BluetoothDevice::ConnectErrorCode error_code,
676 const std::string& device_name) { 671 const std::string& device_name) {
677 BluetoothDevice::UUIDList uuids; 672 BluetoothDevice::UUIDList uuids;
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 return BluetoothUUID(); 1035 return BluetoothUUID();
1041 } 1036 }
1042 1037
1043 // static 1038 // static
1044 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 1039 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
1045 return BluetoothDevice::CanonicalizeAddress( 1040 return BluetoothDevice::CanonicalizeAddress(
1046 base::StringPrintf("%012" PRIx64, addr)); 1041 base::StringPrintf("%012" PRIx64, addr));
1047 } 1042 }
1048 1043
1049 } // namespace content 1044 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698