chromium/chrome/browser/ui/startup/default_browser_prompt/default_browser_prompt_interactive_uitest.cc

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

#include <cstdint>

#include "base/test/scoped_feature_list.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/startup/default_browser_prompt/default_browser_prompt_manager.h"
#include "chrome/browser/ui/toolbar/app_menu_model.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/frame/app_menu_button.h"
#include "chrome/browser/ui/views/infobars/confirm_infobar.h"
#include "chrome/browser/ui/webui/test_support/webui_interactive_test_mixin.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "chrome/test/interaction/tracked_element_webcontents.h"
#include "content/public/test/browser_test.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/switches.h"

#if !BUILDFLAG(IS_LINUX)
#include "chrome/browser/ui/chrome_pages.h"
#endif

namespace {
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
} // namespace

class DefaultBrowserPromptInteractiveTest
    : public WebUiInteractiveTestMixin<InteractiveBrowserTest> {};

IN_PROC_BROWSER_TEST_F(DefaultBrowserPromptInteractiveTest,
                       RemovesAllBrowserDefaultPromptsOnAccept) {}

IN_PROC_BROWSER_TEST_F(DefaultBrowserPromptInteractiveTest,
                       RemovesAllBrowserDefaultPromptsOnDismiss) {}

IN_PROC_BROWSER_TEST_F(DefaultBrowserPromptInteractiveTest,
                       RemovesAllBrowserDefaultPromptsOnAppMenuItemSelected) {}

// Linux test environment doesn't allow setting default via the
// chrome://settings/defaultBrowser page.
#if !BUILDFLAG(IS_LINUX)
IN_PROC_BROWSER_TEST_F(DefaultBrowserPromptInteractiveTest,
                       RemovesAllBrowserDefaultPromptsOnSettingsChange) {
  DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kFirstTabContents);
  const WebContentsInteractionTestUtil::DeepQuery kDefaultBrowserButton = {
      "settings-ui", "settings-main", "settings-basic-page",
      "settings-default-browser-page", "cr-button"};

  DefaultBrowserPromptManager::GetInstance()->MaybeShowPrompt();
  RunTestSequence(RemovesAllBrowserDefaultPromptsWhen(
      Steps(SelectTab(kTabStripElementId, 0), InstrumentTab(kFirstTabContents),
            NavigateWebContents(
                kFirstTabContents,
                GURL(chrome::GetSettingsUrl(chrome::kDefaultBrowserSubPage))),
            ClickElement(kFirstTabContents, kDefaultBrowserButton),
            SelectTab(kTabStripElementId, 1))));
}
#endif

class DefaultBrowserPromptInteractiveTestWithAppMenuDuration
    : public DefaultBrowserPromptInteractiveTest {};

IN_PROC_BROWSER_TEST_F(DefaultBrowserPromptInteractiveTestWithAppMenuDuration,
                       RemovesAllBrowserDefaultPromptsOnAppMenuChipTimeout) {}

class DefaultBrowserPromptHeadlessBrowserTest
    : public DefaultBrowserPromptInteractiveTest {};

IN_PROC_BROWSER_TEST_F(DefaultBrowserPromptHeadlessBrowserTest, DoesNotCrash) {}