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

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

Issue 1427653003: bluetooth: Implement TxPower and RSSI of BluetoothAdvertisementData (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Rename adapter, add TODO for Unknown Tx Power value Created 5 years, 1 month 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 bebec897c7f6f08bed5e74ab2c8d5697c7ec27c3..31e1b234b94973758c8469b1c1ade8142f0d28b3 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
@@ -8,6 +8,9 @@
#include "base/bind_helpers.h"
#include "base/format_macros.h"
#include "base/location.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/thread_task_runner_handle.h"
#include "device/bluetooth/bluetooth_adapter.h"
@@ -20,6 +23,7 @@
#include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h"
#include "testing/gmock/include/gmock/gmock.h"
+using base::StringPiece;
using device::BluetoothAdapter;
using device::BluetoothDevice;
using device::BluetoothGattCharacteristic;
@@ -62,6 +66,10 @@ const char kHeartRateMeasurementUUID[] = "2a37";
const char kBodySensorLocation[] = "2a38";
const char kDeviceNameUUID[] = "2a00";
+const int kDefaultTxPower = -10; // TxPower of a device broadcasting at 0.1mW.
+const int kDefaultRssi = -51; // RSSI at 1m from a device broadcasting at
+ // 0.1mW.
+
// Invokes Run() on the k-th argument of the function with no arguments.
ACTION_TEMPLATE(RunCallback,
HAS_1_TEMPLATE_PARAMS(int, k),
@@ -141,6 +149,36 @@ LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter(
else if (fake_adapter_name == "")
return NULL;
+ if (base::StartsWith(fake_adapter_name, "PowerValueAdapter",
+ base::CompareCase::SENSITIVE)) {
+ std::vector<StringPiece> args =
+ base::SplitStringPiece(fake_adapter_name, ":", base::KEEP_WHITESPACE,
+ base::SPLIT_WANT_NONEMPTY);
+ DCHECK(args[0] == "PowerValueAdapter");
+ DCHECK(args.size() == 3) << "Should contain AdapterName:TxPower:RSSI";
+
+ int tx_power;
+ base::StringToInt(args[1], &tx_power);
+ int rssi;
+ base::StringToInt(args[2], &rssi);
+ return GetPowerValueAdapter(tx_power, rssi);
+ }
+
+ if (base::StartsWith(fake_adapter_name, "PowerPresenceAdapter",
+ base::CompareCase::SENSITIVE)) {
+ std::vector<StringPiece> args =
+ base::SplitStringPiece(fake_adapter_name, ":", base::KEEP_WHITESPACE,
+ base::SPLIT_WANT_NONEMPTY);
+ DCHECK(args[0] == "PowerPresenceAdapter");
+ DCHECK(args.size() == 3)
+ << "Should contain AdapterName:TxPowerPresent:RSSIPResent";
+ DCHECK(args[1] == "true" || args[1] == "false");
+ DCHECK(args[2] == "true" || args[2] == "false");
+
+ return GetPowerPresenceAdapter(args[1] == "true" /* tx_power_present */,
+ args[2] == "true" /* rssi_present */);
+ }
+
NOTREACHED() << fake_adapter_name;
return NULL;
}
@@ -255,6 +293,35 @@ LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() {
// static
scoped_refptr<NiceMockBluetoothAdapter>
+LayoutTestBluetoothAdapterProvider::GetPowerValueAdapter(int tx_power,
+ int rssi) {
+ scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
+ scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get()));
+
+ ON_CALL(*device, GetInquiryTxPower()).WillByDefault(Return(tx_power));
+ ON_CALL(*device, GetInquiryRSSI()).WillByDefault(Return(rssi));
+
+ adapter->AddMockDevice(device.Pass());
+
+ return adapter;
+}
+
+// static
+scoped_refptr<NiceMockBluetoothAdapter>
+LayoutTestBluetoothAdapterProvider::GetPowerPresenceAdapter(
+ bool tx_power_present,
+ bool rssi_present) {
+ // TODO(ortuno): RSSI Unknown and Tx Power Unknown should have different
+ // values. Add kUnknownTxPower when implemented: http://crbug.com/551572
+ int tx_power =
+ tx_power_present ? kDefaultTxPower : BluetoothDevice::kUnknownPower;
+ int rssi = rssi_present ? kDefaultRssi : BluetoothDevice::kUnknownPower;
+
+ return GetPowerValueAdapter(tx_power, rssi);
+}
+
+// static
+scoped_refptr<NiceMockBluetoothAdapter>
LayoutTestBluetoothAdapterProvider::GetGlucoseHeartRateAdapter() {
scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());

Powered by Google App Engine
This is Rietveld 408576698