| 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" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 const Time now_; | 120 const Time now_; |
| 121 | 121 |
| 122 // Notifications intended to be broadcast, we can check these values to make | 122 // Notifications intended to be broadcast, we can check these values to make |
| 123 // sure that the deletor is doing the correct broadcasts. We own the details | 123 // sure that the deletor is doing the correct broadcasts. We own the details |
| 124 // pointers. | 124 // pointers. |
| 125 typedef std::vector< std::pair<int, HistoryDetails*> > | 125 typedef std::vector< std::pair<int, HistoryDetails*> > |
| 126 NotificationList; | 126 NotificationList; |
| 127 NotificationList notifications_; | 127 NotificationList notifications_; |
| 128 | 128 |
| 129 private: | 129 private: |
| 130 void SetUp() { | 130 virtual void SetUp() { |
| 131 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); | 131 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); |
| 132 | 132 |
| 133 FilePath history_name = path().Append(kHistoryFile); | 133 FilePath history_name = path().Append(kHistoryFile); |
| 134 main_db_.reset(new HistoryDatabase); | 134 main_db_.reset(new HistoryDatabase); |
| 135 if (main_db_->Init(history_name, NULL) != sql::INIT_OK) | 135 if (main_db_->Init(history_name, NULL) != sql::INIT_OK) |
| 136 main_db_.reset(); | 136 main_db_.reset(); |
| 137 | 137 |
| 138 FilePath archived_name = path().Append(kArchivedHistoryFile); | 138 FilePath archived_name = path().Append(kArchivedHistoryFile); |
| 139 archived_db_.reset(new ArchivedDatabase); | 139 archived_db_.reset(new ArchivedDatabase); |
| 140 if (!archived_db_->Init(archived_name)) | 140 if (!archived_db_->Init(archived_name)) |
| 141 archived_db_.reset(); | 141 archived_db_.reset(); |
| 142 | 142 |
| 143 FilePath thumb_name = path().Append(kThumbnailFile); | 143 FilePath thumb_name = path().Append(kThumbnailFile); |
| 144 thumb_db_.reset(new ThumbnailDatabase); | 144 thumb_db_.reset(new ThumbnailDatabase); |
| 145 if (thumb_db_->Init(thumb_name, NULL, main_db_.get()) != sql::INIT_OK) | 145 if (thumb_db_->Init(thumb_name, NULL, main_db_.get()) != sql::INIT_OK) |
| 146 thumb_db_.reset(); | 146 thumb_db_.reset(); |
| 147 | 147 |
| 148 text_db_.reset(new TextDatabaseManager(path(), | 148 text_db_.reset(new TextDatabaseManager(path(), |
| 149 main_db_.get(), main_db_.get())); | 149 main_db_.get(), main_db_.get())); |
| 150 if (!text_db_->Init(NULL)) | 150 if (!text_db_->Init(NULL)) |
| 151 text_db_.reset(); | 151 text_db_.reset(); |
| 152 | 152 |
| 153 expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get(), | 153 expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get(), |
| 154 text_db_.get()); | 154 text_db_.get()); |
| 155 profile_.CreateTopSites(); | 155 profile_.CreateTopSites(); |
| 156 profile_.BlockUntilTopSitesLoaded(); | 156 profile_.BlockUntilTopSitesLoaded(); |
| 157 top_sites_ = profile_.GetTopSites(); | 157 top_sites_ = profile_.GetTopSites(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void TearDown() { | 160 virtual void TearDown() { |
| 161 top_sites_ = NULL; | 161 top_sites_ = NULL; |
| 162 | 162 |
| 163 ClearLastNotifications(); | 163 ClearLastNotifications(); |
| 164 | 164 |
| 165 expirer_.SetDatabases(NULL, NULL, NULL, NULL); | 165 expirer_.SetDatabases(NULL, NULL, NULL, NULL); |
| 166 | 166 |
| 167 main_db_.reset(); | 167 main_db_.reset(); |
| 168 archived_db_.reset(); | 168 archived_db_.reset(); |
| 169 thumb_db_.reset(); | 169 thumb_db_.reset(); |
| 170 text_db_.reset(); | 170 text_db_.reset(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 // BroadcastNotificationDelegate implementation. | 173 // BroadcastNotificationDelegate implementation. |
| 174 void BroadcastNotifications(int type, | 174 virtual void BroadcastNotifications( |
| 175 HistoryDetails* details_deleted) { | 175 int type, |
| 176 HistoryDetails* details_deleted) OVERRIDE { |
| 176 // This gets called when there are notifications to broadcast. Instead, we | 177 // This gets called when there are notifications to broadcast. Instead, we |
| 177 // store them so we can tell that the correct notifications were sent. | 178 // store them so we can tell that the correct notifications were sent. |
| 178 notifications_.push_back(std::make_pair(type, details_deleted)); | 179 notifications_.push_back(std::make_pair(type, details_deleted)); |
| 179 } | 180 } |
| 180 }; | 181 }; |
| 181 | 182 |
| 182 // The example data consists of 4 visits. The middle two visits are to the | 183 // The example data consists of 4 visits. The middle two visits are to the |
| 183 // same URL, while the first and last are for unique ones. This allows a test | 184 // same URL, while the first and last are for unique ones. This allows a test |
| 184 // for the oldest or newest to include both a URL that should get totally | 185 // for the oldest or newest to include both a URL that should get totally |
| 185 // deleted (the one on the end) with one that should only get a visit deleted | 186 // deleted (the one on the end) with one that should only get a visit deleted |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 main_db_->GetVisitsForURL(url_id, &archived_visits); | 1015 main_db_->GetVisitsForURL(url_id, &archived_visits); |
| 1015 EXPECT_EQ(0U, archived_visits.size()); | 1016 EXPECT_EQ(0U, archived_visits.size()); |
| 1016 } | 1017 } |
| 1017 | 1018 |
| 1018 // TODO(brettw) add some visits with no URL to make sure everything is updated | 1019 // TODO(brettw) add some visits with no URL to make sure everything is updated |
| 1019 // properly. Have the visits also refer to nonexistent FTS rows. | 1020 // properly. Have the visits also refer to nonexistent FTS rows. |
| 1020 // | 1021 // |
| 1021 // Maybe also refer to invalid favicons. | 1022 // Maybe also refer to invalid favicons. |
| 1022 | 1023 |
| 1023 } // namespace history | 1024 } // namespace history |
| OLD | NEW |