chromium/chrome/browser/pdf/pdf_extension_test.cc

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

#include <stddef.h>

#include <string>
#include <tuple>
#include <variant>
#include <vector>

#include "base/feature_list.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/hash/hash.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/path_service.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_timeouts.h"
#include "base/test/with_feature_override.h"
#include "base/thread_annotations.h"
#include "base/threading/thread_restrictions.h"
#include "base/unguessable_token.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "cc/input/scroll_utils.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/pdf/pdf_extension_test_base.h"
#include "chrome/browser/pdf/pdf_extension_test_util.h"
#include "chrome/browser/pdf/pdf_viewer_stream_manager.h"
#include "chrome/browser/pdf/test_pdf_viewer_stream_manager.h"
#include "chrome/browser/plugins/plugin_test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/download/public/common/download_item.h"
#include "components/guest_view/browser/test_guest_view_manager.h"
#include "components/metrics/content/subprocess_metrics_provider.h"
#include "components/pdf/browser/pdf_frame_util.h"
#include "components/pdf/common/constants.h"
#include "components/pdf/common/pdf_util.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h"
#include "components/zoom/page_zoom.h"
#include "components/zoom/test/zoom_test_utils.h"
#include "components/zoom/zoom_controller.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/site_isolation_policy.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/context_menu_interceptor.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/hit_test_region_observer.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_frame_navigation_observer.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/text_input_test_utils.h"
#include "content/public/test/url_loader_interceptor.h"
#include "extensions/browser/api/file_system/file_system_api.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/extension_web_contents_observer.h"
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_attach_helper.h"
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
#include "extensions/browser/guest_view/mime_handler_view/test_mime_handler_view_guest.h"
#include "extensions/test/result_catcher.h"
#include "extensions/test/test_extension_dir.h"
#include "net/test/embedded_test_server/controllable_http_response.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "pdf/pdf_features.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/context_menu_data/untrustworthy_context_menu_params.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/common/input/web_mouse_event.h"
#include "third_party/blink/public/common/messaging/transferable_message.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/clipboard_monitor.h"
#include "ui/base/clipboard/clipboard_observer.h"
#include "ui/base/clipboard/test/test_clipboard.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "url/gurl.h"

#if defined(TOOLKIT_VIEWS) && !BUILDFLAG(IS_MAC)
#include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
#endif

namespace {

WebContents;
MimeHandlerViewGuest;
TestMimeHandlerViewGuest;
GuestViewManager;
TestGuestViewManager;
TestGuestViewManagerFactory;
ConvertPageCoordToScreenCoord;
GetPdfPluginFrames;
SetInputFocusOnPlugin;
IsEmpty;
StartsWith;

const int kNumberLoadTestParts =;

#if BUILDFLAG(IS_MAC)
const int kDefaultKeyModifier = blink::WebInputEvent::kMetaKey;
#else
const int kDefaultKeyModifier =;
#endif

// Javascript evaluation used to check if inner PDF frames can be accessed.
constexpr char kNestedWindowFramesUndefinedCheck[] =;

struct PDFExtensionLoadTestPassToString {};

struct PDFExtensionIsolatedContentTestPassToString {};

// Calling PluginService::GetPlugins ensures that LoadPlugins is called
// internally. This is an asynchronous task and this method uses a run loop to
// wait for the loading task to complete.
void WaitForPluginServiceToLoad() {}

}  // namespace

class PDFExtensionTest : public base::test::WithFeatureOverride,
                         public PDFExtensionTestBase {};

PDFExtensionTestWithoutOopifOverride;

class PDFExtensionTestWithPartialLoading : public PDFExtensionTest {};

// Historically, https://crrev.com/352991 focused the PDF embed element when it
// was created. To preserve this behavior, make sure the extension frame has
// focus for a full page PDF viewer on creation.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, FullPagePdfHasFocus) {}

