chromium/chrome/browser/devtools/devtools_browsertest.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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <stddef.h>

#include <deque>
#include <memory>
#include <optional>

#include "base/cancelable_callback.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_timeouts.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/devtools/device/tcp_device_provider.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/devtools/devtools_window_testing.h"
#include "chrome/browser/devtools/protocol/browser_handler.h"
#include "chrome/browser/extensions/api/developer_private/developer_private_api.h"
#include "chrome/browser/extensions/chrome_extension_test_notification_observer.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_management_constants.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/lifetime/application_lifetime_desktop.h"
#include "chrome/browser/lifetime/browser_shutdown.h"
#include "chrome/browser/policy/chrome_browser_policy_connector.h"
#include "chrome/browser/policy/developer_tools_policy_handler.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/test/integration/sync_service_impl_harness.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
#include "chrome/browser/ui/autofill/autofill_popup_controller_impl_test_api.h"
#include "chrome/browser/ui/autofill/autofill_suggestion_controller.h"
#include "chrome/browser/ui/autofill/chrome_autofill_client.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/extensions/extension_side_panel_test_utils.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/core/browser/autofill_experiments.h"
#include "components/autofill/core/browser/browser_autofill_manager.h"
#include "components/autofill/core/browser/browser_autofill_manager_test_delegate.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/infobars/content/content_infobar_manager.h"
#include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_delegate.h"
#include "components/javascript_dialogs/app_modal_dialog_controller.h"
#include "components/javascript_dialogs/app_modal_dialog_view.h"
#include "components/keep_alive_registry/keep_alive_registry.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/language/core/browser/pref_names.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/prefs/pref_service.h"
#include "components/search_engines/template_url_service.h"
#include "components/signin/public/identity_manager/account_capabilities_test_mutator.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "components/ukm/test_ukm_recorder.h"
#include "components/variations/service/variations_service.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/url_data_source.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui_controller.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/hit_test_region_observer.h"
#include "content/public/test/scoped_web_ui_controller_factory_registration.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/url_loader_interceptor.h"
#include "extensions/browser/api_test_utils.h"
#include "extensions/browser/extension_host_test_helper.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/offscreen_document_host.h"
#include "extensions/browser/service_worker/service_worker_test_utils.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/manifest.h"
#include "extensions/common/mojom/view_type.mojom.h"
#include "extensions/common/switches.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/test_extension_dir.h"
#include "mojo/public/cpp/bindings/sync_call_restrictions.h"
#include "net/base/filename_util.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 "services/network/public/cpp/features.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/common/chrome_debug_urls.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "ui/base/ui_base_switches.h"
#include "ui/compositor/compositor_switches.h"
#include "ui/gl/gl_switches.h"
#include "url/gurl.h"

DevToolsAgentHost;
DevToolsAgentHostObserver;
NavigationController;
RenderFrameHost;
WebContents;
Extension;
AppModalDialogView;

namespace {

const char kDebuggerTestPage[] =;
const char kPauseWhenLoadingDevTools[] =;
const char kPageWithContentScript[] =;
const char kNavigateBackTestPage[] =;
const char kWindowOpenTestPage[] =;
const char kLatencyInfoTestPage[] =;
const char kChunkedTestPage[] =;
const char kPushTestPage[] =;
// The resource is not really pushed, but mock url request job pretends it is.
const char kPushTestResource[] =;
const char kPushUseNullEndTime[] =;
const char kSlowTestPage[] =;
const char kSharedWorkerTestPage[] =;
const char kSharedWorkerTestWorker[] =;
const char kReloadSharedWorkerTestPage[] =;
const char kReloadSharedWorkerTestWorker[] =;
const char kEmulateNetworkConditionsPage[] =;
const char kDispatchKeyEventShowsAutoFill[] =;
const char kDOMWarningsTestPage[] =;
const char kEmptyTestPage[] =;
// Arbitrary page that returns a 200 response, for tests that don't care about
// more than that.
const char kArbitraryPage[] =;

template <typename... T>
void DispatchOnTestSuiteSkipCheck(DevToolsWindow* window,
                                  const char* method,
                                  T... args) {}

void LoadLegacyFilesInFrontend(DevToolsWindow* window) {}

template <typename... T>
void DispatchOnTestSuite(DevToolsWindow* window,
                         const char* method,
                         T... args) {}

void RunTestFunction(DevToolsWindow* window, const char* test_name) {}

void SwitchToPanel(DevToolsWindow* window, const char* panel) {}

// Version of SwitchToPanel that works with extension-created panels.
void SwitchToExtensionPanel(DevToolsWindow* window,
                            const Extension* devtools_extension,
                            const char* panel_name) {}

void DisallowDevToolsForForceInstalledExtenions(Browser* browser) {}

void DisallowDevTools(Browser* browser) {}

void AllowDevTools(Browser* browser) {}

scoped_refptr<DevToolsAgentHost> GetOrCreateDevToolsHostForWebContents(
    WebContents* wc) {}

}  // namespace

