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

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: 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 CR_DEFINE_STATIC_LOCAL(std::vector<gfx::Size>, kSizesSmallAndLarge, ());
sky 2012/09/07 18:16:47 This is a test, there's no point in forcing a stat
214 if (kSizesSmallAndLarge.empty()) {
215 kSizesSmallAndLarge.push_back(kSmallSize);
216 kSizesSmallAndLarge.push_back(kLargeSize);
217 }
218 return kSizesSmallAndLarge;
219 }
220
211 FaviconID GetFavicon(const GURL& url, IconType icon_type) { 221 FaviconID GetFavicon(const GURL& url, IconType icon_type) {
212 std::vector<IconMapping> icon_mappings; 222 std::vector<IconMapping> icon_mappings;
213 if (backend_->thumbnail_db_->GetIconMappingsForPageURL(url, icon_type, 223 if (backend_->thumbnail_db_->GetIconMappingsForPageURL(url, icon_type,
214 &icon_mappings)) 224 &icon_mappings))
215 return icon_mappings[0].icon_id; 225 return icon_mappings[0].icon_id;
216 else 226 else
217 return 0; 227 return 0;
218 } 228 }
219 229
220 BookmarkModel bookmark_model_; 230 BookmarkModel bookmark_model_;
221 231
222 protected: 232 protected:
223 bool loaded_; 233 bool loaded_;
224 234
225 private: 235 private:
226 friend class HistoryBackendTestDelegate; 236 friend class HistoryBackendTestDelegate;
227 237
228 // testing::Test 238 // testing::Test
229 virtual void SetUp() { 239 virtual void SetUp() {
230 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), 240 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"),
231 &test_dir_)) 241 &test_dir_))
232 return; 242 return;
233 backend_ = new HistoryBackend(test_dir_, 243 backend_ = new HistoryBackend(test_dir_,
234 0, 244 0,
235 new HistoryBackendTestDelegate(this), 245 new HistoryBackendTestDelegate(this),
236 &bookmark_model_); 246 &bookmark_model_);
237 backend_->Init(std::string(), false); 247 backend_->Init(std::string(), false);
238 } 248 }
249
239 virtual void TearDown() { 250 virtual void TearDown() {
240 if (backend_.get()) 251 if (backend_.get())
241 backend_->Closing(); 252 backend_->Closing();
242 backend_ = NULL; 253 backend_ = NULL;
243 mem_backend_.reset(); 254 mem_backend_.reset();
244 file_util::Delete(test_dir_, true); 255 file_util::Delete(test_dir_, true);
245 } 256 }
246 257
247 void SetInMemoryBackend(int backend_id, InMemoryHistoryBackend* backend) { 258 void SetInMemoryBackend(int backend_id, InMemoryHistoryBackend* backend) {
248 mem_backend_.reset(backend); 259 mem_backend_.reset(backend);
249 } 260 }
250 261
251 void BroadcastNotifications(int type, 262 void BroadcastNotifications(int type,
252 HistoryDetails* details) { 263 HistoryDetails* details) {
253 // Send the notifications directly to the in-memory database. 264 // Send the notifications directly to the in-memory database.
254 content::Details<HistoryDetails> det(details); 265 content::Details<HistoryDetails> det(details);
255 mem_backend_->Observe(type, content::Source<HistoryBackendTest>(NULL), det); 266 mem_backend_->Observe(type, content::Source<HistoryBackendTest>(NULL), det);
256 267
257 // The backend passes ownership of the details pointer to us. 268 // The backend passes ownership of the details pointer to us.
258 delete details; 269 delete details;
259 } 270 }
260 271
261 MessageLoop message_loop_; 272 MessageLoop message_loop_;
262 FilePath test_dir_; 273 FilePath test_dir_;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 TEST_F(HistoryBackendTest, DeleteAll) { 308 TEST_F(HistoryBackendTest, DeleteAll) {
298 ASSERT_TRUE(backend_.get()); 309 ASSERT_TRUE(backend_.get());
299 310
300 // Add two favicons, each with two bitmaps. Note that we add favicon2 before 311 // 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 312 // 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 313 // the database, which will change when the other one is deleted. This way
303 // we can test that updating works properly. 314 // we can test that updating works properly.
304 GURL favicon_url1("http://www.google.com/favicon.ico"); 315 GURL favicon_url1("http://www.google.com/favicon.ico");
305 GURL favicon_url2("http://news.google.com/favicon.ico"); 316 GURL favicon_url2("http://news.google.com/favicon.ico");
306 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2, 317 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2,
307 FAVICON); 318 FAVICON, GetSizesSmallAndLarge());
308 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1, 319 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1,
309 FAVICON); 320 FAVICON, GetSizesSmallAndLarge());
310 321
311 std::vector<unsigned char> data; 322 std::vector<unsigned char> data;
312 data.push_back('a'); 323 data.push_back('a');
313 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon1, 324 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon1,
314 new base::RefCountedBytes(data), Time::Now(), kSmallSize)); 325 new base::RefCountedBytes(data), Time::Now(), kSmallSize));
315 data[0] = 'b'; 326 data[0] = 'b';
316 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon1, 327 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon1,
317 new base::RefCountedBytes(data), Time::Now(), kLargeSize)); 328 new base::RefCountedBytes(data), Time::Now(), kLargeSize));
318 329
319 data[0] = 'c'; 330 data[0] = 'c';
(...skipping 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 1690
1680 backend_->DeleteURL(url); 1691 backend_->DeleteURL(url);
1681 backend_->AddPageNoVisitForBookmark(url, string16()); 1692 backend_->AddPageNoVisitForBookmark(url, string16());
1682 backend_->GetURL(url, &row); 1693 backend_->GetURL(url, &row);
1683 EXPECT_EQ(url, row.url()); 1694 EXPECT_EQ(url, row.url());
1684 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); 1695 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title());
1685 EXPECT_EQ(0, row.visit_count()); 1696 EXPECT_EQ(0, row.visit_count());
1686 } 1697 }
1687 1698
1688 } // namespace history 1699 } // 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