#include "extensions/browser/extension_icon_manager.h"
#include <memory>
#include "base/command_line.h"
#include "base/json/json_file_value_serializer.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_command_line.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/crx_file/id_util.h"
#include "extensions/browser/extensions_test.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/extension_paths.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_scale_factor.h"
#include "ui/display/display_list.h"
#include "ui/display/display_switches.h"
#include "ui/display/test/test_screen.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_unittest_util.h"
namespace extensions {
namespace {
class ScopedSetDeviceScaleFactor { … };
class ExtensionIconManagerTest : public ExtensionsTest,
public ExtensionIconManager::Observer { … };
gfx::Image GetDefaultIcon() { … }
TEST_F(ExtensionIconManagerTest, LoadRemoveLoad) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(ExtensionIconManagerTest, LoadComponentExtensionResource) {
gfx::Image default_icon = GetDefaultIcon();
base::FilePath test_dir;
ASSERT_TRUE(base::PathService::Get(DIR_TEST_DATA, &test_dir));
base::FilePath manifest_path =
test_dir.AppendASCII("extension_icon_manager/manifest.json");
JSONFileValueDeserializer deserializer(manifest_path);
std::unique_ptr<base::Value> manifest =
deserializer.Deserialize(nullptr, nullptr);
ASSERT_TRUE(manifest.get());
ASSERT_TRUE(manifest->is_dict());
std::string error;
scoped_refptr<Extension> extension(Extension::Create(
manifest_path.DirName(), mojom::ManifestLocation::kComponent,
manifest->GetDict(), Extension::NO_FLAGS, &error));
ASSERT_TRUE(extension.get());
ExtensionIconManager icon_manager;
icon_manager.set_observer(this);
icon_manager.LoadIcon(browser_context(), extension.get());
WaitForImageLoad();
gfx::Image first_icon = icon_manager.GetIcon(extension->id());
EXPECT_FALSE(gfx::test::AreImagesEqual(first_icon, default_icon));
icon_manager.RemoveIcon(extension->id());
icon_manager.LoadIcon(browser_context(), extension.get());
WaitForImageLoad();
gfx::Image second_icon = icon_manager.GetIcon(extension->id());
EXPECT_FALSE(gfx::test::AreImagesEqual(second_icon, default_icon));
EXPECT_TRUE(gfx::test::AreImagesEqual(first_icon, second_icon));
}
#endif
TEST_F(ExtensionIconManagerTest, ScaleFactors) { … }
}
}