// For GuestView PDF, this test verifies that when a PDF is loaded, the embedder
// WebContents' html consists of a single <embed> tag with appropriate
// properties. It also verifies that the guest WebContents finishes loading. For
// OOPIF PDF, this test verifies that extension frame finished loading. For
// both, the WebContents and the extension frame should have the correct URL for
// the PDF extension.
// TODO(wjmaclean): Are there any attributes we can/should test with respect to
// the extension's loaded html?
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, PdfExtensionLoaded) {}

// Helper class to allow pausing the asynchronous attachment of an inner
// WebContents between MimeHandlerViewAttachHelper's AttachToOuterWebContents()
// and ResumeAttachOrDestroy().  This corresponds to the point where the inner
// WebContents has been created but not yet attached or navigated.
class InnerWebContentsAttachDelayer {};

// Ensure that when the only other PDF instance closes in the middle of
// attaching an inner WebContents for a PDF, the inner WebContents can still
// successfully complete its attachment and subsequent navigation.  See
// https://crbug.com/1295431.
// See PDFExtensionOopifTest.PdfExtensionLoadedWhileOldPdfCloses for the OOPIF
// PDF version.
IN_PROC_BROWSER_TEST_F(PDFExtensionTestWithoutOopifOverride,
                       PdfExtensionLoadedWhileOldPdfCloses) {}

// This test verifies that when a PDF is served with a restrictive
// Content-Security-Policy, the embed tag is still sized correctly.
// Regression test for https://crbug.com/271452.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, CSPDoesNotBlockEmbedStyles) {}

// This test verifies that when a PDF is served with
// Content-Security-Policy: sandbox, this is ignored and the PDF is displayed.
// Regression test for https://crbug.com/1187122.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, CSPWithSandboxDoesNotBlockPDF) {}

// This test verifies that Content-Security-Policy's frame-ancestors 'none'
// directive is effective on a PDF response.
// Regression test for https://crbug.com/1107535.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, CSPFrameAncestorsCanBlockEmbedding) {}

// This test verifies that Content-Security-Policy's frame-ancestors directive
// overrides an X-Frame-Options header on a PDF response.
// Regression test for https://crbug.com/1107535.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest,
                       CSPFrameAncestorsOverridesXFrameOptions) {}

class PDFExtensionLoadTest
    : public PDFExtensionTestWithoutOopifOverride,
      public testing::WithParamInterface<std::tuple<int, bool>> {};

#if BUILDFLAG(IS_LINUX)
#define MAYBE_Load
#else
#define MAYBE_Load
#endif
IN_PROC_BROWSER_TEST_P(PDFExtensionLoadTest, MAYBE_Load) {}

#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
IN_PROC_BROWSER_TEST_P(PDFExtensionLoadTest, LoadPrivate) {
  LoadAllPdfsTest("pdf_private");
}
#endif

// We break PDFExtensionLoadTest up into kNumberLoadTestParts.
INSTANTIATE_TEST_SUITE_P();

PDFExtensionBlobNavigationTest;

IN_PROC_BROWSER_TEST_P(PDFExtensionBlobNavigationTest, NewTab) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionBlobNavigationTest, SameTab) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionTest, LoadInPlatformApp) {}

class DownloadAwaiter : public content::DownloadManager::Observer {};

// Tests behavior when the PDF plugin is disabled in preferences.
class PDFPluginDisabledTest : public PDFExtensionTest {};

IN_PROC_BROWSER_TEST_P(PDFPluginDisabledTest, DirectNavigationToPDF) {}

// TODO(crbug.com/40762344): fix flakiness and reenable. Also, that test
// became flaky on Windows, see crbug.com/1323701.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC) || \
    BUILDFLAG(IS_WIN)
#define MAYBE_EmbedPdfPlaceholderWithCSP
#else
#define MAYBE_EmbedPdfPlaceholderWithCSP
#endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC) ||
        // BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_P(PDFPluginDisabledTest,
                       MAYBE_EmbedPdfPlaceholderWithCSP) {}

#if BUILDFLAG(IS_CHROMEOS)
// TODO(crbug.com/40923384): Deflake and reenable the test.
#define MAYBE_IframePdfPlaceholderWithCSP
#else
#define MAYBE_IframePdfPlaceholderWithCSP
#endif
IN_PROC_BROWSER_TEST_P(PDFPluginDisabledTest,
                       MAYBE_IframePdfPlaceholderWithCSP) {}

IN_PROC_BROWSER_TEST_P(PDFPluginDisabledTest,
                       IframePlaceholderInjectedIntoNewWindow) {}

// Test that if the plugin tries to load a URL that redirects then it will fail
// to load. This is to avoid the source origin of the document changing during
// the redirect, which can have security implications. https://crbug.com/653749.
//
// Note that this can happen only during partial loading, as the initial URL
// load is handled by MimeHandlerView, and the plugin only gets the response.
IN_PROC_BROWSER_TEST_P(PDFExtensionTestWithPartialLoading,
                       PartialRedirectsFailInPlugin) {}

// Ensure that the internal PDF plugin application/x-google-chrome-pdf won't be
// loaded if it's not loaded in the chrome extension page.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, EnsureInternalPluginDisabled) {}

// Ensure cross-origin replies won't work for getSelectedText.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, EnsureCrossOriginRepliesBlocked) {}

// Ensure same-origin replies do work for getSelectedText.
// The full page PDF embedder frame can't post messages to the PDF extension
// frame, so it can't post a getSelectedText message.
IN_PROC_BROWSER_TEST_F(PDFExtensionTestWithoutOopifOverride,
                       EnsureSameOriginRepliesAllowed) {}

// TODO(crbug.com/40647731): Should be allowed?
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, EnsureOpaqueOriginRepliesBlocked) {}

// Ensure that the PDF component extension cannot be loaded directly.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, BlockDirectAccess) {}

// This test ensures that PDF can be loaded from local file
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, EnsurePDFFromLocalFileLoads) {}

// Tests that PDF with no filename extension can be loaded from local file.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, ExtensionlessPDFLocalFileLoads) {}

// This test ensures that link permissions are enforced properly in PDFs.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, LinkPermissions) {}

// This test ensures that titles are set properly for PDFs without /Title.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, TabTitleWithNoTitle) {}

// This test ensures that titles are set properly for PDFs with /Title.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, TabTitleWithTitle) {}

// This test ensures that titles are set properly for embedded PDFs (using data
// URL). PDF /Title should be ignored for embedded PDFs.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, TabTitleWithEmbeddedPdfDataUrl) {}

// This test ensures that tab titles are set properly for embedded PDFs.
// PDF /Title should be ignored for embedded PDFs.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, TabTitleWithEmbeddedPdf) {}

// Tests that PDF MIME type is not set for non-PDF `WebContents`.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, IsContentsMimeTypePdfNonPdf) {}

// Tests that PDF MIME type is not set for embedded PDF `WebContents`.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, IsContentsMimeTypePdfEmbedPdf) {}

// Tests that PDF MIME type is set for full-page PDF `WebContents`.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, IsContentsMimeTypePdfFullPagePdf) {}

// Tests that PDF MIME type is set for full-page PDF `WebContents` with MIME
// type params.
// NOTE: This test is not parameterized as PDF MIME type validation for OOPIF
// variant is already being done in
// PDFExtensionOopifTest.FindFullPagePdfExtensionHostFullPagePdfWithMimeTypeParam.
IN_PROC_BROWSER_TEST_F(PDFExtensionTestWithoutOopifOverride,
                       IsContentsMimeTypePdfFullPagePdfWithMimeTypeParam) {}

// Flaky, http://crbug.com/767427
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
#define MAYBE_PdfZoomWithoutBubble
#else
#define MAYBE_PdfZoomWithoutBubble
#endif
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, MAYBE_PdfZoomWithoutBubble) {}

