chromium/components/favicon/core/large_icon_service_impl_unittest.cc

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

#include "components/favicon/core/large_icon_service_impl.h"

#include <memory>
#include <string>

#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted_memory.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "components/favicon/core/favicon_client.h"
#include "components/favicon/core/test/mock_favicon_service.h"
#include "components/favicon_base/fallback_icon_style.h"
#include "components/favicon_base/favicon_types.h"
#include "components/image_fetcher/core/image_fetcher.h"
#include "components/image_fetcher/core/mock_image_fetcher.h"
#include "components/image_fetcher/core/request_metadata.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/resource/resource_scale_factor.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "url/gurl.h"

namespace favicon {
namespace {

MockImageFetcher;
_;
Eq;
HasSubstr;
IsEmpty;
IsNull;
NiceMock;
Not;
Property;
Return;
SaveArg;
StartsWith;

const char kDummyPageUrl[] =;
const char kDummyIconUrl[] =;
const SkColor kTestColor =;

ACTION_P(PostFetchReply, p0) {}

ACTION_P2(PostFetchReplyWithMetadata, p0, p1) {}

favicon_base::FaviconRawBitmapResult CreateTestBitmapResult(int w,
                                                            int h,
                                                            SkColor color) {}

bool HasBackgroundColor(
    const favicon_base::FallbackIconStyle& fallback_icon_style,
    SkColor color) {}

// TODO(jkrcal): Make the tests a bit crisper, see crbug.com/725822.
class LargeIconServiceTest : public testing::Test {};

TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) {}

TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithOriginalUrl) {}

TEST_F(LargeIconServiceTest, ShouldTrimQueryParametersForGoogleServer) {}

TEST_F(LargeIconServiceTest, ShouldNotQueryGoogleServerIfInvalidScheme) {}

TEST_F(LargeIconServiceTest, ShouldNotQueryGoogleServerIfInvalidURL) {}

TEST_F(LargeIconServiceTest, ShouldReportUnavailableIfFetchFromServerFails) {}

TEST_F(LargeIconServiceTest, ShouldNotGetFromGoogleServerIfUnavailable) {}

TEST_F(LargeIconServiceTest, ShouldNotGetFromGoogleServerIfCannotSet) {}

class LargeIconServiceGetterTest : public LargeIconServiceTest,
                                   public ::testing::WithParamInterface<bool> {};

// Test that `GetLargeIconFromCacheFallbackToGoogleServer()` returns the locally
// stored icon if the requested size matches the stored icon size. Verify that
// the Google server is not queried.
TEST_P(LargeIconServiceGetterTest,
       ShouldReturnIconFromLocalCacheIfSameSizeAvailable) {}

// Test that `GetLargeIconFromCacheFallbackToGoogleServer()` resizes the locally
// stored icon if the requested size is smaller then the database icon size.
// Verify that the Google server is not queried.
TEST_P(LargeIconServiceGetterTest,
       ShouldReturnResizedIconFromLocalCacheIfLargerSizeAvailable) {}

// Test that `GetLargeIconFromCacheFallbackToGoogleServer()` doesn't query the
// Google server if the database icon has a smaller size than the passed-in
// `min_source_size`.
TEST_P(LargeIconServiceGetterTest,
       ShouldReturnResizedIconFromServerIfCachedIconIsTooSmall) {}

// Test that `GetLargeIconFromCacheFallbackToGoogleServer()` queries the Google
// server if there is no icon available locally for the specified `page_url`.
TEST_P(LargeIconServiceGetterTest,
       ShouldReturnResizedIconFromServerIfNoIconInCache) {}

// Test that GetLargeIconFromCacheFallbackToGoogleServer() doesn't crash if the
// CancelableTaskTracker is destroyed before the async call finishes.
TEST_P(LargeIconServiceGetterTest, CancelableTaskTrackerDestroyedEarly) {}

TEST_P(LargeIconServiceGetterTest, SameSize) {}

TEST_P(LargeIconServiceGetterTest, ScaleDown) {}

TEST_P(LargeIconServiceGetterTest, ScaleUp) {}

// `desired_size_in_pixel` == 0 means retrieve original image without scaling.
TEST_P(LargeIconServiceGetterTest, NoScale) {}

TEST_P(LargeIconServiceGetterTest, FallbackSinceIconTooSmall) {}

TEST_P(LargeIconServiceGetterTest, FallbackSinceIconNotSquare) {}

TEST_P(LargeIconServiceGetterTest, FallbackSinceIconMissing) {}

TEST_P(LargeIconServiceGetterTest, FallbackSinceIconMissingNoScale) {}

// Oddball case where we demand a high resolution icon to scale down. Generates
// fallback even though an icon with the final size is available.
TEST_P(LargeIconServiceGetterTest, FallbackSinceTooPicky) {}

TEST_P(LargeIconServiceGetterTest, IconTooSmallStillWantBitmap) {}

TEST_P(LargeIconServiceGetterTest, IconTooSmallDontWantAnything) {}

// Every test will appear with suffix /0 (param false) and /1 (param true), e.g.
//  LargeIconServiceGetterTest.FallbackSinceTooPicky/0: get image.
//  LargeIconServiceGetterTest.FallbackSinceTooPicky/1: get raw bitmap.
INSTANTIATE_TEST_SUITE_P();

}  // namespace
}  // namespace favicon