| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/search/suggestions/thumbnail_manager.h" | 10 #include "chrome/browser/search/suggestions/image_manager_impl.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "components/leveldb_proto/proto_database.h" | 13 #include "components/leveldb_proto/proto_database.h" |
| 14 #include "components/leveldb_proto/testing/fake_db.h" | 14 #include "components/leveldb_proto/testing/fake_db.h" |
| 15 #include "components/suggestions/proto/suggestions.pb.h" | 15 #include "components/suggestions/proto/suggestions.pb.h" |
| 16 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
| 17 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
| 18 #include "net/test/spawned_test_server/spawned_test_server.h" | 18 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "ui/gfx/image/image_skia.h" | 20 #include "ui/gfx/image/image_skia.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 namespace suggestions { | 23 namespace suggestions { |
| 24 | 24 |
| 25 const char kTestUrl1[] = "http://go.com/"; | 25 const char kTestUrl1[] = "http://go.com/"; |
| 26 const char kTestUrl2[] = "http://goal.com/"; | 26 const char kTestUrl2[] = "http://goal.com/"; |
| 27 const char kTestBitmapUrl[] = "http://test.com"; | 27 const char kTestBitmapUrl[] = "http://test.com"; |
| 28 const char kTestImagePath[] = "files/image_decoding/droids.png"; | 28 const char kTestImagePath[] = "files/image_decoding/droids.png"; |
| 29 const char kInvalidImagePath[] = "files/DOESNOTEXIST"; | 29 const char kInvalidImagePath[] = "files/DOESNOTEXIST"; |
| 30 | 30 |
| 31 const base::FilePath::CharType kDocRoot[] = | 31 const base::FilePath::CharType kDocRoot[] = |
| 32 FILE_PATH_LITERAL("chrome/test/data"); | 32 FILE_PATH_LITERAL("chrome/test/data"); |
| 33 | 33 |
| 34 using chrome::BitmapFetcher; | 34 using chrome::BitmapFetcher; |
| 35 using content::BrowserThread; | 35 using content::BrowserThread; |
| 36 using leveldb_proto::test::FakeDB; | 36 using leveldb_proto::test::FakeDB; |
| 37 using suggestions::ThumbnailData; | 37 using suggestions::ImageData; |
| 38 using suggestions::ThumbnailManager; | 38 using suggestions::ImageManagerImpl; |
| 39 | 39 |
| 40 typedef base::hash_map<std::string, ThumbnailData> EntryMap; | 40 typedef base::hash_map<std::string, ImageData> EntryMap; |
| 41 | 41 |
| 42 void AddEntry(const ThumbnailData& d, EntryMap* map) { (*map)[d.url()] = d; } | 42 void AddEntry(const ImageData& d, EntryMap* map) { (*map)[d.url()] = d; } |
| 43 | 43 |
| 44 class ThumbnailManagerBrowserTest : public InProcessBrowserTest { | 44 class ImageManagerImplBrowserTest : public InProcessBrowserTest { |
| 45 public: | 45 public: |
| 46 ThumbnailManagerBrowserTest() | 46 ImageManagerImplBrowserTest() |
| 47 : num_callback_null_called_(0), | 47 : num_callback_null_called_(0), |
| 48 num_callback_valid_called_(0), | 48 num_callback_valid_called_(0), |
| 49 test_server_(net::SpawnedTestServer::TYPE_HTTP, | 49 test_server_(net::SpawnedTestServer::TYPE_HTTP, |
| 50 net::SpawnedTestServer::kLocalhost, | 50 net::SpawnedTestServer::kLocalhost, |
| 51 base::FilePath(kDocRoot)) {} | 51 base::FilePath(kDocRoot)) {} |
| 52 | 52 |
| 53 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 53 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 54 ASSERT_TRUE(test_server_.Start()); | 54 ASSERT_TRUE(test_server_.Start()); |
| 55 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 55 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | 58 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { |
| 59 test_server_.Stop(); | 59 test_server_.Stop(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 virtual void SetUpOnMainThread() OVERRIDE { | 62 virtual void SetUpOnMainThread() OVERRIDE { |
| 63 fake_db_ = new FakeDB<ThumbnailData>(&db_model_); | 63 fake_db_ = new FakeDB<ImageData>(&db_model_); |
| 64 thumbnail_manager_.reset(CreateThumbnailManager(fake_db_)); | 64 image_manager_.reset(CreateImageManagerImpl(fake_db_)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 virtual void TearDownOnMainThread() OVERRIDE { | 67 virtual void TearDownOnMainThread() OVERRIDE { |
| 68 fake_db_ = NULL; | 68 fake_db_ = NULL; |
| 69 db_model_.clear(); | 69 db_model_.clear(); |
| 70 thumbnail_manager_.reset(); | 70 image_manager_.reset(); |
| 71 test_thumbnail_manager_.reset(); | 71 test_image_manager_.reset(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void InitializeTestBitmapData() { | 74 void InitializeTestBitmapData() { |
| 75 FakeDB<ThumbnailData>* test_fake_db = new FakeDB<ThumbnailData>(&db_model_); | 75 FakeDB<ImageData>* test_fake_db = new FakeDB<ImageData>(&db_model_); |
| 76 test_thumbnail_manager_.reset(CreateThumbnailManager(test_fake_db)); | 76 test_image_manager_.reset(CreateImageManagerImpl(test_fake_db)); |
| 77 | 77 |
| 78 suggestions::SuggestionsProfile suggestions_profile; | 78 suggestions::SuggestionsProfile suggestions_profile; |
| 79 suggestions::ChromeSuggestion* suggestion = | 79 suggestions::ChromeSuggestion* suggestion = |
| 80 suggestions_profile.add_suggestions(); | 80 suggestions_profile.add_suggestions(); |
| 81 suggestion->set_url(kTestBitmapUrl); | 81 suggestion->set_url(kTestBitmapUrl); |
| 82 suggestion->set_thumbnail(test_server_.GetURL(kTestImagePath).spec()); | 82 suggestion->set_thumbnail(test_server_.GetURL(kTestImagePath).spec()); |
| 83 | 83 |
| 84 test_thumbnail_manager_->Initialize(suggestions_profile); | 84 test_image_manager_->Initialize(suggestions_profile); |
| 85 | 85 |
| 86 // Initialize empty database. | 86 // Initialize empty database. |
| 87 test_fake_db->InitCallback(true); | 87 test_fake_db->InitCallback(true); |
| 88 test_fake_db->LoadCallback(true); | 88 test_fake_db->LoadCallback(true); |
| 89 | 89 |
| 90 base::RunLoop run_loop; | 90 base::RunLoop run_loop; |
| 91 // Fetch existing URL. | 91 // Fetch existing URL. |
| 92 test_thumbnail_manager_->GetImageForURL( | 92 test_image_manager_->GetImageForURL( |
| 93 GURL(kTestBitmapUrl), | 93 GURL(kTestBitmapUrl), |
| 94 base::Bind(&ThumbnailManagerBrowserTest::OnTestThumbnailAvailable, | 94 base::Bind(&ImageManagerImplBrowserTest::OnTestImageAvailable, |
| 95 base::Unretained(this), &run_loop)); | 95 base::Unretained(this), &run_loop)); |
| 96 run_loop.Run(); | 96 run_loop.Run(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void OnTestThumbnailAvailable(base::RunLoop* loop, const GURL& url, | 99 void OnTestImageAvailable(base::RunLoop* loop, const GURL& url, |
| 100 const SkBitmap* bitmap) { | 100 const SkBitmap* bitmap) { |
| 101 CHECK(bitmap); | 101 CHECK(bitmap); |
| 102 // Copy the resource locally. | 102 // Copy the resource locally. |
| 103 test_bitmap_ = *bitmap; | 103 test_bitmap_ = *bitmap; |
| 104 loop->Quit(); | 104 loop->Quit(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void InitializeDefaultThumbnailMapAndDatabase( | 107 void InitializeDefaultImageMapAndDatabase( |
| 108 ThumbnailManager* thumbnail_manager, FakeDB<ThumbnailData>* fake_db) { | 108 ImageManagerImpl* image_manager, FakeDB<ImageData>* fake_db) { |
| 109 CHECK(thumbnail_manager); | 109 CHECK(image_manager); |
| 110 CHECK(fake_db); | 110 CHECK(fake_db); |
| 111 | 111 |
| 112 suggestions::SuggestionsProfile suggestions_profile; | 112 suggestions::SuggestionsProfile suggestions_profile; |
| 113 suggestions::ChromeSuggestion* suggestion = | 113 suggestions::ChromeSuggestion* suggestion = |
| 114 suggestions_profile.add_suggestions(); | 114 suggestions_profile.add_suggestions(); |
| 115 suggestion->set_url(kTestUrl1); | 115 suggestion->set_url(kTestUrl1); |
| 116 suggestion->set_thumbnail(test_server_.GetURL(kTestImagePath).spec()); | 116 suggestion->set_thumbnail(test_server_.GetURL(kTestImagePath).spec()); |
| 117 | 117 |
| 118 thumbnail_manager->Initialize(suggestions_profile); | 118 image_manager->Initialize(suggestions_profile); |
| 119 | 119 |
| 120 // Initialize empty database. | 120 // Initialize empty database. |
| 121 fake_db->InitCallback(true); | 121 fake_db->InitCallback(true); |
| 122 fake_db->LoadCallback(true); | 122 fake_db->LoadCallback(true); |
| 123 } | 123 } |
| 124 | 124 |
| 125 ThumbnailData GetSampleThumbnailData(const std::string& url) { | 125 ImageData GetSampleImageData(const std::string& url) { |
| 126 ThumbnailData data; | 126 ImageData data; |
| 127 data.set_url(url); | 127 data.set_url(url); |
| 128 std::vector<unsigned char> encoded; | 128 std::vector<unsigned char> encoded; |
| 129 EXPECT_TRUE(ThumbnailManager::EncodeThumbnail(test_bitmap_, &encoded)); | 129 EXPECT_TRUE(ImageManagerImpl::EncodeImage(test_bitmap_, &encoded)); |
| 130 data.set_data(std::string(encoded.begin(), encoded.end())); | 130 data.set_data(std::string(encoded.begin(), encoded.end())); |
| 131 return data; | 131 return data; |
| 132 } | 132 } |
| 133 | 133 |
| 134 void OnThumbnailAvailable(base::RunLoop* loop, const GURL& url, | 134 void OnImageAvailable(base::RunLoop* loop, const GURL& url, |
| 135 const SkBitmap* bitmap) { | 135 const SkBitmap* bitmap) { |
| 136 if (bitmap) { | 136 if (bitmap) { |
| 137 num_callback_valid_called_++; | 137 num_callback_valid_called_++; |
| 138 /*std::vector<unsigned char> actual; | 138 std::vector<unsigned char> actual; |
| 139 std::vector<unsigned char> expected; | 139 std::vector<unsigned char> expected; |
| 140 EXPECT_TRUE(ThumbnailManager::EncodeThumbnail(*bitmap, &actual)); | 140 EXPECT_TRUE(ImageManagerImpl::EncodeImage(*bitmap, &actual)); |
| 141 EXPECT_TRUE(ThumbnailManager::EncodeThumbnail(test_bitmap_, &expected)); | 141 EXPECT_TRUE(ImageManagerImpl::EncodeImage(test_bitmap_, &expected)); |
| 142 // Check first 100 bytes. | 142 // Check first 100 bytes. |
| 143 std::string actual_str(actual.begin(), actual.begin() + 100); | 143 std::string actual_str(actual.begin(), actual.begin() + 100); |
| 144 std::string expected_str(expected.begin(), expected.begin() + 100); | 144 std::string expected_str(expected.begin(), expected.begin() + 100); |
| 145 EXPECT_EQ(expected_str, actual_str);*/ | 145 EXPECT_EQ(expected_str, actual_str); |
| 146 } else { | 146 } else { |
| 147 num_callback_null_called_++; | 147 num_callback_null_called_++; |
| 148 } | 148 } |
| 149 loop->Quit(); | 149 loop->Quit(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 ThumbnailManager* CreateThumbnailManager(FakeDB<ThumbnailData>* fake_db) { | 152 ImageManagerImpl* CreateImageManagerImpl(FakeDB<ImageData>* fake_db) { |
| 153 return new ThumbnailManager( | 153 return new ImageManagerImpl( |
| 154 browser()->profile()->GetRequestContext(), | 154 browser()->profile()->GetRequestContext(), |
| 155 scoped_ptr<leveldb_proto::ProtoDatabase<ThumbnailData> >(fake_db), | 155 scoped_ptr<leveldb_proto::ProtoDatabase<ImageData> >(fake_db), |
| 156 FakeDB<ThumbnailData>::DirectoryForTestDB()); | 156 FakeDB<ImageData>::DirectoryForTestDB()); |
| 157 } | 157 } |
| 158 | 158 |
| 159 EntryMap db_model_; | 159 EntryMap db_model_; |
| 160 // Owned by the ThumbnailManager under test. | 160 // Owned by the ImageManagerImpl under test. |
| 161 FakeDB<ThumbnailData>* fake_db_; | 161 FakeDB<ImageData>* fake_db_; |
| 162 | 162 |
| 163 SkBitmap test_bitmap_; | 163 SkBitmap test_bitmap_; |
| 164 scoped_ptr<ThumbnailManager> test_thumbnail_manager_; | 164 scoped_ptr<ImageManagerImpl> test_image_manager_; |
| 165 | 165 |
| 166 int num_callback_null_called_; | 166 int num_callback_null_called_; |
| 167 int num_callback_valid_called_; | 167 int num_callback_valid_called_; |
| 168 net::SpawnedTestServer test_server_; | 168 net::SpawnedTestServer test_server_; |
| 169 // Under test. | 169 // Under test. |
| 170 scoped_ptr<ThumbnailManager> thumbnail_manager_; | 170 scoped_ptr<ImageManagerImpl> image_manager_; |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 IN_PROC_BROWSER_TEST_F(ThumbnailManagerBrowserTest, GetImageForURLNetwork) { | 173 IN_PROC_BROWSER_TEST_F(ImageManagerImplBrowserTest, GetImageForURLNetwork) { |
| 174 InitializeDefaultThumbnailMapAndDatabase(thumbnail_manager_.get(), fake_db_); | 174 InitializeTestBitmapData(); |
| 175 InitializeDefaultImageMapAndDatabase(image_manager_.get(), fake_db_); |
| 175 | 176 |
| 176 base::RunLoop run_loop; | 177 base::RunLoop run_loop; |
| 177 // Fetch existing URL. | 178 // Fetch existing URL. |
| 178 thumbnail_manager_->GetImageForURL( | 179 image_manager_->GetImageForURL( |
| 179 GURL(kTestUrl1), | 180 GURL(kTestUrl1), |
| 180 base::Bind(&ThumbnailManagerBrowserTest::OnThumbnailAvailable, | 181 base::Bind(&ImageManagerImplBrowserTest::OnImageAvailable, |
| 181 base::Unretained(this), &run_loop)); | 182 base::Unretained(this), &run_loop)); |
| 182 run_loop.Run(); | 183 run_loop.Run(); |
| 183 | 184 |
| 184 EXPECT_EQ(0, num_callback_null_called_); | 185 EXPECT_EQ(0, num_callback_null_called_); |
| 185 EXPECT_EQ(1, num_callback_valid_called_); | 186 EXPECT_EQ(1, num_callback_valid_called_); |
| 186 | 187 |
| 187 base::RunLoop run_loop2; | 188 base::RunLoop run_loop2; |
| 188 // Fetch non-existing URL. | 189 // Fetch non-existing URL. |
| 189 thumbnail_manager_->GetImageForURL( | 190 image_manager_->GetImageForURL( |
| 190 GURL(kTestUrl2), | 191 GURL(kTestUrl2), |
| 191 base::Bind(&ThumbnailManagerBrowserTest::OnThumbnailAvailable, | 192 base::Bind(&ImageManagerImplBrowserTest::OnImageAvailable, |
| 192 base::Unretained(this), &run_loop2)); | 193 base::Unretained(this), &run_loop2)); |
| 193 run_loop2.Run(); | 194 run_loop2.Run(); |
| 194 | 195 |
| 195 EXPECT_EQ(1, num_callback_null_called_); | 196 EXPECT_EQ(1, num_callback_null_called_); |
| 196 EXPECT_EQ(1, num_callback_valid_called_); | 197 EXPECT_EQ(1, num_callback_valid_called_); |
| 197 } | 198 } |
| 198 | 199 |
| 199 IN_PROC_BROWSER_TEST_F(ThumbnailManagerBrowserTest, | 200 IN_PROC_BROWSER_TEST_F(ImageManagerImplBrowserTest, |
| 200 GetImageForURLNetworkMultiple) { | 201 GetImageForURLNetworkMultiple) { |
| 201 InitializeDefaultThumbnailMapAndDatabase(thumbnail_manager_.get(), fake_db_); | 202 InitializeTestBitmapData(); |
| 203 InitializeDefaultImageMapAndDatabase(image_manager_.get(), fake_db_); |
| 202 | 204 |
| 203 // Fetch non-existing URL, and add more while request is in flight. | 205 // Fetch non-existing URL, and add more while request is in flight. |
| 204 base::RunLoop run_loop; | 206 base::RunLoop run_loop; |
| 205 for (int i = 0; i < 5; i++) { | 207 for (int i = 0; i < 5; i++) { |
| 206 // Fetch existing URL. | 208 // Fetch existing URL. |
| 207 thumbnail_manager_->GetImageForURL( | 209 image_manager_->GetImageForURL( |
| 208 GURL(kTestUrl1), | 210 GURL(kTestUrl1), |
| 209 base::Bind(&ThumbnailManagerBrowserTest::OnThumbnailAvailable, | 211 base::Bind(&ImageManagerImplBrowserTest::OnImageAvailable, |
| 210 base::Unretained(this), &run_loop)); | 212 base::Unretained(this), &run_loop)); |
| 211 } | 213 } |
| 212 run_loop.Run(); | 214 run_loop.Run(); |
| 213 | 215 |
| 214 EXPECT_EQ(0, num_callback_null_called_); | 216 EXPECT_EQ(0, num_callback_null_called_); |
| 215 EXPECT_EQ(5, num_callback_valid_called_); | 217 EXPECT_EQ(5, num_callback_valid_called_); |
| 216 } | 218 } |
| 217 | 219 |
| 218 IN_PROC_BROWSER_TEST_F(ThumbnailManagerBrowserTest, | 220 IN_PROC_BROWSER_TEST_F(ImageManagerImplBrowserTest, |
| 219 GetImageForURLNetworkInvalid) { | 221 GetImageForURLNetworkInvalid) { |
| 220 SuggestionsProfile suggestions_profile; | 222 SuggestionsProfile suggestions_profile; |
| 221 ChromeSuggestion* suggestion = suggestions_profile.add_suggestions(); | 223 ChromeSuggestion* suggestion = suggestions_profile.add_suggestions(); |
| 222 suggestion->set_url(kTestUrl1); | 224 suggestion->set_url(kTestUrl1); |
| 223 suggestion->set_thumbnail(test_server_.GetURL(kInvalidImagePath).spec()); | 225 suggestion->set_thumbnail(test_server_.GetURL(kInvalidImagePath).spec()); |
| 224 | 226 |
| 225 thumbnail_manager_->Initialize(suggestions_profile); | 227 image_manager_->Initialize(suggestions_profile); |
| 226 | 228 |
| 227 // Database will be initialized and loaded without anything in it. | 229 // Database will be initialized and loaded without anything in it. |
| 228 fake_db_->InitCallback(true); | 230 fake_db_->InitCallback(true); |
| 229 fake_db_->LoadCallback(true); | 231 fake_db_->LoadCallback(true); |
| 230 | 232 |
| 231 base::RunLoop run_loop; | 233 base::RunLoop run_loop; |
| 232 // Fetch existing URL that has invalid thumbnail. | 234 // Fetch existing URL that has invalid image. |
| 233 thumbnail_manager_->GetImageForURL( | 235 image_manager_->GetImageForURL( |
| 234 GURL(kTestUrl1), | 236 GURL(kTestUrl1), |
| 235 base::Bind(&ThumbnailManagerBrowserTest::OnThumbnailAvailable, | 237 base::Bind(&ImageManagerImplBrowserTest::OnImageAvailable, |
| 236 base::Unretained(this), &run_loop)); | 238 base::Unretained(this), &run_loop)); |
| 237 run_loop.Run(); | 239 run_loop.Run(); |
| 238 | 240 |
| 239 EXPECT_EQ(1, num_callback_null_called_); | 241 EXPECT_EQ(1, num_callback_null_called_); |
| 240 EXPECT_EQ(0, num_callback_valid_called_); | 242 EXPECT_EQ(0, num_callback_valid_called_); |
| 241 } | 243 } |
| 242 | 244 |
| 243 IN_PROC_BROWSER_TEST_F(ThumbnailManagerBrowserTest, | 245 IN_PROC_BROWSER_TEST_F(ImageManagerImplBrowserTest, |
| 244 GetImageForURLNetworkCacheHit) { | 246 GetImageForURLNetworkCacheHit) { |
| 245 InitializeTestBitmapData(); | 247 InitializeTestBitmapData(); |
| 246 | 248 |
| 247 SuggestionsProfile suggestions_profile; | 249 SuggestionsProfile suggestions_profile; |
| 248 ChromeSuggestion* suggestion = suggestions_profile.add_suggestions(); | 250 ChromeSuggestion* suggestion = suggestions_profile.add_suggestions(); |
| 249 suggestion->set_url(kTestUrl1); | 251 suggestion->set_url(kTestUrl1); |
| 250 // The URL we set is invalid, to show that it will fail from network. | 252 // The URL we set is invalid, to show that it will fail from network. |
| 251 suggestion->set_thumbnail(test_server_.GetURL(kInvalidImagePath).spec()); | 253 suggestion->set_thumbnail(test_server_.GetURL(kInvalidImagePath).spec()); |
| 252 | 254 |
| 253 // Create the ThumbnailManager with an added entry in the database. | 255 // Create the ImageManagerImpl with an added entry in the database. |
| 254 AddEntry(GetSampleThumbnailData(kTestUrl1), &db_model_); | 256 AddEntry(GetSampleImageData(kTestUrl1), &db_model_); |
| 255 FakeDB<ThumbnailData>* fake_db = new FakeDB<ThumbnailData>(&db_model_); | 257 FakeDB<ImageData>* fake_db = new FakeDB<ImageData>(&db_model_); |
| 256 thumbnail_manager_.reset(CreateThumbnailManager(fake_db)); | 258 image_manager_.reset(CreateImageManagerImpl(fake_db)); |
| 257 thumbnail_manager_->Initialize(suggestions_profile); | 259 image_manager_->Initialize(suggestions_profile); |
| 258 fake_db->InitCallback(true); | 260 fake_db->InitCallback(true); |
| 259 fake_db->LoadCallback(true); | 261 fake_db->LoadCallback(true); |
| 260 // Expect something in the cache. | 262 // Expect something in the cache. |
| 261 SkBitmap* bitmap = thumbnail_manager_->GetBitmapFromCache(GURL(kTestUrl1)); | 263 SkBitmap* bitmap = image_manager_->GetBitmapFromCache(GURL(kTestUrl1)); |
| 262 EXPECT_FALSE(bitmap->isNull()); | 264 EXPECT_FALSE(bitmap->isNull()); |
| 263 | 265 |
| 264 base::RunLoop run_loop; | 266 base::RunLoop run_loop; |
| 265 thumbnail_manager_->GetImageForURL( | 267 image_manager_->GetImageForURL( |
| 266 GURL(kTestUrl1), | 268 GURL(kTestUrl1), |
| 267 base::Bind(&ThumbnailManagerBrowserTest::OnThumbnailAvailable, | 269 base::Bind(&ImageManagerImplBrowserTest::OnImageAvailable, |
| 268 base::Unretained(this), &run_loop)); | 270 base::Unretained(this), &run_loop)); |
| 269 run_loop.Run(); | 271 run_loop.Run(); |
| 270 | 272 |
| 271 EXPECT_EQ(0, num_callback_null_called_); | 273 EXPECT_EQ(0, num_callback_null_called_); |
| 272 EXPECT_EQ(1, num_callback_valid_called_); | 274 EXPECT_EQ(1, num_callback_valid_called_); |
| 273 } | 275 } |
| 274 | 276 |
| 275 } // namespace suggestions | 277 } // namespace suggestions |
| OLD | NEW |