#include <optional>
#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_future.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/enterprise/util/managed_browser_utils.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h"
#include "chrome/browser/policy/cloud/user_policy_signin_service_test_util.h"
#include "chrome/browser/privacy_sandbox/privacy_sandbox_service.h"
#include "chrome/browser/privacy_sandbox/privacy_sandbox_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engine_choice/search_engine_choice_dialog_service.h"
#include "chrome/browser/search_engine_choice/search_engine_choice_dialog_service_factory.h"
#include "chrome/browser/signin/chrome_signin_client_test_util.h"
#include "chrome/browser/signin/dice_tab_helper.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/process_dice_header_delegate_impl.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/profiles/profile_picker.h"
#include "chrome/browser/ui/startup/first_run_service.h"
#include "chrome/browser/ui/startup/first_run_test_util.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/profiles/profile_picker_interactive_uitest_base.h"
#include "chrome/browser/ui/views/profiles/profile_picker_view.h"
#include "chrome/browser/ui/webui/intro/intro_ui.h"
#include "chrome/browser/ui/webui/signin/signin_url_utils.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "components/privacy_sandbox/privacy_sandbox_features.h"
#include "components/search_engines/prepopulated_engines.h"
#include "components/search_engines/search_engine_choice/search_engine_choice_utils.h"
#include "components/search_engines/search_engines_switches.h"
#include "components/signin/public/base/consent_level.h"
#include "components/signin/public/base/signin_metrics.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/signin/public/identity_manager/account_capabilities_test_mutator.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/views/interaction/element_tracker_views.h"
#include "ui/views/view_class_properties.h"
#if !BUILDFLAG(ENABLE_DICE_SUPPORT)
#error "Unsupported platform"
#endif
namespace {
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(…);
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(…);
DEFINE_LOCAL_CUSTOM_ELEMENT_EVENT_TYPE(…);
DEFINE_LOCAL_CUSTOM_ELEMENT_EVENT_TYPE(…);
DeepQuery;
const DeepQuery kSignInButton{ … };
const DeepQuery kDontSignInButton{ … };
const DeepQuery kLegacyDeclineManagementButton{ … };
const DeepQuery kDeclineManagementButton{ … };
const DeepQuery kOptInSyncButton{ … };
const DeepQuery kDontSyncButton{ … };
const DeepQuery kSettingsButton{ … };
const DeepQuery kConfirmDefaultBrowserButton{ … };
const DeepQuery kSearchEngineChoiceActionButton{ … };
enum class SyncButtonsFeatureConfig : int { … };
struct TestParam { … };
std::optional<::signin_metrics::SyncButtonsType> ExpectedButtonShownMetric(
SyncButtonsFeatureConfig config) { … }
::signin_metrics::SyncButtonClicked ExpectedOptInButtonClickedMetric(
SyncButtonsFeatureConfig config) { … }
::signin_metrics::SyncButtonClicked ExpectedDeclinedButtonClickedMetric(
SyncButtonsFeatureConfig config) { … }
::signin_metrics::SyncButtonClicked ExpectedSettingsButtonClickedMetric(
SyncButtonsFeatureConfig config) { … }
std::string ParamToTestSuffix(const ::testing::TestParamInfo<TestParam>& info) { … }
const TestParam kTestParams[] = …;
}
class FirstRunInteractiveUiTestBase
: public InteractiveBrowserTestT<FirstRunServiceBrowserTestBase>,
public WithProfilePickerInteractiveUiTestHelpers { … };
class FirstRunParameterizedInteractiveUiTest
: public FirstRunInteractiveUiTestBase,
public testing::WithParamInterface<TestParam> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(FirstRunParameterizedInteractiveUiTest, CloseWindow) { … }
#if BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_P(FirstRunParameterizedInteractiveUiTest,
CloseChromeWithKeyboardShortcut) {
base::test::TestFuture<bool> proceed_future;
OpenFirstRun(proceed_future.GetCallback());
RunTestSequenceInContext(
views::ElementTrackerViews::GetContextForView(view()),
WaitForShow(kProfilePickerViewId),
InstrumentNonTabWebView(kWebContentsId, web_view()),
WaitForWebContentsReady(kWebContentsId, GURL(chrome::kChromeUIIntroURL)),
SendAccelerator(kProfilePickerViewId, GetAccelerator(IDC_EXIT))
.SetMustRemainVisible(false));
WaitForPickerClosed();
EXPECT_FALSE(proceed_future.Get());
histogram_tester().ExpectBucketCount(
"ProfilePicker.FirstRun.ExitStatus",
ProfilePicker::FirstRunExitStatus::kAbandonedFlow, 1);
}
#endif
IN_PROC_BROWSER_TEST_P(FirstRunParameterizedInteractiveUiTest, SignInAndSync) { … }
IN_PROC_BROWSER_TEST_P(FirstRunParameterizedInteractiveUiTest, DeclineSync) { … }
IN_PROC_BROWSER_TEST_P(FirstRunParameterizedInteractiveUiTest, GoToSettings) { … }
IN_PROC_BROWSER_TEST_P(FirstRunParameterizedInteractiveUiTest,
PeekAndDeclineSignIn) { … }
IN_PROC_BROWSER_TEST_P(FirstRunParameterizedInteractiveUiTest,
DeclineProfileManagement) { … }