class DevToolsTest : public InProcessBrowserTest {};

class SitePerProcessDevToolsTest : public DevToolsTest {};

// Used to block until a dev tools window gets beforeunload event.
class DevToolsWindowBeforeUnloadObserver : public content::WebContentsObserver {};

DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver(
    DevToolsWindow* devtools_window)
    :{}

void DevToolsWindowBeforeUnloadObserver::Wait() {}

void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired(bool proceed) {}

class DevToolsBeforeUnloadTest : public DevToolsTest {};

constexpr char kPublicKey[] =;

// Base class for DevTools tests that test devtools functionality for
// extensions and content scripts.
class DevToolsExtensionTest : public DevToolsTest {};

class DevToolsExperimentalExtensionTest : public DevToolsExtensionTest {};

class DevToolsServiceWorkerExtensionTest : public InProcessBrowserTest {};

// TODO(crbug.com/40943436): Fix the memory leak and enable the test.
#if defined(LEAK_SANITIZER) && BUILDFLAG(IS_LINUX)
#define MAYBE_AttachOnReload
#else
#define MAYBE_AttachOnReload
#endif
IN_PROC_BROWSER_TEST_F(DevToolsServiceWorkerExtensionTest,
                       MAYBE_AttachOnReload) {}

class WorkerDevToolsTest : public InProcessBrowserTest {};

// Tests that BeforeUnload event gets called on docked devtools if
// we try to close them.
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestDockedDevToolsClose) {}

// Tests that BeforeUnload event gets called on docked devtools if
// we try to close the inspected page.
//
// TODO(crbug.com/40679397): Flaky on Windows.
#if BUILDFLAG(IS_WIN)
#define MAYBE_TestDockedDevToolsInspectedTabClose
#else
#define MAYBE_TestDockedDevToolsInspectedTabClose
#endif
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
                       MAYBE_TestDockedDevToolsInspectedTabClose) {}

// Tests that BeforeUnload event gets called on docked devtools if
// we try to close the inspected browser.
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
                       TestDockedDevToolsInspectedBrowserClose) {}

// Tests that BeforeUnload event gets called on undocked devtools if
// we try to close them.
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestUndockedDevToolsClose) {}

// Tests that BeforeUnload event gets called on undocked devtools if
// we try to close the inspected page.
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
                       TestUndockedDevToolsInspectedTabClose) {}

// Tests that BeforeUnload event gets called on undocked devtools if
// we try to close the inspected browser.
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
                       TestUndockedDevToolsInspectedBrowserClose) {}

// Tests that BeforeUnload event gets called on undocked devtools if
// we try to exit application.
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
                       TestUndockedDevToolsApplicationClose) {}

// Tests that inspected tab gets closed if devtools renderer
// becomes unresponsive during beforeunload event interception.
// @see http://crbug.com/322380
// Disabled because of http://crbug.com/410327
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
                       DISABLED_TestUndockedDevToolsUnresponsive) {}

// Tests that closing worker inspector window does not cause browser crash
// @see http://crbug.com/323031
// TODO(crbug.com/40703256): Disabled due to flakiness.
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
                       DISABLED_TestWorkerWindowClosing) {}

// Tests that BeforeUnload event gets called on devtools that are opened
// on another devtools.
// TODO(crbug.com/40645764): Re-enable this test.
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
                       DISABLED_TestDevToolsOnDevTools) {}

// Tests scripts panel showing.
IN_PROC_BROWSER_TEST_F(DevToolsTest, TestShowScriptsTab) {}

// Tests recorder panel showing.
IN_PROC_BROWSER_TEST_F(DevToolsTest, TestShowRecorderTab) {}

// Tests that chrome.devtools extension is correctly exposed.
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, TestDevToolsExtensionAPI) {}

class DevtoolsPanelForceUpdateTest : public DevToolsExtensionTest,
                                     public testing::WithParamInterface<bool> {};

// Tests that, for a extension using the devtools api to create a custom
// devtools panel, we can navigate to the panel successfully (whether devtools
// force update is enabled or not). Also confirms that we can manually browse to
// an extension resource file before and after loading devtools. Regression test
// for crbug.com/333670353.
IN_PROC_BROWSER_TEST_P(DevtoolsPanelForceUpdateTest, NavigateToDevtoolsPanel) {}

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

