Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: chrome/browser/history/history_backend_unittest.cc

Issue 10915146: Cleanup thumbnail database part #2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <set> 5 #include <set>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 URLID id = backend_->db()->GetRowForURL(url, &row); 201 URLID id = backend_->db()->GetRowForURL(url, &row);
202 VisitVector visits; 202 VisitVector visits;
203 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); 203 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits));
204 return visits[0].transition; 204 return visits[0].transition;
205 } 205 }
206 206
207 FilePath getTestDir() { 207 FilePath getTestDir() {
208 return test_dir_; 208 return test_dir_;
209 } 209 }
210 210
211 // Returns a gfx::Size vector with small and large sizes.
212 const std::vector<gfx::Size> GetSizesSmallAndLarge() {
213 std::vector<gfx::Size> sizes_small_and_large;
214 sizes_small_and_large.push_back(kSmallSize);
215 sizes_small_and_large.push_back(kLargeSize);
216 return sizes_small_and_large;
217 }
218
211 FaviconID GetFavicon(const GURL& url, IconType icon_type) { 219 FaviconID GetFavicon(const GURL& url, IconType icon_type) {
212 std::vector<IconMapping> icon_mappings; 220 std::vector<IconMapping> icon_mappings;
213 if (backend_->thumbnail_db_->GetIconMappingsForPageURL(url, icon_type, 221 if (backend_->thumbnail_db_->GetIconMappingsForPageURL(url, icon_type,
214 &icon_mappings)) 222 &icon_mappings))
215 return icon_mappings[0].icon_id; 223 return icon_mappings[0].icon_id;
216 else 224 else
217 return 0; 225 return 0;
218 } 226 }
219 227
220 BookmarkModel bookmark_model_; 228 BookmarkModel bookmark_model_;
221 229
222 protected: 230 protected:
223 bool loaded_; 231 bool loaded_;
224 232
225 private: 233 private:
226 friend class HistoryBackendTestDelegate; 234 friend class HistoryBackendTestDelegate;
227 235
228 // testing::Test 236 // testing::Test
229 virtual void SetUp() { 237 virtual void SetUp() {
230 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), 238 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"),
231 &test_dir_)) 239 &test_dir_))
232 return; 240 return;
233 backend_ = new HistoryBackend(test_dir_, 241 backend_ = new HistoryBackend(test_dir_,
234 0, 242 0,
235 new HistoryBackendTestDelegate(this), 243 new HistoryBackendTestDelegate(this),
236 &bookmark_model_); 244 &bookmark_model_);
237 backend_->Init(std::string(), false); 245 backend_->Init(std::string(), false);
238 } 246 }
247
239 virtual void TearDown() { 248 virtual void TearDown() {
240 if (backend_.get()) 249 if (backend_.get())
241 backend_->Closing(); 250 backend_->Closing();
242 backend_ = NULL; 251 backend_ = NULL;
243 mem_backend_.reset(); 252 mem_backend_.reset();
244 file_util::Delete(test_dir_, true); 253 file_util::Delete(test_dir_, true);
245 } 254 }
246 255
247 void SetInMemoryBackend(int backend_id, InMemoryHistoryBackend* backend) { 256 void SetInMemoryBackend(int backend_id, InMemoryHistoryBackend* backend) {
248 mem_backend_.reset(backend); 257 mem_backend_.reset(backend);
249 } 258 }
250 259
251 void BroadcastNotifications(int type, 260 void BroadcastNotifications(int type,
252 HistoryDetails* details) { 261 HistoryDetails* details) {
253 // Send the notifications directly to the in-memory database. 262 // Send the notifications directly to the in-memory database.
254 content::Details<HistoryDetails> det(details); 263 content::Details<HistoryDetails> det(details);
255 mem_backend_->Observe(type, content::Source<HistoryBackendTest>(NULL), det); 264 mem_backend_->Observe(type, content::Source<HistoryBackendTest>(NULL), det);
256 265
257 // The backend passes ownership of the details pointer to us. 266 // The backend passes ownership of the details pointer to us.
258 delete details; 267 delete details;
259 } 268 }
260 269
261 MessageLoop message_loop_; 270 MessageLoop message_loop_;
262 FilePath test_dir_; 271 FilePath test_dir_;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 TEST_F(HistoryBackendTest, DeleteAll) { 306 TEST_F(HistoryBackendTest, DeleteAll) {
298 ASSERT_TRUE(backend_.get()); 307 ASSERT_TRUE(backend_.get());
299 308
300 // Add two favicons, each with two bitmaps. Note that we add favicon2 before 309 // Add two favicons, each with two bitmaps. Note that we add favicon2 before
301 // adding favicon1. This is so that favicon1 one gets ID 2 autoassigned to 310 // adding favicon1. This is so that favicon1 one gets ID 2 autoassigned to
302 // the database, which will change when the other one is deleted. This way 311 // the database, which will change when the other one is deleted. This way
303 // we can test that updating works properly. 312 // we can test that updating works properly.
304 GURL favicon_url1("http://www.google.com/favicon.ico"); 313 GURL favicon_url1("http://www.google.com/favicon.ico");
305 GURL favicon_url2("http://news.google.com/favicon.ico"); 314 GURL favicon_url2("http://news.google.com/favicon.ico");
306 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2, 315 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2,
307 FAVICON); 316 FAVICON, GetSizesSmallAndLarge());
308 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1, 317 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1,
309 FAVICON); 318 FAVICON, GetSizesSmallAndLarge());
310 319
311 std::vector<unsigned char> data; 320 std::vector<unsigned char> data;
312 data.push_back('a'); 321 data.push_back('a');
313 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon1, 322 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon1,
314 new base::RefCountedBytes(data), Time::Now(), kSmallSize)); 323 new base::RefCountedBytes(data), Time::Now(), kSmallSize));
315 data[0] = 'b'; 324 data[0] = 'b';
316 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon1, 325 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon1,
317 new base::RefCountedBytes(data), Time::Now(), kLargeSize)); 326 new base::RefCountedBytes(data), Time::Now(), kLargeSize));
318 327
319 data[0] = 'c'; 328 data[0] = 'c';
(...skipping 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 1688
1680 backend_->DeleteURL(url); 1689 backend_->DeleteURL(url);
1681 backend_->AddPageNoVisitForBookmark(url, string16()); 1690 backend_->AddPageNoVisitForBookmark(url, string16());
1682 backend_->GetURL(url, &row); 1691 backend_->GetURL(url, &row);
1683 EXPECT_EQ(url, row.url()); 1692 EXPECT_EQ(url, row.url());
1684 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); 1693 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title());
1685 EXPECT_EQ(0, row.visit_count()); 1694 EXPECT_EQ(0, row.visit_count());
1686 } 1695 }
1687 1696
1688 } // namespace history 1697 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/expire_history_backend_unittest.cc ('k') | chrome/browser/history/thumbnail_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698