chromium/chrome/browser/themes/browser_theme_pack_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "chrome/browser/themes/browser_theme_pack.h"

#include <stddef.h>

#include <memory>
#include <string_view>

#include "base/containers/flat_map.h"
#include "base/files/scoped_temp_dir.h"
#include "base/json/json_file_value_serializer.h"
#include "base/json/json_reader.h"
#include "base/path_service.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/frame/window_frame_util.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/themes/autogenerated_theme_util.h"
#include "chrome/grit/theme_resources.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/color/color_mixer.h"
#include "ui/color/color_provider.h"
#include "ui/color/color_provider_key.h"
#include "ui/color/color_recipe.h"
#include "ui/color/color_test_ids.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_rep.h"

Extension;
TP;
ThemeType;

// Maps scale factors (enum values) to file path.
// A similar typedef in BrowserThemePack is private.
TestScaleFactorToFileMap;

// Maps image ids to maps of scale factors to file paths.
// A similar typedef in BrowserThemePack is private.
TestFilePathMap;

// BrowserThemePackTest --------------------------------------------------------

class BrowserThemePackTest : public ::testing::Test {};

BrowserThemePackTest::BrowserThemePackTest()
    :{}

// static
std::map<int, SkColor> BrowserThemePackTest::GetDefaultColorMap() {}

void BrowserThemePackTest::VerifyColorMap(
    const std::map<int, SkColor>& color_map) {}

void BrowserThemePackTest::LoadColorJSON(const std::string& json) {}

void BrowserThemePackTest::LoadColorDictionary(const base::Value::Dict* value) {}

void BrowserThemePackTest::LoadTintJSON(const std::string& json) {}

void BrowserThemePackTest::LoadTintDictionary(const base::Value::Dict* value) {}

void BrowserThemePackTest::LoadDisplayPropertiesJSON(const std::string& json) {}

void BrowserThemePackTest::LoadDisplayPropertiesDictionary(
    const base::Value::Dict* value) {}

void BrowserThemePackTest::ParseImageNamesJSON(
    const std::string& json,
    TestFilePathMap* out_file_paths) {}

void BrowserThemePackTest::ParseImageNamesDictionary(
    const base::Value::Dict* value,
    TestFilePathMap* out_file_paths) {}

bool BrowserThemePackTest::LoadRawBitmapsTo(
    const TestFilePathMap& out_file_paths) {}

// static
void BrowserThemePackTest::BuildFromUnpackedExtension(
    const base::FilePath& extension_path,
    BrowserThemePack* pack) {}

// static
void BrowserThemePackTest::BuildFromUnpackedExtensionCheckValid(
    const base::FilePath& extension_path,
    BrowserThemePack* pack) {}

// static
void BrowserThemePackTest::BuildTestExtensionThemeCheckValid(
    std::string_view theme_folder,
    BrowserThemePack* pack) {}

// static
base::FilePath BrowserThemePackTest::GetTestExtensionThemePath(
    std::string_view theme_folder) {}

// static
base::FilePath BrowserThemePackTest::GetStarGazingPath() {}

// static
base::FilePath BrowserThemePackTest::GetHiDpiThemePath() {}

// static
void BrowserThemePackTest::VerifyStarGazing(BrowserThemePack* pack) {}

// static
void BrowserThemePackTest::VerifyHiDpiTheme(BrowserThemePack* pack) {}

// static
void BrowserThemePackTest::VerifyColorsMatch(BrowserThemePack* pack,
                                             int color_id_a,
                                             int color_id_b) {}

// static
void BrowserThemePackTest::VerifyCalculatedColorContrast(const SkColor colors[],
                                                         int colors_num,
                                                         float contrast_ratio) {}

// static
SkColor BrowserThemePackTest::BuildThirdOpacity(SkColor color_link) {}

// static
SkColor BrowserThemePackTest::GetDefaultColor(int id) {}

// static
void BrowserThemePackTest::GenerateDefaultFrameColor(
    std::map<int, SkColor>* colors,
    int color,
    int tint,
    bool otr) {}

// Actual tests ----------------------------------------------------------------

// 'ntp_section' used to correspond to COLOR_NTP_SECTION, but COLOR_NTP_SECTION
// was since removed because it was never used.  While it was in use,
// COLOR_NTP_HEADER used 'ntp_section' as a fallback when 'ntp_header' was
// absent.  We still preserve this fallback for themes that relied on this.
TEST_F(BrowserThemePackTest, UseSectionColorAsNTPHeader) {}

