Commit 89892f36 authored by Oleh Lamzin's avatar Oleh Lamzin Committed by Commit Bot

[Telemetry SWX] add bluetooth info browser test

Bug: b:158658869
Change-Id: Ic523b315c8fcffd8f47d8ef517d4f365b2e6b3df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2386801
Commit-Queue: Oleh Lamzin <lamzin@google.com>
Reviewed-by: default avatarMahmoud Gawad <mgawad@google.com>
Cr-Commit-Position: refs/heads/master@{#803651}
parent bd2526d9
......@@ -409,7 +409,8 @@ class TelemetryProxy {
/**
* This method converts Mojo types to WebIDL types applying next rules:
* 1. remove null objects from arrays;
* 2. convert objects like { value: X } to X, where X is a number;
* 2. convert objects like { value: X } to X, where X is either a number or
* a boolean;
* 3. omit null/undefined properties;
* 4. convert objects without properties to null.
* @param {?Object|string|number|null|undefined} input
......@@ -439,9 +440,11 @@ class TelemetryProxy {
// At this point, closure compiler knows that the input is {!Object}.
// Rule #2: convert objects like { value: X } to X, where X is a number.
// Rule #2: convert objects like { value: X } to X, where X is either a
// number or a boolean.
if (Object.entries(input).length === 1 &&
typeof input['value'] === 'number') {
(typeof input['value'] === 'number' ||
typeof input['value'] === 'boolean')) {
return input['value'];
}
......
......@@ -306,6 +306,21 @@ void TelemetryExtensionUiBrowserTest::SetUpOnMainThread() {
telemetry_info->stateful_partition_result = chromeos::cros_healthd::mojom::
StatefulPartitionResult::NewPartitionInfo(std::move(partition_info));
}
{
auto bluetooth_info =
chromeos::cros_healthd::mojom::BluetoothAdapterInfo::New();
bluetooth_info->name = "hci0";
bluetooth_info->address = "ab:cd:ef:12:34:56";
bluetooth_info->powered = true;
bluetooth_info->num_connected_devices = 4294967295;
std::vector<chromeos::cros_healthd::mojom::BluetoothAdapterInfoPtr> infos;
infos.push_back(std::move(bluetooth_info));
telemetry_info->bluetooth_result =
chromeos::cros_healthd::mojom::BluetoothResult::NewBluetoothAdapterInfo(
std::move(infos));
}
DCHECK(chromeos::cros_healthd::FakeCrosHealthdClient::Get());
......
......@@ -160,6 +160,10 @@ TEST_F(
assertEquals(telemetryProxy.convert({value: 15}), 15);
assertEquals(telemetryProxy.convert({value: 777.555}), 777.555);
// {value: X} --> X if X is a booelan.
assertEquals(telemetryProxy.convert({value: false}), false);
assertEquals(telemetryProxy.convert({value: true}), true);
// {value: X} --> {value: X} if X is not a number.
assertDeepEquals(telemetryProxy.convert({value: 'ABC'}), {value: 'ABC'});
assertDeepEquals(
......
......@@ -255,6 +255,14 @@ UNTRUSTED_TEST('UntrustedRequestTelemetryInfo', async () => {
availableSpace: availableSpace,
totalSpace: 1125900006842624,
}
},
bluetoothResult: {
bluetoothAdapterInfo: [{
name: 'hci0',
address: 'ab:cd:ef:12:34:56',
powered: true,
numConnectedDevices: 4294967295
}]
}
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment