| OLD | NEW |
| 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/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/history/archived_database.h" | 22 #include "chrome/browser/history/archived_database.h" |
| 23 #include "chrome/browser/history/expire_history_backend.h" | 23 #include "chrome/browser/history/expire_history_backend.h" |
| 24 #include "chrome/browser/history/history_database.h" | 24 #include "chrome/browser/history/history_database.h" |
| 25 #include "chrome/browser/history/history_notifications.h" | 25 #include "chrome/browser/history/history_notifications.h" |
| 26 #include "chrome/browser/history/text_database_manager.h" |
| 26 #include "chrome/browser/history/thumbnail_database.h" | 27 #include "chrome/browser/history/thumbnail_database.h" |
| 27 #include "chrome/browser/history/top_sites.h" | 28 #include "chrome/browser/history/top_sites.h" |
| 28 #include "chrome/common/thumbnail_score.h" | 29 #include "chrome/common/thumbnail_score.h" |
| 29 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
| 30 #include "chrome/tools/profiles/thumbnail-inl.h" | 31 #include "chrome/tools/profiles/thumbnail-inl.h" |
| 31 #include "content/public/test/test_browser_thread.h" | 32 #include "content/public/test/test_browser_thread.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "third_party/skia/include/core/SkBitmap.h" | 34 #include "third_party/skia/include/core/SkBitmap.h" |
| 34 #include "ui/gfx/codec/jpeg_codec.h" | 35 #include "ui/gfx/codec/jpeg_codec.h" |
| 35 | 36 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // Add visits with source information. | 70 // Add visits with source information. |
| 70 void AddExampleSourceData(const GURL& url, URLID* id); | 71 void AddExampleSourceData(const GURL& url, URLID* id); |
| 71 | 72 |
| 72 // Returns true if the given favicon/thumanil has an entry in the DB. | 73 // Returns true if the given favicon/thumanil has an entry in the DB. |
| 73 bool HasFavicon(chrome::FaviconID favicon_id); | 74 bool HasFavicon(chrome::FaviconID favicon_id); |
| 74 bool HasThumbnail(URLID url_id); | 75 bool HasThumbnail(URLID url_id); |
| 75 | 76 |
| 76 chrome::FaviconID GetFavicon(const GURL& page_url, | 77 chrome::FaviconID GetFavicon(const GURL& page_url, |
| 77 chrome::IconType icon_type); | 78 chrome::IconType icon_type); |
| 78 | 79 |
| 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 |
| 79 // EXPECTs that each URL-specific history thing (basically, everything but | 84 // EXPECTs that each URL-specific history thing (basically, everything but |
| 80 // favicons) is gone. | 85 // favicons) is gone. |
| 81 void EnsureURLInfoGone(const URLRow& row); | 86 void EnsureURLInfoGone(const URLRow& row); |
| 82 | 87 |
| 83 // Clears the list of notifications received. | 88 // Clears the list of notifications received. |
| 84 void ClearLastNotifications() { | 89 void ClearLastNotifications() { |
| 85 STLDeleteValues(¬ifications_); | 90 STLDeleteValues(¬ifications_); |
| 86 } | 91 } |
| 87 | 92 |
| 88 void StarURL(const GURL& url) { | 93 void StarURL(const GURL& url) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 102 | 107 |
| 103 base::MessageLoopForUI message_loop_; | 108 base::MessageLoopForUI message_loop_; |
| 104 content::TestBrowserThread ui_thread_; | 109 content::TestBrowserThread ui_thread_; |
| 105 content::TestBrowserThread db_thread_; | 110 content::TestBrowserThread db_thread_; |
| 106 | 111 |
| 107 ExpireHistoryBackend expirer_; | 112 ExpireHistoryBackend expirer_; |
| 108 | 113 |
| 109 scoped_ptr<HistoryDatabase> main_db_; | 114 scoped_ptr<HistoryDatabase> main_db_; |
| 110 scoped_ptr<ArchivedDatabase> archived_db_; | 115 scoped_ptr<ArchivedDatabase> archived_db_; |
| 111 scoped_ptr<ThumbnailDatabase> thumb_db_; | 116 scoped_ptr<ThumbnailDatabase> thumb_db_; |
| 117 scoped_ptr<TextDatabaseManager> text_db_; |
| 112 TestingProfile profile_; | 118 TestingProfile profile_; |
| 113 scoped_refptr<TopSites> top_sites_; | 119 scoped_refptr<TopSites> top_sites_; |
| 114 | 120 |
| 115 // Time at the beginning of the test, so everybody agrees what "now" is. | 121 // Time at the beginning of the test, so everybody agrees what "now" is. |
| 116 const Time now_; | 122 const Time now_; |
| 117 | 123 |
| 118 // Notifications intended to be broadcast, we can check these values to make | 124 // Notifications intended to be broadcast, we can check these values to make |
| 119 // sure that the deletor is doing the correct broadcasts. We own the details | 125 // sure that the deletor is doing the correct broadcasts. We own the details |
| 120 // pointers. | 126 // pointers. |
| 121 typedef std::vector< std::pair<int, HistoryDetails*> > | 127 typedef std::vector< std::pair<int, HistoryDetails*> > |
| (...skipping 12 matching lines...) Expand all Loading... |
| 134 base::FilePath archived_name = path().Append(kArchivedHistoryFile); | 140 base::FilePath archived_name = path().Append(kArchivedHistoryFile); |
| 135 archived_db_.reset(new ArchivedDatabase); | 141 archived_db_.reset(new ArchivedDatabase); |
| 136 if (!archived_db_->Init(archived_name)) | 142 if (!archived_db_->Init(archived_name)) |
| 137 archived_db_.reset(); | 143 archived_db_.reset(); |
| 138 | 144 |
| 139 base::FilePath thumb_name = path().Append(kThumbnailFile); | 145 base::FilePath thumb_name = path().Append(kThumbnailFile); |
| 140 thumb_db_.reset(new ThumbnailDatabase); | 146 thumb_db_.reset(new ThumbnailDatabase); |
| 141 if (thumb_db_->Init(thumb_name, NULL, main_db_.get()) != sql::INIT_OK) | 147 if (thumb_db_->Init(thumb_name, NULL, main_db_.get()) != sql::INIT_OK) |
| 142 thumb_db_.reset(); | 148 thumb_db_.reset(); |
| 143 | 149 |
| 144 expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get()); | 150 text_db_.reset(new TextDatabaseManager(path(), |
| 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()); |
| 145 profile_.CreateTopSites(); | 157 profile_.CreateTopSites(); |
| 146 profile_.BlockUntilTopSitesLoaded(); | 158 profile_.BlockUntilTopSitesLoaded(); |
| 147 top_sites_ = profile_.GetTopSites(); | 159 top_sites_ = profile_.GetTopSites(); |
| 148 } | 160 } |
| 149 | 161 |
| 150 virtual void TearDown() { | 162 virtual void TearDown() { |
| 151 top_sites_ = NULL; | 163 top_sites_ = NULL; |
| 152 | 164 |
| 153 ClearLastNotifications(); | 165 ClearLastNotifications(); |
| 154 | 166 |
| 155 expirer_.SetDatabases(NULL, NULL, NULL); | 167 expirer_.SetDatabases(NULL, NULL, NULL, NULL); |
| 156 | 168 |
| 157 main_db_.reset(); | 169 main_db_.reset(); |
| 158 archived_db_.reset(); | 170 archived_db_.reset(); |
| 159 thumb_db_.reset(); | 171 thumb_db_.reset(); |
| 172 text_db_.reset(); |
| 160 } | 173 } |
| 161 | 174 |
| 162 // BroadcastNotificationDelegate implementation. | 175 // BroadcastNotificationDelegate implementation. |
| 163 virtual void BroadcastNotifications( | 176 virtual void BroadcastNotifications( |
| 164 int type, | 177 int type, |
| 165 HistoryDetails* details_deleted) OVERRIDE { | 178 HistoryDetails* details_deleted) OVERRIDE { |
| 166 // This gets called when there are notifications to broadcast. Instead, we | 179 // This gets called when there are notifications to broadcast. Instead, we |
| 167 // store them so we can tell that the correct notifications were sent. | 180 // store them so we can tell that the correct notifications were sent. |
| 168 notifications_.push_back(std::make_pair(type, details_deleted)); | 181 notifications_.push_back(std::make_pair(type, details_deleted)); |
| 169 } | 182 } |
| 170 virtual void NotifySyncURLsDeleted( | 183 virtual void NotifySyncURLsDeleted( |
| 171 bool all_history, | 184 bool all_history, |
| 172 bool archived, | 185 bool archived, |
| 173 URLRows* rows) OVERRIDE {} | 186 URLRows* rows) OVERRIDE {} |
| 174 }; | 187 }; |
| 175 | 188 |
| 176 // The example data consists of 4 visits. The middle two visits are to the | 189 // The example data consists of 4 visits. The middle two visits are to the |
| 177 // same URL, while the first and last are for unique ones. This allows a test | 190 // same URL, while the first and last are for unique ones. This allows a test |
| 178 // for the oldest or newest to include both a URL that should get totally | 191 // for the oldest or newest to include both a URL that should get totally |
| 179 // deleted (the one on the end) with one that should only get a visit deleted | 192 // deleted (the one on the end) with one that should only get a visit deleted |
| 180 // (with the one in the middle) when it picks the proper threshold time. | 193 // (with the one in the middle) when it picks the proper threshold time. |
| 181 // | 194 // |
| 182 // Each visit has indexed data, each URL has thumbnail. The first two URLs will | 195 // Each visit has indexed data, each URL has thumbnail. The first two URLs will |
| 183 // share the same avicon, while the last one will have a unique favicon. The | 196 // share the same avicon, while the last one will have a unique favicon. The |
| 184 // second visit for the middle URL is typed. | 197 // second visit for the middle URL is typed. |
| 185 // | 198 // |
| 186 // The IDs of the added URLs, and the times of the four added visits will be | 199 // The IDs of the added URLs, and the times of the four added visits will be |
| 187 // added to the given arrays. | 200 // added to the given arrays. |
| 188 void ExpireHistoryTest::AddExampleData(URLID url_ids[3], Time visit_times[4]) { | 201 void ExpireHistoryTest::AddExampleData(URLID url_ids[3], Time visit_times[4]) { |
| 189 if (!main_db_.get()) | 202 if (!main_db_.get() || !text_db_) |
| 190 return; | 203 return; |
| 191 | 204 |
| 192 // Four times for each visit. | 205 // Four times for each visit. |
| 193 visit_times[3] = Time::Now(); | 206 visit_times[3] = Time::Now(); |
| 194 visit_times[2] = visit_times[3] - TimeDelta::FromDays(1); | 207 visit_times[2] = visit_times[3] - TimeDelta::FromDays(1); |
| 195 visit_times[1] = visit_times[3] - TimeDelta::FromDays(2); | 208 visit_times[1] = visit_times[3] - TimeDelta::FromDays(2); |
| 196 visit_times[0] = visit_times[3] - TimeDelta::FromDays(3); | 209 visit_times[0] = visit_times[3] - TimeDelta::FromDays(3); |
| 197 | 210 |
| 198 // Two favicons. The first two URLs will share the same one, while the last | 211 // Two favicons. The first two URLs will share the same one, while the last |
| 199 // one will have a unique favicon. | 212 // one will have a unique favicon. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 Time time; | 244 Time time; |
| 232 GURL gurl; | 245 GURL gurl; |
| 233 top_sites_->SetPageThumbnail(url_row1.url(), thumbnail, score); | 246 top_sites_->SetPageThumbnail(url_row1.url(), thumbnail, score); |
| 234 top_sites_->SetPageThumbnail(url_row2.url(), thumbnail, score); | 247 top_sites_->SetPageThumbnail(url_row2.url(), thumbnail, score); |
| 235 top_sites_->SetPageThumbnail(url_row3.url(), thumbnail, score); | 248 top_sites_->SetPageThumbnail(url_row3.url(), thumbnail, score); |
| 236 | 249 |
| 237 // Four visits. | 250 // Four visits. |
| 238 VisitRow visit_row1; | 251 VisitRow visit_row1; |
| 239 visit_row1.url_id = url_ids[0]; | 252 visit_row1.url_id = url_ids[0]; |
| 240 visit_row1.visit_time = visit_times[0]; | 253 visit_row1.visit_time = visit_times[0]; |
| 254 visit_row1.is_indexed = true; |
| 241 main_db_->AddVisit(&visit_row1, SOURCE_BROWSED); | 255 main_db_->AddVisit(&visit_row1, SOURCE_BROWSED); |
| 242 | 256 |
| 243 VisitRow visit_row2; | 257 VisitRow visit_row2; |
| 244 visit_row2.url_id = url_ids[1]; | 258 visit_row2.url_id = url_ids[1]; |
| 245 visit_row2.visit_time = visit_times[1]; | 259 visit_row2.visit_time = visit_times[1]; |
| 260 visit_row2.is_indexed = true; |
| 246 main_db_->AddVisit(&visit_row2, SOURCE_BROWSED); | 261 main_db_->AddVisit(&visit_row2, SOURCE_BROWSED); |
| 247 | 262 |
| 248 VisitRow visit_row3; | 263 VisitRow visit_row3; |
| 249 visit_row3.url_id = url_ids[1]; | 264 visit_row3.url_id = url_ids[1]; |
| 250 visit_row3.visit_time = visit_times[2]; | 265 visit_row3.visit_time = visit_times[2]; |
| 266 visit_row3.is_indexed = true; |
| 251 visit_row3.transition = content::PAGE_TRANSITION_TYPED; | 267 visit_row3.transition = content::PAGE_TRANSITION_TYPED; |
| 252 main_db_->AddVisit(&visit_row3, SOURCE_BROWSED); | 268 main_db_->AddVisit(&visit_row3, SOURCE_BROWSED); |
| 253 | 269 |
| 254 VisitRow visit_row4; | 270 VisitRow visit_row4; |
| 255 visit_row4.url_id = url_ids[2]; | 271 visit_row4.url_id = url_ids[2]; |
| 256 visit_row4.visit_time = visit_times[3]; | 272 visit_row4.visit_time = visit_times[3]; |
| 273 visit_row4.is_indexed = true; |
| 257 main_db_->AddVisit(&visit_row4, SOURCE_BROWSED); | 274 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")); |
| 258 } | 293 } |
| 259 | 294 |
| 260 void ExpireHistoryTest::AddExampleSourceData(const GURL& url, URLID* id) { | 295 void ExpireHistoryTest::AddExampleSourceData(const GURL& url, URLID* id) { |
| 261 if (!main_db_) | 296 if (!main_db_) |
| 262 return; | 297 return; |
| 263 | 298 |
| 264 Time last_visit_time = Time::Now(); | 299 Time last_visit_time = Time::Now(); |
| 265 // Add one URL. | 300 // Add one URL. |
| 266 URLRow url_row1(url); | 301 URLRow url_row1(url); |
| 267 url_row1.set_last_visit(last_visit_time); | 302 url_row1.set_last_visit(last_visit_time); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 // TODO(sky): fix this. This test isn't really valid for TopSites. For | 342 // TODO(sky): fix this. This test isn't really valid for TopSites. For |
| 308 // TopSites we should be checking URL always, not the id. | 343 // TopSites we should be checking URL always, not the id. |
| 309 URLRow info; | 344 URLRow info; |
| 310 if (!main_db_->GetURLRow(url_id, &info)) | 345 if (!main_db_->GetURLRow(url_id, &info)) |
| 311 return false; | 346 return false; |
| 312 GURL url = info.url(); | 347 GURL url = info.url(); |
| 313 scoped_refptr<base::RefCountedMemory> data; | 348 scoped_refptr<base::RefCountedMemory> data; |
| 314 return top_sites_->GetPageThumbnail(url, &data); | 349 return top_sites_->GetPageThumbnail(url, &data); |
| 315 } | 350 } |
| 316 | 351 |
| 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 |
| 317 void ExpireHistoryTest::EnsureURLInfoGone(const URLRow& row) { | 371 void ExpireHistoryTest::EnsureURLInfoGone(const URLRow& row) { |
| 318 // Verify the URL no longer exists. | 372 // Verify the URL no longer exists. |
| 319 URLRow temp_row; | 373 URLRow temp_row; |
| 320 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row)); | 374 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row)); |
| 321 | 375 |
| 376 // The indexed data should be gone. |
| 377 EXPECT_EQ(0, CountTextMatchesForURL(row.url())); |
| 378 |
| 322 // There should be no visits. | 379 // There should be no visits. |
| 323 VisitVector visits; | 380 VisitVector visits; |
| 324 main_db_->GetVisitsForURL(row.id(), &visits); | 381 main_db_->GetVisitsForURL(row.id(), &visits); |
| 325 EXPECT_EQ(0U, visits.size()); | 382 EXPECT_EQ(0U, visits.size()); |
| 326 | 383 |
| 327 // Thumbnail should be gone. | 384 // Thumbnail should be gone. |
| 328 // TODO(sky): fix this, see comment in HasThumbnail. | 385 // TODO(sky): fix this, see comment in HasThumbnail. |
| 329 // EXPECT_FALSE(HasThumbnail(row.id())); | 386 // EXPECT_FALSE(HasThumbnail(row.id())); |
| 330 | 387 |
| 331 bool found_delete_notification = false; | 388 bool found_delete_notification = false; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 URLRow last_row; | 464 URLRow last_row; |
| 408 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &last_row)); | 465 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &last_row)); |
| 409 chrome::FaviconID favicon_id = GetFavicon(last_row.url(), chrome::FAVICON); | 466 chrome::FaviconID favicon_id = GetFavicon(last_row.url(), chrome::FAVICON); |
| 410 EXPECT_TRUE(HasFavicon(favicon_id)); | 467 EXPECT_TRUE(HasFavicon(favicon_id)); |
| 411 // TODO(sky): fix this, see comment in HasThumbnail. | 468 // TODO(sky): fix this, see comment in HasThumbnail. |
| 412 // EXPECT_TRUE(HasThumbnail(url_ids[2])); | 469 // EXPECT_TRUE(HasThumbnail(url_ids[2])); |
| 413 | 470 |
| 414 VisitVector visits; | 471 VisitVector visits; |
| 415 main_db_->GetVisitsForURL(url_ids[2], &visits); | 472 main_db_->GetVisitsForURL(url_ids[2], &visits); |
| 416 ASSERT_EQ(1U, visits.size()); | 473 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()); |
| 417 | 494 |
| 418 // Delete the URL and its dependencies. | 495 // Delete the URL and its dependencies. |
| 419 expirer_.DeleteURL(last_row.url()); | 496 expirer_.DeleteURL(last_row.url()); |
| 420 | 497 |
| 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 |
| 421 // All the normal data + the favicon should be gone. | 514 // All the normal data + the favicon should be gone. |
| 422 EnsureURLInfoGone(last_row); | 515 EnsureURLInfoGone(last_row); |
| 423 EXPECT_FALSE(GetFavicon(last_row.url(), chrome::FAVICON)); | 516 EXPECT_FALSE(GetFavicon(last_row.url(), chrome::FAVICON)); |
| 424 EXPECT_FALSE(HasFavicon(favicon_id)); | 517 EXPECT_FALSE(HasFavicon(favicon_id)); |
| 425 } | 518 } |
| 426 | 519 |
| 427 // Deletes a URL with a favicon that other URLs reference, so that the favicon | 520 // Deletes a URL with a favicon that other URLs reference, so that the favicon |
| 428 // should not get deleted. This also tests deleting more than one visit. | 521 // should not get deleted. This also tests deleting more than one visit. |
| 429 TEST_F(ExpireHistoryTest, DeleteURLWithoutFavicon) { | 522 TEST_F(ExpireHistoryTest, DeleteURLWithoutFavicon) { |
| 430 URLID url_ids[3]; | 523 URLID url_ids[3]; |
| 431 Time visit_times[4]; | 524 Time visit_times[4]; |
| 432 AddExampleData(url_ids, visit_times); | 525 AddExampleData(url_ids, visit_times); |
| 433 | 526 |
| 434 // Verify things are the way we expect with a URL row, favicon, thumbnail. | 527 // Verify things are the way we expect with a URL row, favicon, thumbnail. |
| 435 URLRow last_row; | 528 URLRow last_row; |
| 436 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &last_row)); | 529 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &last_row)); |
| 437 chrome::FaviconID favicon_id = GetFavicon(last_row.url(), chrome::FAVICON); | 530 chrome::FaviconID favicon_id = GetFavicon(last_row.url(), chrome::FAVICON); |
| 438 EXPECT_TRUE(HasFavicon(favicon_id)); | 531 EXPECT_TRUE(HasFavicon(favicon_id)); |
| 439 // TODO(sky): fix this, see comment in HasThumbnail. | 532 // TODO(sky): fix this, see comment in HasThumbnail. |
| 440 // EXPECT_TRUE(HasThumbnail(url_ids[1])); | 533 // EXPECT_TRUE(HasThumbnail(url_ids[1])); |
| 441 | 534 |
| 442 VisitVector visits; | 535 VisitVector visits; |
| 443 main_db_->GetVisitsForURL(url_ids[1], &visits); | 536 main_db_->GetVisitsForURL(url_ids[1], &visits); |
| 444 EXPECT_EQ(2U, visits.size()); | 537 EXPECT_EQ(2U, visits.size()); |
| 538 EXPECT_EQ(1, CountTextMatchesForURL(last_row.url())); |
| 445 | 539 |
| 446 // Delete the URL and its dependencies. | 540 // Delete the URL and its dependencies. |
| 447 expirer_.DeleteURL(last_row.url()); | 541 expirer_.DeleteURL(last_row.url()); |
| 448 | 542 |
| 449 // All the normal data except the favicon should be gone. | 543 // All the normal data except the favicon should be gone. |
| 450 EnsureURLInfoGone(last_row); | 544 EnsureURLInfoGone(last_row); |
| 451 EXPECT_TRUE(HasFavicon(favicon_id)); | 545 EXPECT_TRUE(HasFavicon(favicon_id)); |
| 452 } | 546 } |
| 453 | 547 |
| 454 // DeleteURL should not delete starred urls. | 548 // DeleteURL should not delete starred urls. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 467 expirer_.DeleteURL(url_row.url()); | 561 expirer_.DeleteURL(url_row.url()); |
| 468 | 562 |
| 469 // Because the url is starred, it shouldn't be deleted. | 563 // Because the url is starred, it shouldn't be deleted. |
| 470 GURL url = url_row.url(); | 564 GURL url = url_row.url(); |
| 471 ASSERT_TRUE(main_db_->GetRowForURL(url, &url_row)); | 565 ASSERT_TRUE(main_db_->GetRowForURL(url, &url_row)); |
| 472 | 566 |
| 473 // And the favicon should exist. | 567 // And the favicon should exist. |
| 474 chrome::FaviconID favicon_id = GetFavicon(url_row.url(), chrome::FAVICON); | 568 chrome::FaviconID favicon_id = GetFavicon(url_row.url(), chrome::FAVICON); |
| 475 EXPECT_TRUE(HasFavicon(favicon_id)); | 569 EXPECT_TRUE(HasFavicon(favicon_id)); |
| 476 | 570 |
| 571 // But there should be no fts. |
| 572 ASSERT_EQ(0, CountTextMatchesForURL(url_row.url())); |
| 573 |
| 477 // And no visits. | 574 // And no visits. |
| 478 VisitVector visits; | 575 VisitVector visits; |
| 479 main_db_->GetVisitsForURL(url_row.id(), &visits); | 576 main_db_->GetVisitsForURL(url_row.id(), &visits); |
| 480 ASSERT_EQ(0U, visits.size()); | 577 ASSERT_EQ(0U, visits.size()); |
| 481 | 578 |
| 482 // Should still have the thumbnail. | 579 // Should still have the thumbnail. |
| 483 // TODO(sky): fix this, see comment in HasThumbnail. | 580 // TODO(sky): fix this, see comment in HasThumbnail. |
| 484 // ASSERT_TRUE(HasThumbnail(url_row.id())); | 581 // ASSERT_TRUE(HasThumbnail(url_row.id())); |
| 485 | 582 |
| 486 // Unstar the URL and delete again. | 583 // Unstar the URL and delete again. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 // the two visits) and one is deleted. | 630 // the two visits) and one is deleted. |
| 534 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarred) { | 631 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarred) { |
| 535 URLID url_ids[3]; | 632 URLID url_ids[3]; |
| 536 Time visit_times[4]; | 633 Time visit_times[4]; |
| 537 AddExampleData(url_ids, visit_times); | 634 AddExampleData(url_ids, visit_times); |
| 538 | 635 |
| 539 URLRow url_row1, url_row2; | 636 URLRow url_row1, url_row2; |
| 540 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); | 637 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); |
| 541 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); | 638 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); |
| 542 | 639 |
| 640 // In this test we also make sure that any pending entries in the text |
| 641 // database manager are removed. |
| 543 VisitVector visits; | 642 VisitVector visits; |
| 544 main_db_->GetVisitsForURL(url_ids[2], &visits); | 643 main_db_->GetVisitsForURL(url_ids[2], &visits); |
| 545 ASSERT_EQ(1U, visits.size()); | 644 ASSERT_EQ(1U, visits.size()); |
| 645 text_db_->AddPageURL(url_row2.url(), url_row2.id(), visits[0].visit_id, |
| 646 visits[0].visit_time); |
| 546 | 647 |
| 547 // This should delete the last two visits. | 648 // This should delete the last two visits. |
| 548 std::set<GURL> restrict_urls; | 649 std::set<GURL> restrict_urls; |
| 549 expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time()); | 650 expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time()); |
| 550 | 651 |
| 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 |
| 551 // Verify that the middle URL had its last visit deleted only. | 658 // Verify that the middle URL had its last visit deleted only. |
| 552 visits.clear(); | 659 visits.clear(); |
| 553 main_db_->GetVisitsForURL(url_ids[1], &visits); | 660 main_db_->GetVisitsForURL(url_ids[1], &visits); |
| 554 EXPECT_EQ(1U, visits.size()); | 661 EXPECT_EQ(1U, visits.size()); |
| 662 EXPECT_EQ(0, CountTextMatchesForURL(url_row1.url())); |
| 555 | 663 |
| 556 // Verify that the middle URL visit time and visit counts were updated. | 664 // Verify that the middle URL visit time and visit counts were updated. |
| 557 URLRow temp_row; | 665 URLRow temp_row; |
| 558 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); | 666 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); |
| 559 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. | 667 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. |
| 560 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. | 668 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. |
| 561 EXPECT_EQ(2, url_row1.visit_count()); | 669 EXPECT_EQ(2, url_row1.visit_count()); |
| 562 EXPECT_EQ(1, temp_row.visit_count()); | 670 EXPECT_EQ(1, temp_row.visit_count()); |
| 563 EXPECT_EQ(1, url_row1.typed_count()); | 671 EXPECT_EQ(1, url_row1.typed_count()); |
| 564 EXPECT_EQ(0, temp_row.typed_count()); | 672 EXPECT_EQ(0, temp_row.typed_count()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 578 // Expires all URLs with times in a given set. | 686 // Expires all URLs with times in a given set. |
| 579 TEST_F(ExpireHistoryTest, FlushURLsForTimes) { | 687 TEST_F(ExpireHistoryTest, FlushURLsForTimes) { |
| 580 URLID url_ids[3]; | 688 URLID url_ids[3]; |
| 581 Time visit_times[4]; | 689 Time visit_times[4]; |
| 582 AddExampleData(url_ids, visit_times); | 690 AddExampleData(url_ids, visit_times); |
| 583 | 691 |
| 584 URLRow url_row1, url_row2; | 692 URLRow url_row1, url_row2; |
| 585 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); | 693 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); |
| 586 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); | 694 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); |
| 587 | 695 |
| 696 // In this test we also make sure that any pending entries in the text |
| 697 // database manager are removed. |
| 588 VisitVector visits; | 698 VisitVector visits; |
| 589 main_db_->GetVisitsForURL(url_ids[2], &visits); | 699 main_db_->GetVisitsForURL(url_ids[2], &visits); |
| 590 ASSERT_EQ(1U, visits.size()); | 700 ASSERT_EQ(1U, visits.size()); |
| 701 text_db_->AddPageURL(url_row2.url(), url_row2.id(), visits[0].visit_id, |
| 702 visits[0].visit_time); |
| 591 | 703 |
| 592 // This should delete the last two visits. | 704 // This should delete the last two visits. |
| 593 std::vector<base::Time> times; | 705 std::vector<base::Time> times; |
| 594 times.push_back(visit_times[3]); | 706 times.push_back(visit_times[3]); |
| 595 times.push_back(visit_times[2]); | 707 times.push_back(visit_times[2]); |
| 596 expirer_.ExpireHistoryForTimes(times); | 708 expirer_.ExpireHistoryForTimes(times); |
| 597 | 709 |
| 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 |
| 598 // Verify that the middle URL had its last visit deleted only. | 716 // Verify that the middle URL had its last visit deleted only. |
| 599 visits.clear(); | 717 visits.clear(); |
| 600 main_db_->GetVisitsForURL(url_ids[1], &visits); | 718 main_db_->GetVisitsForURL(url_ids[1], &visits); |
| 601 EXPECT_EQ(1U, visits.size()); | 719 EXPECT_EQ(1U, visits.size()); |
| 720 EXPECT_EQ(0, CountTextMatchesForURL(url_row1.url())); |
| 602 | 721 |
| 603 // Verify that the middle URL visit time and visit counts were updated. | 722 // Verify that the middle URL visit time and visit counts were updated. |
| 604 URLRow temp_row; | 723 URLRow temp_row; |
| 605 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); | 724 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); |
| 606 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. | 725 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. |
| 607 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. | 726 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. |
| 608 EXPECT_EQ(2, url_row1.visit_count()); | 727 EXPECT_EQ(2, url_row1.visit_count()); |
| 609 EXPECT_EQ(1, temp_row.visit_count()); | 728 EXPECT_EQ(1, temp_row.visit_count()); |
| 610 EXPECT_EQ(1, url_row1.typed_count()); | 729 EXPECT_EQ(1, url_row1.typed_count()); |
| 611 EXPECT_EQ(0, temp_row.typed_count()); | 730 EXPECT_EQ(0, temp_row.typed_count()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 627 // one of the two visits). | 746 // one of the two visits). |
| 628 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarredRestricted) { | 747 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarredRestricted) { |
| 629 URLID url_ids[3]; | 748 URLID url_ids[3]; |
| 630 Time visit_times[4]; | 749 Time visit_times[4]; |
| 631 AddExampleData(url_ids, visit_times); | 750 AddExampleData(url_ids, visit_times); |
| 632 | 751 |
| 633 URLRow url_row1, url_row2; | 752 URLRow url_row1, url_row2; |
| 634 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); | 753 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); |
| 635 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); | 754 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); |
| 636 | 755 |
| 756 // In this test we also make sure that any pending entries in the text |
| 757 // database manager are removed. |
| 637 VisitVector visits; | 758 VisitVector visits; |
| 638 main_db_->GetVisitsForURL(url_ids[2], &visits); | 759 main_db_->GetVisitsForURL(url_ids[2], &visits); |
| 639 ASSERT_EQ(1U, visits.size()); | 760 ASSERT_EQ(1U, visits.size()); |
| 761 text_db_->AddPageURL(url_row2.url(), url_row2.id(), visits[0].visit_id, |
| 762 visits[0].visit_time); |
| 640 | 763 |
| 641 // This should delete the last two visits. | 764 // This should delete the last two visits. |
| 642 std::set<GURL> restrict_urls; | 765 std::set<GURL> restrict_urls; |
| 643 restrict_urls.insert(url_row1.url()); | 766 restrict_urls.insert(url_row1.url()); |
| 644 expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time()); | 767 expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time()); |
| 645 | 768 |
| 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 |
| 646 // Verify that the middle URL had its last visit deleted only. | 775 // Verify that the middle URL had its last visit deleted only. |
| 647 visits.clear(); | 776 visits.clear(); |
| 648 main_db_->GetVisitsForURL(url_ids[1], &visits); | 777 main_db_->GetVisitsForURL(url_ids[1], &visits); |
| 649 EXPECT_EQ(1U, visits.size()); | 778 EXPECT_EQ(1U, visits.size()); |
| 779 EXPECT_EQ(0, CountTextMatchesForURL(url_row1.url())); |
| 650 | 780 |
| 651 // Verify that the middle URL visit time and visit counts were updated. | 781 // Verify that the middle URL visit time and visit counts were updated. |
| 652 URLRow temp_row; | 782 URLRow temp_row; |
| 653 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); | 783 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); |
| 654 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. | 784 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. |
| 655 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. | 785 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. |
| 656 EXPECT_EQ(2, url_row1.visit_count()); | 786 EXPECT_EQ(2, url_row1.visit_count()); |
| 657 EXPECT_EQ(1, temp_row.visit_count()); | 787 EXPECT_EQ(1, temp_row.visit_count()); |
| 658 EXPECT_EQ(1, url_row1.typed_count()); | 788 EXPECT_EQ(1, url_row1.typed_count()); |
| 659 EXPECT_EQ(0, temp_row.typed_count()); | 789 EXPECT_EQ(0, temp_row.typed_count()); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 main_db_->GetVisitsForURL(url_id, &archived_visits); | 1026 main_db_->GetVisitsForURL(url_id, &archived_visits); |
| 897 EXPECT_EQ(0U, archived_visits.size()); | 1027 EXPECT_EQ(0U, archived_visits.size()); |
| 898 } | 1028 } |
| 899 | 1029 |
| 900 // TODO(brettw) add some visits with no URL to make sure everything is updated | 1030 // TODO(brettw) add some visits with no URL to make sure everything is updated |
| 901 // properly. Have the visits also refer to nonexistent FTS rows. | 1031 // properly. Have the visits also refer to nonexistent FTS rows. |
| 902 // | 1032 // |
| 903 // Maybe also refer to invalid favicons. | 1033 // Maybe also refer to invalid favicons. |
| 904 | 1034 |
| 905 } // namespace history | 1035 } // namespace history |
| OLD | NEW |