summaryrefslogtreecommitdiffstats
path: root/chrome/browser/thumbnail_store_unittest.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-09 20:04:28 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-09 20:04:28 +0000
commit449478308895f2f09eacfb4971b9917627aa3152 (patch)
tree8e5986eb759388f6eafb16dcbb532b850516e5c4 /chrome/browser/thumbnail_store_unittest.cc
parent7670df01a5a53fc1c39a0e0008813985d80ebae7 (diff)
downloadchromium_src-449478308895f2f09eacfb4971b9917627aa3152.zip
chromium_src-449478308895f2f09eacfb4971b9917627aa3152.tar.gz
chromium_src-449478308895f2f09eacfb4971b9917627aa3152.tar.bz2
Modified ThumbnailStore to cache/store JPEGs instead
of SkBitmaps. Add command line flag "--thumbnail-store" to enable using the ThumbnailStore facility instead of the current ThumbnailDatabase. Original review: http://codereview.chromium.org/118409 Patch by Meelap Shah git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17971 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/thumbnail_store_unittest.cc')
-rw-r--r--chrome/browser/thumbnail_store_unittest.cc75
1 files changed, 31 insertions, 44 deletions
diff --git a/chrome/browser/thumbnail_store_unittest.cc b/chrome/browser/thumbnail_store_unittest.cc
index 53ec322..eb00993 100644
--- a/chrome/browser/thumbnail_store_unittest.cc
+++ b/chrome/browser/thumbnail_store_unittest.cc
@@ -12,7 +12,9 @@
#include "base/file_util.h"
#include "base/gfx/jpeg_codec.h"
#include "base/path_service.h"
+#include "base/ref_counted.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/ref_counted_util.h"
#include "chrome/common/thumbnail_score.h"
#include "chrome/tools/profiles/thumbnail-inl.h"
#include "googleurl/src/gurl.h"
@@ -46,7 +48,8 @@ class ThumbnailStoreTest : public testing::Test {
// The directory where ThumbnailStore will store data.
FilePath file_path_;
- SkBitmap read_image_, image_enc_dec_, image_;
+ SkBitmap image_;
+ scoped_refptr<RefCountedBytes> jpeg_image_;
ThumbnailScore score1_, score2_;
GURL url1_, url2_;
base::Time time_;
@@ -63,21 +66,14 @@ void ThumbnailStoreTest::SetUp() {
// image is the original SkBitmap representing the thumbnail
image_ = *(JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail)));
- // The ThumbnailStore will encode the thumbnail to jpeg at 90% quality, so
- // we do this to image. When image is stored, image_enc_dec_ is what
- // ThumbnailStore should return.
- std::vector<unsigned char> jpeg_data;
SkAutoLockPixels thumbnail_lock(image_);
+ jpeg_image_ = new RefCountedBytes;
bool encoded = JPEGCodec::Encode(
reinterpret_cast<unsigned char*>(image_.getAddr32(0, 0)),
JPEGCodec::FORMAT_BGRA, image_.width(),
image_.height(),
static_cast<int>(image_.rowBytes()), 90,
- &jpeg_data);
-
- image_enc_dec_ = *(JPEGCodec::Decode(
- reinterpret_cast<const unsigned char*>(&jpeg_data[0]),
- jpeg_data.size()));
+ &(jpeg_image_->data));
}
void ThumbnailStoreTest::PrintPixelDiff(SkBitmap* image_a, SkBitmap* image_b) {
@@ -86,15 +82,20 @@ void ThumbnailStoreTest::PrintPixelDiff(SkBitmap* image_a, SkBitmap* image_b) {
// differences should be small since encoding was done at 90% before
// writing to disk.
+ if (image_a->height() != image_b->height() ||
+ image_b->width() != image_b->width() ||
+ image_a->rowBytes() != image_b->rowBytes())
+ return;
+
SkAutoLockPixels lock_a(*image_a);
SkAutoLockPixels lock_b(*image_b);
- int ppr = read_image_.rowBytesAsPixels();
+ int ppr = image_a->rowBytesAsPixels();
unsigned int *a, *b;
unsigned int maxv[4];
memset(maxv, 0, sizeof(maxv));
- for (int nrows = read_image_.height()-1; nrows >= 0; nrows--) {
+ for (int nrows = image_a->height()-1; nrows >= 0; nrows--) {
a = image_a->getAddr32(0, nrows);
b = image_b->getAddr32(0, nrows);
for (int i = 0; i < ppr; i += 4) {
@@ -114,61 +115,47 @@ void ThumbnailStoreTest::PrintPixelDiff(SkBitmap* image_a, SkBitmap* image_b) {
}
TEST_F(ThumbnailStoreTest, RetrieveFromCache) {
- ThumbnailStore* store = new ThumbnailStore;
- store->AddRef();
+ RefCountedBytes* read_image = NULL;
+ scoped_refptr<ThumbnailStore> store = new ThumbnailStore;
+
store->file_path_ = file_path_;
store->cache_.reset(new ThumbnailStore::Cache);
store->cache_initialized_ = true;
- read_image_.reset();
-
// Retrieve a thumbnail/score for a nonexistent page.
- EXPECT_FALSE(store->GetPageThumbnail(url2_, &read_image_, &score2_));
+ EXPECT_FALSE(store->GetPageThumbnail(url2_, &read_image));
// Store a thumbnail into the cache and retrieve it.
EXPECT_TRUE(store->SetPageThumbnail(url1_, image_, score1_, false));
- EXPECT_TRUE(store->GetPageThumbnail(url1_, &read_image_, &score2_));
- EXPECT_TRUE(score1_.Equals(score2_));
- EXPECT_TRUE(read_image_.getSize() == image_.getSize());
- EXPECT_TRUE(read_image_.pixelRef() == image_.pixelRef());
- EXPECT_FALSE(read_image_.isNull());
+ EXPECT_TRUE(store->GetPageThumbnail(url1_, &read_image));
+ EXPECT_TRUE(score1_.Equals((*store->cache_)[url1_].second));
+ EXPECT_TRUE(read_image->data.size() == jpeg_image_->data.size());
+ EXPECT_EQ(0, memcmp(&read_image->data[0], &jpeg_image_->data[0],
+ jpeg_image_->data.size()));
- store->Release();
+ read_image->Release();
}
TEST_F(ThumbnailStoreTest, RetrieveFromDisk) {
- ThumbnailStore* store = new ThumbnailStore;
- store->AddRef();
+ scoped_refptr<RefCountedBytes> read_image = new RefCountedBytes;
+ scoped_refptr<ThumbnailStore> store = new ThumbnailStore;
+
store->file_path_ = file_path_;
store->cache_.reset(new ThumbnailStore::Cache);
store->cache_initialized_ = true;
- read_image_.reset();
-
// Store a thumbnail onto the disk and retrieve it.
EXPECT_TRUE(store->SetPageThumbnail(url1_, image_, score1_, false));
EXPECT_TRUE(store->WriteThumbnailToDisk(url1_));
EXPECT_TRUE(store->GetPageThumbnailFromDisk(
- file_path_.AppendASCII(url1_.host()), &url2_, &read_image_, &score2_));
+ file_path_.AppendASCII(url1_.host()), &url2_, read_image, &score2_));
+ read_image->AddRef();
EXPECT_TRUE(url1_ == url2_);
EXPECT_TRUE(score1_.Equals(score2_));
- EXPECT_TRUE(read_image_.getSize() == image_enc_dec_.getSize());
- EXPECT_FALSE(read_image_.isNull());
-
- // The retrieved SkBitmap should be the same as the original image
- // encoded at 90% quality to jpeg, then decoded.
-
- {
- SkAutoLockPixels lock_a(read_image_);
- SkAutoLockPixels lock_b(image_enc_dec_);
- EXPECT_TRUE(0 == memcmp(read_image_.getPixels(),
- image_enc_dec_.getPixels(),
- read_image_.getSize()));
- }
- PrintPixelDiff(&read_image_, &image_);
-
- store->Release();
+ EXPECT_TRUE(read_image->data.size() == jpeg_image_->data.size());
+ EXPECT_EQ(0, memcmp(&read_image->data[0], &jpeg_image_->data[0],
+ jpeg_image_->data.size()));
}