chromium/chrome/browser/ui/webui/new_tab_page/new_tab_page_handler_unittest.cc

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

#include "chrome/browser/ui/webui/new_tab_page/new_tab_page_handler.h"

#include <array>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/json/json_writer.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/token.h"
#include "chrome/browser/new_tab_page/feature_promo_helper/new_tab_page_feature_promo_helper.h"
#include "chrome/browser/new_tab_page/promos/promo_data.h"
#include "chrome/browser/new_tab_page/promos/promo_service.h"
#include "chrome/browser/new_tab_page/promos/promo_service_factory.h"
#include "chrome/browser/new_tab_page/promos/promo_service_observer.h"
#include "chrome/browser/search/background/ntp_background_data.h"
#include "chrome/browser/search/background/ntp_custom_background_service.h"
#include "chrome/browser/search/background/ntp_custom_background_service_observer.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/themes/theme_helper.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_observer.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/hats/hats_service_factory.h"
#include "chrome/browser/ui/hats/mock_hats_service.h"
#include "chrome/browser/ui/views/side_panel/customize_chrome/side_panel_controller_views.h"
#include "chrome/browser/ui/webui/new_tab_page/new_tab_page.mojom.h"
#include "chrome/browser/ui/webui/side_panel/customize_chrome/customize_chrome_section.h"
#include "chrome/browser/ui/webui/webui_util_desktop.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_profile.h"
#include "components/feature_engagement/public/event_constants.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/feature_engagement/test/scoped_iph_feature_list.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/prefs/pref_service.h"
#include "components/search/ntp_features.h"
#include "components/search_provider_logos/logo_common.h"
#include "components/search_provider_logos/logo_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_web_contents_factory.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/theme_provider.h"
#include "ui/color/color_mixer.h"
#include "ui/color/color_provider_source.h"
#include "ui/color/color_recipe.h"
#include "ui/color/color_transform.h"
#include "ui/gfx/color_palette.h"
#include "url/gurl.h"

namespace {

_;
DoAll;
ElementsAre;
Optional;
SaveArg;

class MockPage : public new_tab_page::mojom::Page {};

class MockLogoService : public search_provider_logos::LogoService {};

class MockColorProviderSource : public ui::ColorProviderSource {};

class MockThemeProvider : public ui::ThemeProvider {};

class MockNtpCustomBackgroundService : public NtpCustomBackgroundService {};

class MockThemeService : public ThemeService {};

class MockPromoService : public PromoService {};

class MockCustomizeChromeTabHelper
    : public customize_chrome::SidePanelController {};

class MockFeaturePromoHelper : public NewTabPageFeaturePromoHelper {};

std::unique_ptr<TestingProfile> MakeTestingProfile(
    scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) {}

int GetDictPrefKeyCount(Profile* profile,
                        const std::string& pref_name,
                        const std::string& key) {}

}  // namespace

class NewTabPageHandlerTest : public testing::Test {};

class NewTabPageHandlerThemeTest : public NewTabPageHandlerTest,
                                   public ::testing::WithParamInterface<bool> {};

TEST_P(NewTabPageHandlerThemeTest, SetTheme) {}

TEST_P(NewTabPageHandlerThemeTest, SetCustomBackground) {}

TEST_P(NewTabPageHandlerThemeTest, SetDailyRefresh) {}

TEST_P(NewTabPageHandlerThemeTest, SetUploadedImage) {}

TEST_P(NewTabPageHandlerThemeTest, SetWallpaperSearchImage) {}

TEST_P(NewTabPageHandlerThemeTest, SetWallpaperSearchInspirationImage) {}

TEST_P(NewTabPageHandlerThemeTest, SetThirdPartyTheme) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(NewTabPageHandlerTest, Histograms) {}

TEST_F(NewTabPageHandlerTest, GetAnimatedDoodle) {}

TEST_F(NewTabPageHandlerTest, GetInteractiveDoodle) {}

TEST_F(NewTabPageHandlerTest, UpdatePromoData) {}

TEST_F(NewTabPageHandlerTest, OnDoodleImageClicked) {}

TEST_F(NewTabPageHandlerTest, OnDoodleImageRendered) {}

TEST_F(NewTabPageHandlerTest, OnDoodleShared) {}

TEST_F(NewTabPageHandlerTest, GetModulesIdNames) {}

TEST_F(NewTabPageHandlerTest, GetModulesOrder) {}

TEST_F(NewTabPageHandlerTest, SurveyLaunchedEligibleModulesCriteria) {}

TEST_F(NewTabPageHandlerTest, SurveyLaunchSkippedEligibleModulesCriteria) {}

TEST_F(NewTabPageHandlerTest, SetModuleDisabledTriggersPageCall) {}

TEST_F(NewTabPageHandlerTest, ModulesVisiblePrefChangeTriggersPageCall) {}

TEST_F(NewTabPageHandlerTest, OpenSidePanel) {}

TEST_F(NewTabPageHandlerTest, CloseSidePanel) {}

TEST_F(NewTabPageHandlerTest, IncrementCustomizeChromeButtonOpenCount) {}

// TODO (crbug/1521350): Fails when ChromeRefresh2023 is enabled.
TEST_F(NewTabPageHandlerTest, DISABLED_MaybeShowFeaturePromo_CustomizeChrome) {}

TEST_F(NewTabPageHandlerTest, MaybeShowFeaturePromo_CustomizeChromeRefresh) {}

TEST_F(NewTabPageHandlerTest, MaybeShowFeaturePromo_CustomizeModules) {}

TEST_F(NewTabPageHandlerTest,
       DontShowCustomizeChromeFeaturePromoWhenModalDialogIsOpen) {}

TEST_F(NewTabPageHandlerTest, OnModuleUsedRecordFeatureUsageAndClosePromo) {}

TEST_F(NewTabPageHandlerTest, ShowWebstoreToast) {}

TEST_F(NewTabPageHandlerTest, DoNotShowWebstoreToastOnCountExceeded) {}

TEST_F(NewTabPageHandlerTest, IncrementWallpaperSearchButtonShownCount) {}

class NewTabPageHandlerHaTSTest : public NewTabPageHandlerTest {};

TEST_F(NewTabPageHandlerHaTSTest, ModuleInteractionTriggersHaTS) {}

TEST_F(NewTabPageHandlerHaTSTest, IgnoredModuleTriggersHaTS) {}

TEST_F(NewTabPageHandlerHaTSTest, InteractedModuleDoesNotTriggerIgnoredHaTS) {}