chromium/chrome/browser/ui/webui/top_chrome/webui_contents_preload_manager_unittest.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 <memory>
#include <optional>
#include <vector>

#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.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/preload_context.h"
#include "chrome/browser/ui/webui/top_chrome/top_chrome_web_ui_controller.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/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/memory_pressure/fake_memory_pressure_monitor.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/web_contents_tester.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

_;
Return;
RequestResult;

namespace {

template <typename T>
T ExpectHasValue(std::optional<T> optional) {}

class MockPreloadCandidateSelector : public webui::PreloadCandidateSelector {};

}  // namespace

class WebUIContentsPreloadManagerTest : public ChromeRenderViewHostTestHarness {};

TEST_F(WebUIContentsPreloadManagerTest, PreloadedContentsIsNullWithoutWarmup) {}

TEST_F(WebUIContentsPreloadManagerTest, PreloadedContentsIsNotNullAfterWarmup) {}

TEST_F(WebUIContentsPreloadManagerTest, NoPreloadUnderHeavyMemoryPressure) {}

TEST_F(WebUIContentsPreloadManagerTest, RequestReturnsNonNull) {}

TEST_F(WebUIContentsPreloadManagerTest,
       PreloadedContentsIsNotNullAfterRequest) {}

TEST_F(WebUIContentsPreloadManagerTest,
       PreloadedContentsChangesAfterSecondWarmupWithDifferentContext) {}

TEST_F(WebUIContentsPreloadManagerTest,
       WebContentsDiffersAfterWarmupThenRequestWithDifferentContext) {}

TEST_F(WebUIContentsPreloadManagerTest,
       WebContentsSameAfterWarmupThenRequestWithSameContext) {}

TEST_F(WebUIContentsPreloadManagerTest,
       PreloadedContentsBecomesNullAfterProfileDestruction) {}

// Verify that calling Request() navigates to the requested URL.
TEST_F(WebUIContentsPreloadManagerTest, RequestNavigation) {}

// Test that RequestResult::is_ready_to_show is initially false, and it
// becomes true after the preloaded WebUI calls
// TopChromeWebUIController::Embedder::ShowUI().
TEST_F(WebUIContentsPreloadManagerTest, IsReadyToShow) {}

// Regression test for crbug.com/329954901.
TEST_F(WebUIContentsPreloadManagerTest, RequestThenWarmupShouldNotCrash) {}

// Tests that the preload manager preloads the WebUI decided by the candidate
// selector.
TEST_F(WebUIContentsPreloadManagerTest, CandidateSelector) {}

// Tests that WebUI destroy may trigger new preloading.
TEST_F(WebUIContentsPreloadManagerTest, PreloadOnWebUIDestroy) {}

// Tests that `Request(url)` retains the url path if it exists.
TEST_F(WebUIContentsPreloadManagerTest, RequestURLHasPath) {}

// Tests that the preloading does not happen until the observed web contents
// emits the non-empty paint.
TEST_F(WebUIContentsPreloadManagerTest, DelayPreloadUntilNonEmptyPaint) {}

// Tests that the preloading does not happen until the deadline has passed.
TEST_F(WebUIContentsPreloadManagerTest, DelayPreloadUntilDeadline) {}

// Tests that a pending preload is cancelled when a new preload comes in.
TEST_F(WebUIContentsPreloadManagerTest, PendingDelayCancelDueToNewPreload) {}

// Tests that a pending preload is cancelled when its profile is destroying.
TEST_F(WebUIContentsPreloadManagerTest, PendingDelayCancelDueToProfileDestroy) {}

// Tests that delayed preload is eventually fired only once due to non-empty
// paint or deadline passing, but not both.
TEST_F(WebUIContentsPreloadManagerTest, DelayPreloadFireOnce) {}