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

Unified Diff: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc

Issue 2014473002: bluetooth: Web Bluetooth can filter by empty device names, doesn't leak MACs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bt-GetNameOrEmpty-
Patch Set: Correct null handling in renderer; Null and Empty Named fakes & tests. Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc
diff --git a/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc
index 1c7714cdf817f2ce1c8b1f0127b851ad48d2306a..24fbbc236b669b7a36e4f6a0d6ebe84d3932e7e0 100644
--- a/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc
+++ b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc
@@ -160,6 +160,10 @@ LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter(
return GetMissingCharacteristicHeartRateAdapter();
if (fake_adapter_name == "HeartRateAdapter")
return GetHeartRateAdapter();
+ if (fake_adapter_name == "EmptyNameHeartRateAdapter")
+ return GetEmptyNameHeartRateAdapter();
+ if (fake_adapter_name == "NoNameHeartRateAdapter")
+ return GetNoNameHeartRateAdapter();
if (fake_adapter_name == "TwoHeartRateServicesAdapter")
return GetTwoHeartRateServicesAdapter();
if (fake_adapter_name == "DisconnectingHeartRateAdapter")
@@ -444,6 +448,45 @@ LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() {
// static
scoped_refptr<NiceMockBluetoothAdapter>
+LayoutTestBluetoothAdapterProvider::GetEmptyNameHeartRateAdapter() {
+ scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
+ std::unique_ptr<NiceMockBluetoothDevice> device(
+ GetHeartRateDevice(adapter.get(), /* device_name */ std::string("")));
ortuno 2016/07/31 18:00:05 optional nit: you can use base::EmptyString() htt
scheib 2016/08/02 03:24:33 No longer needed, but also FYI reading the comment
+
+ // TODO(ortuno): Implement the rest of the service's characteristics
+ // See: http://crbug.com/529975
+
+ device->AddMockService(GetGenericAccessService(device.get()));
+ device->AddMockService(GetHeartRateService(adapter.get(), device.get()));
+
+ adapter->AddMockDevice(std::move(device));
+
+ return adapter;
+}
+
+// static
+scoped_refptr<NiceMockBluetoothAdapter>
+LayoutTestBluetoothAdapterProvider::GetNoNameHeartRateAdapter() {
+ scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
+ std::unique_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(
+ adapter.get(),
+ /* device_name set to Null. base::nullopt doesn't work due to multiple
+ possible type conversions. */
+ base::Optional<std::string>()));
+
+ // TODO(ortuno): Implement the rest of the service's characteristics
+ // See: http://crbug.com/529975
+
+ device->AddMockService(GetGenericAccessService(device.get()));
+ device->AddMockService(GetHeartRateService(adapter.get(), device.get()));
+
+ adapter->AddMockDevice(std::move(device));
+
+ return adapter;
+}
+
+// static
+scoped_refptr<NiceMockBluetoothAdapter>
LayoutTestBluetoothAdapterProvider::GetTwoHeartRateServicesAdapter() {
scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
std::unique_ptr<NiceMockBluetoothDevice> device(
@@ -630,7 +673,7 @@ LayoutTestBluetoothAdapterProvider::GetDiscoverySession() {
std::unique_ptr<NiceMockBluetoothDevice>
LayoutTestBluetoothAdapterProvider::GetBaseDevice(
MockBluetoothAdapter* adapter,
- const std::string& device_name,
+ const base::Optional<std::string>& device_name,
device::BluetoothDevice::UUIDList uuids,
const std::string& address) {
std::unique_ptr<NiceMockBluetoothDevice> device(new NiceMockBluetoothDevice(
@@ -686,7 +729,7 @@ LayoutTestBluetoothAdapterProvider::GetGlucoseDevice(
std::unique_ptr<NiceMockBluetoothDevice>
LayoutTestBluetoothAdapterProvider::GetConnectableDevice(
device::MockBluetoothAdapter* adapter,
- const std::string& device_name,
+ const base::Optional<std::string>& device_name,
BluetoothDevice::UUIDList uuids,
const std::string& address) {
std::unique_ptr<NiceMockBluetoothDevice> device(
@@ -728,12 +771,13 @@ LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice(
// static
std::unique_ptr<NiceMockBluetoothDevice>
LayoutTestBluetoothAdapterProvider::GetHeartRateDevice(
- MockBluetoothAdapter* adapter) {
+ MockBluetoothAdapter* adapter,
+ const base::Optional<std::string>& device_name) {
BluetoothDevice::UUIDList uuids;
uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID));
uuids.push_back(BluetoothUUID(kHeartRateServiceUUID));
- return GetConnectableDevice(adapter, "Heart Rate Device", uuids);
+ return GetConnectableDevice(adapter, device_name, uuids);
}
// Services

Powered by Google App Engine
This is Rietveld 408576698