chromium/services/service_manager/tests/connect/connect_unittest.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stddef.h>
#include <stdint.h>

#include <memory>
#include <optional>
#include <utility>
#include <vector>

#include "base/functional/bind.h"
#include "base/no_destructor.h"
#include "base/process/process.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/test/task_environment.h"
#include "base/test/test_suite.h"
#include "base/token.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/constants.h"
#include "services/service_manager/public/cpp/manifest.h"
#include "services/service_manager/public/cpp/manifest_builder.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_receiver.h"
#include "services/service_manager/public/cpp/test/test_service_manager.h"
#include "services/service_manager/public/mojom/service_manager.mojom.h"
#include "services/service_manager/tests/connect/connect.test-mojom.h"
#include "services/service_manager/tests/util.h"
#include "testing/gtest/include/gtest/gtest.h"

// Tests that multiple services can be packaged in a single service by
// specifying the packaged service manifests within a parent manifest and
// implementing Service::CreatePackagedServiceInstance in the parent service.

namespace service_manager {

namespace {

const char kTestServiceName[] =;
const char kTestPackageName[] =;
const char kTestAppName[] =;
const char kTestExeName[] =;
const char kTestAppAName[] =;
const char kTestAppBName[] =;
const char kTestNonexistentAppName[] =;
const char kTestSandboxedAppName[] =;
const char kTestClassAppName[] =;
const char kTestSingletonAppName[] =;

const char kIdentityTestCapability[] =;
const char kConnectTestServiceCapability[] =;
const char kStandaloneAppControlCapability[] =;

const char kConnectClassCapability[] =;
const char kExposedInterfaceCapability[] =;

const std::vector<Manifest>& GetTestManifests() {}

void ReceiveOneString(std::string* out_string,
                      base::RunLoop* loop,
                      const std::string& in_string) {}

void ReceiveTwoStrings(std::string* out_string_1,
                       std::string* out_string_2,
                       base::RunLoop* loop,
                       const std::string& in_string_1,
                       const std::string& in_string_2) {}

void ReceiveQueryResult(mojom::ServiceInfoPtr* out_info,
                        base::RunLoop* loop,
                        mojom::ServiceInfoPtr info) {}

void ReceiveConnectionResult(mojom::ConnectResult* out_result,
                             std::optional<Identity>* out_target,
                             base::RunLoop* loop,
                             int32_t in_result,
                             const std::optional<Identity>& in_identity) {}

void StartServiceResponse(base::RunLoop* quit_loop,
                          mojom::ConnectResult* out_result,
                          std::optional<Identity>* out_resolved_identity,
                          mojom::ConnectResult result,
                          const std::optional<Identity>& resolved_identity) {}

void QuitLoop(base::RunLoop* loop) {}

class TestTargetService : public Service {};

class ConnectTest : public testing::Test,
                    public Service,
                    public test::mojom::ExposedInterface {};

// Ensure the connection was properly established and that a round trip
// method call/response is completed.
TEST_F(ConnectTest, BindInterface) {}

TEST_F(ConnectTest, Instances) {}

TEST_F(ConnectTest, ConnectWithGloballyUniqueId) {}

TEST_F(ConnectTest, QueryService) {}

TEST_F(ConnectTest, QueryNonexistentService) {}

#if DCHECK_IS_ON()
// This test triggers intentional DCHECKs but is not suitable for death testing.
#define MAYBE_BlockedInterface
#else
#define MAYBE_BlockedInterface
#endif

// BlockedInterface should not be exposed to this application because it is not
// in our CapabilityFilter whitelist.
TEST_F(ConnectTest, MAYBE_BlockedInterface) {}

TEST_F(ConnectTest, AlwaysAllowedInterface) {}

// Connects to an app provided by a package.
TEST_F(ConnectTest, PackagedApp) {}

#if DCHECK_IS_ON()
// This test triggers intentional DCHECKs but is not suitable for death testing.
#define MAYBE_BlockedPackage
#else
#define MAYBE_BlockedPackage
#endif

// Ask the target application to attempt to connect to a third application
// provided by a package whose id is permitted by the primary target's
// CapabilityFilter but whose package is not. The connection should be
// allowed regardless of the target's CapabilityFilter with respect to the
// package.
TEST_F(ConnectTest, MAYBE_BlockedPackage) {}

#if DCHECK_IS_ON()
// This test triggers intentional DCHECKs but is not suitable for death testing.
#define MAYBE_PackagedApp_BlockedInterface
#else
#define MAYBE_PackagedApp_BlockedInterface
#endif

// BlockedInterface should not be exposed to this application because it is not
// in our CapabilityFilter whitelist.
TEST_F(ConnectTest, MAYBE_PackagedApp_BlockedInterface) {}

#if DCHECK_IS_ON()
// This test triggers intentional DCHECKs but is not suitable for death testing.
#define MAYBE_BlockedPackagedApplication
#else
#define MAYBE_BlockedPackagedApplication
#endif

// Connection to another application provided by the same package, blocked
// because it's not in the capability filter whitelist.
TEST_F(ConnectTest, MAYBE_BlockedPackagedApplication) {}

TEST_F(ConnectTest, CapabilityClasses) {}

#if DCHECK_IS_ON()
// This test triggers intentional DCHECKs but is not suitable for death testing.
#define MAYBE_ConnectWithoutExplicitClassBlocked
#else
#define MAYBE_ConnectWithoutExplicitClassBlocked
#endif

TEST_F(ConnectTest, MAYBE_ConnectWithoutExplicitClassBlocked) {}

TEST_F(ConnectTest, ConnectToDifferentGroup_Allowed) {}

TEST_F(ConnectTest, ConnectToDifferentGroup_Blocked) {}

TEST_F(ConnectTest, ConnectWithDifferentInstanceId_Blocked) {}

// There are various other tests (service manager, lifecycle) that test valid
// client process specifications. This is the only one for blocking.
TEST_F(ConnectTest, ConnectToClientProcess_Blocked) {}

// Verifies that a client with the "shared_instance_across_users" value of
// "instance_sharing" option can receive connections from clients run as other
// users.
TEST_F(ConnectTest, AllUsersSingleton) {}

}  // namespace
}  // namespace service_manager