// Tests that http Iframes within the visible devtools panel for the devtools
// extension are rendered in their own processes and not in the devtools process
// or the extension's process.  This is tested because this is one of the
// extension pages with devtools access
// (https://developer.chrome.com/extensions/devtools).  Also tests that frames
// with data URLs and about:blank URLs are rendered in the devtools process,
// unless a web OOPIF navigates itself to about:blank, in which case it does not
// end up back in the devtools process.  Also tests that when a web IFrame is
// navigated back to a devtools extension page, it gets put back in the devtools
// process.
// http://crbug.com/570483
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       HttpIframeInDevToolsExtensionPanel) {}

// Tests that http Iframes within the sidebar pane page for the devtools
// extension that is visible in the elements panel are rendered in their own
// processes and not in the devtools process or the extension's process.  This
// is tested because this is one of the extension pages with devtools access
// (https://developer.chrome.com/extensions/devtools).  http://crbug.com/570483
// TODO(crbug.com/40944663): Enable once the test is fixed.
#if BUILDFLAG(IS_LINUX)
#define MAYBE_HttpIframeInDevToolsExtensionSideBarPane
#else
#define MAYBE_HttpIframeInDevToolsExtensionSideBarPane
#endif
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       MAYBE_HttpIframeInDevToolsExtensionSideBarPane) {}

// Tests that http Iframes within the devtools background page, which is
// different from the extension's background page, are rendered in their own
// processes and not in the devtools process or the extension's process.
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       HttpIframeInDevToolsExtensionDevtools) {}

// Tests that iframes to a non-devtools extension embedded in a devtools
// extension will be isolated from devtools and the devtools extension.
// http://crbug.com/570483
// Disabled due to flakiness https://crbug.com/1062802
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       DISABLED_NonDevToolsExtensionInDevToolsExtension) {}

// Tests that if a devtools extension's devtools panel page has a subframe to a
// page for another devtools extension, the subframe is rendered in the devtools
// process as well.  http://crbug.com/570483
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       DevToolsExtensionInDevToolsExtension) {}

// Tests that a devtools extension can still have subframes to itself in a
// "devtools page" and that they will be rendered within the extension process
// as well, not in some other process.
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevToolsExtensionInItself) {}

// Tests that a devtools (not a devtools extension) Iframe can be injected into
// devtools.  http://crbug.com/570483
// crbug.com/1124981: flaky on win
#if BUILDFLAG(IS_WIN)
#define MAYBE_DevtoolsInDevTools
#else
#define MAYBE_DevtoolsInDevTools
#endif
IN_PROC_BROWSER_TEST_F(DevToolsTest, MAYBE_DevtoolsInDevTools) {}

// Some web features, when used from an extension, are subject to browser-side
// security policy enforcement. Make sure they work properly from inside a
// devtools extension.
// ToDo(993982): The test is flaky (timeout, crash, and fail) on several builds:
// Debug, Windows, Mac, MSan, and ASan.
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       DISABLED_DevToolsExtensionSecurityPolicyGrants) {}

// Disabled on Windows due to flakiness. http://crbug.com/183649
#if BUILDFLAG(IS_WIN)
#define MAYBE_TestDevToolsExtensionMessaging
#else
#define MAYBE_TestDevToolsExtensionMessaging
#endif

// Tests that chrome.devtools extension can communicate with background page
// using extension messaging.
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       MAYBE_TestDevToolsExtensionMessaging) {}

// Tests that chrome.experimental.devtools extension is correctly exposed
// when the extension has experimental permission.
IN_PROC_BROWSER_TEST_F(DevToolsExperimentalExtensionTest,
                       TestDevToolsExperimentalExtensionAPI) {}

// Tests that a content script is in the scripts list.
//
// TODO(crbug.com/40933538): Flaky on "Linux Tests (dbg)(1)".
#if BUILDFLAG(IS_LINUX)
#define MAYBE_TestContentScriptIsPresent
#else
#define MAYBE_TestContentScriptIsPresent
#endif
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       MAYBE_TestContentScriptIsPresent) {}

// Tests that console selector shows correct context names.
// TODO(crbug.com/328131890): Test is flaky on multiple platforms. Tends to time
// out when trying to open the devtools window.
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       DISABLED_TestConsoleContextNames) {}

// TODO(crbug.com/40930033): Flaky on Linux and ChromeOS Tests.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_CantInspectNewTabPage
#else
#define MAYBE_CantInspectNewTabPage
#endif
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, MAYBE_CantInspectNewTabPage) {}

// TODO(crbug.com/40943634): Re-enable the test once it is fixed.
#if BUILDFLAG(IS_LINUX)
#define MAYBE_CantInspectChromeScheme
#else
#define MAYBE_CantInspectChromeScheme
#endif
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, MAYBE_CantInspectChromeScheme) {}

IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, CantInspectDevtoolsScheme) {}

IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       CantInspectViewSourceDevtoolsScheme) {}

IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, CantInspectComponentExtension) {}

IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, CantInspectRemoteNewTabPage) {}

IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       CantInspectViewSourceComponentExtension) {}

