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

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: 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) {
scheib 2016/04/20 17:50:35 This request of mine will make the code diff large
ortuno 2016/04/20 18:03:19 Done.
466 return services; 460 return true;
467 } 461 }
468 462
469 std::unique_ptr<NiceMockBluetoothGattService> heart_rate( 463 std::unique_ptr<NiceMockBluetoothGattService> heart_rate(
470 GetBaseGATTService(device_ptr, kHeartRateServiceUUID)); 464 GetBaseGATTService(device_ptr, kHeartRateServiceUUID));
471 465
472 device_ptr->AddMockService(std::move(heart_rate)); 466 device_ptr->AddMockService(std::move(heart_rate));
473 base::ThreadTaskRunnerHandle::Get()->PostTask( 467 base::ThreadTaskRunnerHandle::Get()->PostTask(
474 FROM_HERE, base::Bind(&NotifyServicesDiscovered, 468 FROM_HERE, base::Bind(&NotifyServicesDiscovered,
475 base::RetainedRef(adapter_ptr), device_ptr)); 469 base::RetainedRef(adapter_ptr), device_ptr));
476 470
477 DCHECK(services.size() == 0); 471 DCHECK(services.size() == 0);
478 return services; 472 return false;
479 })); 473 }));
480 474
481 adapter->AddMockDevice(std::move(device)); 475 adapter->AddMockDevice(std::move(device));
482 476
483 return adapter; 477 return adapter;
484 } 478 }
485 479
486 // static 480 // static
487 scoped_refptr<NiceMockBluetoothAdapter> 481 scoped_refptr<NiceMockBluetoothAdapter>
488 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { 482 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 BluetoothDevice::UUIDList uuids, 645 BluetoothDevice::UUIDList uuids,
652 const std::string& address) { 646 const std::string& address) {
653 std::unique_ptr<NiceMockBluetoothDevice> device( 647 std::unique_ptr<NiceMockBluetoothDevice> device(
654 GetBaseDevice(adapter, device_name, uuids, address)); 648 GetBaseDevice(adapter, device_name, uuids, address));
655 649
656 MockBluetoothDevice* device_ptr = device.get(); 650 MockBluetoothDevice* device_ptr = device.get();
657 651
658 ON_CALL(*device, CreateGattConnection(_, _)) 652 ON_CALL(*device, CreateGattConnection(_, _))
659 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( 653 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>(
660 [adapter, device_ptr]() { 654 [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( 655 return base::WrapUnique(new NiceMockBluetoothGattConnection(
665 adapter, device_ptr->GetAddress())); 656 adapter, device_ptr->GetAddress()));
666 })); 657 }));
667 658
659 ON_CALL(*device, IsGattServicesDiscoveryComplete())
660 .WillByDefault(Return(true));
661
668 return device; 662 return device;
669 } 663 }
670 664
671 // static 665 // static
672 std::unique_ptr<NiceMockBluetoothDevice> 666 std::unique_ptr<NiceMockBluetoothDevice>
673 LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice( 667 LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice(
674 MockBluetoothAdapter* adapter, 668 MockBluetoothAdapter* adapter,
675 BluetoothDevice::ConnectErrorCode error_code, 669 BluetoothDevice::ConnectErrorCode error_code,
676 const std::string& device_name) { 670 const std::string& device_name) {
677 BluetoothDevice::UUIDList uuids; 671 BluetoothDevice::UUIDList uuids;
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 return BluetoothUUID(); 1034 return BluetoothUUID();
1041 } 1035 }
1042 1036
1043 // static 1037 // static
1044 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 1038 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
1045 return BluetoothDevice::CanonicalizeAddress( 1039 return BluetoothDevice::CanonicalizeAddress(
1046 base::StringPrintf("%012" PRIx64, addr)); 1040 base::StringPrintf("%012" PRIx64, addr));
1047 } 1041 }
1048 1042
1049 } // namespace content 1043 } // 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