chromium/chrome/browser/ui/webui/top_chrome/webui_contents_preload_manager_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/ui/webui/top_chrome/webui_contents_preload_manager.h"

#include <map>

#include "base/containers/span.h"
#include "base/metrics/statistics_recorder.h"
#include "base/run_loop.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/page_load_metrics/observers/non_tab_webui_page_load_metrics_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/webui/top_chrome/preload_candidate_selector.h"
#include "chrome/browser/ui/webui/top_chrome/top_chrome_web_ui_controller.h"
#include "chrome/browser/ui/webui/top_chrome/top_chrome_webui_config.h"
#include "chrome/browser/ui/webui/top_chrome/webui_contents_preload_manager_test_api.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/scoped_web_ui_controller_factory_registration.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/url_loader_interceptor.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/widget/widget.h"
#include "url/gurl.h"

_;
Return;

namespace {

void WaitForHistogram(const std::string& histogram_name) {}

// Returns the command ID that can be used to trigger the WebUI.
int GetCommandIdForURL(GURL webui_url) {}

PreloadModeName;
std::vector<PreloadModeName> GetAllPreloadManagerModes() {}

class MockPreloadCandidateSelector : public webui::PreloadCandidateSelector {};

}  // namespace

class WebUIContentsPreloadManagerBrowserTestBase : public InProcessBrowserTest {};

class WebUIContentsPreloadManagerBrowserSmokeTest
    : public WebUIContentsPreloadManagerBrowserTestBase,
      public ::testing::WithParamInterface<PreloadModeName> {};

// A smoke test that ensures the browser does not crash when triggering
// preloaded WebUIs. Each WebUI is triggered in a new browser.
// Note: the list of preloadable WebUIs is not available until their WebUIConfig
// is registered during browser startup, therefore cannot be used as test
// parameters.
IN_PROC_BROWSER_TEST_P(WebUIContentsPreloadManagerBrowserSmokeTest,
                       TriggerPreloadedUIs) {}

INSTANTIATE_TEST_SUITE_P();

namespace {

constexpr char kTestWebUIHost[] =;
constexpr char kTestWebUIOrigin[] =;
// This URL will be served with the content of //chrome/test/data/title1.html
constexpr char kTestWebUIURL[] =;

class TestTopChromeWebUIController : public TopChromeWebUIController {};

class TestTopChromeWebUIConfig
    : public DefaultTopChromeWebUIConfig<TestTopChromeWebUIController> {};

}  // namespace

class WebUIContentsPreloadManagerPageLoadMetricsTest
    : public WebUIContentsPreloadManagerBrowserTestBase {};

#if BUILDFLAG(IS_CHROMEOS_LACROS)
// The page load metrics test is flaky on LaCrOS because sometimes viz::Display
// reports a negative frame latency that causes page load metrics to stop
// propagation.
#define MAYBE_RequestToFCP
#else
#define MAYBE_RequestToFCP
#endif
// Tests that the time from the WebUI is requested to when First Contentful
// Paint (FCP) is recorded.
IN_PROC_BROWSER_TEST_F(WebUIContentsPreloadManagerPageLoadMetricsTest,
                       MAYBE_RequestToFCP) {}

class WebUIContentsPreloadManagerHistoryClusterMetricTest
    : public WebUIContentsPreloadManagerBrowserTestBase {};

// Tests that history cluster metrics are NOT recorded for a preloaded History
// Clusters UI that is never shown.
IN_PROC_BROWSER_TEST_F(WebUIContentsPreloadManagerHistoryClusterMetricTest,
                       PreloadButNeverShow) {}

// Tests that history cluster metrics are recorded for a preloaded History
// Clusters UI that is shown.
IN_PROC_BROWSER_TEST_F(WebUIContentsPreloadManagerHistoryClusterMetricTest,
                       PreloadAndShow) {}