class PDFExtensionScrollTest : public PDFExtensionTest {};

IN_PROC_BROWSER_TEST_P(PDFExtensionScrollTest, WithSpace) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionScrollTest, WithPageDownUp) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionScrollTest, WithArrowLeftRight) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionScrollTest, WithArrowDownUp) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionTest, SelectAllShortcut) {}

// TODO(crbug.com/40793934): Add tests for using space and shift+space shortcuts
// for scrolling PDFs.

// Test that even if a different tab is selected when a navigation occurs,
// the correct tab still gets navigated (see crbug.com/672563).
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, NavigationOnCorrectTab) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionTest, MultipleDomains) {}

namespace {

class PDFExtensionIsolatedContentTest
    : public PDFExtensionTestWithoutOopifOverride,
      public testing::WithParamInterface<std::tuple<bool, bool>> {};

INSTANTIATE_TEST_SUITE_P();

}  // namespace

// Makes sure `PDFExtensionIsolatedContentTest` runs with and without Site
// Isolation enabled (see crbug.com/1298269).
//
// This is a separate test because fatal assertions in `SetUpInMainThread()`
// don't terminate early, so there's no point asserting before every test.
IN_PROC_BROWSER_TEST_P(PDFExtensionIsolatedContentTest, ExpectSiteIsolation) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionIsolatedContentTest, PdfAndHtml) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionIsolatedContentTest, DataNavigation) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionIsolatedContentTest, HistoryNavigation) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionIsolatedContentTest, Jitless) {}

class PDFExtensionLinkClickTest : public PDFExtensionTest {};

IN_PROC_BROWSER_TEST_P(PDFExtensionLinkClickTest, CtrlLeft) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionLinkClickTest, Middle) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionLinkClickTest, CtrlShiftLeft) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionLinkClickTest, ShiftMiddle) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionLinkClickTest, ShiftLeft) {}

// This test opens a PDF by clicking a link via javascript and verifies that
// the PDF is loaded and functional by clicking a link in the PDF. The link
// click in the PDF opens a new tab. The main page handles the pageShow event
// and updates the history state.
IN_PROC_BROWSER_TEST_P(PDFExtensionLinkClickTest, OpenPDFWithReplaceState) {}

namespace {
// Fails the test if a navigation is started in the given WebContents.
class FailOnNavigation : public content::WebContentsObserver {};
}  // namespace

// If the PDF viewer can't navigate the tab using a tab id, make sure it doesn't
// try to navigate the extension frame.
// Regression test for https://crbug.com/1158381
IN_PROC_BROWSER_TEST_P(PDFExtensionLinkClickTest, LinkClickInPdfInNonTab) {}

class PDFExtensionInternalLinkClickTest : public PDFExtensionTest {};

IN_PROC_BROWSER_TEST_P(PDFExtensionInternalLinkClickTest, CtrlLeft) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionInternalLinkClickTest, Middle) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionInternalLinkClickTest, ShiftLeft) {}

class PDFExtensionComboBoxTest : public PDFExtensionTest {};

class PDFExtensionSaveTest : public PDFExtensionComboBoxTest {};

// Flaky, https://crbug.com/1269103, https://crbug.com/1520715
IN_PROC_BROWSER_TEST_P(PDFExtensionSaveTest, DISABLED_Save) {}

class PDFExtensionSaveWithPolicyTest : public PDFExtensionSaveTest {};

// Flaky, https://crbug.com/1269103, https://crbug.com/1520715
IN_PROC_BROWSER_TEST_P(PDFExtensionSaveWithPolicyTest,
                       DISABLED_SaveWithPolicy) {}

// Flaky, https://crbug.com/1269103, https://crbug.com/1520715
IN_PROC_BROWSER_TEST_P(PDFExtensionSaveWithPolicyTest,
                       DISABLED_SaveWithPolicyUniqueNumberSuffix) {}

