chromium/components/performance_manager/v8_memory/v8_detailed_memory_unittest.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/public/v8_memory/v8_detailed_memory.h"
#include "components/performance_manager/public/v8_memory/v8_detailed_memory_any_seq.h"

#include <memory>
#include <tuple>
#include <utility>

#include "base/barrier_closure.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/gtest_util.h"
#include "base/test/test_timeouts.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "build/build_config.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/graph/worker_node_impl.h"
#include "components/performance_manager/public/performance_manager.h"
#include "components/performance_manager/public/render_process_host_id.h"
#include "components/performance_manager/public/render_process_host_proxy.h"
#include "components/performance_manager/test_support/graph_test_harness.h"
#include "components/performance_manager/v8_memory/v8_memory_test_helpers.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_renderer_host.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/tokens/tokens.h"

namespace performance_manager {

namespace v8_memory {

_;
InSequence;
Mock;
StrictMock;

constexpr uint64_t kDetachedBytes =;
constexpr uint64_t kSharedBytes =;
constexpr uint64_t kBlinkBytes =;

namespace {

class LenientMockV8DetailedMemoryObserver : public V8DetailedMemoryObserver {};

MockV8DetailedMemoryObserver;

class LenientMockV8DetailedMemoryObserverAnySeq
    : public V8DetailedMemoryObserverAnySeq {};

MockV8DetailedMemoryObserverAnySeq;

// The mode enum used in the API.
MeasurementMode;

// An arbitrary object used to test object lifetimes with WeakPtr.
class LifetimeTestObject final {};

constexpr base::TimeDelta kMinTimeBetweenRequests =;

}  // namespace

class V8DetailedMemoryDecoratorTest : public GraphTestHarness,
                                      public V8MemoryTestBase {};

// kBounded mode and kEagerForTesting mode behave identically as far as
// V8DetailedMemoryDecorator is concerned. (The differences are all on the
// renderer side.) So mode tests hardcode kLazy mode and use a parameter to
// choose which of the two to use for bounded mode.
class V8DetailedMemoryDecoratorModeTest
    : public V8DetailedMemoryDecoratorTest,
      public ::testing::WithParamInterface<
          std::pair<MeasurementMode, ExpectedMode>> {};

class V8DetailedMemoryDecoratorSingleProcessModeTest
    : public V8DetailedMemoryDecoratorTest,
      public ::testing::WithParamInterface<MeasurementMode> {};

V8DetailedMemoryDecoratorDeathTest;

V8DetailedMemoryRequestAnySeqTest;

TEST_F(V8DetailedMemoryDecoratorTest, InstantiateOnEmptyGraph) {}

TEST_F(V8DetailedMemoryDecoratorTest, InstantiateOnNonEmptyGraph) {}

TEST_F(V8DetailedMemoryDecoratorTest, OnlyMeasureRenderers) {}

TEST_F(V8DetailedMemoryDecoratorTest, OneShot) {}

TEST_F(V8DetailedMemoryDecoratorTest, OneShotLifetime) {}

TEST_F(V8DetailedMemoryDecoratorTest, OneShotLifetimeAtExit) {}

TEST_F(V8DetailedMemoryDecoratorTest, QueryRateIsLimited) {}

TEST_F(V8DetailedMemoryDecoratorTest, MultipleProcessesHaveDistinctSchedules) {}

TEST_F(V8DetailedMemoryDecoratorTest, MultipleIsolatesInRenderer) {}

TEST_F(V8DetailedMemoryDecoratorTest, DataIsDistributed) {}

TEST_P(V8DetailedMemoryDecoratorModeTest, LazyRequests) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(V8DetailedMemoryDecoratorTest, MeasurementRequestsSorted) {}

TEST_F(V8DetailedMemoryDecoratorTest, MeasurementRequestsWithDelay) {}

TEST_F(V8DetailedMemoryDecoratorTest, MeasurementRequestOutlivesDecorator) {}

TEST_F(V8DetailedMemoryDecoratorTest, NotifyObservers) {}

TEST_F(V8DetailedMemoryDecoratorTest, ObserverOutlivesDecorator) {}

TEST_F(V8DetailedMemoryDecoratorTest, SingleProcessRequest) {}

TEST_P(V8DetailedMemoryDecoratorSingleProcessModeTest,
       SingleProcessLazyRequest) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(V8DetailedMemoryDecoratorDeathTest, MultipleStartMeasurement) {}

TEST_F(V8DetailedMemoryDecoratorDeathTest, EnforceObserversRemoved) {}

TEST_F(V8DetailedMemoryDecoratorDeathTest, InvalidEagerModeConfig) {}

TEST_F(V8DetailedMemoryDecoratorDeathTest, NonPositiveTimeDeltas) {}

TEST_F(V8DetailedMemoryDecoratorDeathTest, ExtremeTImeDeltas) {}

TEST_F(V8DetailedMemoryRequestAnySeqTest, RequestIsSequenceSafe) {}

// TODO(crbug.com/40763536) Sometimes timing out on Windows.
#if BUILDFLAG(IS_WIN)
#define MAYBE_SingleProcessRequest
#else
#define MAYBE_SingleProcessRequest
#endif
TEST_F(V8DetailedMemoryRequestAnySeqTest, MAYBE_SingleProcessRequest) {}

TEST_F(V8DetailedMemoryRequestAnySeqTest, OneShot) {}

TEST_F(V8DetailedMemoryRequestAnySeqTest, OneShotLifetime) {}

TEST_F(V8DetailedMemoryRequestAnySeqTest, OneShotLifetimeAtExit) {}

TEST_F(V8DetailedMemoryDecoratorTest, DedicatedWorkers) {}

TEST_F(V8DetailedMemoryDecoratorTest, CanvasMemory) {}

}  // namespace v8_memory

}  // namespace performance_manager