Commit e6a36ea3 authored by Oleh Lamzin's avatar Oleh Lamzin Committed by Commit Bot

[Telemetry SWX] Unit tests for probe service

Add unit tests for probe service.

Bug: b:158658869
Change-Id: I3feff23e437d1883b7f4be9c9dcb97910f3ad85d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2248185
Commit-Queue: Oleh Lamzin <lamzin@google.com>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781797}
parent 6436110a
...@@ -6,7 +6,7 @@ assert(is_chromeos, "Telemetry Extension is Chrome OS only") ...@@ -6,7 +6,7 @@ assert(is_chromeos, "Telemetry Extension is Chrome OS only")
assert(!is_official_build, assert(!is_official_build,
"Telemetry Extension is only built for unofficial builds") "Telemetry Extension is only built for unofficial builds")
static_library("telemetry_extension_ui") { source_set("telemetry_extension_ui") {
sources = [ sources = [
"probe_service.cc", "probe_service.cc",
"probe_service.h", "probe_service.h",
...@@ -32,7 +32,10 @@ static_library("telemetry_extension_ui") { ...@@ -32,7 +32,10 @@ static_library("telemetry_extension_ui") {
source_set("unit_tests") { source_set("unit_tests") {
testonly = true testonly = true
sources = [ "probe_service_converters_unittest.cc" ] sources = [
"probe_service_converters_unittest.cc",
"probe_service_unittest.cc",
]
deps = [ deps = [
":telemetry_extension_ui", ":telemetry_extension_ui",
"//base", "//base",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#if defined(OFFICIAL_BUILD)
#error Probe service unit tests should only be included in unofficial builds.
#endif
#include "chromeos/components/telemetry_extension_ui/probe_service.h"
#include <cstdint>
#include <utility>
#include "base/bind.h"
#include "base/test/bind_test_util.h"
#include "base/test/task_environment.h"
#include "chromeos/dbus/cros_healthd/cros_healthd_client.h"
#include "chromeos/dbus/cros_healthd/fake_cros_healthd_client.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
class ProbeServiceTest : public testing::Test {
public:
void SetUp() override { CrosHealthdClient::InitializeFake(); }
void TearDown() override {
CrosHealthdClient::Shutdown();
// Wait for cros_healthd::ServiceConnection to observe the destruction of
// the client.
base::RunLoop().RunUntilIdle();
}
health::mojom::ProbeServiceProxy* probe_service() const {
return remote_probe_service_.get();
}
private:
base::test::TaskEnvironment task_environment_;
mojo::Remote<health::mojom::ProbeService> remote_probe_service_;
ProbeService probe_service_{
remote_probe_service_.BindNewPipeAndPassReceiver()};
};
// Tests that ProbeTelemetryInfo requests telemetry info in cros_healthd and
// forwards response via callback.
TEST_F(ProbeServiceTest, ProbeTelemetryInfoSuccess) {
constexpr int64_t kCycleCount = 512;
{
auto battery_info = cros_healthd::mojom::BatteryInfo::New();
battery_info->cycle_count = kCycleCount;
auto info = cros_healthd::mojom::TelemetryInfo::New();
info->battery_result = cros_healthd::mojom::BatteryResult::NewBatteryInfo(
std::move(battery_info));
cros_healthd::FakeCrosHealthdClient::Get()
->SetProbeTelemetryInfoResponseForTesting(info);
}
base::RunLoop run_loop;
probe_service()->ProbeTelemetryInfo(
{health::mojom::ProbeCategoryEnum::kBattery},
base::BindLambdaForTesting([&](health::mojom::TelemetryInfoPtr ptr) {
ASSERT_TRUE(ptr);
ASSERT_TRUE(ptr->battery_result);
ASSERT_TRUE(ptr->battery_result->is_battery_info());
EXPECT_EQ(ptr->battery_result->get_battery_info()->cycle_count,
kCycleCount);
run_loop.Quit();
}));
run_loop.Run();
}
} // namespace chromeos
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