// TODO(crbug.com/40803991): Make this test non-flaky.
IN_PROC_BROWSER_TEST_P(PDFExtensionSaveWithPolicyTest,
                       DISABLED_SaveWithPolicyUniqueTimeSuffix) {}

class PDFExtensionClipboardTest : public PDFExtensionComboBoxTest,
                                  public ui::ClipboardObserver {};

// TODO(crbug.com/40715498): Fix flakiness.
// TODO(crbug.com/41493691): Fix flakiness.
IN_PROC_BROWSER_TEST_P(PDFExtensionClipboardTest,
                       DISABLED_IndividualShiftRightArrowPresses) {}

// TODO(crbug.com/40599189): test is flaky.
IN_PROC_BROWSER_TEST_P(PDFExtensionClipboardTest,
                       DISABLED_IndividualShiftLeftArrowPresses) {}

// Flaky, https://crbug.com/1121446, https://crbug.com/1520715
IN_PROC_BROWSER_TEST_P(PDFExtensionClipboardTest,
                       DISABLED_CombinedShiftRightArrowPresses) {}

// Flaky on multiple platforms (https://crbug.com/1121446)
IN_PROC_BROWSER_TEST_P(PDFExtensionClipboardTest,
                       DISABLED_CombinedShiftArrowPresses) {}

// Verifies that an <embed> of size zero will still instantiate a guest and post
// message to the <embed> is correctly forwarded to the extension. This is for
// catching future regression in docs/ and slides/ pages (see
// https://crbug.com/763812).
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, PostMessageForZeroSizedEmbed) {}

// In response to the events sent in |send_events|, ensures the PDF viewer zooms
// in and that the viewer's custom pinch zooming mechanism is used to do so.
void EnsureCustomPinchZoomInvoked(content::RenderFrameHost* guest_mainframe,
                                  WebContents* contents,
                                  base::OnceClosure send_events) {}

// Ensure that touchpad pinch events are handled by the PDF viewer.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, TouchpadPinchInvokesCustomZoom) {}

#if !BUILDFLAG(IS_MAC)
// Ensure that ctrl-wheel events are handled by the PDF viewer.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, CtrlWheelInvokesCustomZoom) {}

// Flaky on ChromeOS (https://crbug.com/922974)
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define MAYBE_TouchscreenPinchInvokesCustomZoom
#else
#define MAYBE_TouchscreenPinchInvokesCustomZoom
#endif
IN_PROC_BROWSER_TEST_P(PDFExtensionTest,
                       MAYBE_TouchscreenPinchInvokesCustomZoom) {}

#endif  // !BUILDFLAG(IS_MAC)

PDFExtensionHitTestTest;

// Flaky in nearly all configurations; see https://crbug.com/856169.
IN_PROC_BROWSER_TEST_P(PDFExtensionHitTestTest, DISABLED_MouseLeave) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionHitTestTest, ContextMenuCoordinates) {}

// The plugin document and the mime handler should both use the same background
// color.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, BackgroundColor) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionTest, DefaultFocusForEmbeddedPDF) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionTest, DefaultFocusForNonEmbeddedPDF) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionTest, PdfVisibility) {}

// A helper for waiting for the first request for |url_to_intercept|.
class RequestWaiter {};

// This is a regression test for a problem where DidStopLoading didn't get
// propagated from a remote frame into the main frame.  See also
// https://crbug.com/964364.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, DidStopLoading) {}

// This test verifies that it is possible to add an <embed src=pdf> element into
// a new popup window when using document.write.  See also
// https://crbug.com/1041880.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, DocumentWriteIntoNewPopup) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionTest, LoadPdfFromExtension) {}

// Tests that the PDF extension loads in the presence of an extension that, on
// the completion of document loading, adds an <iframe> to the body element.
// See crbug.com/40671023.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest,
                       PdfLoadsWithExtensionThatInjectsFrame) {}

IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Metrics) {}

// Test that the PDF.LoadStatus metric is incremented correctly when the PDF is
// loaded with PDFium.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest,
                       MetricsPDFLoadStatusLoadedPdfWithPdfium) {}

// Flaky. See https://crbug.com/1101514.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, DISABLED_TabInAndOutOfPDFPlugin) {}

// Test that a PDF with COEP: require-corp header can load successfully.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest,
                       CrossOriginEmbedderPolicyRequireCorpPdf) {}

// Test that a PDF without the COEP: require-corp header fails to load when
// embedded in a page that has the header.
IN_PROC_BROWSER_TEST_P(PDFExtensionTest,
                       CrossOriginEmbedderPolicyRequireCorpIframe) {}

class PDFExtensionPrerenderTest : public PDFExtensionTest {};

// TODO(crbug.com/40180674): The PDF viewer cannot currently be prerendered
// correctly. This tests that prerendering is cancelled. Once we're able to
// support this, this test should be replaced with one that prerenders the PDF
// viewer.
IN_PROC_BROWSER_TEST_P(PDFExtensionPrerenderTest, CancelPrerender) {}

// TODO(crbug.com/40180674): The PDF viewer cannot currently be prerendered
// correctly. This tests that prerendering is cancelled if a PDF is embedded in
// a prerendered page. Once we're able to support this, this test should be
// replaced with one that prerenders the PDF viewer.
IN_PROC_BROWSER_TEST_P(PDFExtensionPrerenderTest,
                       CancelPrerenderWithEmbeddedPdf) {}

// Cross-origin subframe navigations are deferred during prerendering, which
// means that an embedded cross-site PDF will not cause the PDF viewer to be
// created until prerender activation.
IN_PROC_BROWSER_TEST_P(PDFExtensionPrerenderTest,
                       PrerenderWithCrossSiteEmbeddedPdf) {}

class PDFExtensionSubmitFormTest : public PDFExtensionTest {};

IN_PROC_BROWSER_TEST_P(PDFExtensionSubmitFormTest, SubmitForm) {}

class PDFExtensionPrerenderAndFencedFrameTest : public PDFExtensionTest {};

// TODO(crbug.com/40180674): The PDF viewer cannot currently be prerendered
// correctly. Once this is supported, this test should be re-enabled for
// GuestView PDF viewer and enabled for OOPIF PDF viewer.
IN_PROC_BROWSER_TEST_P(PDFExtensionPrerenderAndFencedFrameTest,
                       DISABLED_LoadPDFInPrerender) {}

// Test that ensures we cannot navigate a fenced frame to a PDF because PDF
// isn't allowed by default static sandbox flags of fenced frames.
IN_PROC_BROWSER_TEST_P(PDFExtensionPrerenderAndFencedFrameTest,
                       LoadPdfInFencedFrame) {}

// Like `LoadPdfInFencedFrame`, but without Supports-Loading-Mode headers set.
IN_PROC_BROWSER_TEST_P(PDFExtensionPrerenderAndFencedFrameTest,
                       LoadPdfInFencedFrameWithoutFencedFrameOptIn) {}

// Test that ensures a fenced frame cannot load a document embedding a PDF
// because PDF isn't allowed in fenced frames.
IN_PROC_BROWSER_TEST_P(PDFExtensionPrerenderAndFencedFrameTest,
                       LoadEmbeddedPdfInFencedFrame) {}

// Exercise a race condition where the profile is destroyed in the middle of a
// PDF navigation and ensure that this doesn't crash.  Specifically,
// `PdfNavigationThrottle` intercepts PDF navigations to PDF stream URLs,
// cancels them, and posts a task to navigate to the original URL instead.
// Triggering profile destruction after this task is posted but before it runs
// has previously led to issues in https://crbug.com/1382761.
// See PDFExtensionOopifTest.PdfNavigationDuringProfileShutdown for the OOPIF
// PDF version.
IN_PROC_BROWSER_TEST_F(PDFExtensionTestWithoutOopifOverride,
                       PdfNavigationDuringProfileShutdown) {}

