blob: 18fa00341451ea302ee27aab5744db21d366210f [file] [log] [blame]
// Copyright 2019 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/ui/activity/cpp/fidl.h>
#include "lib/async/dispatcher.h"
namespace activity {
namespace testing {
// Test fixture for faking a listener to the fuchsia.ui.activity.Provider API.
class FakeListener : public fuchsia::ui::activity::Listener {
FakeListener() = default;
// Creates a new handle which can be passed to fuchsia.ui.activity.Provider.WatchState
// to register this listener to the provider.
fidl::InterfaceHandle<fuchsia::ui::activity::Listener> NewHandle(
async_dispatcher_t* dispatcher = nullptr) {
return binding_.NewBinding(dispatcher);
// fuchsia.ui.activity.Listener API
virtual void OnStateChanged(fuchsia::ui::activity::State state, zx_time_t transition_time,
OnStateChangedCallback callback) {
state_changes_.emplace_back(state, transition_time);
struct StateChange {
StateChange(fuchsia::ui::activity::State state, zx_time_t time) : state(state), time(time) {}
fuchsia::ui::activity::State state;
zx::time time;
// Returns a list of state changes received by the listener.
const std::vector<StateChange>& StateChanges() const { return state_changes_; }
fidl::Binding<fuchsia::ui::activity::Listener> binding_{this};
std::vector<StateChange> state_changes_;
} // namespace testing
} // namespace activity