| 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 "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "components/leveldb_proto/proto_database.h" | 10 #include "components/leveldb_proto/proto_database.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 image_manager_->Initialize(suggestions_profile); | 143 image_manager_->Initialize(suggestions_profile); |
| 144 | 144 |
| 145 GURL output; | 145 GURL output; |
| 146 EXPECT_TRUE(image_manager_->GetImageURL(GURL(kTestUrl1), &output)); | 146 EXPECT_TRUE(image_manager_->GetImageURL(GURL(kTestUrl1), &output)); |
| 147 EXPECT_EQ(GURL(kTestImagePath), output); | 147 EXPECT_EQ(GURL(kTestImagePath), output); |
| 148 | 148 |
| 149 EXPECT_FALSE(image_manager_->GetImageURL(GURL("http://b.com"), &output)); | 149 EXPECT_FALSE(image_manager_->GetImageURL(GURL("http://b.com"), &output)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 TEST_F(ImageManagerTest, AddImageURL) { |
| 153 InitializeDefaultImageMapAndDatabase(image_manager_.get(), fake_db_); |
| 154 |
| 155 GURL output; |
| 156 // Try a URL the ImageManager doesn't know about. |
| 157 ASSERT_FALSE(image_manager_->GetImageURL(GURL(kTestUrl2), &output)); |
| 158 |
| 159 // Explicitly add the URL and try again. |
| 160 image_manager_->AddImageURL(GURL(kTestUrl2), GURL(kTestImagePath)); |
| 161 EXPECT_TRUE(image_manager_->GetImageURL(GURL(kTestUrl2), &output)); |
| 162 EXPECT_EQ(GURL(kTestImagePath), output); |
| 163 } |
| 164 |
| 152 TEST_F(ImageManagerTest, GetImageForURLNetwork) { | 165 TEST_F(ImageManagerTest, GetImageForURLNetwork) { |
| 153 InitializeDefaultImageMapAndDatabase(image_manager_.get(), fake_db_); | 166 InitializeDefaultImageMapAndDatabase(image_manager_.get(), fake_db_); |
| 154 | 167 |
| 155 // We expect the fetcher to go to network and call the callback. | 168 // We expect the fetcher to go to network and call the callback. |
| 156 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _)); | 169 EXPECT_CALL(*mock_image_fetcher_, StartOrQueueNetworkRequest(_, _, _)); |
| 157 | 170 |
| 158 // Fetch existing URL. | 171 // Fetch existing URL. |
| 159 base::RunLoop run_loop; | 172 base::RunLoop run_loop; |
| 160 image_manager_->GetImageForURL(GURL(kTestUrl1), | 173 image_manager_->GetImageForURL(GURL(kTestUrl1), |
| 161 base::Bind(&ImageManagerTest::OnImageAvailable, | 174 base::Bind(&ImageManagerTest::OnImageAvailable, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 image_manager_->GetImageForURL(GURL(kTestUrl1), | 207 image_manager_->GetImageForURL(GURL(kTestUrl1), |
| 195 base::Bind(&ImageManagerTest::OnImageAvailable, | 208 base::Bind(&ImageManagerTest::OnImageAvailable, |
| 196 base::Unretained(this), &run_loop)); | 209 base::Unretained(this), &run_loop)); |
| 197 run_loop.Run(); | 210 run_loop.Run(); |
| 198 | 211 |
| 199 EXPECT_EQ(0, num_callback_null_called_); | 212 EXPECT_EQ(0, num_callback_null_called_); |
| 200 EXPECT_EQ(1, num_callback_valid_called_); | 213 EXPECT_EQ(1, num_callback_valid_called_); |
| 201 } | 214 } |
| 202 | 215 |
| 203 } // namespace suggestions | 216 } // namespace suggestions |
| OLD | NEW |