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

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

Issue 16951015: Remove TextDatabase from the history service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@replace_fts
Patch Set: Created 7 years, 6 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
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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "chrome/browser/bookmarks/bookmark_model.h" 19 #include "chrome/browser/bookmarks/bookmark_model.h"
20 #include "chrome/browser/bookmarks/bookmark_utils.h" 20 #include "chrome/browser/bookmarks/bookmark_utils.h"
21 #include "chrome/browser/history/archived_database.h" 21 #include "chrome/browser/history/archived_database.h"
22 #include "chrome/browser/history/expire_history_backend.h" 22 #include "chrome/browser/history/expire_history_backend.h"
23 #include "chrome/browser/history/history_database.h" 23 #include "chrome/browser/history/history_database.h"
24 #include "chrome/browser/history/history_notifications.h" 24 #include "chrome/browser/history/history_notifications.h"
25 #include "chrome/browser/history/text_database_manager.h"
26 #include "chrome/browser/history/thumbnail_database.h" 25 #include "chrome/browser/history/thumbnail_database.h"
27 #include "chrome/browser/history/top_sites.h" 26 #include "chrome/browser/history/top_sites.h"
28 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
29 #include "chrome/common/thumbnail_score.h" 28 #include "chrome/common/thumbnail_score.h"
30 #include "chrome/test/base/testing_profile.h" 29 #include "chrome/test/base/testing_profile.h"
31 #include "chrome/tools/profiles/thumbnail-inl.h" 30 #include "chrome/tools/profiles/thumbnail-inl.h"
32 #include "content/public/test/test_browser_thread.h" 31 #include "content/public/test/test_browser_thread.h"
33 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
34 #include "third_party/skia/include/core/SkBitmap.h" 33 #include "third_party/skia/include/core/SkBitmap.h"
35 #include "ui/gfx/codec/jpeg_codec.h" 34 #include "ui/gfx/codec/jpeg_codec.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // Add visits with source information. 69 // Add visits with source information.
71 void AddExampleSourceData(const GURL& url, URLID* id); 70 void AddExampleSourceData(const GURL& url, URLID* id);
72 71
73 // Returns true if the given favicon/thumanil has an entry in the DB. 72 // Returns true if the given favicon/thumanil has an entry in the DB.
74 bool HasFavicon(chrome::FaviconID favicon_id); 73 bool HasFavicon(chrome::FaviconID favicon_id);
75 bool HasThumbnail(URLID url_id); 74 bool HasThumbnail(URLID url_id);
76 75
77 chrome::FaviconID GetFavicon(const GURL& page_url, 76 chrome::FaviconID GetFavicon(const GURL& page_url,
78 chrome::IconType icon_type); 77 chrome::IconType icon_type);
79 78
80 // Returns the number of text matches for the given URL in the example data
81 // added by AddExampleData.
82 int CountTextMatchesForURL(const GURL& url);
83
84 // EXPECTs that each URL-specific history thing (basically, everything but 79 // EXPECTs that each URL-specific history thing (basically, everything but
85 // favicons) is gone. 80 // favicons) is gone.
86 void EnsureURLInfoGone(const URLRow& row); 81 void EnsureURLInfoGone(const URLRow& row);
87 82
88 // Clears the list of notifications received. 83 // Clears the list of notifications received.
89 void ClearLastNotifications() { 84 void ClearLastNotifications() {
90 STLDeleteValues(&notifications_); 85 STLDeleteValues(&notifications_);
91 } 86 }
92 87
93 void StarURL(const GURL& url) { 88 void StarURL(const GURL& url) {
(...skipping 13 matching lines...) Expand all
107 102
108 base::MessageLoopForUI message_loop_; 103 base::MessageLoopForUI message_loop_;
109 content::TestBrowserThread ui_thread_; 104 content::TestBrowserThread ui_thread_;
110 content::TestBrowserThread db_thread_; 105 content::TestBrowserThread db_thread_;
111 106
112 ExpireHistoryBackend expirer_; 107 ExpireHistoryBackend expirer_;
113 108
114 scoped_ptr<HistoryDatabase> main_db_; 109 scoped_ptr<HistoryDatabase> main_db_;
115 scoped_ptr<ArchivedDatabase> archived_db_; 110 scoped_ptr<ArchivedDatabase> archived_db_;
116 scoped_ptr<ThumbnailDatabase> thumb_db_; 111 scoped_ptr<ThumbnailDatabase> thumb_db_;
117 scoped_ptr<TextDatabaseManager> text_db_;
118 TestingProfile profile_; 112 TestingProfile profile_;
119 scoped_refptr<TopSites> top_sites_; 113 scoped_refptr<TopSites> top_sites_;
120 114
121 // Time at the beginning of the test, so everybody agrees what "now" is. 115 // Time at the beginning of the test, so everybody agrees what "now" is.
122 const Time now_; 116 const Time now_;
123 117
124 // Notifications intended to be broadcast, we can check these values to make 118 // Notifications intended to be broadcast, we can check these values to make
125 // sure that the deletor is doing the correct broadcasts. We own the details 119 // sure that the deletor is doing the correct broadcasts. We own the details
126 // pointers. 120 // pointers.
127 typedef std::vector< std::pair<int, HistoryDetails*> > 121 typedef std::vector< std::pair<int, HistoryDetails*> >
(...skipping 12 matching lines...) Expand all
140 base::FilePath archived_name = path().Append(kArchivedHistoryFile); 134 base::FilePath archived_name = path().Append(kArchivedHistoryFile);
141 archived_db_.reset(new ArchivedDatabase); 135 archived_db_.reset(new ArchivedDatabase);
142 if (!archived_db_->Init(archived_name)) 136 if (!archived_db_->Init(archived_name))
143 archived_db_.reset(); 137 archived_db_.reset();
144 138
145 base::FilePath thumb_name = path().Append(kThumbnailFile); 139 base::FilePath thumb_name = path().Append(kThumbnailFile);
146 thumb_db_.reset(new ThumbnailDatabase); 140 thumb_db_.reset(new ThumbnailDatabase);
147 if (thumb_db_->Init(thumb_name, NULL, main_db_.get()) != sql::INIT_OK) 141 if (thumb_db_->Init(thumb_name, NULL, main_db_.get()) != sql::INIT_OK)
148 thumb_db_.reset(); 142 thumb_db_.reset();
149 143
150 text_db_.reset(new TextDatabaseManager(path(), 144 expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get());
151 main_db_.get(), main_db_.get()));
152 if (!text_db_->Init(NULL))
153 text_db_.reset();
154
155 expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get(),
156 text_db_.get());
157 profile_.CreateTopSites(); 145 profile_.CreateTopSites();
158 profile_.BlockUntilTopSitesLoaded(); 146 profile_.BlockUntilTopSitesLoaded();
159 top_sites_ = profile_.GetTopSites(); 147 top_sites_ = profile_.GetTopSites();
160 } 148 }
161 149
162 virtual void TearDown() { 150 virtual void TearDown() {
163 top_sites_ = NULL; 151 top_sites_ = NULL;
164 152
165 ClearLastNotifications(); 153 ClearLastNotifications();
166 154
167 expirer_.SetDatabases(NULL, NULL, NULL, NULL); 155 expirer_.SetDatabases(NULL, NULL, NULL);
168 156
169 main_db_.reset(); 157 main_db_.reset();
170 archived_db_.reset(); 158 archived_db_.reset();
171 thumb_db_.reset(); 159 thumb_db_.reset();
172 text_db_.reset();
173 } 160 }
174 161
175 // BroadcastNotificationDelegate implementation. 162 // BroadcastNotificationDelegate implementation.
176 virtual void BroadcastNotifications( 163 virtual void BroadcastNotifications(
177 int type, 164 int type,
178 HistoryDetails* details_deleted) OVERRIDE { 165 HistoryDetails* details_deleted) OVERRIDE {
179 // This gets called when there are notifications to broadcast. Instead, we 166 // This gets called when there are notifications to broadcast. Instead, we
180 // store them so we can tell that the correct notifications were sent. 167 // store them so we can tell that the correct notifications were sent.
181 notifications_.push_back(std::make_pair(type, details_deleted)); 168 notifications_.push_back(std::make_pair(type, details_deleted));
182 } 169 }
183 virtual void NotifySyncURLsDeleted( 170 virtual void NotifySyncURLsDeleted(
184 bool all_history, 171 bool all_history,
185 bool archived, 172 bool archived,
186 URLRows* rows) OVERRIDE {} 173 URLRows* rows) OVERRIDE {}
187 }; 174 };
188 175
189 // The example data consists of 4 visits. The middle two visits are to the 176 // The example data consists of 4 visits. The middle two visits are to the
190 // same URL, while the first and last are for unique ones. This allows a test 177 // same URL, while the first and last are for unique ones. This allows a test
191 // for the oldest or newest to include both a URL that should get totally 178 // for the oldest or newest to include both a URL that should get totally
192 // deleted (the one on the end) with one that should only get a visit deleted 179 // deleted (the one on the end) with one that should only get a visit deleted
193 // (with the one in the middle) when it picks the proper threshold time. 180 // (with the one in the middle) when it picks the proper threshold time.
194 // 181 //
195 // Each visit has indexed data, each URL has thumbnail. The first two URLs will 182 // Each visit has indexed data, each URL has thumbnail. The first two URLs will
196 // share the same avicon, while the last one will have a unique favicon. The 183 // share the same avicon, while the last one will have a unique favicon. The
197 // second visit for the middle URL is typed. 184 // second visit for the middle URL is typed.
198 // 185 //
199 // The IDs of the added URLs, and the times of the four added visits will be 186 // The IDs of the added URLs, and the times of the four added visits will be
200 // added to the given arrays. 187 // added to the given arrays.
201 void ExpireHistoryTest::AddExampleData(URLID url_ids[3], Time visit_times[4]) { 188 void ExpireHistoryTest::AddExampleData(URLID url_ids[3], Time visit_times[4]) {
202 if (!main_db_.get() || !text_db_) 189 if (!main_db_.get())
203 return; 190 return;
204 191
205 // Four times for each visit. 192 // Four times for each visit.
206 visit_times[3] = Time::Now(); 193 visit_times[3] = Time::Now();
207 visit_times[2] = visit_times[3] - TimeDelta::FromDays(1); 194 visit_times[2] = visit_times[3] - TimeDelta::FromDays(1);
208 visit_times[1] = visit_times[3] - TimeDelta::FromDays(2); 195 visit_times[1] = visit_times[3] - TimeDelta::FromDays(2);
209 visit_times[0] = visit_times[3] - TimeDelta::FromDays(3); 196 visit_times[0] = visit_times[3] - TimeDelta::FromDays(3);
210 197
211 // Two favicons. The first two URLs will share the same one, while the last 198 // Two favicons. The first two URLs will share the same one, while the last
212 // one will have a unique favicon. 199 // one will have a unique favicon.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 visit_row3.visit_time = visit_times[2]; 252 visit_row3.visit_time = visit_times[2];
266 visit_row3.is_indexed = true; 253 visit_row3.is_indexed = true;
267 visit_row3.transition = content::PAGE_TRANSITION_TYPED; 254 visit_row3.transition = content::PAGE_TRANSITION_TYPED;
268 main_db_->AddVisit(&visit_row3, SOURCE_BROWSED); 255 main_db_->AddVisit(&visit_row3, SOURCE_BROWSED);
269 256
270 VisitRow visit_row4; 257 VisitRow visit_row4;
271 visit_row4.url_id = url_ids[2]; 258 visit_row4.url_id = url_ids[2];
272 visit_row4.visit_time = visit_times[3]; 259 visit_row4.visit_time = visit_times[3];
273 visit_row4.is_indexed = true; 260 visit_row4.is_indexed = true;
274 main_db_->AddVisit(&visit_row4, SOURCE_BROWSED); 261 main_db_->AddVisit(&visit_row4, SOURCE_BROWSED);
275
276 // Full text index for each visit.
277 text_db_->AddPageData(url_row1.url(), visit_row1.url_id, visit_row1.visit_id,
278 visit_row1.visit_time, UTF8ToUTF16("title"),
279 UTF8ToUTF16("body"));
280
281 text_db_->AddPageData(url_row2.url(), visit_row2.url_id, visit_row2.visit_id,
282 visit_row2.visit_time, UTF8ToUTF16("title"),
283 UTF8ToUTF16("body"));
284 text_db_->AddPageData(url_row2.url(), visit_row3.url_id, visit_row3.visit_id,
285 visit_row3.visit_time, UTF8ToUTF16("title"),
286 UTF8ToUTF16("body"));
287
288 // Note the special text in this URL. We'll search the file for this string
289 // to make sure it doesn't hang around after the delete.
290 text_db_->AddPageData(url_row3.url(), visit_row4.url_id, visit_row4.visit_id,
291 visit_row4.visit_time, UTF8ToUTF16("title"),
292 UTF8ToUTF16("goats body"));
293 } 262 }
294 263
295 void ExpireHistoryTest::AddExampleSourceData(const GURL& url, URLID* id) { 264 void ExpireHistoryTest::AddExampleSourceData(const GURL& url, URLID* id) {
296 if (!main_db_) 265 if (!main_db_)
297 return; 266 return;
298 267
299 Time last_visit_time = Time::Now(); 268 Time last_visit_time = Time::Now();
300 // Add one URL. 269 // Add one URL.
301 URLRow url_row1(url); 270 URLRow url_row1(url);
302 url_row1.set_last_visit(last_visit_time); 271 url_row1.set_last_visit(last_visit_time);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // TODO(sky): fix this. This test isn't really valid for TopSites. For 311 // TODO(sky): fix this. This test isn't really valid for TopSites. For
343 // TopSites we should be checking URL always, not the id. 312 // TopSites we should be checking URL always, not the id.
344 URLRow info; 313 URLRow info;
345 if (!main_db_->GetURLRow(url_id, &info)) 314 if (!main_db_->GetURLRow(url_id, &info))
346 return false; 315 return false;
347 GURL url = info.url(); 316 GURL url = info.url();
348 scoped_refptr<base::RefCountedMemory> data; 317 scoped_refptr<base::RefCountedMemory> data;
349 return top_sites_->GetPageThumbnail(url, &data); 318 return top_sites_->GetPageThumbnail(url, &data);
350 } 319 }
351 320
352 int ExpireHistoryTest::CountTextMatchesForURL(const GURL& url) {
353 if (!text_db_)
354 return 0;
355
356 // "body" should match all pages in the example data.
357 std::vector<TextDatabase::Match> results;
358 QueryOptions options;
359 Time first_time;
360 text_db_->GetTextMatches(UTF8ToUTF16("body"), options,
361 &results, &first_time);
362
363 int count = 0;
364 for (size_t i = 0; i < results.size(); i++) {
365 if (results[i].url == url)
366 count++;
367 }
368 return count;
369 }
370
371 void ExpireHistoryTest::EnsureURLInfoGone(const URLRow& row) { 321 void ExpireHistoryTest::EnsureURLInfoGone(const URLRow& row) {
372 // Verify the URL no longer exists. 322 // Verify the URL no longer exists.
373 URLRow temp_row; 323 URLRow temp_row;
374 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row)); 324 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row));
375 325
376 // The indexed data should be gone.
377 EXPECT_EQ(0, CountTextMatchesForURL(row.url()));
378
379 // There should be no visits. 326 // There should be no visits.
380 VisitVector visits; 327 VisitVector visits;
381 main_db_->GetVisitsForURL(row.id(), &visits); 328 main_db_->GetVisitsForURL(row.id(), &visits);
382 EXPECT_EQ(0U, visits.size()); 329 EXPECT_EQ(0U, visits.size());
383 330
384 // Thumbnail should be gone. 331 // Thumbnail should be gone.
385 // TODO(sky): fix this, see comment in HasThumbnail. 332 // TODO(sky): fix this, see comment in HasThumbnail.
386 // EXPECT_FALSE(HasThumbnail(row.id())); 333 // EXPECT_FALSE(HasThumbnail(row.id()));
387 334
388 bool found_delete_notification = false; 335 bool found_delete_notification = false;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 URLRow last_row; 411 URLRow last_row;
465 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &last_row)); 412 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &last_row));
466 chrome::FaviconID favicon_id = GetFavicon(last_row.url(), chrome::FAVICON); 413 chrome::FaviconID favicon_id = GetFavicon(last_row.url(), chrome::FAVICON);
467 EXPECT_TRUE(HasFavicon(favicon_id)); 414 EXPECT_TRUE(HasFavicon(favicon_id));
468 // TODO(sky): fix this, see comment in HasThumbnail. 415 // TODO(sky): fix this, see comment in HasThumbnail.
469 // EXPECT_TRUE(HasThumbnail(url_ids[2])); 416 // EXPECT_TRUE(HasThumbnail(url_ids[2]));
470 417
471 VisitVector visits; 418 VisitVector visits;
472 main_db_->GetVisitsForURL(url_ids[2], &visits); 419 main_db_->GetVisitsForURL(url_ids[2], &visits);
473 ASSERT_EQ(1U, visits.size()); 420 ASSERT_EQ(1U, visits.size());
474 EXPECT_EQ(1, CountTextMatchesForURL(last_row.url()));
475
476 // In this test we also make sure that any pending entries in the text
477 // database manager are removed.
478 text_db_->AddPageURL(last_row.url(), last_row.id(), visits[0].visit_id,
479 visits[0].visit_time);
480
481 // Compute the text DB filename.
482 base::FilePath fts_filename = path().Append(
483 TextDatabase::IDToFileName(text_db_->TimeToID(visit_times[3])));
484
485 // When checking the file, the database must be closed. We then re-initialize
486 // it just like the test set-up did.
487 text_db_.reset();
488 EXPECT_TRUE(IsStringInFile(fts_filename, "goats"));
489 text_db_.reset(new TextDatabaseManager(path(),
490 main_db_.get(), main_db_.get()));
491 ASSERT_TRUE(text_db_->Init(NULL));
492 expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get(),
493 text_db_.get());
494 421
495 // Delete the URL and its dependencies. 422 // Delete the URL and its dependencies.
496 expirer_.DeleteURL(last_row.url()); 423 expirer_.DeleteURL(last_row.url());
497 424
498 // The string should be removed from the file. FTS can mark it as gone but
499 // doesn't remove it from the file, we want to be sure we're doing the latter.
500 text_db_.reset();
501 EXPECT_FALSE(IsStringInFile(fts_filename, "goats"));
502 text_db_.reset(new TextDatabaseManager(path(),
503 main_db_.get(), main_db_.get()));
504 ASSERT_TRUE(text_db_->Init(NULL));
505 expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get(),
506 text_db_.get());
507
508 // Run the text database expirer. This will flush any pending entries so we
509 // can check that nothing was committed. We use a time far in the future so
510 // that anything added recently will get flushed.
511 TimeTicks expiration_time = TimeTicks::Now() + TimeDelta::FromDays(1);
512 text_db_->FlushOldChangesForTime(expiration_time);
513
514 // All the normal data + the favicon should be gone. 425 // All the normal data + the favicon should be gone.
515 EnsureURLInfoGone(last_row); 426 EnsureURLInfoGone(last_row);
516 EXPECT_FALSE(GetFavicon(last_row.url(), chrome::FAVICON)); 427 EXPECT_FALSE(GetFavicon(last_row.url(), chrome::FAVICON));
517 EXPECT_FALSE(HasFavicon(favicon_id)); 428 EXPECT_FALSE(HasFavicon(favicon_id));
518 } 429 }
519 430
520 // Deletes a URL with a favicon that other URLs reference, so that the favicon 431 // Deletes a URL with a favicon that other URLs reference, so that the favicon
521 // should not get deleted. This also tests deleting more than one visit. 432 // should not get deleted. This also tests deleting more than one visit.
522 TEST_F(ExpireHistoryTest, DeleteURLWithoutFavicon) { 433 TEST_F(ExpireHistoryTest, DeleteURLWithoutFavicon) {
523 URLID url_ids[3]; 434 URLID url_ids[3];
524 Time visit_times[4]; 435 Time visit_times[4];
525 AddExampleData(url_ids, visit_times); 436 AddExampleData(url_ids, visit_times);
526 437
527 // Verify things are the way we expect with a URL row, favicon, thumbnail. 438 // Verify things are the way we expect with a URL row, favicon, thumbnail.
528 URLRow last_row; 439 URLRow last_row;
529 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &last_row)); 440 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &last_row));
530 chrome::FaviconID favicon_id = GetFavicon(last_row.url(), chrome::FAVICON); 441 chrome::FaviconID favicon_id = GetFavicon(last_row.url(), chrome::FAVICON);
531 EXPECT_TRUE(HasFavicon(favicon_id)); 442 EXPECT_TRUE(HasFavicon(favicon_id));
532 // TODO(sky): fix this, see comment in HasThumbnail. 443 // TODO(sky): fix this, see comment in HasThumbnail.
533 // EXPECT_TRUE(HasThumbnail(url_ids[1])); 444 // EXPECT_TRUE(HasThumbnail(url_ids[1]));
534 445
535 VisitVector visits; 446 VisitVector visits;
536 main_db_->GetVisitsForURL(url_ids[1], &visits); 447 main_db_->GetVisitsForURL(url_ids[1], &visits);
537 EXPECT_EQ(2U, visits.size()); 448 EXPECT_EQ(2U, visits.size());
538 EXPECT_EQ(1, CountTextMatchesForURL(last_row.url()));
539 449
540 // Delete the URL and its dependencies. 450 // Delete the URL and its dependencies.
541 expirer_.DeleteURL(last_row.url()); 451 expirer_.DeleteURL(last_row.url());
542 452
543 // All the normal data except the favicon should be gone. 453 // All the normal data except the favicon should be gone.
544 EnsureURLInfoGone(last_row); 454 EnsureURLInfoGone(last_row);
545 EXPECT_TRUE(HasFavicon(favicon_id)); 455 EXPECT_TRUE(HasFavicon(favicon_id));
546 } 456 }
547 457
548 // DeleteURL should not delete starred urls. 458 // DeleteURL should not delete starred urls.
(...skipping 12 matching lines...) Expand all
561 expirer_.DeleteURL(url_row.url()); 471 expirer_.DeleteURL(url_row.url());
562 472
563 // Because the url is starred, it shouldn't be deleted. 473 // Because the url is starred, it shouldn't be deleted.
564 GURL url = url_row.url(); 474 GURL url = url_row.url();
565 ASSERT_TRUE(main_db_->GetRowForURL(url, &url_row)); 475 ASSERT_TRUE(main_db_->GetRowForURL(url, &url_row));
566 476
567 // And the favicon should exist. 477 // And the favicon should exist.
568 chrome::FaviconID favicon_id = GetFavicon(url_row.url(), chrome::FAVICON); 478 chrome::FaviconID favicon_id = GetFavicon(url_row.url(), chrome::FAVICON);
569 EXPECT_TRUE(HasFavicon(favicon_id)); 479 EXPECT_TRUE(HasFavicon(favicon_id));
570 480
571 // But there should be no fts.
572 ASSERT_EQ(0, CountTextMatchesForURL(url_row.url()));
573
574 // And no visits. 481 // And no visits.
575 VisitVector visits; 482 VisitVector visits;
576 main_db_->GetVisitsForURL(url_row.id(), &visits); 483 main_db_->GetVisitsForURL(url_row.id(), &visits);
577 ASSERT_EQ(0U, visits.size()); 484 ASSERT_EQ(0U, visits.size());
578 485
579 // Should still have the thumbnail. 486 // Should still have the thumbnail.
580 // TODO(sky): fix this, see comment in HasThumbnail. 487 // TODO(sky): fix this, see comment in HasThumbnail.
581 // ASSERT_TRUE(HasThumbnail(url_row.id())); 488 // ASSERT_TRUE(HasThumbnail(url_row.id()));
582 489
583 // Unstar the URL and delete again. 490 // Unstar the URL and delete again.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 // the two visits) and one is deleted. 537 // the two visits) and one is deleted.
631 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarred) { 538 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarred) {
632 URLID url_ids[3]; 539 URLID url_ids[3];
633 Time visit_times[4]; 540 Time visit_times[4];
634 AddExampleData(url_ids, visit_times); 541 AddExampleData(url_ids, visit_times);
635 542
636 URLRow url_row1, url_row2; 543 URLRow url_row1, url_row2;
637 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); 544 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1));
638 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); 545 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2));
639 546
640 // In this test we also make sure that any pending entries in the text
641 // database manager are removed.
642 VisitVector visits; 547 VisitVector visits;
643 main_db_->GetVisitsForURL(url_ids[2], &visits); 548 main_db_->GetVisitsForURL(url_ids[2], &visits);
644 ASSERT_EQ(1U, visits.size()); 549 ASSERT_EQ(1U, visits.size());
645 text_db_->AddPageURL(url_row2.url(), url_row2.id(), visits[0].visit_id,
646 visits[0].visit_time);
647 550
648 // This should delete the last two visits. 551 // This should delete the last two visits.
649 std::set<GURL> restrict_urls; 552 std::set<GURL> restrict_urls;
650 expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time()); 553 expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time());
651 554
652 // Run the text database expirer. This will flush any pending entries so we
653 // can check that nothing was committed. We use a time far in the future so
654 // that anything added recently will get flushed.
655 TimeTicks expiration_time = TimeTicks::Now() + TimeDelta::FromDays(1);
656 text_db_->FlushOldChangesForTime(expiration_time);
657
658 // Verify that the middle URL had its last visit deleted only. 555 // Verify that the middle URL had its last visit deleted only.
659 visits.clear(); 556 visits.clear();
660 main_db_->GetVisitsForURL(url_ids[1], &visits); 557 main_db_->GetVisitsForURL(url_ids[1], &visits);
661 EXPECT_EQ(1U, visits.size()); 558 EXPECT_EQ(1U, visits.size());
662 EXPECT_EQ(0, CountTextMatchesForURL(url_row1.url()));
663 559
664 // Verify that the middle URL visit time and visit counts were updated. 560 // Verify that the middle URL visit time and visit counts were updated.
665 URLRow temp_row; 561 URLRow temp_row;
666 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); 562 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row));
667 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. 563 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value.
668 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. 564 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value.
669 EXPECT_EQ(2, url_row1.visit_count()); 565 EXPECT_EQ(2, url_row1.visit_count());
670 EXPECT_EQ(1, temp_row.visit_count()); 566 EXPECT_EQ(1, temp_row.visit_count());
671 EXPECT_EQ(1, url_row1.typed_count()); 567 EXPECT_EQ(1, url_row1.typed_count());
672 EXPECT_EQ(0, temp_row.typed_count()); 568 EXPECT_EQ(0, temp_row.typed_count());
(...skipping 13 matching lines...) Expand all
686 // Expires all URLs with times in a given set. 582 // Expires all URLs with times in a given set.
687 TEST_F(ExpireHistoryTest, FlushURLsForTimes) { 583 TEST_F(ExpireHistoryTest, FlushURLsForTimes) {
688 URLID url_ids[3]; 584 URLID url_ids[3];
689 Time visit_times[4]; 585 Time visit_times[4];
690 AddExampleData(url_ids, visit_times); 586 AddExampleData(url_ids, visit_times);
691 587
692 URLRow url_row1, url_row2; 588 URLRow url_row1, url_row2;
693 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); 589 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1));
694 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); 590 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2));
695 591
696 // In this test we also make sure that any pending entries in the text
697 // database manager are removed.
698 VisitVector visits; 592 VisitVector visits;
699 main_db_->GetVisitsForURL(url_ids[2], &visits); 593 main_db_->GetVisitsForURL(url_ids[2], &visits);
700 ASSERT_EQ(1U, visits.size()); 594 ASSERT_EQ(1U, visits.size());
701 text_db_->AddPageURL(url_row2.url(), url_row2.id(), visits[0].visit_id,
702 visits[0].visit_time);
703 595
704 // This should delete the last two visits. 596 // This should delete the last two visits.
705 std::vector<base::Time> times; 597 std::vector<base::Time> times;
706 times.push_back(visit_times[3]); 598 times.push_back(visit_times[3]);
707 times.push_back(visit_times[2]); 599 times.push_back(visit_times[2]);
708 expirer_.ExpireHistoryForTimes(times); 600 expirer_.ExpireHistoryForTimes(times);
709 601
710 // Run the text database expirer. This will flush any pending entries so we
711 // can check that nothing was committed. We use a time far in the future so
712 // that anything added recently will get flushed.
713 TimeTicks expiration_time = TimeTicks::Now() + TimeDelta::FromDays(1);
714 text_db_->FlushOldChangesForTime(expiration_time);
715
716 // Verify that the middle URL had its last visit deleted only. 602 // Verify that the middle URL had its last visit deleted only.
717 visits.clear(); 603 visits.clear();
718 main_db_->GetVisitsForURL(url_ids[1], &visits); 604 main_db_->GetVisitsForURL(url_ids[1], &visits);
719 EXPECT_EQ(1U, visits.size()); 605 EXPECT_EQ(1U, visits.size());
720 EXPECT_EQ(0, CountTextMatchesForURL(url_row1.url()));
721 606
722 // Verify that the middle URL visit time and visit counts were updated. 607 // Verify that the middle URL visit time and visit counts were updated.
723 URLRow temp_row; 608 URLRow temp_row;
724 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); 609 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row));
725 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. 610 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value.
726 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. 611 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value.
727 EXPECT_EQ(2, url_row1.visit_count()); 612 EXPECT_EQ(2, url_row1.visit_count());
728 EXPECT_EQ(1, temp_row.visit_count()); 613 EXPECT_EQ(1, temp_row.visit_count());
729 EXPECT_EQ(1, url_row1.typed_count()); 614 EXPECT_EQ(1, url_row1.typed_count());
730 EXPECT_EQ(0, temp_row.typed_count()); 615 EXPECT_EQ(0, temp_row.typed_count());
(...skipping 15 matching lines...) Expand all
746 // one of the two visits). 631 // one of the two visits).
747 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarredRestricted) { 632 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarredRestricted) {
748 URLID url_ids[3]; 633 URLID url_ids[3];
749 Time visit_times[4]; 634 Time visit_times[4];
750 AddExampleData(url_ids, visit_times); 635 AddExampleData(url_ids, visit_times);
751 636
752 URLRow url_row1, url_row2; 637 URLRow url_row1, url_row2;
753 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); 638 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1));
754 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); 639 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2));
755 640
756 // In this test we also make sure that any pending entries in the text
757 // database manager are removed.
758 VisitVector visits; 641 VisitVector visits;
759 main_db_->GetVisitsForURL(url_ids[2], &visits); 642 main_db_->GetVisitsForURL(url_ids[2], &visits);
760 ASSERT_EQ(1U, visits.size()); 643 ASSERT_EQ(1U, visits.size());
761 text_db_->AddPageURL(url_row2.url(), url_row2.id(), visits[0].visit_id,
762 visits[0].visit_time);
763 644
764 // This should delete the last two visits. 645 // This should delete the last two visits.
765 std::set<GURL> restrict_urls; 646 std::set<GURL> restrict_urls;
766 restrict_urls.insert(url_row1.url()); 647 restrict_urls.insert(url_row1.url());
767 expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time()); 648 expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time());
768 649
769 // Run the text database expirer. This will flush any pending entries so we
770 // can check that nothing was committed. We use a time far in the future so
771 // that anything added recently will get flushed.
772 TimeTicks expiration_time = TimeTicks::Now() + TimeDelta::FromDays(1);
773 text_db_->FlushOldChangesForTime(expiration_time);
774
775 // Verify that the middle URL had its last visit deleted only. 650 // Verify that the middle URL had its last visit deleted only.
776 visits.clear(); 651 visits.clear();
777 main_db_->GetVisitsForURL(url_ids[1], &visits); 652 main_db_->GetVisitsForURL(url_ids[1], &visits);
778 EXPECT_EQ(1U, visits.size()); 653 EXPECT_EQ(1U, visits.size());
779 EXPECT_EQ(0, CountTextMatchesForURL(url_row1.url()));
780 654
781 // Verify that the middle URL visit time and visit counts were updated. 655 // Verify that the middle URL visit time and visit counts were updated.
782 URLRow temp_row; 656 URLRow temp_row;
783 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); 657 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row));
784 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. 658 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value.
785 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. 659 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value.
786 EXPECT_EQ(2, url_row1.visit_count()); 660 EXPECT_EQ(2, url_row1.visit_count());
787 EXPECT_EQ(1, temp_row.visit_count()); 661 EXPECT_EQ(1, temp_row.visit_count());
788 EXPECT_EQ(1, url_row1.typed_count()); 662 EXPECT_EQ(1, url_row1.typed_count());
789 EXPECT_EQ(0, temp_row.typed_count()); 663 EXPECT_EQ(0, temp_row.typed_count());
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 main_db_->GetVisitsForURL(url_id, &archived_visits); 900 main_db_->GetVisitsForURL(url_id, &archived_visits);
1027 EXPECT_EQ(0U, archived_visits.size()); 901 EXPECT_EQ(0U, archived_visits.size());
1028 } 902 }
1029 903
1030 // TODO(brettw) add some visits with no URL to make sure everything is updated 904 // TODO(brettw) add some visits with no URL to make sure everything is updated
1031 // properly. Have the visits also refer to nonexistent FTS rows. 905 // properly. Have the visits also refer to nonexistent FTS rows.
1032 // 906 //
1033 // Maybe also refer to invalid favicons. 907 // Maybe also refer to invalid favicons.
1034 908
1035 } // namespace history 909 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698