chromium/chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc

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

#include <list>
#include <set>

#include "base/command_line.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_browser_main.h"
#include "chrome/browser/download/download_browsertest_utils.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
#include "chrome/browser/ssl/https_upgrades_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/context_menu_params.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "content/public/common/isolated_world_ids.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/download_test_observer.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/no_renderer_crashes_assertion.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/switches.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/chrome_debug_urls.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/common/switches.h"
#include "third_party/blink/public/mojom/context_menu/context_menu.mojom.h"

WebContents;

namespace extensions {

namespace {

// Waits for a WC to be created. Once it starts loading |delay_url| (after at
// least the first navigation has committed), it delays the load, executes
// |script| in the last committed RVH and resumes the load when a URL ending in
// |until_url_suffix| commits. This class expects |script| to trigger the load
// of an URL ending in |until_url_suffix|.
class DelayLoadStartAndExecuteJavascript : public TabStripModelObserver,
                                           public content::WebContentsObserver {};

// Handles requests for URLs with paths of "/test*" sent to the test server, so
// tests request a URL that receives a non-error response.
std::unique_ptr<net::test_server::HttpResponse> HandleTestRequest(
    const net::test_server::HttpRequest& request) {}

}  // namespace

class WebNavigationApiTest : public ExtensionApiTest {};

class WebNavigationApiBackForwardCacheTest : public WebNavigationApiTest {};

ContextType;

class WebNavigationApiTestWithContextType
    : public WebNavigationApiTest,
      public testing::WithParamInterface<ContextType> {};

class WebNavigationApiPrerenderTestWithContextType
    : public WebNavigationApiTest,
      public testing::WithParamInterface<ContextType> {};

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, Api) {}

// TODO(crbug.com/40858121): Flakily timing out.
IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, DISABLED_GetFrame) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiPrerenderTestWithContextType, GetFrame) {}

IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, GetFrameIncognito) {}

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, ClientRedirect) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, ServerRedirect) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, FormSubmission) {}

class WebNavigationApiPrerenderTestWithServiceWorker
    : public WebNavigationApiTest {};

// Tests that prerender events emit the correct events in the expected order.
IN_PROC_BROWSER_TEST_F(WebNavigationApiPrerenderTestWithServiceWorker,
                       Prerendering) {}

// TODO(crbug.com/40791797):
// WebNavigationApiTestWithContextType.Download test is flaky.
#if BUILDFLAG(IS_WIN)
#define MAYBE_Download
#else
#define MAYBE_Download
#endif
IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, MAYBE_Download) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType,
                       ServerRedirectSingleProcess) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, ForwardBack) {}

// TODO(crbug.com/40221198): Flaky on several platforms.
IN_PROC_BROWSER_TEST_F(WebNavigationApiBackForwardCacheTest,
                       DISABLED_ForwardBack) {}

#if BUILDFLAG(IS_MAC) && defined(ARCH_CPU_ARM64)
// https://crbug.com/1223028
#define MAYBE_IFrame
#else
#define MAYBE_IFrame
#endif
IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, MAYBE_IFrame) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, SrcDoc) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, OpenTab) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, ReferenceFragment) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, SimpleLoad) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, Failures) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, FilteredTest) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, UserAction) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, RequestOpenTab) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, TargetBlank) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType,
                       TargetBlankIncognito) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, History) {}

IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, CrossProcess) {}

// crbug.com/708139.
IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, DISABLED_CrossProcessFragment) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType,
                       CrossProcessHistory) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType,
                       CrossProcessIframe) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, PendingDeletion) {}

IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, Crash) {}

#if BUILDFLAG(IS_MAC)
// TODO(crbug.com/40187463): Re-enable this test.
#define MAYBE_Xslt
#else
#define MAYBE_Xslt
#endif
IN_PROC_BROWSER_TEST_P(WebNavigationApiTestWithContextType, MAYBE_Xslt) {}

class WebNavigationApiFencedFrameTest : public WebNavigationApiTest {};

IN_PROC_BROWSER_TEST_F(WebNavigationApiFencedFrameTest, Load) {}
}  // namespace extensions