chromium/chrome/browser/ui/views/location_bar/cookie_controls/cookie_controls_interactive_uitest.cc

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

#include <algorithm>
#include <vector>

#include "base/feature_list_buildflags.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "base/time/time_override.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/privacy_sandbox/tracking_protection_settings_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/views/controls/rich_controls_container_view.h"
#include "chrome/browser/ui/views/location_bar/cookie_controls/cookie_controls_bubble_view.h"
#include "chrome/browser/ui/views/location_bar/cookie_controls/cookie_controls_content_view.h"
#include "chrome/browser/ui/views/location_bar/cookie_controls/cookie_controls_icon_view.h"
#include "chrome/browser/ui/webui/feedback/feedback_dialog.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "chrome/test/user_education/interactive_feature_promo_test.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/common/features.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/privacy_sandbox/privacy_sandbox_features.h"
#include "components/privacy_sandbox/tracking_protection_prefs.h"
#include "components/site_engagement/content/site_engagement_service.h"
#include "components/strings/grit/privacy_sandbox_strings.h"
#include "components/user_education/views/help_bubble_view.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_mock_cert_verifier.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "ui/base/interaction/interaction_sequence.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/button/toggle_button.h"
#include "ui/views/vector_icons.h"

namespace {
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();

const char kUMABubbleAllowThirdPartyCookies[] =;
const char kUMABubbleBlockThirdPartyCookies[] =;
const char kUMABubbleSendFeedback[] =;
const char kUMABubbleReloadingShown[] =;
const char kUMABubbleReloadingTimeout[] =;
}  // namespace

class CookieControlsInteractiveUiBaseTest : public InteractiveFeaturePromoTest {};

class CookieControlsInteractiveUiTest
    : public CookieControlsInteractiveUiBaseTest,
      public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

class CookieControlsInteractiveUiNoFeedbackTest
    : public CookieControlsInteractiveUiTest {};

IN_PROC_BROWSER_TEST_P(CookieControlsInteractiveUiTest,
                       BubbleOpensWhenIconPressed) {}

IN_PROC_BROWSER_TEST_F(CookieControlsInteractiveUiTest,
                       CreateExceptionPre3pcd) {}

IN_PROC_BROWSER_TEST_F(CookieControlsInteractiveUiNoFeedbackTest,
                       CreateExceptionFeedbackDisabledPre3pcd) {}

IN_PROC_BROWSER_TEST_F(CookieControlsInteractiveUiTest,
                       RemoveExceptionPre3pcd) {}

IN_PROC_BROWSER_TEST_P(CookieControlsInteractiveUiTest,
                       IconAnimatesOnHighSiteEngagement) {}

// Need a separate fixture to override the enabled feature list.
class CookieControlsInteractiveUiWithCookieControlsIphTest
    : public CookieControlsInteractiveUiBaseTest {};

IN_PROC_BROWSER_TEST_F(CookieControlsInteractiveUiWithCookieControlsIphTest,
                       ShowAndDismissIphOnHighSiteEngagement) {}

IN_PROC_BROWSER_TEST_F(CookieControlsInteractiveUiWithCookieControlsIphTest,
                       OpenUserBypassViaIph) {}

IN_PROC_BROWSER_TEST_F(CookieControlsInteractiveUiWithCookieControlsIphTest,
                       OpenUserBypassViaIconWhenIphVisible) {}

IN_PROC_BROWSER_TEST_F(CookieControlsInteractiveUiWithCookieControlsIphTest,
                       NotShownWhen3pcdEnabled) {}
// Opening the feedback dialog on CrOS & LaCrOS open a system level dialog,
// which cannot be easily tested here. Instead, LaCrOS has a separate feedback
// browser test which gives some coverage.
#if !BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_P(CookieControlsInteractiveUiTest, FeedbackOpens) {}
#endif

IN_PROC_BROWSER_TEST_P(CookieControlsInteractiveUiTest, ReloadView) {}

IN_PROC_BROWSER_TEST_P(CookieControlsInteractiveUiTest, ReloadViewTimeout) {}

IN_PROC_BROWSER_TEST_P(CookieControlsInteractiveUiTest,
                       ReloadView_TabChanged_NoReload) {}

IN_PROC_BROWSER_TEST_P(CookieControlsInteractiveUiTest,
                       ReloadView_TabChanged_Reload) {}

IN_PROC_BROWSER_TEST_P(CookieControlsInteractiveUiTest,
                       ReloadView_TabChangedDifferentSetting_NoReload) {}

IN_PROC_BROWSER_TEST_P(CookieControlsInteractiveUiTest, NoReloadView) {}

class CookieControlsInteractiveUi3pcdTest
    : public CookieControlsInteractiveUiBaseTest,
      public testing::WithParamInterface<testing::tuple<bool, bool>> {};

IN_PROC_BROWSER_TEST_P(CookieControlsInteractiveUi3pcdTest, CreateException) {}

IN_PROC_BROWSER_TEST_P(CookieControlsInteractiveUi3pcdTest, RemoveException) {}

INSTANTIATE_TEST_SUITE_P();

class CookieControlsInteractiveUiTrackingProtectionTest
    : public CookieControlsInteractiveUiBaseTest,
      public testing::WithParamInterface<bool> {};

IN_PROC_BROWSER_TEST_P(CookieControlsInteractiveUiTrackingProtectionTest,
                       CreateException) {}

IN_PROC_BROWSER_TEST_P(CookieControlsInteractiveUiTrackingProtectionTest,
                       RemoveException) {}

INSTANTIATE_TEST_SUITE_P();