chromium/chrome/browser/paint_preview/paint_preview_browsertest.cc

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

#include <optional>
#include <string_view>

#include "base/base64.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/paint_preview/browser/paint_preview_client.h"
#include "components/paint_preview/common/file_stream.h"
#include "components/paint_preview/common/mojom/paint_preview_recorder.mojom-shared.h"
#include "components/paint_preview/common/proto/paint_preview.pb.h"
#include "components/paint_preview/common/recording_map.h"
#include "components/paint_preview/common/serialized_recording.h"
#include "components/paint_preview/common/test_utils.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkStream.h"
#include "url/gurl.h"

namespace paint_preview {

class NoOpPaintPreviewRecorder : public mojom::PaintPreviewRecorder {};

// Test harness for a integration test of paint previews. In this test:
// - Each RenderFrame has an instance of PaintPreviewRecorder attached.
// - Each WebContents has an instance of PaintPreviewClient attached.
// This permits end-to-end testing of the flow of paint previews.
class PaintPreviewBrowserTest
    : public InProcessBrowserTest,
      public testing::WithParamInterface<RecordingPersistence> {};

IN_PROC_BROWSER_TEST_P(PaintPreviewBrowserTest, CaptureFrame) {}

IN_PROC_BROWSER_TEST_P(PaintPreviewBrowserTest,
                       CaptureMainFrameWithCrossProcessSubframe) {}

class PaintPreviewFencedFrameBrowserTest : public PaintPreviewBrowserTest {};

IN_PROC_BROWSER_TEST_P(PaintPreviewFencedFrameBrowserTest,
                       CaptureMainFrameWithCrossProcessFencedFrames) {}

IN_PROC_BROWSER_TEST_P(PaintPreviewFencedFrameBrowserTest,
                       DoNotAffectAnotherFrameWhenRemovingFencedFrame) {}

IN_PROC_BROWSER_TEST_P(PaintPreviewBrowserTest,
                       CaptureMainFrameWithScrollableSameProcessSubframe) {}

IN_PROC_BROWSER_TEST_P(PaintPreviewBrowserTest,
                       CaptureMainFrameWithNonScrollableSameProcessSubframe) {}

// https://crbug.com/1146573 reproduction. If a renderer crashes,
// WebContentsObserver::RenderFrameDeleted. Paint preview implements this in an
// observer which in turn releases the capture handle which can cause the
// WebContents to be reloaded on Android where we have auto-reload. This reload
// occurs *during* crash handling, leaving the frame in an invalid state and
// leading to a crash when it subsequently unloaded.
// This is fixed by deferring it to a PostTask.
IN_PROC_BROWSER_TEST_P(PaintPreviewBrowserTest, DontReloadInRenderProcessExit) {}

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
}  // namespace paint_preview