blob: 1a1a51f6fadf127a40d984438516673cf5506133 [file] [log] [blame]
// Copyright 2018 The Fuchsia 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 <fuchsia/modular/cpp/fidl.h>
#include <fuchsia/ui/viewsv1token/cpp/fidl.h>
#include <lib/component/cpp/startup_context.h>
#include <lib/fidl/cpp/binding_set.h>
#include <lib/fxl/logging.h>
#include <lib/fxl/macros.h>
#include <lib/fxl/time/time_delta.h>
namespace modular {
namespace testing {
// An implementation of the fuchsia.modular.SessionShell FIDL service, to be
// used in session shell components in integration tests. Usually used through
// SessionShellBase.
class SessionShellImpl : fuchsia::modular::SessionShell {
~SessionShellImpl() override;
using ViewId = fuchsia::modular::ViewIdentifier;
// Produces a handler function that can be used in the outgoing service
// provider.
fidl::InterfaceRequestHandler<fuchsia::modular::SessionShell> GetHandler();
// Whenever SessionShell.AttachView() is called, the supplied callback is
// invoked with the view ID. The ViewOwner is dropped.
void set_on_attach_view(std::function<void(ViewId view_id)> callback) {
on_attach_view_ = std::move(callback);
// Whenever SessionShell.DetachView() is called, the supplied callback is
// invoked with the view ID. The return callback of DetachView() is invoked
// asynchronously after a delay that can be configured by the client with
// set_detach_delay().
void set_on_detach_view(std::function<void(ViewId view_id)> callback) {
on_detach_view_ = std::move(callback);
// Configures the delay after which the return callback of DetachView() is
// invoked. Used to test the timeout behavior of sessionmgr.
void set_detach_delay(zx::duration detach_delay) {
detach_delay_ = std::move(detach_delay);
// |SessionShell|
void AttachView(fuchsia::modular::ViewIdentifier view_id,
view_owner) override;
// |SessionShell|
void DetachView(fuchsia::modular::ViewIdentifier view_id,
std::function<void()> done) override;
fidl::BindingSet<fuchsia::modular::SessionShell> bindings_;
std::function<void(ViewId view_id)> on_attach_view_{[](ViewId) {}};
std::function<void(ViewId view_id)> on_detach_view_{[](ViewId) {}};
zx::duration detach_delay_{};
} // namespace testing
} // namespace modular