// Ensure that extensions do not get multiple bound LocalMainFrames for guest
// views. This is a regression test for crbug.com/1367582.
// Not applicable to OOPIF PDF, since the bug was about iterating over a frame
// twice because of the inner WebContents.
IN_PROC_BROWSER_TEST_F(PDFExtensionTestWithoutOopifOverride,
                       ExtensionsBindingLocalHost) {}

// PDF extension tests for loading the PDF in an incognito browser.
class PDFExtensionIncognitoTest : public PDFExtensionTest {};

// Test that full page PDF viewer successfully loads in incognito.
IN_PROC_BROWSER_TEST_P(PDFExtensionIncognitoTest, IncognitoFullPage) {}

// Test that an embed-embedded PDF viewer successfully loads in incognito.
IN_PROC_BROWSER_TEST_P(PDFExtensionIncognitoTest, IncognitoEmbed) {}

// Test that an iframe-embedded PDF viewer successfully loads in incognito.
IN_PROC_BROWSER_TEST_P(PDFExtensionIncognitoTest, IncognitoIframe) {}

class PDFExtensionSameSiteProcessTest : public PDFExtensionTest {};

// Test that multiple tabs containing same-site PDFs don't share a process for
// the PDF content frame when under the process limit.
IN_PROC_BROWSER_TEST_P(PDFExtensionSameSiteProcessTest,
                       SameSitePdfContentFramesInSeparateProcesses) {}

// Test that multiple tabs containing same-site PDFs share a process for the PDF
// content frame when at the process limit.
IN_PROC_BROWSER_TEST_P(PDFExtensionSameSiteProcessTest,
                       SameSitePdfContentFramesInSameProcess) {}

// PDF extension tests for the OOPIF PDF viewer.
class PDFExtensionOopifTest : public PDFExtensionTestWithoutOopifOverride {};

// Test that an embed-embedded PDF can send and receive postMessage() messages
// to and from its embedder.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, OopifPdfPostMessageEmbed) {}

// Tests that `FindFullPagePdfExtensionHost` fails to find the PDF extension
// host on a non-PDF page.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest,
                       FindFullPagePdfExtensionHostNonPdf) {}

// Tests that `FindFullPagePdfExtensionHost` fails to find the PDF extension
// host on an embedded PDF.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest,
                       FindFullPagePdfExtensionHostEmbedPdf) {}

// Tests that `FindFullPagePdfExtensionHost` finds the correct PDF extension
// host on a full-page PDF.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest,
                       FindFullPagePdfExtensionHostFullPagePdf) {}

// Tests that `FindFullPagePdfExtensionHost` finds the correct PDF extension
// host on a full-page PDF loaded with MIME type params.
IN_PROC_BROWSER_TEST_F(
    PDFExtensionOopifTest,
    FindFullPagePdfExtensionHostFullPagePdfWithMimeTypeParam) {}

// Test that re-navigating to the same PDF successfully loads the PDF.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, NavigateToSamePdf) {}

// TODO(crbug.com/41495156): Add a test for reloading the same URL with a new
// Content-Security-Policy: sandbox header.

// Test that navigating to a different PDF successfully loads the PDF.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, NavigateToDifferentPdf) {}

// Test that the inner frames in a full page PDF can't be accessed.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, FailToAccessInnerFramesFullPage) {}

// Test that the inner frames in an embed-embedded PDF can't be accessed.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, FailToAccessInnerFramesEmbed) {}

// Test that the inner frames in an iframe-embedded PDF can't be accessed.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, FailToAccessInnerFramesIframe) {}

// Tests that a data URL to a PDF loads successfully.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, LoadDataUrlPdfFullPage) {}