// Flaky on several platforms: https://crbug.com/1487065
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       DISABLED_CantInspectFileUrlWithoutFileAccess) {}

class DevToolsExtensionSidePanelTest
    : public DevToolsExtensionTest,
      public ::testing::WithParamInterface<bool> {};

// Test that an extension's side panel view is inspectable whether or not the
// `kDevToolsTabTarget` flag is enabled.
IN_PROC_BROWSER_TEST_P(DevToolsExtensionSidePanelTest,
                       CanInspectExtensionSidePanelView) {}

INSTANTIATE_TEST_SUITE_P();
// TODO(crbug.com/41495883): Re-enable on linux.
#if BUILDFLAG(IS_LINUX)
#define MAYBE_CanInspectExtensionOffscreenDoc
#else
#define MAYBE_CanInspectExtensionOffscreenDoc
#endif
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       MAYBE_CanInspectExtensionOffscreenDoc) {}

class DevToolsExtensionFileAccessTest : public DevToolsExtensionTest {};

IN_PROC_BROWSER_TEST_F(DevToolsExtensionFileAccessTest,
                       CanGetFileResourceWithFileAccess) {}

IN_PROC_BROWSER_TEST_F(DevToolsExtensionFileAccessTest,
                       CantGetFileResourceWithoutFileAccess) {}

IN_PROC_BROWSER_TEST_F(DevToolsExtensionFileAccessTest,
                       CantGetFileResourceWithoutFileAccessNoSlashes) {}

IN_PROC_BROWSER_TEST_F(DevToolsExtensionFileAccessTest,
                       CantGetFileResourceWithoutFileAccessMixedCase) {}

// Tests that scripts are not duplicated after Scripts Panel switch.
IN_PROC_BROWSER_TEST_F(DevToolsTest, TestNoScriptDuplicatesOnPanelSwitch) {}

// Tests that debugger works correctly if pause event occurs when DevTools
// frontend is being loaded.
// Flaky on win and linux: crbug.com/1092924.
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_TestPauseWhenLoadingDevTools
#else
#define MAYBE_TestPauseWhenLoadingDevTools
#endif
IN_PROC_BROWSER_TEST_F(DevToolsTest, MAYBE_TestPauseWhenLoadingDevTools) {}

// Tests network timing.
IN_PROC_BROWSER_TEST_F(DevToolsTest, TestNetworkTiming) {}

// Tests network size.
// TODO(crbug/40218872): Enable this flaky test. This is flaky on Linux debug
// build. See also: https://crrev.com/c/2772698
#if BUILDFLAG(IS_LINUX) && !defined(NDEBUG)
#define MAYBE_TestNetworkSize
#else
#define MAYBE_TestNetworkSize
#endif
IN_PROC_BROWSER_TEST_F(DevToolsTest, MAYBE_TestNetworkSize) {}

// Tests raw headers text.
IN_PROC_BROWSER_TEST_F(DevToolsTest, TestNetworkSyncSize) {}

namespace {

bool InterceptURLLoad(content::URLLoaderInterceptor::RequestParams* params) {}

}  // namespace

// TODO(crbug.com/40116595) Flaky
IN_PROC_BROWSER_TEST_F(DevToolsTest, DISABLED_TestNetworkPushTime) {}

#if BUILDFLAG(IS_WIN)
// Flaky on Windows: https://crbug.com/1087320
#define MAYBE_TestDOMWarnings
#else
#define MAYBE_TestDOMWarnings
#endif
IN_PROC_BROWSER_TEST_F(DevToolsTest, MAYBE_TestDOMWarnings) {}

// Tests that console messages are not duplicated on navigation back.
#if BUILDFLAG(IS_WIN) || defined(MEMORY_SANITIZER)
// Flaking on windows swarm try runs: crbug.com/409285.
// Also flaking on MSan runs: crbug.com/1182861
#define MAYBE_TestConsoleOnNavigateBack
#else
#define MAYBE_TestConsoleOnNavigateBack
#endif
IN_PROC_BROWSER_TEST_F(DevToolsTest, MAYBE_TestConsoleOnNavigateBack) {}

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// Flaking on linux runs, see crbug.com/990692.
#define MAYBE_TestDeviceEmulation
#else
#define MAYBE_TestDeviceEmulation
#endif
IN_PROC_BROWSER_TEST_F(DevToolsTest, MAYBE_TestDeviceEmulation) {}

IN_PROC_BROWSER_TEST_F(DevToolsTest, TestDispatchKeyEventDoesNotCrash) {}

class BrowserAutofillManagerTestDelegateDevtoolsImpl
    : public autofill::BrowserAutofillManagerTestDelegate {};

