#include "services/device/battery/battery_status_manager_linux.h"
#include <limits>
#include <list>
#include <string>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "dbus/mock_bus.h"
#include "dbus/mock_object_proxy.h"
#include "dbus/object_path.h"
#include "dbus/property.h"
#include "services/device/battery/battery_status_manager_linux-inl.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
_;
Invoke;
NiceMock;
Return;
Unused;
namespace device {
namespace {
const char kUPowerDeviceACLinePath[] = …;
const char kUPowerDeviceBattery0Path[] = …;
const char kUPowerDeviceBattery1Path[] = …;
const char kUPowerDisplayDevicePath[] = …;
class MockUPowerObject { … };
void MockUPowerObject::ConnectToSignal(
const std::string& interface_name,
const std::string& signal_name,
dbus::ObjectProxy::SignalCallback signal_callback,
dbus::ObjectProxy::OnConnectedCallback* on_connected_callback) { … }
std::unique_ptr<dbus::Response> MockUPowerObject::CreateCallMethodResponse(
dbus::MethodCall* method_call,
Unused) { … }
void MockUPowerObject::SignalDeviceAdded(const std::string& added_device_path) { … }
void MockUPowerObject::SignalDeviceRemoved(
const std::string& removed_device_path) { … }
struct MockBatteryProperties { … };
class MockBatteryObject { … };
MockBatteryObject::MockBatteryObject(dbus::Bus* bus,
const std::string& object_path,
MockBatteryProperties* properties)
: … { … }
void MockBatteryObject::ConnectToSignal(
const std::string& interface_name,
const std::string& signal_name,
dbus::ObjectProxy::SignalCallback signal_callback,
dbus::ObjectProxy::OnConnectedCallback* on_connected_callback) { … }
std::unique_ptr<dbus::Response> MockBatteryObject::CreateCallMethodResponse(
dbus::MethodCall* method_call,
Unused) { … }
MockBatteryObject& MockBatteryObject::ExpectConnectToSignalChanged() { … }
MockBatteryObject& MockBatteryObject::ExpectConnectToSignalPropertyChanged() { … }
void MockBatteryObject::SignalChanged() { … }
void MockBatteryObject::SignalPropertyChanged(
const std::string& property_name) { … }
void MockBatteryObject::AppendPropertyToWriter(
dbus::MessageWriter* writer,
const std::string& property_name) { … }
void MockBatteryObject::AppendAllPropertiesToWriter(
dbus::MessageWriter* writer) { … }
}
class BatteryStatusManagerLinuxTest : public testing::Test { … };
void BatteryStatusManagerLinuxTest::SetUp() { … }
MockBatteryObject& BatteryStatusManagerLinuxTest::SetUpDisplayDeviceProxy(
MockBatteryProperties* properties) { … }
void BatteryStatusManagerLinuxTest::AddDevicePath(
const std::string& object_path) { … }
void BatteryStatusManagerLinuxTest::PushFrontDevicePath(
const std::string& object_path) { … }
MockBatteryObject& BatteryStatusManagerLinuxTest::AddDeviceProxy(
const std::string& object_path,
MockBatteryProperties* properties) { … }
MockBatteryObject& BatteryStatusManagerLinuxTest::PushFrontDeviceProxy(
const std::string& object_path,
MockBatteryProperties* properties) { … }
void BatteryStatusManagerLinuxTest::ExpectGetObjectProxy(
const std::string& object_path,
MockBatteryObject* mock_object) { … }
void BatteryStatusManagerLinuxTest::ExpectGetObjectProxy(
const std::string& object_path,
dbus::ObjectProxy* object_proxy) { … }
void BatteryStatusManagerLinuxTest::DeviceSignalChanged(
MockBatteryObject* device) { … }
void BatteryStatusManagerLinuxTest::DeviceSignalPropertyChanged(
MockBatteryObject* device,
const std::string& property_name) { … }
void BatteryStatusManagerLinuxTest::UPowerSignalDeviceAdded(
const std::string& device_path) { … }
void BatteryStatusManagerLinuxTest::UPowerSignalDeviceRemoved(
const std::string& device_path) { … }
void BatteryStatusManagerLinuxTest::StartBatteryStatusManagerLinux() { … }
std::unique_ptr<MockBatteryObject>
BatteryStatusManagerLinuxTest::CreateMockBatteryObject(
const std::string& object_path,
MockBatteryProperties* properties) { … }
void BatteryStatusManagerLinuxTest::BatteryUpdateCallback(
const mojom::BatteryStatus& status) { … }
void BatteryStatusManagerLinuxTest::SyncWithNotifierThread() { … }
TEST_F(BatteryStatusManagerLinuxTest, NoBattery) { … }
TEST_F(BatteryStatusManagerLinuxTest, ChargingHalfFull) { … }
TEST_F(BatteryStatusManagerLinuxTest, ChargingTimeToFull) { … }
TEST_F(BatteryStatusManagerLinuxTest, FullyCharged) { … }
TEST_F(BatteryStatusManagerLinuxTest, Discharging) { … }
TEST_F(BatteryStatusManagerLinuxTest, DischargingTimeToEmptyUnknown) { … }
TEST_F(BatteryStatusManagerLinuxTest, DeviceStateUnknown) { … }
TEST_F(BatteryStatusManagerLinuxTest, DeviceStateEmpty) { … }
TEST_F(BatteryStatusManagerLinuxTest, LevelRoundedToThreeSignificantDigits) { … }
TEST_F(BatteryStatusManagerLinuxTest, UsingFirstBatteryDevice) { … }
TEST_F(BatteryStatusManagerLinuxTest, SkipNonBatteryDevice) { … }
TEST_F(BatteryStatusManagerLinuxTest, UpdateDevicePropertyState) { … }
TEST_F(BatteryStatusManagerLinuxTest, UpdateDevicePropertyPercentage) { … }
TEST_F(BatteryStatusManagerLinuxTest, UpdateDevicePropertyTimeToEmpty) { … }
TEST_F(BatteryStatusManagerLinuxTest, UpdateDevicePropertyTimeToFull) { … }
TEST_F(BatteryStatusManagerLinuxTest, OldDaemonDeviceSignalChanged) { … }
TEST_F(BatteryStatusManagerLinuxTest, DisplayDeviceNoBattery) { … }
TEST_F(BatteryStatusManagerLinuxTest, DisplayDeviceBattery) { … }
TEST_F(BatteryStatusManagerLinuxTest, DisplayDeviceBatterySkipsEnumerate) { … }
TEST_F(BatteryStatusManagerLinuxTest, SignalDeviceAddedDisplayDevice) { … }
TEST_F(BatteryStatusManagerLinuxTest, SignalDeviceAddedBatteryAtFront) { … }
TEST_F(BatteryStatusManagerLinuxTest, SignalDeviceAddedBatteryAtBack) { … }
TEST_F(BatteryStatusManagerLinuxTest, SignalDeviceAddedNoBattery) { … }
TEST_F(BatteryStatusManagerLinuxTest, SignalDeviceRemovedBattery) { … }
TEST_F(BatteryStatusManagerLinuxTest, SignalDeviceRemovedOther) { … }
}