summaryrefslogtreecommitdiffstats
path: root/ios
diff options
context:
space:
mode:
authorjustincohen <justincohen@chromium.org>2015-11-02 17:55:01 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-03 01:55:44 +0000
commitba2118d943cfdbbfa407948089b557ed523561d6 (patch)
treef7b51a8da0acc53d1feaa6bfd004db8e93692985 /ios
parentc7ae33be12bedb2862e67b5052305b934753ab0a (diff)
downloadchromium_src-ba2118d943cfdbbfa407948089b557ed523561d6.zip
chromium_src-ba2118d943cfdbbfa407948089b557ed523561d6.tar.gz
chromium_src-ba2118d943cfdbbfa407948089b557ed523561d6.tar.bz2
Adding large icon cache unit tests.
BUG=543738 Review URL: https://codereview.chromium.org/1410373007 Cr-Commit-Position: refs/heads/master@{#357511}
Diffstat (limited to 'ios')
-rw-r--r--ios/chrome/browser/favicon/large_icon_cache_unittest.cc97
-rw-r--r--ios/chrome/ios_chrome_tests.gyp5
2 files changed, 102 insertions, 0 deletions
diff --git a/ios/chrome/browser/favicon/large_icon_cache_unittest.cc b/ios/chrome/browser/favicon/large_icon_cache_unittest.cc
new file mode 100644
index 0000000..7773cd0
--- /dev/null
+++ b/ios/chrome/browser/favicon/large_icon_cache_unittest.cc
@@ -0,0 +1,97 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/chrome/browser/favicon/large_icon_cache.h"
+
+#include "components/favicon_base/fallback_icon_style.h"
+#include "components/favicon_base/favicon_types.h"
+#include "skia/ext/skia_utils_ios.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/codec/png_codec.h"
+
+namespace {
+
+const char kDummyUrl[] = "http://www.example.com";
+const char kDummyUrl2[] = "http://www.example2.com";
+const SkColor kTestColor = SK_ColorRED;
+
+favicon_base::FaviconRawBitmapResult CreateTestBitmap(int w,
+ int h,
+ SkColor color) {
+ favicon_base::FaviconRawBitmapResult result;
+ result.expired = false;
+
+ // Create bitmap and fill with |color|.
+ scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes());
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(w, h);
+ bitmap.eraseColor(color);
+ gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &data->data());
+ result.bitmap_data = data;
+
+ result.pixel_size = gfx::Size(w, h);
+ result.icon_url = GURL(kDummyUrl);
+ result.icon_type = favicon_base::TOUCH_ICON;
+ CHECK(result.is_valid());
+ return result;
+}
+
+class LargeIconCacheTest : public testing::Test {
+ public:
+ LargeIconCacheTest() {
+ expected_fallback_icon_style_.reset(new favicon_base::FallbackIconStyle());
+ expected_fallback_icon_style_->background_color = kTestColor;
+ expected_bitmap_ = CreateTestBitmap(24, 24, kTestColor);
+ large_icon_cache_.reset(new LargeIconCache);
+ }
+
+ ~LargeIconCacheTest() override {}
+
+ protected:
+ scoped_ptr<LargeIconCache> large_icon_cache_;
+ favicon_base::FaviconRawBitmapResult expected_bitmap_;
+ scoped_ptr<favicon_base::FallbackIconStyle> expected_fallback_icon_style_;
+
+ bool is_callback_invoked_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LargeIconCacheTest);
+};
+
+TEST_F(LargeIconCacheTest, EmptyCache) {
+ scoped_ptr<LargeIconCache> large_icon_cache(new LargeIconCache);
+ EXPECT_EQ(nullptr, large_icon_cache->GetCachedResult(GURL(kDummyUrl)));
+}
+
+TEST_F(LargeIconCacheTest, RetreiveItem) {
+ scoped_ptr<favicon_base::LargeIconResult> expected_result1;
+ scoped_ptr<favicon_base::LargeIconResult> expected_result2;
+ expected_result1.reset(new favicon_base::LargeIconResult(expected_bitmap_));
+ expected_result2.reset(new favicon_base::LargeIconResult(
+ new favicon_base::FallbackIconStyle(*expected_fallback_icon_style_)));
+
+ large_icon_cache_->SetCachedResult(GURL(kDummyUrl), *expected_result1);
+ large_icon_cache_->SetCachedResult(GURL(kDummyUrl2), *expected_result2);
+
+ scoped_ptr<favicon_base::LargeIconResult> result1 =
+ large_icon_cache_->GetCachedResult(GURL(kDummyUrl));
+ EXPECT_EQ(true, result1->bitmap.is_valid());
+ EXPECT_EQ(expected_result1->bitmap.pixel_size, result1->bitmap.pixel_size);
+
+ scoped_ptr<favicon_base::LargeIconResult> result2 =
+ large_icon_cache_->GetCachedResult(GURL(kDummyUrl2));
+ EXPECT_EQ(false, result2->bitmap.is_valid());
+ EXPECT_EQ(expected_result2->fallback_icon_style->background_color,
+ result2->fallback_icon_style->background_color);
+
+ // Test overwriting kDummyUrl.
+ large_icon_cache_->SetCachedResult(GURL(kDummyUrl), *expected_result2);
+ scoped_ptr<favicon_base::LargeIconResult> result3 =
+ large_icon_cache_->GetCachedResult(GURL(kDummyUrl2));
+ EXPECT_EQ(false, result3->bitmap.is_valid());
+ EXPECT_EQ(expected_result2->fallback_icon_style->background_color,
+ result3->fallback_icon_style->background_color);
+}
+
+} // namespace
diff --git a/ios/chrome/ios_chrome_tests.gyp b/ios/chrome/ios_chrome_tests.gyp
index 29b6553..828d956 100644
--- a/ios/chrome/ios_chrome_tests.gyp
+++ b/ios/chrome/ios_chrome_tests.gyp
@@ -15,14 +15,18 @@
'../../base/base.gyp:test_support_base',
'../../components/components.gyp:bookmarks_test_support',
'../../components/components.gyp:enhanced_bookmarks_test_support',
+ '../../components/components.gyp:favicon_base',
'../../components/components.gyp:metrics',
'../../components/components.gyp:metrics_test_support',
'../../components/components.gyp:update_client',
'../../components/components.gyp:version_info',
'../../net/net.gyp:net_test_support',
+ '../../skia/skia.gyp:skia',
'../../testing/gmock.gyp:gmock',
'../../testing/gtest.gyp:gtest',
'../../third_party/ocmock/ocmock.gyp:ocmock',
+ '../../ui/gfx/gfx.gyp:gfx',
+ '../../ui/gfx/gfx.gyp:gfx_test_support',
'../ios_tests.gyp:test_support_ios',
'../web/ios_web.gyp:ios_web',
'../web/ios_web.gyp:ios_web_test_support',
@@ -38,6 +42,7 @@
'app/safe_mode_util_unittest.cc',
'browser/chrome_url_util_unittest.mm',
'browser/crash_loop_detection_util_unittest.mm',
+ 'browser/favicon/large_icon_cache_unittest.cc',
'browser/geolocation/CLLocation+XGeoHeaderTest.mm',
'browser/geolocation/location_manager_unittest.mm',
'browser/geolocation/omnibox_geolocation_local_state_unittest.mm',