// Disabled. Failing on MacOS MSAN. See https://crbug.com/849129.
// Also failing on Linux. See https://crbug.com/1187693.
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_TestDispatchKeyEventShowsAutoFill
#else
#define MAYBE_TestDispatchKeyEventShowsAutoFill
#endif
IN_PROC_BROWSER_TEST_F(DevToolsTest, MAYBE_TestDispatchKeyEventShowsAutoFill) {}

// Tests that allowed unhandled shortcuts are forwarded from inspected page
// into devtools frontend
IN_PROC_BROWSER_TEST_F(DevToolsTest, testKeyEventUnhandled) {}

// Tests that the keys that are forwarded from the browser update
// when their shortcuts change
IN_PROC_BROWSER_TEST_F(DevToolsTest, testForwardedKeysChanged) {}

IN_PROC_BROWSER_TEST_F(DevToolsTest, testCloseActionRecorded) {}

// Test that showing a certificate in devtools does not crash the process.
// Disabled on windows as this opens a modal in its own thread, which leads to a
// test timeout.
#if BUILDFLAG(IS_WIN)
#define MAYBE_testShowCertificate
#else
#define MAYBE_testShowCertificate
#endif
IN_PROC_BROWSER_TEST_F(DevToolsTest, MAYBE_testShowCertificate) {}

// Tests that settings are stored in profile correctly.
IN_PROC_BROWSER_TEST_F(DevToolsTest, TestSettings) {}

// Tests that external navigation from inspector page is always handled by
// DevToolsWindow and results in inspected page navigation.  See also
// https://crbug.com/180555.
IN_PROC_BROWSER_TEST_F(DevToolsTest, TestDevToolsExternalNavigation) {}

// Tests that toolbox window is loaded when DevTools window is undocked.
// TODO(crbug.com/40929457) - Fix this failing browser test.
IN_PROC_BROWSER_TEST_F(DevToolsTest, DISABLED_TestToolboxLoadedUndocked) {}

// Tests that toolbox window is not loaded when DevTools window is docked.
// TODO(crbug.com/40836594): Re-enable this test
IN_PROC_BROWSER_TEST_F(DevToolsTest, DISABLED_TestToolboxNotLoadedDocked) {}

// Tests that inspector will reattach to inspected page when it is reloaded
// after a crash. See http://crbug.com/101952
// Disabled. it doesn't check anything right now: http://crbug.com/461790
IN_PROC_BROWSER_TEST_F(DevToolsTest, DISABLED_TestReattachAfterCrash) {}

IN_PROC_BROWSER_TEST_F(DevToolsTest, TestPageWithNoJavaScript) {}

class DevToolsAutoOpenerTest : public DevToolsTest {};

// TODO(crbug.com/40742539): Flaky on debug builds.
#if !defined(NDEBUG)
#define MAYBE_TestAutoOpenForTabs
#elif BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
// TODO(crbug.com/40817460): Flaky failures
#define MAYBE_TestAutoOpenForTabs
#else
#define MAYBE_TestAutoOpenForTabs
#endif
IN_PROC_BROWSER_TEST_F(DevToolsAutoOpenerTest, MAYBE_TestAutoOpenForTabs) {}

class DevToolsReattachAfterCrashTest : public DevToolsTest {};

// TODO(crbug.com/40936829): Reenable after fixing consistent Windows failure.
IN_PROC_BROWSER_TEST_F(DevToolsReattachAfterCrashTest,
                       DISABLED_TestReattachAfterCrashOnTimeline) {}

// TODO(crbug.com/40938244): Gardener 2023-10-26: Flaky on bots.
IN_PROC_BROWSER_TEST_F(DevToolsReattachAfterCrashTest,
                       DISABLED_TestReattachAfterCrashOnNetwork) {}

// Very flaky on Linux only.  http://crbug.com/1216219
#if BUILDFLAG(IS_LINUX)
#define MAYBE_AutoAttachToWindowOpen
#else
#define MAYBE_AutoAttachToWindowOpen
#endif
IN_PROC_BROWSER_TEST_F(DevToolsTest, MAYBE_AutoAttachToWindowOpen) {}

// TODO(crbug.com/40704377) Flaky
IN_PROC_BROWSER_TEST_F(DevToolsTest, DISABLED_SecondTabAfterDevTools) {}

IN_PROC_BROWSER_TEST_F(WorkerDevToolsTest, InspectSharedWorker) {}

// Flaky on multiple platforms. See http://crbug.com/1263230
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
    BUILDFLAG(IS_MAC)
#define MAYBE_PauseInSharedWorkerInitialization
#else
#define MAYBE_PauseInSharedWorkerInitialization
#endif
IN_PROC_BROWSER_TEST_F(WorkerDevToolsTest,
                       MAYBE_PauseInSharedWorkerInitialization) {}

class DevToolsAgentHostTest : public InProcessBrowserTest {};

