chromium/components/performance_manager/resource_attribution/queries_unittest.cc

// Copyright 2023 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/resource_attribution/queries.h"

#include <map>
#include <optional>
#include <set>
#include <utility>

#include "base/barrier_closure.h"
#include "base/containers/enum_set.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/observer_list_threadsafe.h"
#include "base/run_loop.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "components/performance_manager/embedder/graph_features.h"
#include "components/performance_manager/public/graph/graph.h"
#include "components/performance_manager/public/graph/page_node.h"
#include "components/performance_manager/public/graph/process_node.h"
#include "components/performance_manager/public/resource_attribution/query_results.h"
#include "components/performance_manager/public/resource_attribution/resource_contexts.h"
#include "components/performance_manager/public/resource_attribution/resource_types.h"
#include "components/performance_manager/resource_attribution/context_collection.h"
#include "components/performance_manager/resource_attribution/performance_manager_aliases.h"
#include "components/performance_manager/resource_attribution/query_params.h"
#include "components/performance_manager/resource_attribution/query_scheduler.h"
#include "components/performance_manager/test_support/graph_test_harness.h"
#include "components/performance_manager/test_support/mock_graphs.h"
#include "components/performance_manager/test_support/performance_manager_test_harness.h"
#include "components/performance_manager/test_support/resource_attribution/gtest_util.h"
#include "components/performance_manager/test_support/resource_attribution/measurement_delegates.h"
#include "components/performance_manager/test_support/run_in_graph.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/navigation_simulator.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace resource_attribution {

namespace {

_;
ElementsAre;
IsEmpty;
QueryParams;
QueryScheduler;
ResourceContextTypeId;

constexpr auto kFrameContextTypeId =;
constexpr auto kWorkerContextTypeId =;

// Fake memory results.
constexpr uint64_t kFakeResidentSetSize =;
constexpr uint64_t kFakePrivateFootprint =;

class LenientMockQueryResultObserver : public QueryResultObserver {};
MockQueryResultObserver;

ResourceAttrQueriesTest;

// Tests that interact with the QueryScheduler use PerformanceManagerTestHarness
// to test its interactions on the PM sequence.
class ResourceAttrQueriesPMTest
    : public performance_manager::PerformanceManagerTestHarness {};

QueryParams CreateQueryParams(
    ResourceTypeSet resource_types = {}

// Returns a MemorySummaryResult containing the default fake memory results.
// This can be used for the results from a process, or a page or frame that gets
// all the memory from one process. `expected_algorithm` is the measurement
// algorithm for that context type, and `expected_measurement_time` is the time
// the measurement should be taken. By default, since the tests use the mock
// clock, the expected measurement time is the same time the fake result is
// created.
MemorySummaryResult FakeMemorySummaryResult(
    MeasurementAlgorithm expected_algorithm,
    base::TimeTicks expected_measurement_time = base::TimeTicks::Now()) {}

}  // namespace

namespace internal {

// Allow EXPECT_EQ to compare QueryParams, not including the QueryId.
bool operator==(const QueryParams& a, const QueryParams& b) {}

}  // namespace internal

TEST_F(ResourceAttrQueriesTest, QueryBuilder_Params) {}

TEST_F(ResourceAttrQueriesTest, QueryBuilder_Clone) {}

TEST_F(ResourceAttrQueriesPMTest, QueryBuilder_QueryOnce_CPU) {}

TEST_F(ResourceAttrQueriesPMTest, QueryBuilder_QueryOnce_Memory) {}

TEST_F(ResourceAttrQueriesPMTest, QueryBuilder_QueryOnce_CPUAndMemory) {}

TEST_F(ResourceAttrQueriesPMTest, QueryBuilder_QueryOnceWithTaskRunner) {}

TEST_F(ResourceAttrQueriesPMTest, AddRemoveScopedQuery) {}

TEST_F(ResourceAttrQueriesPMTest, ScopedQueryIsMovable) {}

TEST_F(ResourceAttrQueriesPMTest, Observers) {}

TEST_F(ResourceAttrQueriesPMTest, GraphTeardown) {}

TEST_F(ResourceAttrQueriesPMTest, ScopedQueryAndQueryOnce) {}

TEST_F(ResourceAttrQueriesPMTest, RepeatingQueries) {}

TEST_F(ResourceAttrQueriesPMTest, ThrottleQueryOnce) {}

}  // namespace resource_attribution