Commit 485a4432 authored by Yusuke Sato's avatar Yusuke Sato Committed by Commit Bot

Allow set_xxx_response() methods to accept base::nullopt

This allows unit tests that uses FakeConciergeClient to test the
case where base::nullopt response is passed to these callbacks
without needing to modify the existing tests at all.

BUG=b:136128691
TEST=try

Change-Id: I25b31be7f060b419184e891413d21b5a645ac46b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1894042Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Commit-Queue: Yusuke Sato <yusukes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711635}
parent 33a62ac8
...@@ -148,7 +148,8 @@ void FakeConciergeClient::StartTerminaVm( ...@@ -148,7 +148,8 @@ void FakeConciergeClient::StartTerminaVm(
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), start_vm_response_)); FROM_HERE, base::BindOnce(std::move(callback), start_vm_response_));
if (start_vm_response_.status() != vm_tools::concierge::VM_STATUS_STARTING) { if (!start_vm_response_ ||
start_vm_response_->status() != vm_tools::concierge::VM_STATUS_STARTING) {
// Don't send the tremplin signal unless the VM was STARTING. // Don't send the tremplin signal unless the VM was STARTING.
return; return;
} }
...@@ -264,42 +265,49 @@ void FakeConciergeClient::StartArcVm( ...@@ -264,42 +265,49 @@ void FakeConciergeClient::StartArcVm(
} }
void FakeConciergeClient::InitializeProtoResponses() { void FakeConciergeClient::InitializeProtoResponses() {
create_disk_image_response_.Clear(); create_disk_image_response_.emplace();
create_disk_image_response_.set_status( create_disk_image_response_->set_status(
vm_tools::concierge::DISK_STATUS_CREATED); vm_tools::concierge::DISK_STATUS_CREATED);
create_disk_image_response_.set_disk_path("foo"); create_disk_image_response_->set_disk_path("foo");
destroy_disk_image_response_.Clear(); destroy_disk_image_response_.emplace();
destroy_disk_image_response_.set_status( destroy_disk_image_response_->set_status(
vm_tools::concierge::DISK_STATUS_DESTROYED); vm_tools::concierge::DISK_STATUS_DESTROYED);
list_vm_disks_response_.Clear(); import_disk_image_response_.emplace();
list_vm_disks_response_.set_success(true); cancel_disk_image_response_.emplace();
disk_image_status_response_.emplace();
start_vm_response_.Clear(); list_vm_disks_response_.emplace();
start_vm_response_.set_status(vm_tools::concierge::VM_STATUS_STARTING); list_vm_disks_response_->set_success(true);
stop_vm_response_.Clear(); start_vm_response_.emplace();
stop_vm_response_.set_success(true); start_vm_response_->set_status(vm_tools::concierge::VM_STATUS_STARTING);
get_vm_info_response_.Clear(); stop_vm_response_.emplace();
get_vm_info_response_.set_success(true); stop_vm_response_->set_success(true);
get_vm_info_response_.mutable_vm_info()->set_seneschal_server_handle(1);
container_ssh_keys_response_.Clear(); get_vm_info_response_.emplace();
container_ssh_keys_response_.set_container_public_key("pubkey"); get_vm_info_response_->set_success(true);
container_ssh_keys_response_.set_host_private_key("privkey"); get_vm_info_response_->mutable_vm_info()->set_seneschal_server_handle(1);
container_ssh_keys_response_.set_hostname("hostname");
attach_usb_device_response_.Clear(); get_vm_enterprise_reporting_info_response_.emplace();
attach_usb_device_response_.set_success(true); set_vm_cpu_restriction_response_.emplace();
attach_usb_device_response_.set_guest_port(0);
detach_usb_device_response_.Clear(); container_ssh_keys_response_.emplace();
detach_usb_device_response_.set_success(true); container_ssh_keys_response_->set_container_public_key("pubkey");
container_ssh_keys_response_->set_host_private_key("privkey");
container_ssh_keys_response_->set_hostname("hostname");
list_usb_devices_response_.Clear(); attach_usb_device_response_.emplace();
list_usb_devices_response_.set_success(true); attach_usb_device_response_->set_success(true);
attach_usb_device_response_->set_guest_port(0);
detach_usb_device_response_.emplace();
detach_usb_device_response_->set_success(true);
list_usb_devices_response_.emplace();
list_usb_devices_response_->set_success(true);
} }
} // namespace chromeos } // namespace chromeos
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/optional.h"
#include "chromeos/dbus/cicerone_client.h" #include "chromeos/dbus/cicerone_client.h"
#include "chromeos/dbus/concierge_client.h" #include "chromeos/dbus/concierge_client.h"
...@@ -156,75 +157,77 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS) FakeConciergeClient ...@@ -156,75 +157,77 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS) FakeConciergeClient
wait_for_service_to_be_available_response; wait_for_service_to_be_available_response;
} }
void set_create_disk_image_response( void set_create_disk_image_response(
const vm_tools::concierge::CreateDiskImageResponse& base::Optional<vm_tools::concierge::CreateDiskImageResponse>
create_disk_image_response) { create_disk_image_response) {
create_disk_image_response_ = create_disk_image_response; create_disk_image_response_ = create_disk_image_response;
} }
void set_destroy_disk_image_response( void set_destroy_disk_image_response(
const vm_tools::concierge::DestroyDiskImageResponse& base::Optional<vm_tools::concierge::DestroyDiskImageResponse>
destroy_disk_image_response) { destroy_disk_image_response) {
destroy_disk_image_response_ = destroy_disk_image_response; destroy_disk_image_response_ = destroy_disk_image_response;
} }
void set_import_disk_image_response( void set_import_disk_image_response(
const vm_tools::concierge::ImportDiskImageResponse& base::Optional<vm_tools::concierge::ImportDiskImageResponse>
import_disk_image_response) { import_disk_image_response) {
import_disk_image_response_ = import_disk_image_response; import_disk_image_response_ = import_disk_image_response;
} }
void set_cancel_disk_image_response( void set_cancel_disk_image_response(
const vm_tools::concierge::CancelDiskImageResponse& base::Optional<vm_tools::concierge::CancelDiskImageResponse>
cancel_disk_image_response) { cancel_disk_image_response) {
cancel_disk_image_response_ = cancel_disk_image_response; cancel_disk_image_response_ = cancel_disk_image_response;
} }
void set_disk_image_status_response( void set_disk_image_status_response(
const vm_tools::concierge::DiskImageStatusResponse& base::Optional<vm_tools::concierge::DiskImageStatusResponse>
disk_image_status_response) { disk_image_status_response) {
disk_image_status_response_ = disk_image_status_response; disk_image_status_response_ = disk_image_status_response;
} }
void set_list_vm_disks_response( void set_list_vm_disks_response(
const vm_tools::concierge::ListVmDisksResponse& list_vm_disks_response) { base::Optional<vm_tools::concierge::ListVmDisksResponse>
list_vm_disks_response) {
list_vm_disks_response_ = list_vm_disks_response; list_vm_disks_response_ = list_vm_disks_response;
} }
void set_start_vm_response( void set_start_vm_response(
const vm_tools::concierge::StartVmResponse& start_vm_response) { base::Optional<vm_tools::concierge::StartVmResponse> start_vm_response) {
start_vm_response_ = start_vm_response; start_vm_response_ = start_vm_response;
} }
void set_stop_vm_response( void set_stop_vm_response(
const vm_tools::concierge::StopVmResponse& stop_vm_response) { base::Optional<vm_tools::concierge::StopVmResponse> stop_vm_response) {
stop_vm_response_ = stop_vm_response; stop_vm_response_ = stop_vm_response;
} }
void set_get_vm_info_response( void set_get_vm_info_response(
const vm_tools::concierge::GetVmInfoResponse& get_vm_info_response) { base::Optional<vm_tools::concierge::GetVmInfoResponse>
get_vm_info_response) {
get_vm_info_response_ = get_vm_info_response; get_vm_info_response_ = get_vm_info_response;
} }
void set_get_vm_enterprise_reporting_info_response( void set_get_vm_enterprise_reporting_info_response(
const vm_tools::concierge::GetVmEnterpriseReportingInfoResponse& base::Optional<vm_tools::concierge::GetVmEnterpriseReportingInfoResponse>
get_vm_enterprise_reporting_info_response) { get_vm_enterprise_reporting_info_response) {
get_vm_enterprise_reporting_info_response_ = get_vm_enterprise_reporting_info_response_ =
get_vm_enterprise_reporting_info_response; get_vm_enterprise_reporting_info_response;
} }
void set_set_vm_cpu_restriction_response( void set_set_vm_cpu_restriction_response(
const vm_tools::concierge::SetVmCpuRestrictionResponse& base::Optional<vm_tools::concierge::SetVmCpuRestrictionResponse>
set_vm_cpu_restriction_response) { set_vm_cpu_restriction_response) {
set_vm_cpu_restriction_response_ = set_vm_cpu_restriction_response; set_vm_cpu_restriction_response_ = set_vm_cpu_restriction_response;
} }
void set_container_ssh_keys_response( void set_container_ssh_keys_response(
const vm_tools::concierge::ContainerSshKeysResponse& base::Optional<vm_tools::concierge::ContainerSshKeysResponse>
container_ssh_keys_response) { container_ssh_keys_response) {
container_ssh_keys_response_ = container_ssh_keys_response; container_ssh_keys_response_ = container_ssh_keys_response;
} }
void set_attach_usb_device_response( void set_attach_usb_device_response(
const vm_tools::concierge::AttachUsbDeviceResponse& base::Optional<vm_tools::concierge::AttachUsbDeviceResponse>
attach_usb_device_response) { attach_usb_device_response) {
attach_usb_device_response_ = attach_usb_device_response; attach_usb_device_response_ = attach_usb_device_response;
} }
void set_detach_usb_device_response( void set_detach_usb_device_response(
const vm_tools::concierge::DetachUsbDeviceResponse& base::Optional<vm_tools::concierge::DetachUsbDeviceResponse>
detach_usb_device_response) { detach_usb_device_response) {
detach_usb_device_response_ = detach_usb_device_response; detach_usb_device_response_ = detach_usb_device_response;
} }
void set_list_usb_devices_response( void set_list_usb_devices_response(
const vm_tools::concierge::ListUsbDeviceResponse& base::Optional<vm_tools::concierge::ListUsbDeviceResponse>
list_usb_devices_response) { list_usb_devices_response) {
list_usb_devices_response_ = list_usb_devices_response; list_usb_devices_response_ = list_usb_devices_response;
} }
void set_disk_image_status_signals( void set_disk_image_status_signals(
...@@ -272,23 +275,33 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS) FakeConciergeClient ...@@ -272,23 +275,33 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS) FakeConciergeClient
bool is_disk_image_progress_signal_connected_ = true; bool is_disk_image_progress_signal_connected_ = true;
bool wait_for_service_to_be_available_response_ = true; bool wait_for_service_to_be_available_response_ = true;
vm_tools::concierge::CreateDiskImageResponse create_disk_image_response_; base::Optional<vm_tools::concierge::CreateDiskImageResponse>
vm_tools::concierge::DestroyDiskImageResponse destroy_disk_image_response_; create_disk_image_response_;
vm_tools::concierge::ImportDiskImageResponse import_disk_image_response_; base::Optional<vm_tools::concierge::DestroyDiskImageResponse>
vm_tools::concierge::CancelDiskImageResponse cancel_disk_image_response_; destroy_disk_image_response_;
vm_tools::concierge::DiskImageStatusResponse disk_image_status_response_; base::Optional<vm_tools::concierge::ImportDiskImageResponse>
vm_tools::concierge::ListVmDisksResponse list_vm_disks_response_; import_disk_image_response_;
vm_tools::concierge::StartVmResponse start_vm_response_; base::Optional<vm_tools::concierge::CancelDiskImageResponse>
vm_tools::concierge::StopVmResponse stop_vm_response_; cancel_disk_image_response_;
vm_tools::concierge::GetVmInfoResponse get_vm_info_response_; base::Optional<vm_tools::concierge::DiskImageStatusResponse>
vm_tools::concierge::GetVmEnterpriseReportingInfoResponse disk_image_status_response_;
base::Optional<vm_tools::concierge::ListVmDisksResponse>
list_vm_disks_response_;
base::Optional<vm_tools::concierge::StartVmResponse> start_vm_response_;
base::Optional<vm_tools::concierge::StopVmResponse> stop_vm_response_;
base::Optional<vm_tools::concierge::GetVmInfoResponse> get_vm_info_response_;
base::Optional<vm_tools::concierge::GetVmEnterpriseReportingInfoResponse>
get_vm_enterprise_reporting_info_response_; get_vm_enterprise_reporting_info_response_;
vm_tools::concierge::SetVmCpuRestrictionResponse base::Optional<vm_tools::concierge::SetVmCpuRestrictionResponse>
set_vm_cpu_restriction_response_; set_vm_cpu_restriction_response_;
vm_tools::concierge::ContainerSshKeysResponse container_ssh_keys_response_; base::Optional<vm_tools::concierge::ContainerSshKeysResponse>
vm_tools::concierge::AttachUsbDeviceResponse attach_usb_device_response_; container_ssh_keys_response_;
vm_tools::concierge::DetachUsbDeviceResponse detach_usb_device_response_; base::Optional<vm_tools::concierge::AttachUsbDeviceResponse>
vm_tools::concierge::ListUsbDeviceResponse list_usb_devices_response_; attach_usb_device_response_;
base::Optional<vm_tools::concierge::DetachUsbDeviceResponse>
detach_usb_device_response_;
base::Optional<vm_tools::concierge::ListUsbDeviceResponse>
list_usb_devices_response_;
// Can be set to fake a series of disk image status signals. // Can be set to fake a series of disk image status signals.
std::vector<vm_tools::concierge::DiskImageStatusResponse> std::vector<vm_tools::concierge::DiskImageStatusResponse>
......
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