| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string.h> | 5 #include <string.h> |
| 6 #include <algorithm> | 6 #include <algorithm> |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "chrome/browser/thumbnail_store.h" | 10 #include "chrome/browser/thumbnail_store.h" |
| 11 | 11 |
| 12 #include "app/gfx/codec/jpeg_codec.h" |
| 12 #include "app/sql/connection.h" | 13 #include "app/sql/connection.h" |
| 13 #include "app/sql/statement.h" | 14 #include "app/sql/statement.h" |
| 14 #include "base/time.h" | 15 #include "base/time.h" |
| 15 #include "base/file_path.h" | 16 #include "base/file_path.h" |
| 16 #include "base/file_util.h" | 17 #include "base/file_util.h" |
| 17 #include "base/gfx/jpeg_codec.h" | |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/ref_counted.h" | 19 #include "base/ref_counted.h" |
| 20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 21 #include "chrome/common/ref_counted_util.h" | 21 #include "chrome/common/ref_counted_util.h" |
| 22 #include "chrome/common/thumbnail_score.h" | 22 #include "chrome/common/thumbnail_score.h" |
| 23 #include "chrome/tools/profiles/thumbnail-inl.h" | 23 #include "chrome/tools/profiles/thumbnail-inl.h" |
| 24 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "third_party/skia/include/core/SkBitmap.h" | 26 #include "third_party/skia/include/core/SkBitmap.h" |
| 27 #include "third_party/skia/include/core/SkPixelRef.h" | 27 #include "third_party/skia/include/core/SkPixelRef.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 void ThumbnailStoreTest::SetUp() { | 65 void ThumbnailStoreTest::SetUp() { |
| 66 if (!file_util::GetTempDir(&db_name_)) | 66 if (!file_util::GetTempDir(&db_name_)) |
| 67 FAIL(); | 67 FAIL(); |
| 68 | 68 |
| 69 // Delete any old thumbnail files if they exist. | 69 // Delete any old thumbnail files if they exist. |
| 70 db_name_ = db_name_.AppendASCII("ThumbnailDB"); | 70 db_name_ = db_name_.AppendASCII("ThumbnailDB"); |
| 71 file_util::Delete(db_name_, false); | 71 file_util::Delete(db_name_, false); |
| 72 | 72 |
| 73 google_.reset(JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); | 73 google_.reset(gfx::JPEGCodec::Decode(kGoogleThumbnail, |
| 74 weewar_.reset(JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail))); | 74 sizeof(kGoogleThumbnail))); |
| 75 weewar_.reset(gfx::JPEGCodec::Decode(kWeewarThumbnail, |
| 76 sizeof(kWeewarThumbnail))); |
| 75 | 77 |
| 76 SkAutoLockPixels lock1(*google_); | 78 SkAutoLockPixels lock1(*google_); |
| 77 jpeg_google_ = new RefCountedBytes; | 79 jpeg_google_ = new RefCountedBytes; |
| 78 JPEGCodec::Encode( | 80 gfx::JPEGCodec::Encode( |
| 79 reinterpret_cast<unsigned char*>(google_->getAddr32(0, 0)), | 81 reinterpret_cast<unsigned char*>(google_->getAddr32(0, 0)), |
| 80 JPEGCodec::FORMAT_BGRA, google_->width(), | 82 gfx::JPEGCodec::FORMAT_BGRA, google_->width(), |
| 81 google_->height(), | 83 google_->height(), |
| 82 static_cast<int>(google_->rowBytes()), 90, | 84 static_cast<int>(google_->rowBytes()), 90, |
| 83 &(jpeg_google_->data)); | 85 &(jpeg_google_->data)); |
| 84 | 86 |
| 85 SkAutoLockPixels lock2(*weewar_); | 87 SkAutoLockPixels lock2(*weewar_); |
| 86 jpeg_weewar_ = new RefCountedBytes; | 88 jpeg_weewar_ = new RefCountedBytes; |
| 87 JPEGCodec::Encode( | 89 gfx::JPEGCodec::Encode( |
| 88 reinterpret_cast<unsigned char*>(weewar_->getAddr32(0,0)), | 90 reinterpret_cast<unsigned char*>(weewar_->getAddr32(0,0)), |
| 89 JPEGCodec::FORMAT_BGRA, weewar_->width(), | 91 gfx::JPEGCodec::FORMAT_BGRA, weewar_->width(), |
| 90 weewar_->height(), | 92 weewar_->height(), |
| 91 static_cast<int>(weewar_->rowBytes()), 90, | 93 static_cast<int>(weewar_->rowBytes()), 90, |
| 92 &(jpeg_weewar_->data)); | 94 &(jpeg_weewar_->data)); |
| 93 | 95 |
| 94 store_ = new ThumbnailStore; | 96 store_ = new ThumbnailStore; |
| 95 | 97 |
| 96 store_->cache_.reset(new ThumbnailStore::Cache); | 98 store_->cache_.reset(new ThumbnailStore::Cache); |
| 97 store_->redirect_urls_.reset(new history::RedirectMap); | 99 store_->redirect_urls_.reset(new history::RedirectMap); |
| 98 | 100 |
| 99 store_->most_visited_urls_.reset(new ThumbnailStore::MostVisitedMap); | 101 store_->most_visited_urls_.reset(new ThumbnailStore::MostVisitedMap); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 (*store_->redirect_urls_)[my_url] = new RefCountedVector<GURL>(redirects); | 218 (*store_->redirect_urls_)[my_url] = new RefCountedVector<GURL>(redirects); |
| 217 | 219 |
| 218 (*store_->most_visited_urls_)[url_] = my_url; | 220 (*store_->most_visited_urls_)[url_] = my_url; |
| 219 | 221 |
| 220 EXPECT_TRUE(store_->SetPageThumbnail(GURL("google.com"), *google_, score_, | 222 EXPECT_TRUE(store_->SetPageThumbnail(GURL("google.com"), *google_, score_, |
| 221 false)); | 223 false)); |
| 222 EXPECT_TRUE(store_->GetPageThumbnail(my_url, &read_image)); | 224 EXPECT_TRUE(store_->GetPageThumbnail(my_url, &read_image)); |
| 223 | 225 |
| 224 read_image->Release(); | 226 read_image->Release(); |
| 225 } | 227 } |
| OLD | NEW |