Commit 560f859d authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS MultiDevice] Add TestClientConnectionParametersFactory.

This test-only class is a utility which will be used in the upcoming CL
which adds ActiveConnectionManager.

Bug: 824568, 752273
Change-Id: I41a8fb1a63965b8160e4f2f70852cbefe038a531
Reviewed-on: https://chromium-review.googlesource.com/1072569
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561894}
parent bec05e14
...@@ -73,6 +73,8 @@ static_library("test_support") { ...@@ -73,6 +73,8 @@ static_library("test_support") {
"fake_pending_connection_request_delegate.h", "fake_pending_connection_request_delegate.h",
"fake_single_client_message_proxy.cc", "fake_single_client_message_proxy.cc",
"fake_single_client_message_proxy.h", "fake_single_client_message_proxy.h",
"test_client_connection_parameters_factory.cc",
"test_client_connection_parameters_factory.h",
] ]
deps = [ deps = [
......
// Copyright 2018 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.
#include "chromeos/services/secure_channel/test_client_connection_parameters_factory.h"
namespace chromeos {
namespace secure_channel {
// static
TestClientConnectionParametersFactory*
TestClientConnectionParametersFactory::Get() {
static base::NoDestructor<TestClientConnectionParametersFactory> factory;
return factory.get();
}
TestClientConnectionParametersFactory::TestClientConnectionParametersFactory() =
default;
TestClientConnectionParametersFactory::
~TestClientConnectionParametersFactory() = default;
ClientConnectionParameters TestClientConnectionParametersFactory::Create(
const std::string& feature) {
auto fake_connection_delegate = std::make_unique<FakeConnectionDelegate>();
ClientConnectionParameters parameters(
feature, fake_connection_delegate->GenerateInterfacePtr());
client_id_to_delegate_map_[parameters.id()] =
std::move(fake_connection_delegate);
return parameters;
}
FakeConnectionDelegate*
TestClientConnectionParametersFactory::GetDelegateForParameters(
const ClientConnectionParameters& client_connection_parameters) {
if (!base::ContainsKey(client_id_to_delegate_map_,
client_connection_parameters.id())) {
return nullptr;
}
return client_id_to_delegate_map_[client_connection_parameters.id()].get();
}
} // namespace secure_channel
} // namespace chromeos
// Copyright 2018 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.
#ifndef CHROMEOS_SERVICES_SECURE_CHANNEL_TEST_CLIENT_CONNECTION_PARAMETERS_FACTORY_H_
#define CHROMEOS_SERVICES_SECURE_CHANNEL_TEST_CLIENT_CONNECTION_PARAMETERS_FACTORY_H_
#include <memory>
#include <string>
#include <unordered_map>
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/unguessable_token.h"
#include "chromeos/services/secure_channel/client_connection_parameters.h"
#include "chromeos/services/secure_channel/fake_connection_delegate.h"
namespace chromeos {
namespace secure_channel {
// Test utility which provides an easy way to generate
// ClientConnectionParameters.
class TestClientConnectionParametersFactory {
public:
static TestClientConnectionParametersFactory* Get();
~TestClientConnectionParametersFactory();
ClientConnectionParameters Create(const std::string& feature);
// Returns the FakeConnectionDelegate* associated with the
// mojom::ConnectionDelegatePtr which resides in
// |client_connection_parameters|. If this function is passed a
// ClientConnectionParameters that was not created by this factory, nullptr is
// returned.
FakeConnectionDelegate* GetDelegateForParameters(
const ClientConnectionParameters& client_connection_parameters);
private:
friend class base::NoDestructor<TestClientConnectionParametersFactory>;
TestClientConnectionParametersFactory();
std::unordered_map<base::UnguessableToken,
std::unique_ptr<FakeConnectionDelegate>,
base::UnguessableTokenHash>
client_id_to_delegate_map_;
DISALLOW_COPY_AND_ASSIGN(TestClientConnectionParametersFactory);
};
} // namespace secure_channel
} // namespace chromeos
#endif // CHROMEOS_SERVICES_SECURE_CHANNEL_TEST_CLIENT_CONNECTION_PARAMETERS_FACTORY_H_
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