Commit be88eebc authored by Andrew Moylan's avatar Andrew Moylan Committed by Commit Bot

Reland "Add basic ServiceConnection unit test"

This is a reland of 453eba23

Removed the call to mojo::core::Init from the test startup. It
caused a memory leak because //chromeos/run_all_unittests.cc
already calls it.

Original change's description:
> Add basic ServiceConnection unit test
>
> The is just testing that ServiceConnection::BindModelProvider returns
> successfully. The Mojo invitation won't go anywhere beyond the no-op
> FakeMachineLearningClient D-Bus client.
>
> To make this test compile, I had to fix an #include from an
> overlooked file rename in an earlier CL ...
>
> Bug: 863794
>
> Change-Id: Ifd31fea950145561cd5954ae16e930b801bfe49b
> Reviewed-on: https://chromium-review.googlesource.com/1139942
> Commit-Queue: Andrew Moylan <amoylan@chromium.org>
> Reviewed-by: Ken Rockot <rockot@chromium.org>
> Reviewed-by: Dan Erat <derat@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#578329}

Tested by: manual detect_leaks=1 invocation of the test.

TBR=rockot@chromium.org,derat@chromium.org

Bug: 863794
Change-Id: I1258de74273551cebdc9dd1a76f86a35ffa50147
Reviewed-on: https://chromium-review.googlesource.com/1154647Reviewed-by: default avatarAndrew Moylan <amoylan@chromium.org>
Commit-Queue: Andrew Moylan <amoylan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579234}
parent 237ff499
......@@ -15,7 +15,7 @@ void FakeMachineLearningClient::Init(dbus::Bus* const bus) {}
void FakeMachineLearningClient::BootstrapMojoConnection(
base::ScopedFD fd,
base::OnceCallback<void(bool success)> result_callback) {
const bool success = false;
const bool success = true;
std::move(result_callback).Run(success);
}
......
......@@ -22,6 +22,7 @@ source_set("unit_tests") {
testonly = true
deps = [
"//chromeos/services/device_sync:unit_tests",
"//chromeos/services/machine_learning/public/cpp:unit_tests",
"//chromeos/services/multidevice_setup:unit_tests",
"//chromeos/services/secure_channel:unit_tests",
]
......
include_rules = [
"+chromeos/dbus",
"+mojo/core/embedder",
"+mojo/public",
]
......@@ -15,3 +15,19 @@ source_set("cpp") {
"//chromeos/services/machine_learning/public/mojom",
]
}
source_set("unit_tests") {
testonly = true
sources = [
"service_connection_unittest.cc",
]
deps = [
":cpp",
"//base/test:test_support",
"//chromeos",
"//chromeos/services/machine_learning/public/mojom",
"//mojo/core/embedder",
"//mojo/public/cpp/bindings",
"//testing/gtest",
]
}
......@@ -7,7 +7,7 @@
#include "base/no_destructor.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/machine_learning_client.h"
#include "chromeos/services/machine_learning/public/mojom/interface.mojom.h"
#include "chromeos/services/machine_learning/public/mojom/machine_learning_service.mojom.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/system/invitation.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
......
......@@ -8,7 +8,7 @@
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/sequence_checker.h"
#include "chromeos/services/machine_learning/public/mojom/interface.mojom.h"
#include "chromeos/services/machine_learning/public/mojom/machine_learning_service.mojom.h"
namespace chromeos {
namespace machine_learning {
......
// 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/machine_learning/public/cpp/service_connection.h"
#include "base/macros.h"
#include "base/test/scoped_task_environment.h"
#include "base/threading/thread.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/services/machine_learning/public/mojom/machine_learning_service.mojom.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/core/embedder/scoped_ipc_support.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace machine_learning {
namespace {
class ServiceConnectionTest : public testing::Test {
public:
ServiceConnectionTest() = default;
protected:
static void SetUpTestCase() {
DBusThreadManager::Initialize();
static base::Thread ipc_thread("ipc");
ipc_thread.StartWithOptions(
base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
static mojo::core::ScopedIPCSupport ipc_support(
ipc_thread.task_runner(),
mojo::core::ScopedIPCSupport::ShutdownPolicy::CLEAN);
}
private:
base::test::ScopedTaskEnvironment scoped_task_environment_;
DISALLOW_COPY_AND_ASSIGN(ServiceConnectionTest);
};
// Tests that BindModelProvider runs OK (no crash) in a basic Mojo environment.
TEST_F(ServiceConnectionTest, BindModelProvider) {
mojom::ModelProviderPtr model_provider;
ServiceConnection::GetInstance()->BindModelProvider(
mojo::MakeRequest(&model_provider));
}
} // namespace
} // namespace machine_learning
} // 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