chromium/components/performance_manager/v8_memory/v8_memory_test_helpers.cc

// Copyright 2020 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/performance_manager/v8_memory/v8_memory_test_helpers.h"

#include <utility>

#include "base/check.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "components/performance_manager/embedder/graph_features.h"
#include "components/performance_manager/graph/frame_node_impl.h"
#include "components/performance_manager/graph/page_node_impl.h"
#include "components/performance_manager/graph/process_node_impl.h"
#include "components/performance_manager/public/features.h"
#include "components/performance_manager/public/mojom/v8_contexts.mojom.h"
#include "components/performance_manager/public/performance_manager.h"
#include "components/performance_manager/v8_memory/v8_context_tracker.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/test_utils.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace performance_manager {

namespace v8_memory {

_;

////////////////////////////////////////////////////////////////////////////////
// LenientMockV8DetailedMemoryReporter

LenientMockV8DetailedMemoryReporter::LenientMockV8DetailedMemoryReporter() =
    default;

LenientMockV8DetailedMemoryReporter::~LenientMockV8DetailedMemoryReporter() =
    default;

void LenientMockV8DetailedMemoryReporter::Bind(
    mojo::PendingReceiver<blink::mojom::V8DetailedMemoryReporter>
        pending_receiver) {}

////////////////////////////////////////////////////////////////////////////////
// V8MemoryTestBase

V8MemoryTestBase::V8MemoryTestBase()
    :{}

V8MemoryTestBase::~V8MemoryTestBase() {}

void V8MemoryTestBase::ReplyWithData(
    blink::mojom::PerProcessV8MemoryUsagePtr data,
    MockV8DetailedMemoryReporter::GetV8MemoryUsageCallback callback) {}

void V8MemoryTestBase::DelayedReplyWithData(
    const base::TimeDelta& delay,
    blink::mojom::PerProcessV8MemoryUsagePtr data,
    MockV8DetailedMemoryReporter::GetV8MemoryUsageCallback callback) {}

void V8MemoryTestBase::ExpectQuery(
    MockV8DetailedMemoryReporter* mock_reporter,
    base::OnceCallback<
        void(MockV8DetailedMemoryReporter::GetV8MemoryUsageCallback callback)>
        responder,
    ExpectedMode expected_mode) {}

void V8MemoryTestBase::ExpectQueryAndReply(
    MockV8DetailedMemoryReporter* mock_reporter,
    blink::mojom::PerProcessV8MemoryUsagePtr data,
    ExpectedMode expected_mode) {}

void V8MemoryTestBase::ExpectQueryAndDelayReply(
    MockV8DetailedMemoryReporter* mock_reporter,
    const base::TimeDelta& delay,
    blink::mojom::PerProcessV8MemoryUsagePtr data,
    ExpectedMode expected_mode) {}

void V8MemoryTestBase::ExpectBindReceiver(
    MockV8DetailedMemoryReporter* mock_reporter,
    RenderProcessHostId expected_process_id) {}

void V8MemoryTestBase::ExpectBindAndRespondToQuery(
    MockV8DetailedMemoryReporter* mock_reporter,
    blink::mojom::PerProcessV8MemoryUsagePtr data,
    RenderProcessHostId expected_process_id,
    ExpectedMode expected_mode) {}

void V8MemoryTestBase::BindReceiverOnMainSequence(
    mojo::PendingReceiver<blink::mojom::V8DetailedMemoryReporter>
        pending_receiver,
    RenderProcessHostProxy proxy) {}

// Storage for static members.
constexpr RenderProcessHostId V8MemoryTestBase::kTestProcessID;

////////////////////////////////////////////////////////////////////////////////
// V8MemoryPerformanceManagerTestHarness

V8MemoryPerformanceManagerTestHarness::V8MemoryPerformanceManagerTestHarness()
    :{}

V8MemoryPerformanceManagerTestHarness::
    ~V8MemoryPerformanceManagerTestHarness() = default;

void V8MemoryPerformanceManagerTestHarness::SetUp() {}

void V8MemoryPerformanceManagerTestHarness::CreateCrossProcessChildFrame() {}

scoped_refptr<base::SingleThreadTaskRunner>
V8MemoryPerformanceManagerTestHarness::GetMainThreadTaskRunner() {}

// Storage for static members.
constexpr char V8MemoryPerformanceManagerTestHarness::kMainFrameUrl[];
constexpr char V8MemoryPerformanceManagerTestHarness::kChildFrameUrl[];

////////////////////////////////////////////////////////////////////////////////
// WebMemoryTestHarness

WebMemoryTestHarness::WebMemoryTestHarness() = default;

WebMemoryTestHarness::~WebMemoryTestHarness() = default;

void WebMemoryTestHarness::SetUp() {}

int WebMemoryTestHarness::GetNextUniqueId() {}

FrameNodeImpl* WebMemoryTestHarness::AddFrameNodeImpl(
    std::optional<std::string> url,
    int browsing_instance_id,
    Bytes memory_usage,
    FrameNodeImpl* parent,
    FrameNodeImpl* opener,
    ProcessNodeImpl* process,
    std::optional<std::string> id_attribute,
    std::optional<std::string> src_attribute,
    Bytes canvas_memory_usage) {}

WorkerNodeImpl* WebMemoryTestHarness::AddWorkerNode(
    WorkerNode::WorkerType worker_type,
    std::string script_url,
    Bytes bytes,
    FrameNodeImpl* parent) {}

WorkerNodeImpl* WebMemoryTestHarness::AddWorkerNodeWithoutData(
    WorkerNode::WorkerType worker_type,
    FrameNodeImpl* parent) {}

WorkerNodeImpl* WebMemoryTestHarness::AddWorkerNode(
    WorkerNode::WorkerType worker_type,
    std::string script_url,
    Bytes bytes,
    WorkerNodeImpl* parent) {}

WorkerNodeImpl* WebMemoryTestHarness::AddWorkerNodeImpl(
    WorkerNode::WorkerType worker_type,
    const url::Origin& origin,
    std::string script_url,
    Bytes bytes) {}

void WebMemoryTestHarness::SetBlinkMemory(Bytes bytes) {}

////////////////////////////////////////////////////////////////////////////////
// Free functions

blink::mojom::PerProcessV8MemoryUsagePtr NewPerProcessV8MemoryUsage(
    size_t number_of_isolates) {}

void AddIsolateMemoryUsage(blink::ExecutionContextToken token,
                           uint64_t bytes_used,
                           blink::mojom::PerIsolateV8MemoryUsage* isolate) {}

void AddIsolateCanvasMemoryUsage(
    blink::ExecutionContextToken token,
    uint64_t bytes_used,
    blink::mojom::PerIsolateV8MemoryUsage* isolate) {}

}  // namespace v8_memory

}  // namespace performance_manager