| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
| 15 #include "base/string16.h" | 15 #include "base/string16.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_model.h" | 17 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 18 #include "chrome/browser/history/archived_database.h" | 18 #include "chrome/browser/history/archived_database.h" |
| 19 #include "chrome/browser/history/expire_history_backend.h" | 19 #include "chrome/browser/history/expire_history_backend.h" |
| 20 #include "chrome/browser/history/history_database.h" | 20 #include "chrome/browser/history/history_database.h" |
| 21 #include "chrome/browser/history/history_notifications.h" | 21 #include "chrome/browser/history/history_notifications.h" |
| 22 #include "chrome/browser/history/text_database_manager.h" | 22 #include "chrome/browser/history/text_database_manager.h" |
| 23 #include "chrome/browser/history/thumbnail_database.h" | 23 #include "chrome/browser/history/thumbnail_database.h" |
| 24 #include "chrome/browser/history/top_sites.h" | 24 #include "chrome/browser/history/top_sites.h" |
| 25 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "chrome/common/thumbnail_score.h" | 26 #include "chrome/common/thumbnail_score.h" |
| 26 #include "chrome/test/testing_profile.h" | 27 #include "chrome/test/testing_profile.h" |
| 27 #include "chrome/tools/profiles/thumbnail-inl.h" | 28 #include "chrome/tools/profiles/thumbnail-inl.h" |
| 28 #include "content/browser/browser_thread.h" | 29 #include "content/browser/browser_thread.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "third_party/skia/include/core/SkBitmap.h" | 31 #include "third_party/skia/include/core/SkBitmap.h" |
| 31 #include "ui/gfx/codec/jpeg_codec.h" | 32 #include "ui/gfx/codec/jpeg_codec.h" |
| 32 | 33 |
| 33 using base::Time; | 34 using base::Time; |
| 34 using base::TimeDelta; | 35 using base::TimeDelta; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 scoped_ptr<TextDatabaseManager> text_db_; | 113 scoped_ptr<TextDatabaseManager> text_db_; |
| 113 TestingProfile profile_; | 114 TestingProfile profile_; |
| 114 scoped_refptr<TopSites> top_sites_; | 115 scoped_refptr<TopSites> top_sites_; |
| 115 | 116 |
| 116 // Time at the beginning of the test, so everybody agrees what "now" is. | 117 // Time at the beginning of the test, so everybody agrees what "now" is. |
| 117 const Time now_; | 118 const Time now_; |
| 118 | 119 |
| 119 // Notifications intended to be broadcast, we can check these values to make | 120 // Notifications intended to be broadcast, we can check these values to make |
| 120 // sure that the deletor is doing the correct broadcasts. We own the details | 121 // sure that the deletor is doing the correct broadcasts. We own the details |
| 121 // pointers. | 122 // pointers. |
| 122 typedef std::vector< std::pair<NotificationType, HistoryDetails*> > | 123 typedef std::vector< std::pair<int, HistoryDetails*> > |
| 123 NotificationList; | 124 NotificationList; |
| 124 NotificationList notifications_; | 125 NotificationList notifications_; |
| 125 | 126 |
| 126 private: | 127 private: |
| 127 void SetUp() { | 128 void SetUp() { |
| 128 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); | 129 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); |
| 129 | 130 |
| 130 FilePath history_name = path().Append(kHistoryFile); | 131 FilePath history_name = path().Append(kHistoryFile); |
| 131 main_db_.reset(new HistoryDatabase); | 132 main_db_.reset(new HistoryDatabase); |
| 132 if (main_db_->Init(history_name, FilePath()) != sql::INIT_OK) | 133 if (main_db_->Init(history_name, FilePath()) != sql::INIT_OK) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 161 | 162 |
| 162 expirer_.SetDatabases(NULL, NULL, NULL, NULL); | 163 expirer_.SetDatabases(NULL, NULL, NULL, NULL); |
| 163 | 164 |
| 164 main_db_.reset(); | 165 main_db_.reset(); |
| 165 archived_db_.reset(); | 166 archived_db_.reset(); |
| 166 thumb_db_.reset(); | 167 thumb_db_.reset(); |
| 167 text_db_.reset(); | 168 text_db_.reset(); |
| 168 } | 169 } |
| 169 | 170 |
| 170 // BroadcastNotificationDelegate implementation. | 171 // BroadcastNotificationDelegate implementation. |
| 171 void BroadcastNotifications(NotificationType type, | 172 void BroadcastNotifications(int type, |
| 172 HistoryDetails* details_deleted) { | 173 HistoryDetails* details_deleted) { |
| 173 // This gets called when there are notifications to broadcast. Instead, we | 174 // This gets called when there are notifications to broadcast. Instead, we |
| 174 // store them so we can tell that the correct notifications were sent. | 175 // store them so we can tell that the correct notifications were sent. |
| 175 notifications_.push_back(std::make_pair(type, details_deleted)); | 176 notifications_.push_back(std::make_pair(type, details_deleted)); |
| 176 } | 177 } |
| 177 }; | 178 }; |
| 178 | 179 |
| 179 // The example data consists of 4 visits. The middle two visits are to the | 180 // The example data consists of 4 visits. The middle two visits are to the |
| 180 // same URL, while the first and last are for unique ones. This allows a test | 181 // same URL, while the first and last are for unique ones. This allows a test |
| 181 // for the oldest or newest to include both a URL that should get totally | 182 // for the oldest or newest to include both a URL that should get totally |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 VisitVector visits; | 370 VisitVector visits; |
| 370 main_db_->GetVisitsForURL(row.id(), &visits); | 371 main_db_->GetVisitsForURL(row.id(), &visits); |
| 371 EXPECT_EQ(0U, visits.size()); | 372 EXPECT_EQ(0U, visits.size()); |
| 372 | 373 |
| 373 // Thumbnail should be gone. | 374 // Thumbnail should be gone. |
| 374 // TODO(sky): fix this, see comment in HasThumbnail. | 375 // TODO(sky): fix this, see comment in HasThumbnail. |
| 375 // EXPECT_FALSE(HasThumbnail(row.id())); | 376 // EXPECT_FALSE(HasThumbnail(row.id())); |
| 376 | 377 |
| 377 bool found_delete_notification = false; | 378 bool found_delete_notification = false; |
| 378 for (size_t i = 0; i < notifications_.size(); i++) { | 379 for (size_t i = 0; i < notifications_.size(); i++) { |
| 379 if (notifications_[i].first == NotificationType::HISTORY_URLS_DELETED) { | 380 if (notifications_[i].first == chrome::NOTIFICATION_HISTORY_URLS_DELETED) { |
| 380 const URLsDeletedDetails* deleted_details = | 381 const URLsDeletedDetails* deleted_details = |
| 381 reinterpret_cast<URLsDeletedDetails*>(notifications_[i].second); | 382 reinterpret_cast<URLsDeletedDetails*>(notifications_[i].second); |
| 382 if (deleted_details->urls.find(row.url()) != | 383 if (deleted_details->urls.find(row.url()) != |
| 383 deleted_details->urls.end()) { | 384 deleted_details->urls.end()) { |
| 384 found_delete_notification = true; | 385 found_delete_notification = true; |
| 385 } | 386 } |
| 386 } else { | 387 } else { |
| 387 EXPECT_NE(notifications_[i].first, NotificationType::HISTORY_URL_VISITED); | |
| 388 EXPECT_NE(notifications_[i].first, | 388 EXPECT_NE(notifications_[i].first, |
| 389 NotificationType::HISTORY_TYPED_URLS_MODIFIED); | 389 chrome::NOTIFICATION_HISTORY_URL_VISITED); |
| 390 EXPECT_NE(notifications_[i].first, |
| 391 chrome::NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED); |
| 390 } | 392 } |
| 391 } | 393 } |
| 392 EXPECT_TRUE(found_delete_notification); | 394 EXPECT_TRUE(found_delete_notification); |
| 393 } | 395 } |
| 394 | 396 |
| 395 TEST_F(ExpireHistoryTest, DeleteFaviconsIfPossible) { | 397 TEST_F(ExpireHistoryTest, DeleteFaviconsIfPossible) { |
| 396 // Add a favicon record. | 398 // Add a favicon record. |
| 397 const GURL favicon_url("http://www.google.com/favicon.ico"); | 399 const GURL favicon_url("http://www.google.com/favicon.ico"); |
| 398 FaviconID icon_id = thumb_db_->AddFavicon(favicon_url, FAVICON); | 400 FaviconID icon_id = thumb_db_->AddFavicon(favicon_url, FAVICON); |
| 399 EXPECT_TRUE(icon_id); | 401 EXPECT_TRUE(icon_id); |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 main_db_->GetVisitsForURL(url_id, &archived_visits); | 912 main_db_->GetVisitsForURL(url_id, &archived_visits); |
| 911 EXPECT_EQ(0U, archived_visits.size()); | 913 EXPECT_EQ(0U, archived_visits.size()); |
| 912 } | 914 } |
| 913 | 915 |
| 914 // TODO(brettw) add some visits with no URL to make sure everything is updated | 916 // TODO(brettw) add some visits with no URL to make sure everything is updated |
| 915 // properly. Have the visits also refer to nonexistent FTS rows. | 917 // properly. Have the visits also refer to nonexistent FTS rows. |
| 916 // | 918 // |
| 917 // Maybe also refer to invalid favicons. | 919 // Maybe also refer to invalid favicons. |
| 918 | 920 |
| 919 } // namespace history | 921 } // namespace history |
| OLD | NEW |