#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/ui/browser.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <string>
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "base/system/sys_info.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/test_future.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/app_service/app_registry_cache_waiter.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/app_service/browser_app_launcher.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/devtools/devtools_window_testing.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/resource_coordinator/lifecycle_unit.h"
#include "chrome/browser/resource_coordinator/tab_manager.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_ui_prefs.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
#include "chrome/browser/ui/search/search_tab_helper.h"
#include "chrome/browser/ui/startup/launch_mode_recorder.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
#include "chrome/browser/ui/startup/startup_types.h"
#include "chrome/browser/ui/startup/web_app_startup_utils.h"
#include "chrome/browser/ui/tabs/pinned_tab_codec.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/web_applications/policy/web_app_policy_constants.h"
#include "chrome/browser/web_applications/policy/web_app_policy_manager.h"
#include "chrome/browser/web_applications/test/os_integration_test_override_impl.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/browser/web_applications/web_app_id_constants.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/search_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/captive_portal/core/buildflags.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/embedder_support/switches.h"
#include "components/javascript_dialogs/app_modal_dialog_controller.h"
#include "components/javascript_dialogs/app_modal_dialog_queue.h"
#include "components/javascript_dialogs/app_modal_dialog_view.h"
#include "components/javascript_dialogs/tab_modal_dialog_manager.h"
#include "components/omnibox/common/omnibox_focus_state.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/template_url_service.h"
#include "components/services/app_service/public/cpp/app_launch_util.h"
#include "components/sessions/core/command_storage_manager_test_helper.h"
#include "components/strings/grit/components_strings.h"
#include "components/translate/core/browser/language_state.h"
#include "components/translate/core/common/language_detection_details.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/reload_type.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/render_widget_host_view.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/ssl_status.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/isolated_world_ids.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/download_test_observer.h"
#include "content/public/test/no_renderer_crashes_assertion.h"
#include "content/public/test/slow_http_response.h"
#include "content/public/test/test_navigation_observer.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/uninstall_reason.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/request_handler_util.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/abseil-cpp/absl/cleanup/cleanup.h"
#include "third_party/blink/public/mojom/frame/fullscreen.mojom.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/page_transition_types.h"
#include "ui/base/ui_base_features.h"
#if BUILDFLAG(IS_MAC)
#include "base/apple/scoped_nsautorelease_pool.h"
#include "chrome/browser/ui/cocoa/test/run_loop_testing.h"
#include "ui/accelerated_widget_mac/ca_transaction_observer.h"
#include "ui/base/test/scoped_fake_nswindow_fullscreen.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/i18n/rtl.h"
#include "base/test/file_path_reparse_point_win.h"
#endif
ASCIIToUTF16;
HostZoomMap;
NavigationController;
NavigationEntry;
OpenURLParams;
Referrer;
WebContents;
WebContentsObserver;
Extension;
AppModalDialogController;
AppModalDialogQueue;
namespace {
const char* kBeforeUnloadHTML = …;
const char16_t* kOpenNewBeforeUnloadPage = …;
const base::FilePath::CharType* kTitle1File = …);
const base::FilePath::CharType* kTitle2File = …);
std::u16string WindowCaptionFromPageTitle(const std::u16string& page_title) { … }
int CountRenderProcessHosts() { … }
class TabClosingObserver : public TabStripModelObserver { … };
void RunCloseWithAppMenuCallback(Browser* browser) { … }
class RenderViewSizeObserver : public content::WebContentsObserver { … };
}
class BrowserTest : public extensions::ExtensionBrowserTest,
public BrowserListObserver { … };
IN_PROC_BROWSER_TEST_F(BrowserTest, NoTitle) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, NoTitleFileUrl) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, Title) { … }
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
IN_PROC_BROWSER_TEST_F(BrowserTest, CaptivePortalWindowTitle) { … }
#endif
IN_PROC_BROWSER_TEST_F(BrowserTest, NoJavaScriptDialogsActivateTab) { … }
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC)
#define MAYBE_ThirtyFourTabs …
#else
#define MAYBE_ThirtyFourTabs …
#endif
IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_ThirtyFourTabs) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, ClearPendingOnFailUnlessNTP) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, DialogDefersNavigationCommit) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, CrossProcessNavCancelsDialogs) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, RendererCrossProcessNavCancelsDialogs) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, DownloadDoesntDismissDialog) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_SadTabCancelsDialogs …
#else
#define MAYBE_SadTabCancelsDialogs …
#endif
IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_SadTabCancelsDialogs) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsSubframeDialogs) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, DISABLED_ReloadThenCancelBeforeUnload) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest,
DISABLED_SingleBeforeUnloadAfterWindowClose) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, BeforeUnloadVsBeforeReload) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, TargetBlankLinkOpensInGroup) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, NewTabFromLinkInGroupedTabOpensInGroup) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, OtherRedirectsDontForkProcess) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest,
DISABLED_FaviconOfOnloadRedirectToAnchorPage) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, TabClosingWhenRemovingExtension) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(BrowserTest, AppIdSwitch) { … }
#endif
#if defined(USE_AURA)
IN_PROC_BROWSER_TEST_F(BrowserTest, OverscrollEnabledInRegularWindows) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, OverscrollEnabledInPopups) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, OverscrollDisabledInDevToolsWindows) { … }
#endif
IN_PROC_BROWSER_TEST_F(BrowserTest, ShouldShowLocationBar) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, ReattachDevToolsWindow) { … }
#if !BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) { … }
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_CloseWithAppMenuOpen …
#else
#define MAYBE_CloseWithAppMenuOpen …
#endif
IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_CloseWithAppMenuOpen) { … }
#if !BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(BrowserTest, OpenAppWindowLikeNtp) { … }
#endif
IN_PROC_BROWSER_TEST_F(BrowserTest, StartMaximized) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS) && defined(ADDRESS_SANITIZER)
#define MAYBE_StartMinimized …
#else
#define MAYBE_StartMinimized …
#endif
IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_StartMinimized) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, ForwardDisabledOnForward) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, DisableMenuItemsWhenIncognitoIsForced) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(BrowserTest, ArcBrowserWindowFeaturesSetCorrectly) {
Browser* new_browser = Browser::Create(
Browser::CreateParams(Browser::TYPE_CUSTOM_TAB, browser()->profile(),
true));
ASSERT_TRUE(new_browser);
EXPECT_FALSE(new_browser->SupportsWindowFeature(
Browser::WindowFeature::FEATURE_LOCATIONBAR));
EXPECT_FALSE(new_browser->SupportsWindowFeature(
Browser::WindowFeature::FEATURE_TITLEBAR));
EXPECT_FALSE(new_browser->SupportsWindowFeature(
Browser::WindowFeature::FEATURE_TABSTRIP));
EXPECT_FALSE(new_browser->SupportsWindowFeature(
Browser::WindowFeature::FEATURE_BOOKMARKBAR));
EXPECT_FALSE(
new_browser->SupportsWindowFeature(Browser::WindowFeature::FEATURE_NONE));
EXPECT_TRUE(new_browser->SupportsWindowFeature(
Browser::WindowFeature::FEATURE_TOOLBAR));
}
#endif
IN_PROC_BROWSER_TEST_F(BrowserTest,
NoNewIncognitoWindowWhenIncognitoIsDisabled) { … }
class BrowserTestWithExtensionsDisabled : public BrowserTest { … };
IN_PROC_BROWSER_TEST_F(BrowserTestWithExtensionsDisabled,
DisableExtensionsAndSettingsWhenIncognitoIsDisabled) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest,
DisableOptionsAndImportMenuItemsConsistently) { … }
namespace {
void OnZoomLevelChanged(base::OnceClosure* callback,
const HostZoomMap::ZoomLevelChange& host) { … }
int GetZoomPercent(content::WebContents* contents,
bool* enable_plus,
bool* enable_minus) { … }
}
IN_PROC_BROWSER_TEST_F(BrowserTest, PageZoom) { … }
#if 0
class BrowserTest2 : public InProcessBrowserTest {
public:
BrowserTest2() {
host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL);
host_resolver_proc_->AddSimulatedFailure("*.google.com");
scoped_host_resolver_proc_.Init(host_resolver_proc_.get());
}
private:
scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_;
net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_;
};
IN_PROC_BROWSER_TEST_F(BrowserTest2, NoTabsInPopups) {
chrome::RegisterAppPrefs(L"Test");
EXPECT_EQ(1, browser()->tab_strip_model()->count());
Browser* popup_browser = Browser::Create(
Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile()));
chrome::AddTabAt(popup_browser, GURL(), -1, true);
EXPECT_EQ(1, popup_browser->tab_strip_model()->count());
AddTabWithURLParams params1(url, ui::PAGE_TRANSITION_TYPED);
popup_browser->AddTabWithURL(¶ms1);
EXPECT_EQ(popup_browser, params1.target);
EXPECT_EQ(1, popup_browser->tab_strip_model()->count());
EXPECT_EQ(2, browser()->tab_strip_model()->count());
Browser* app_browser = Browser::Create(Browser::CreateParams::CreateForApp(
L"Test", browser()->profile(), false));
chrome::AddTabAt(app_browser, GURL(), -1, true);
EXPECT_EQ(1, app_browser->tab_strip_model()->count());
AddTabWithURLParams params2(GURL(url::kAboutBlankURL),
ui::PAGE_TRANSITION_TYPED);
app_browser->AddTabWithURL(¶ms2);
EXPECT_EQ(app_browser, params2.target);
EXPECT_EQ(1, app_browser->tab_strip_model()->count());
EXPECT_EQ(3, browser()->tab_strip_model()->count());
Browser* app_popup_browser = Browser::Create(
Browser::CreateParams::CreateForApp(
L"Test", browser()->profile(), false));
chrome::AddTabAt(app_popup_browser, GURL(), -1, true);
EXPECT_EQ(1, app_popup_browser->tab_strip_model()->count());
AddTabWithURLParams params3(GURL(url::kAboutBlankURL),
ui::PAGE_TRANSITION_TYPED);
app_popup_browser->AddTabWithURL(¶ms3);
EXPECT_EQ(app_popup_browser, params3.target);
EXPECT_EQ(1, app_popup_browser->tab_strip_model()->count());
EXPECT_EQ(4, browser()->tab_strip_model()->count());
popup_browser->tab_strip_model()->CloseAllTabs();
app_browser->tab_strip_model()->CloseAllTabs();
app_popup_browser->tab_strip_model()->CloseAllTabs();
}
#endif
IN_PROC_BROWSER_TEST_F(BrowserTest, WindowOpenClose1) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, WindowOpenClose2) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, DISABLED_WindowOpenClose3) { … }
#if !(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
IN_PROC_BROWSER_TEST_F(BrowserTest, FullscreenBookmarkBar) {
#if BUILDFLAG(IS_MAC)
ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
#endif
chrome::ToggleBookmarkBar(browser());
EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state());
chrome::ToggleFullscreenMode(browser());
EXPECT_TRUE(browser()->window()->IsFullscreen());
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS_ASH)
EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state());
#else
EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state());
#endif
}
#endif
IN_PROC_BROWSER_TEST_F(BrowserTest, DisallowFileUrlUniversalAccessTest) { … }
class KioskModeTest : public BrowserTest { … };
#if BUILDFLAG(IS_MAC) || (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
#define MAYBE_EnableKioskModeTest …
#else
#define MAYBE_EnableKioskModeTest …
#endif
IN_PROC_BROWSER_TEST_F(KioskModeTest, MAYBE_EnableKioskModeTest) { … }
#if BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(KioskModeTest, DoNotExitFullscreen) {
browser()->window()->GetExclusiveAccessContext()->ExitFullscreen();
ASSERT_TRUE(browser()->window()->IsFullscreen());
}
IN_PROC_BROWSER_TEST_F(KioskModeTest, DoNotChangeBounds) {
gfx::Rect old_bounds = browser()->window()->GetBounds();
browser()->window()->SetBounds(gfx::Rect(10, 10, 10, 10));
gfx::Rect new_bounds = browser()->window()->GetBounds();
ASSERT_TRUE(browser()->window()->IsFullscreen());
ASSERT_EQ(old_bounds, new_bounds);
}
#endif
#if BUILDFLAG(IS_WIN)
class LaunchBrowserWithNonAsciiUserDatadir : public BrowserTest {
public:
LaunchBrowserWithNonAsciiUserDatadir() {}
void SetUpCommandLine(base::CommandLine* command_line) override {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
base::FilePath tmp_profile = temp_dir_.GetPath().AppendASCII("tmp_profile");
tmp_profile = tmp_profile.Append(L"Test Chrome G\u00E9raldine");
ASSERT_TRUE(base::CreateDirectory(tmp_profile));
command_line->AppendSwitchPath(switches::kUserDataDir, tmp_profile);
}
base::ScopedTempDir temp_dir_;
};
IN_PROC_BROWSER_TEST_F(LaunchBrowserWithNonAsciiUserDatadir,
TestNonAsciiUserDataDir) {
ASSERT_TRUE(browser());
ASSERT_TRUE(browser()->profile());
ASSERT_EQ(1u, g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetNumberOfProfiles());
}
class LaunchBrowserWithReparsePointUserDatadir : public BrowserTest {
public:
LaunchBrowserWithReparsePointUserDatadir() {}
void SetUpCommandLine(base::CommandLine* command_line) override {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
base::FilePath tmp_profile = temp_dir_.GetPath().AppendASCII("profile");
ASSERT_TRUE(base::CreateDirectory(tmp_profile));
base::FilePath reparse_profile =
temp_dir_.GetPath().AppendASCII("profile_reparse");
ASSERT_TRUE(base::CreateDirectory(reparse_profile));
auto reparse_point =
base::test::FilePathReparsePoint::Create(reparse_profile, tmp_profile);
ASSERT_TRUE(reparse_point.has_value());
reparse_point_.emplace(std::move(reparse_point.value()));
command_line->AppendSwitchPath(switches::kUserDataDir, reparse_profile);
}
base::ScopedTempDir temp_dir_;
std::optional<base::test::FilePathReparsePoint> reparse_point_;
};
IN_PROC_BROWSER_TEST_F(LaunchBrowserWithReparsePointUserDatadir,
TestReparsePointUserDataDir) {
ASSERT_TRUE(browser());
ASSERT_TRUE(browser()->profile());
ASSERT_EQ(1u, g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetNumberOfProfiles());
}
#endif
#if BUILDFLAG(IS_WIN)
class LaunchBrowserWithTrailingSlashDatadir : public BrowserTest {
public:
LaunchBrowserWithTrailingSlashDatadir() {}
void SetUpCommandLine(base::CommandLine* command_line) override {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
base::FilePath tmp_profile = temp_dir_.GetPath().AppendASCII("tmp_profile");
tmp_profile = tmp_profile.Append(L"Test Chrome\\");
ASSERT_TRUE(base::CreateDirectory(tmp_profile));
command_line->AppendSwitchPath(switches::kUserDataDir, tmp_profile);
}
base::ScopedTempDir temp_dir_;
};
IN_PROC_BROWSER_TEST_F(LaunchBrowserWithTrailingSlashDatadir,
TestTrailingSlashUserDataDir) {
ASSERT_TRUE(browser());
ASSERT_TRUE(browser()->profile());
ASSERT_EQ(1u, g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetNumberOfProfiles());
}
#endif
#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
class RunInBackgroundTest : public BrowserTest { … };
IN_PROC_BROWSER_TEST_F(RunInBackgroundTest, RunInBackgroundBasicTest) { … }
#endif
class NoStartupWindowTest : public BrowserTest { … };
IN_PROC_BROWSER_TEST_F(NoStartupWindowTest, NoStartupWindowBasicTest) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(NoStartupWindowTest, DontInitSessionServiceForApps) { … }
#endif
class AppModeTest : public BrowserTest { … };
IN_PROC_BROWSER_TEST_F(AppModeTest, EnableAppModeTest) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, AboutVersion) { … }
static const base::FilePath::CharType* kTestDir = …);
static const char16_t kFirstPageTitle[] = …;
static const char16_t kSecondPageTitle[] = …;
class ClickModifierTest : public InProcessBrowserTest { … };
IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenBasicClickTest) { … }
IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenShiftClickTest) { … }
IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenControlClickTest) { … }
IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenControlShiftClickTest) { … }
IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefBasicClickTest) { … }
IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefShiftClickTest) { … }
IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefControlClickTest) { … }
IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefControlShiftClickTest) { … }
IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefMiddleClickTest) { … }
IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefShiftMiddleClickTest) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, GetSizeForNewRenderView) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, CanDuplicateTab) { … }
namespace {
void CheckDisplayModeMQ(const std::u16string& display_mode,
content::WebContents* web_contents) { … }
}
IN_PROC_BROWSER_TEST_F(BrowserTest, DISABLED_ChangeDisplayMode) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, TestPopupBounds) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, IsOffTheRecordBrowserInUse) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, TestActiveTabChangedUserAction) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, TestNavEntryCommittedUserAction) { … }
namespace {
void SetTestDefaultSearchProvider(TemplateURLService* service,
const GURL& search_template) { … }
}
IN_PROC_BROWSER_TEST_F(BrowserTest,
TestNavEntryCommittedUserActionOnlyRecordedForTabs) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, TestTabCountMetrics) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest,
TestTabCountMetricsOnlyRecordedWhenTabLoads) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest,
TestTabCountMetricsNotRecordedWhenIframeLoads) { … }
IN_PROC_BROWSER_TEST_F(
BrowserTest,
TestTabCountMetricsNotRecordedForSameDocumentNavigation) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, TestTabCountMetricsRecordedOnReload) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest,
TestTabCountMetricsRecordedOnBackNavigation) { … }
IN_PROC_BROWSER_TEST_F(BrowserTest, TestActiveBrowserChangedUserAction) { … }
IN_PROC_BROWSER_TEST_F(
BrowserTest,
DISABLED_SameDocumentNavigationWithNothingCommittedAfterCrash) { … }
IN_PROC_BROWSER_TEST_F(
BrowserTest,
DISABLED_SameDocumentHistoryNavigationWithNothingCommittedAfterCrash) { … }
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
IN_PROC_BROWSER_TEST_F(BrowserTest, CreatePictureInPicture) { … }
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(BrowserTest, PreventCloseYieldsCancelledEvent) {
base::ScopedObservation<BrowserList, BrowserListObserver> observer(this);
observer.Observe(BrowserList::GetInstance());
base::test::TestFuture<void> policy_refresh_sync_future;
web_app::WebAppProvider::GetForWebApps(profile())
->policy_manager()
.SetRefreshPolicySettingsCompletedCallbackForTesting(
policy_refresh_sync_future.GetCallback());
const absl::Cleanup policy_cleanup = [this]() {
profile()->GetPrefs()->SetList(prefs::kWebAppSettings, base::Value::List());
};
static constexpr char kCalculatorAppUrl[] = "https://calculator.apps.chrome/";
profile()->GetPrefs()->SetList(
prefs::kWebAppSettings,
base::Value::List().Append(
base::Value::Dict()
.Set(web_app::kManifestId, kCalculatorAppUrl)
.Set(web_app::kRunOnOsLogin, web_app::kRunWindowed)
.Set(web_app::kPreventClose, true)));
profile()->GetPrefs()->SetList(
prefs::kWebAppInstallForceList,
base::Value::List().Append(
base::Value::Dict()
.Set(web_app::kUrlKey, kCalculatorAppUrl)
.Set(web_app::kDefaultLaunchContainerKey,
web_app::kDefaultLaunchContainerWindowValue)));
ASSERT_TRUE(policy_refresh_sync_future.Wait());
apps::AppUpdateWaiter waiter(
profile(), web_app::kCalculatorAppId,
base::BindRepeating([](const apps::AppUpdate& update) {
return update.AllowClose().has_value() && !update.AllowClose().value();
}));
waiter.Await();
Browser* const browser =
web_app::LaunchWebAppBrowser(profile(), web_app::kCalculatorAppId);
ASSERT_TRUE(browser);
EXPECT_EQ(BrowserClosingStatus::kDeniedByPolicy,
browser->HandleBeforeClose());
EXPECT_CALL(*this, OnBrowserCloseCancelled(
browser, BrowserClosingStatus::kDeniedByPolicy))
.Times(1);
browser->OnWindowClosing();
}
#endif