// Tests DevToolsAgentHost retention by its target.
IN_PROC_BROWSER_TEST_F(DevToolsAgentHostTest, TestAgentHostReleased) {}

class RemoteDebuggingTest : public extensions::ExtensionApiTest {};

// Fails on CrOS. crbug.com/431399
#if BUILDFLAG(IS_CHROMEOS_ASH)
#define MAYBE_RemoteDebugger
#else
// TODO(crbug.com/41478279): Flaky on all platforms.
#define MAYBE_RemoteDebugger
#endif
IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, MAYBE_RemoteDebugger) {}

IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, DiscoveryPage) {}

IN_PROC_BROWSER_TEST_F(DevToolsTest, PolicyDisallowed) {}

IN_PROC_BROWSER_TEST_F(DevToolsTest, PolicyDisallowedCloseConnection) {}

ManifestLocation;
class DevToolsDisallowedForForceInstalledExtensionsPolicyTest
    : public extensions::ExtensionBrowserTest {};

IN_PROC_BROWSER_TEST_F(DevToolsDisallowedForForceInstalledExtensionsPolicyTest,
                       DisallowedForExternalPolicyDownloadExtension) {}

IN_PROC_BROWSER_TEST_F(DevToolsDisallowedForForceInstalledExtensionsPolicyTest,
                       DisallowedForComponentExtensionForManagedUsers) {}

IN_PROC_BROWSER_TEST_F(DevToolsDisallowedForForceInstalledExtensionsPolicyTest,
                       AllowedForComponentExtensionForNonManagedUsers) {}

IN_PROC_BROWSER_TEST_F(DevToolsDisallowedForForceInstalledExtensionsPolicyTest,
                       ExtensionConnectionClosedOnPolicyChange) {}

IN_PROC_BROWSER_TEST_F(DevToolsDisallowedForForceInstalledExtensionsPolicyTest,
                       ClosedAfterNavigationToExtension) {}

IN_PROC_BROWSER_TEST_F(DevToolsDisallowedForForceInstalledExtensionsPolicyTest,
                       AboutBlankConnectionKeptOnPolicyChange) {}

class DevToolsAllowedByCommandLineSwitch
    : public DevToolsDisallowedForForceInstalledExtensionsPolicyTest {};

IN_PROC_BROWSER_TEST_F(DevToolsAllowedByCommandLineSwitch,
                       SwitchOverridesPolicyOnChromeOS) {}

class DevToolsPixelOutputTests : public DevToolsTest {};

// This test enables switches::kUseGpuInTests which causes false positives
// with MemorySanitizer. This is also flakey on many configurations.
// See https://crbug.com/510291
IN_PROC_BROWSER_TEST_F(DevToolsPixelOutputTests,
                       DISABLED_TestScreenshotRecording) {}

// This test enables switches::kUseGpuInTests which causes false positives
// with MemorySanitizer.
// Flaky on multiple platforms https://crbug.com/624215
IN_PROC_BROWSER_TEST_F(DevToolsPixelOutputTests,
                       DISABLED_TestLatencyInfoInstrumentation) {}

class DevToolsNetInfoTest : public DevToolsTest {};

IN_PROC_BROWSER_TEST_F(DevToolsNetInfoTest, EmulateNetworkConditions) {}

IN_PROC_BROWSER_TEST_F(DevToolsNetInfoTest, OfflineNetworkConditions) {}

class StaticURLDataSource : public content::URLDataSource {};

class MockWebUIProvider
    : public TestChromeWebUIControllerFactory::WebUIProvider {};

// This tests checks that window is correctly initialized when DevTools is
// opened while navigation through history with forward and back actions.
// (crbug.com/627407)
// TODO(crbug.com/40267320): Deflake and re-enable this test.
IN_PROC_BROWSER_TEST_F(DevToolsTest,
                       DISABLED_TestWindowInitializedOnNavigateBack) {}

IN_PROC_BROWSER_TEST_F(DevToolsTest, TestRawHeadersWithRedirectAndHSTS) {}

// Tests that OpenInNewTab filters URLs.
// TODO(crbug.com/40847130): Flaky on Windows and Linux.
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
#define MAYBE_TestOpenInNewTabFilter
#else
#define MAYBE_TestOpenInNewTabFilter
#endif
IN_PROC_BROWSER_TEST_F(DevToolsTest, MAYBE_TestOpenInNewTabFilter) {}

IN_PROC_BROWSER_TEST_F(DevToolsTest, TestOpenSearchResultsInNewTab) {}

IN_PROC_BROWSER_TEST_F(DevToolsTest, LoadNetworkResourceForFrontend) {}

// TODO(crbug.com/41435439) Disabled for flakiness.
IN_PROC_BROWSER_TEST_F(DevToolsTest, DISABLED_CreateBrowserContext) {}

