chromium/components/viz/service/frame_sinks/frame_sink_bundle_impl_unittest.cc

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

#include "components/viz/service/frame_sinks/frame_sink_bundle_impl.h"

#include <cstdint>
#include <optional>
#include <utility>

#include "base/auto_reset.h"
#include "base/json/values_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/test/task_environment.h"
#include "base/unguessable_token.h"
#include "components/viz/common/features.h"
#include "components/viz/common/frame_sinks/begin_frame_source.h"
#include "components/viz/common/quads/compositor_frame.h"
#include "components/viz/common/resources/resource_id.h"
#include "components/viz/common/resources/transferable_resource.h"
#include "components/viz/common/surfaces/frame_sink_bundle_id.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "components/viz/common/surfaces/local_surface_id.h"
#include "components/viz/service/display_embedder/server_shared_bitmap_manager.h"
#include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
#include "components/viz/test/compositor_frame_helpers.h"
#include "components/viz/test/fake_external_begin_frame_source.h"
#include "components/viz/test/mock_compositor_frame_sink_client.h"
#include "components/viz/test/mock_display_client.h"
#include "components/viz/test/test_output_surface_provider.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/viz/public/mojom/compositing/compositor_frame_sink.mojom-params-data.h"
#include "services/viz/public/mojom/compositing/compositor_frame_sink.mojom.h"
#include "services/viz/public/mojom/compositing/frame_sink_bundle.mojom-forward.h"
#include "services/viz/public/mojom/compositing/frame_sink_bundle.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/khronos/GLES2/gl2.h"

namespace viz {
namespace {

ElementsAre;
UnorderedElementsAre;

constexpr FrameSinkId kRootFrame(1, 1);
constexpr FrameSinkBundleId kBundleId(2, 1);
constexpr FrameSinkId kMainFrame(2, 1);
constexpr FrameSinkId kSubFrameA(2, 2);
constexpr FrameSinkId kSubFrameB(2, 3);
constexpr FrameSinkId kSubFrameC(2, 4);

const base::UnguessableToken kSurfaceTokenA =;
const base::UnguessableToken kSurfaceTokenB =;
const base::UnguessableToken kSurfaceTokenC =;

const LocalSurfaceId kSurfaceA{};
const LocalSurfaceId kSurfaceB{};
const LocalSurfaceId kSurfaceC{};

const uint64_t kBeginFrameSourceId =;

gpu::SyncToken MakeVerifiedSyncToken(int id) {}

// Matches a pointer to a structure with a sink_id field against a given
// FrameSinkId.
MATCHER_P(ForSink, id, "is for " + id.ToString()) {}

// Matches a ReturnedResource with an ID matching a given ResourceId.
MATCHER_P(ForResource,
          id,
          "is for resource " + base::NumberToString(id.GetUnsafeValue())) {}

// Holds the four interface objects needed to create a RootCompositorFrameSink.
struct TestRootFrameSink {};

// Holds objects needed to create other kinds of CompositorFrameSinks.
struct TestFrameSink {};

// Helper to receive FrameSinkBundleClient notifications and aggregate their
// contents for inspection by tests.
class TestBundleClient : public mojom::FrameSinkBundleClient {};

class FrameSinkBundleImplTest : public testing::Test {};

TEST_F(FrameSinkBundleImplTest, DestroyOnDisconnect) {}

TEST_F(FrameSinkBundleImplTest, OnBeginFrame) {}

class OnBeginFrameAcksFrameSinkBundleImplTest
    : public FrameSinkBundleImplTest,
      public testing::WithParamInterface<bool> {};

OnBeginFrameAcksFrameSinkBundleImplTest::
    OnBeginFrameAcksFrameSinkBundleImplTest() {}

void OnBeginFrameAcksFrameSinkBundleImplTest::MaybeIssueOnBeginFrame() {}

TEST_P(OnBeginFrameAcksFrameSinkBundleImplTest, SubmitAndAck) {}

TEST_P(OnBeginFrameAcksFrameSinkBundleImplTest, NoAckIfDidNotProduceFrame) {}

TEST_P(OnBeginFrameAcksFrameSinkBundleImplTest, ReclaimResourcesOnAck) {}

INSTANTIATE_TEST_SUITE_P();
}  // namespace
}  // namespace viz