TEST_F(BrowserThemePackTest, ProvideNtpHeaderColor) {}

TEST_F(BrowserThemePackTest, SupportsAlpha) {}

TEST_F(BrowserThemePackTest, OutOfRangeColors) {}

TEST_F(BrowserThemePackTest, CanReadTints) {}

TEST_F(BrowserThemePackTest, CanReadDisplayProperties) {}

TEST_F(BrowserThemePackTest, CanParsePaths) {}

TEST_F(BrowserThemePackTest, InvalidPathNames) {}

TEST_F(BrowserThemePackTest, InvalidColors) {}

TEST_F(BrowserThemePackTest, InvalidTints) {}

TEST_F(BrowserThemePackTest, InvalidDisplayProperties) {}

// These four tests should just not cause a segmentation fault.
TEST_F(BrowserThemePackTest, NullPaths) {}

TEST_F(BrowserThemePackTest, NullTints) {}

TEST_F(BrowserThemePackTest, NullColors) {}

TEST_F(BrowserThemePackTest, NullDisplayProperties) {}

TEST_F(BrowserThemePackTest, TestHasCustomImage) {}

TEST_F(BrowserThemePackTest, TestNonExistantImages) {}

TEST_F(BrowserThemePackTest, TestCreateColorMixersOmniboxAllValues) {}

// TODO(erg): This test should actually test more of the built resources from
// the extension data, but for now, exists so valgrind can test some of the
// tricky memory stuff that BrowserThemePack does.
TEST_F(BrowserThemePackTest, CanBuildAndReadPack) {}

TEST_F(BrowserThemePackTest, HiDpiThemeTest) {}

// Ensure that, given a theme which only specifies a frame color, the calculated
// caption button background colors appropriately match the frame color.
TEST_F(BrowserThemePackTest, TestWindowControlButtonBGColor_FrameColor) {}

// Ensure that, given a theme which specifies a button background color, the
// calculated caption button background colors appropriately match the button
// background color blended with the frame color.
TEST_F(BrowserThemePackTest, TestWindowControlButtonBGColor_ButtonBGColor) {}

// Ensure that, given a theme which specifies a light frame color, but a dark
// caption button image, the calculated caption button background color is dark
// (to match the bg image).
TEST_F(BrowserThemePackTest, TestWindowControlButtonBGColor_ButtonBGImage) {}

// Ensure that specified 'toolbar' button and foreground colors are propagated
// correctly to their dependent colors
TEST_F(BrowserThemePackTest, TestFrameAndToolbarColorPropagation) {}

// Ensure that, given an explicit toolbar color and a toolbar image, the output
// color in COLOR_TOOLBAR reflects the explicit color.
TEST_F(BrowserThemePackTest,
       TestToolbarColorComputedFromImageOverridesInputColor) {}

// Ensure that, given an explicit frame color and a frame image, the output
// color in COLOR_FRAME_ACTIVE reflects the explicit color.
TEST_F(BrowserThemePackTest,
       TestFrameColorComputedFromImageOverridesInputColor) {}

// Test theme generation for a given color.
TEST_F(BrowserThemePackTest, TestBuildFromColor) {}

TEST_F(BrowserThemePackTest, BuildFromColor_BasicTestColors) {}

TEST_F(BrowserThemePackTest, BuildFromColor_TestAdjustedFrameColor) {}

// TODO(gayane): Consider moving color calculation tests to
// autogenerated_theme_util_unittest.cc.
TEST_F(BrowserThemePackTest, BuildFromColor_TestPreferredActiveTabContrast) {}

TEST_F(BrowserThemePackTest, TestToolbarButtonColor) {}

TEST_F(BrowserThemePackTest, TestNtpTextCaclulation) {}

TEST_F(BrowserThemePackTest, TestLogoColors) {}

// Test that building a theme from an extension where "theme_ntp_background"
// points to a jpg does not crash.
TEST_F(BrowserThemePackTest, JpegNtpBackground) {}

// Test that building a theme from an extension where "theme_frame" points to a
// jpg fails.
TEST_F(BrowserThemePackTest, JpegThemeFrame) {}