// Tests that a data URL to a HTML page embedding a PDF in an embed loads
// successfully.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, LoadDataUrlPdfEmbed) {}

// Tests that a data URL to a HTML page embedding a PDF in an iframe loads
// successfully.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, LoadDataUrlPdfIframe) {}

// If the document.body of the PDF viewer is replaced, there should no longer
// be a PDF stream.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, ReplaceDocumentBody) {}

// If the document.body of the PDF viewer is replaced, any subframes appended
// should be able to navigate.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, ReplaceDocumentBodyWithIframe) {}

// Subframes appended to the original document.body should be able to navigate.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, DocumentBodyAppendIframe) {}

// Loading a PDF in a subframe without a corresponding FrameNavigationEntry
// should not cause a crash. See https://crbug.com/358084015 and
// https://crbug.com/40467594.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, SubframePDFMissingFrameEntry) {}

// Ensure that when the only other PDF instance closes in the middle of another
// PDF's extension frame load, the PDF extension frame can still complete its
// subsequent navigation. See https://crbug.com/1295431.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest,
                       PdfExtensionLoadedWhileOldPdfCloses) {}

// Test that the PDF embedder frame can't postMessage() to the PDF content
// frame. OOPIF PDF only, since GuestView PDF's embedder frame doesn't have a
// proxy host to the content frame.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest,
                       BlockPdfEmbedderFramePostMessageToContentFrame) {}

// Exercise a race condition where the profile is destroyed in the middle of a
// PDF navigation and ensure that this doesn't crash.  Specifically,
// `PdfNavigationThrottle` intercepts PDF navigations to PDF stream URLs,
// cancels them, and posts a task to navigate to the original URL instead.
// Triggering profile destruction after this task is posted but before it runs
// has previously led to issues in https://crbug.com/1382761.
// See PDFExtensionTestWithoutOopifOverride.PdfNavigationDuringProfileShutdown
// for the GuestView PDF version.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest,
                       PdfNavigationDuringProfileShutdown) {}

// Test that the PDF.LoadStatus metric is incremented only after the PDF fully
// loads.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifTest, MetricsPDFLoadStatusPartialLoad) {}

class PDFExtensionOopifBlockPdfFrameNavigationTest
    : public PDFExtensionOopifTest {};

// Test that navigations in the inner PDF frames fail if they aren't for PDF
// viewer setup in a full page PDF.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifBlockPdfFrameNavigationTest,
                       NonPdfNavigationFullPage) {}

// Test that navigations in the inner PDF frames fail if they aren't for PDF
// viewer setup in an embed-embedded PDF.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifBlockPdfFrameNavigationTest,
                       NonPdfNavigationEmbed) {}

// Test that navigations in the inner PDF frames fail if they aren't for PDF
// viewer setup in an iframe-embedded PDF.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifBlockPdfFrameNavigationTest,
                       NonPdfNavigationIframe) {}

// Test that after the PDF load in a full page PDF, the PDF extension frame
// cannot re-navigate to the PDF extension URL and the PDF content frame cannot
// re-navigate to the PDF URL.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifBlockPdfFrameNavigationTest,
                       SameUrlNavigationFullPage) {}

// Test that after the PDF load in an embed-embedded PDF, the PDF extension
// frame cannot re-navigate to the PDF extension URL and the PDF content frame
// cannot re-navigate to the PDF URL.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifBlockPdfFrameNavigationTest,
                       SameUrlNavigationEmbed) {}

// Test that after the PDF load in an iframe-embedded PDF, the PDF extension
// frame cannot re-navigate to the PDF extension URL and the PDF content frame
// cannot re-navigate to the PDF URL.
IN_PROC_BROWSER_TEST_F(PDFExtensionOopifBlockPdfFrameNavigationTest,
                       SameUrlNavigationIframe) {}

// TODO(crbug.com/40268279): Stop testing both modes after OOPIF PDF viewer
// launches.
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();