// TODO(crbug.com/40708597): Flaky.
IN_PROC_BROWSER_TEST_F(DevToolsTest, DISABLED_DisposeEmptyBrowserContext) {}

// TODO(crbug.com/40689291): Find a better strategy for testing protocol methods
// against non-headless Chrome.
IN_PROC_BROWSER_TEST_F(DevToolsTest, NewWindowFromBrowserContext) {}

IN_PROC_BROWSER_TEST_F(SitePerProcessDevToolsTest, InspectElement) {}

class DevToolsTabTargetTest : public DevToolsTest {};

IN_PROC_BROWSER_TEST_F(DevToolsTabTargetTest, InspectElement) {}

IN_PROC_BROWSER_TEST_F(DevToolsTabTargetTest, UKMTest) {}

IN_PROC_BROWSER_TEST_F(DevToolsTest, ExistsForWebContentsAfterClosing) {}

IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, BrowserCloseWithBeforeUnload) {}

// Flaky.
// TODO(crbug.com/40721876): Re-enable.
IN_PROC_BROWSER_TEST_F(InProcessBrowserTest,
                       DISABLED_BrowserCloseWithContextMenuOpened) {}

#if !BUILDFLAG(IS_CHROMEOS)
// Skip for ChromeOS because the keep alive is not created for ChromeOS.
// See https://crbug.com/1174627.
class KeepAliveDevToolsTest : public InProcessBrowserTest {};

IN_PROC_BROWSER_TEST_F(KeepAliveDevToolsTest, KeepsAliveUntilBrowserClose) {}
#endif  // !BUILDFLAG(IS_CHROMEOS)

class DevToolsPolicyTest : public InProcessBrowserTest {};

IN_PROC_BROWSER_TEST_F(DevToolsPolicyTest, OpenBlockedDevTools) {}

class DevToolsExtensionHostsPolicyTest : public DevToolsExtensionTest {};

IN_PROC_BROWSER_TEST_F(DevToolsExtensionHostsPolicyTest,
                       CantInspectBlockedHost) {}

IN_PROC_BROWSER_TEST_F(DevToolsExtensionHostsPolicyTest,
                       CantInspectBlockedSubdomainHost) {}

// TODO(crbug.com/333791064): Flaky on multiple Mac & Linux builders.
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
#define MAYBE_CanInspectAllowedHttpHost
#else
#define MAYBE_CanInspectAllowedHttpHost
#endif
IN_PROC_BROWSER_TEST_F(DevToolsExtensionHostsPolicyTest,
                       MAYBE_CanInspectAllowedHttpHost) {}

// Times out. See https://crbug.com/819285.
IN_PROC_BROWSER_TEST_F(SitePerProcessDevToolsTest,
                       DISABLED_InputDispatchEventsToOOPIF) {}

// See https://crbug.com/971241
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       DISABLED_ExtensionWebSocketUserAgentOverride) {}

IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, SourceMapsFromExtension) {}

IN_PROC_BROWSER_TEST_F(DevToolsTest, SourceMapsFromDevtools) {}

IN_PROC_BROWSER_TEST_F(DevToolsTest,
                       DoesNotCrashOnSourceMapsFromUnknownScheme) {}

// TODO(crbug.com/40937316): Test is flaky on Linux.
#if BUILDFLAG(IS_LINUX)
#define MAYBE_ExtensionWebSocketOfflineNetworkConditions
#else
#define MAYBE_ExtensionWebSocketOfflineNetworkConditions
#endif
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
                       MAYBE_ExtensionWebSocketOfflineNetworkConditions) {}

IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, IsDeveloperModeTrueHistogram) {}

IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, IsDeveloperModeFalseHistogram) {}

namespace {

class DevToolsLocalizationTest : public DevToolsTest {};

}  // namespace

IN_PROC_BROWSER_TEST_F(DevToolsLocalizationTest,
                       NavigatorLanguageMatchesApplicationLocaleDocked) {}

IN_PROC_BROWSER_TEST_F(DevToolsLocalizationTest,
                       NavigatorLanguageMatchesApplicationLocaleUndocked) {}

IN_PROC_BROWSER_TEST_F(DevToolsLocalizationTest,
                       AcceptedLanguageChangesWhileDevToolsIsOpen) {}

namespace {

class DevToolsFetchTest : public DevToolsTest {};

}  // namespace

IN_PROC_BROWSER_TEST_F(DevToolsFetchTest,
                       DevToolsFetchFromDevToolsSchemeUndocked) {}

IN_PROC_BROWSER_TEST_F(DevToolsFetchTest,
                       DevToolsFetchFromDevToolsSchemeDocked) {}

IN_PROC_BROWSER_TEST_F(DevToolsFetchTest, DevToolsFetchFromHttpDisallowed) {}

IN_PROC_BROWSER_TEST_F(DevToolsFetchTest, FetchFromDevToolsSchemeIsProhibited) {}

