chromium/chrome/browser/performance_manager/persistence/site_data/site_data_cache_facade_browsertest.cc

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

#include "chrome/browser/performance_manager/persistence/site_data/site_data_cache_facade.h"

#include <memory>
#include <optional>
#include <ostream>
#include <string>
#include <string_view>
#include <utility>

#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/scoped_observation.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/performance_manager/persistence/site_data/site_data_cache_facade_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/performance_manager/persistence/site_data/site_data_cache.h"
#include "components/performance_manager/persistence/site_data/site_data_cache_factory.h"
#include "components/performance_manager/persistence/site_data/site_data_cache_inspector.h"
#include "components/performance_manager/persistence/site_data/site_data_impl.h"
#include "components/performance_manager/persistence/site_data/site_data_writer.h"
#include "components/performance_manager/public/decorators/site_data_recorder.h"
#include "components/performance_manager/public/features.h"
#include "components/performance_manager/public/graph/page_node.h"
#include "components/performance_manager/public/persistence/site_data/feature_usage.h"
#include "components/performance_manager/public/persistence/site_data/site_data_reader.h"
#include "components/performance_manager/test_support/run_in_graph.h"
#include "content/public/browser/visibility.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/page_transition_types.h"
#include "ui/base/window_open_disposition.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace performance_manager {

std::ostream& operator<<(std::ostream& os, SiteFeatureUsage feature_usage) {}

namespace {

static constexpr char kSiteA[] =;

// An observer that clears all site data for a profile at the moment it's
// destroyed. In tests that call CloseAllBrowsers() at the end of the test, the
// Profile for each browser is destroyed during the last cycle of the UI thread
// message loop that processes outstanding messages just before starting the
// browser shutdown. At this point any tasks posted to a non-BLOCK_SHUTDOWN
// sequence will be lost, so this is a good time to call ClearAllSiteData() to
// verify that it succeeds.
class ClearSiteDataOnProfileDestroyed final : public ProfileObserver {};

// Overrides heuristics that are fragile to fake in a test.
class TestSiteDataRecorderHeuristics final : public SiteDataRecorderHeuristics {};

struct PMThreadingConfiguration {};

// Tests SiteDataCacheFacade in different threading configurations.
class SiteDataCacheFacadeBrowserTest
    : public InProcessBrowserTest,
      public ::testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

// TODO(crbug.com/330771327): This test is consistently failing across multiple
// builders. Pre-test: Sets up state before the main test by writing some
// feature usage for a site.
IN_PROC_BROWSER_TEST_P(SiteDataCacheFacadeBrowserTest,
                       DISABLED_PRE_PRE_ClearAllSiteData) {}

// TODO(crbug.com/330771327): This test is consistently failing across multiple
// builders. Main test: clears the feature usage written in
// PRE_PRE_ClearAllSiteData, to validate that the DB is updated when racing with
// shutdown.
IN_PROC_BROWSER_TEST_P(SiteDataCacheFacadeBrowserTest,
                       DISABLED_PRE_ClearAllSiteData) {}

// TODO(crbug.com/330771327): This test is consistently failing across multiple
// builders. Post-test: validates that PRE_ClearAllSiteData deleted the feature
// usage written in PRE_PRE_ClearAllSiteData.
IN_PROC_BROWSER_TEST_P(SiteDataCacheFacadeBrowserTest,
                       DISABLED_ClearAllSiteData) {}

}  // namespace

}  // namespace performance_manager