IN_PROC_BROWSER_TEST_F(DevToolsTest, HostBindingsSyncIntegration) {}

IN_PROC_BROWSER_TEST_F(DevToolsTest, NoJavascriptUrlOnDevtools) {}

// According to DevToolsTest.AutoAttachToWindowOpen, using
// `waitForDebuggerPaused()` is flaky on Linux.
// TODO(crbug.com/40770357): Enable the test on Linux.
#if BUILDFLAG(IS_LINUX)
#define MAYBE_PauseWhenSameOriginDebuggerAlreadyAttached
#else
#define MAYBE_PauseWhenSameOriginDebuggerAlreadyAttached
#endif
IN_PROC_BROWSER_TEST_F(DevToolsTest,
                       MAYBE_PauseWhenSameOriginDebuggerAlreadyAttached) {}

// According to DevToolsTest.AutoAttachToWindowOpen, using
// `waitForDebuggerPaused()` is flaky on Linux.
// TODO(crbug.com/40770357): Enable the test on Linux.
#if BUILDFLAG(IS_LINUX)
#define MAYBE_PauseWhenSameOriginDebuggerAlreadyPaused
#else
#define MAYBE_PauseWhenSameOriginDebuggerAlreadyPaused
#endif
IN_PROC_BROWSER_TEST_F(DevToolsTest,
                       MAYBE_PauseWhenSameOriginDebuggerAlreadyPaused) {}

class DevToolsSyncTest : public SyncTest {};

IN_PROC_BROWSER_TEST_F(DevToolsSyncTest, GetSyncInformation) {}

// Regression test for https://crbug.com/1270184.
// TODO(crbug.com/40809266): Fix flakyness. Test is disabled for now.
IN_PROC_BROWSER_TEST_F(DevToolsTest, DISABLED_NoCrashFor1270184) {}

class DevToolsProcessPerSiteUpToMainFrameThresholdTest : public DevToolsTest {};

IN_PROC_BROWSER_TEST_F(DevToolsProcessPerSiteUpToMainFrameThresholdTest,
                       DevToolsWasAttachedBefore) {}

// TODO(crbug.com/40924806): The test is failing on multiple builders.
IN_PROC_BROWSER_TEST_F(DevToolsProcessPerSiteUpToMainFrameThresholdTest,
                       DISABLED_DontReuseProcess) {}

class DevToolsProcessPerSiteTest
    : public DevToolsProcessPerSiteUpToMainFrameThresholdTest {};

// TODO(https://crbug.com/328693031): Flaky on Linux dbg.
#if BUILDFLAG(IS_LINUX) && !defined(NDEBUG)
#define MAYBE_DevToolsSharedProcessInfobar
#else
#define MAYBE_DevToolsSharedProcessInfobar
#endif
IN_PROC_BROWSER_TEST_F(DevToolsProcessPerSiteTest,
                       MAYBE_DevToolsSharedProcessInfobar) {}

// Observe that the active tab has changed.
class ActiveTabChangedObserver : public TabStripModelObserver {};

// TODO: crbug.com/337141755 - Flaky on Windows ASAN.
#if BUILDFLAG(IS_WIN) && defined(ADDRESS_SANITIZER)
#define MAYBE_PausedDebuggerFocus
#else
#define MAYBE_PausedDebuggerFocus
#endif
IN_PROC_BROWSER_TEST_F(DevToolsProcessPerSiteTest, MAYBE_PausedDebuggerFocus) {}

class DevToolsConsoleInsightsTest : public DevToolsTest {};

bool hasQueryParam(WebContents* wc, std::string query_param) {}

IN_PROC_BROWSER_TEST_F(DevToolsConsoleInsightsTest, NotBeBlockedByFeatureFlag) {}

IN_PROC_BROWSER_TEST_F(DevToolsConsoleInsightsTest,
                       EnterprisePolicyEnabledByDefault) {}

IN_PROC_BROWSER_TEST_F(DevToolsConsoleInsightsTest, IsBlockedByGeo) {}

IN_PROC_BROWSER_TEST_F(DevToolsConsoleInsightsTest, IsNotEnabledForMinors) {}

IN_PROC_BROWSER_TEST_F(DevToolsConsoleInsightsTest,
                       CanBeDisabledByEnterprisePolicy) {}

IN_PROC_BROWSER_TEST_F(DevToolsConsoleInsightsTest,
                       CanBeEnabledByEnterprisePolicy) {}

IN_PROC_BROWSER_TEST_F(DevToolsConsoleInsightsTest,
                       IsDisabledWhenPolicySetToOne) {}

class DevToolsSelfXssTest : public DevToolsTest {};

IN_PROC_BROWSER_TEST_F(DevToolsSelfXssTest, FooFoo) {}