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" | |
27 #include "chrome/browser/history/thumbnail_database.h" | 26 #include "chrome/browser/history/thumbnail_database.h" |
28 #include "chrome/browser/history/top_sites.h" | 27 #include "chrome/browser/history/top_sites.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" |
36 | 35 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(¬ifications_); | 85 STLDeleteValues(¬ifications_); |
91 } | 86 } |
92 | 87 |
93 void StarURL(const GURL& url) { | 88 void StarURL(const GURL& url) { |
(...skipping 13 matching lines...) Expand all Loading... |
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 Loading... |
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 Time time; | 231 Time time; |
245 GURL gurl; | 232 GURL gurl; |
246 top_sites_->SetPageThumbnail(url_row1.url(), thumbnail, score); | 233 top_sites_->SetPageThumbnail(url_row1.url(), thumbnail, score); |
247 top_sites_->SetPageThumbnail(url_row2.url(), thumbnail, score); | 234 top_sites_->SetPageThumbnail(url_row2.url(), thumbnail, score); |
248 top_sites_->SetPageThumbnail(url_row3.url(), thumbnail, score); | 235 top_sites_->SetPageThumbnail(url_row3.url(), thumbnail, score); |
249 | 236 |
250 // Four visits. | 237 // Four visits. |
251 VisitRow visit_row1; | 238 VisitRow visit_row1; |
252 visit_row1.url_id = url_ids[0]; | 239 visit_row1.url_id = url_ids[0]; |
253 visit_row1.visit_time = visit_times[0]; | 240 visit_row1.visit_time = visit_times[0]; |
254 visit_row1.is_indexed = true; | |
255 main_db_->AddVisit(&visit_row1, SOURCE_BROWSED); | 241 main_db_->AddVisit(&visit_row1, SOURCE_BROWSED); |
256 | 242 |
257 VisitRow visit_row2; | 243 VisitRow visit_row2; |
258 visit_row2.url_id = url_ids[1]; | 244 visit_row2.url_id = url_ids[1]; |
259 visit_row2.visit_time = visit_times[1]; | 245 visit_row2.visit_time = visit_times[1]; |
260 visit_row2.is_indexed = true; | |
261 main_db_->AddVisit(&visit_row2, SOURCE_BROWSED); | 246 main_db_->AddVisit(&visit_row2, SOURCE_BROWSED); |
262 | 247 |
263 VisitRow visit_row3; | 248 VisitRow visit_row3; |
264 visit_row3.url_id = url_ids[1]; | 249 visit_row3.url_id = url_ids[1]; |
265 visit_row3.visit_time = visit_times[2]; | 250 visit_row3.visit_time = visit_times[2]; |
266 visit_row3.is_indexed = true; | |
267 visit_row3.transition = content::PAGE_TRANSITION_TYPED; | 251 visit_row3.transition = content::PAGE_TRANSITION_TYPED; |
268 main_db_->AddVisit(&visit_row3, SOURCE_BROWSED); | 252 main_db_->AddVisit(&visit_row3, SOURCE_BROWSED); |
269 | 253 |
270 VisitRow visit_row4; | 254 VisitRow visit_row4; |
271 visit_row4.url_id = url_ids[2]; | 255 visit_row4.url_id = url_ids[2]; |
272 visit_row4.visit_time = visit_times[3]; | 256 visit_row4.visit_time = visit_times[3]; |
273 visit_row4.is_indexed = true; | |
274 main_db_->AddVisit(&visit_row4, SOURCE_BROWSED); | 257 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 } | 258 } |
294 | 259 |
295 void ExpireHistoryTest::AddExampleSourceData(const GURL& url, URLID* id) { | 260 void ExpireHistoryTest::AddExampleSourceData(const GURL& url, URLID* id) { |
296 if (!main_db_) | 261 if (!main_db_) |
297 return; | 262 return; |
298 | 263 |
299 Time last_visit_time = Time::Now(); | 264 Time last_visit_time = Time::Now(); |
300 // Add one URL. | 265 // Add one URL. |
301 URLRow url_row1(url); | 266 URLRow url_row1(url); |
302 url_row1.set_last_visit(last_visit_time); | 267 url_row1.set_last_visit(last_visit_time); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 // TODO(sky): fix this. This test isn't really valid for TopSites. For | 307 // TODO(sky): fix this. This test isn't really valid for TopSites. For |
343 // TopSites we should be checking URL always, not the id. | 308 // TopSites we should be checking URL always, not the id. |
344 URLRow info; | 309 URLRow info; |
345 if (!main_db_->GetURLRow(url_id, &info)) | 310 if (!main_db_->GetURLRow(url_id, &info)) |
346 return false; | 311 return false; |
347 GURL url = info.url(); | 312 GURL url = info.url(); |
348 scoped_refptr<base::RefCountedMemory> data; | 313 scoped_refptr<base::RefCountedMemory> data; |
349 return top_sites_->GetPageThumbnail(url, &data); | 314 return top_sites_->GetPageThumbnail(url, &data); |
350 } | 315 } |
351 | 316 |
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) { | 317 void ExpireHistoryTest::EnsureURLInfoGone(const URLRow& row) { |
372 // Verify the URL no longer exists. | 318 // Verify the URL no longer exists. |
373 URLRow temp_row; | 319 URLRow temp_row; |
374 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row)); | 320 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row)); |
375 | 321 |
376 // The indexed data should be gone. | |
377 EXPECT_EQ(0, CountTextMatchesForURL(row.url())); | |
378 | |
379 // There should be no visits. | 322 // There should be no visits. |
380 VisitVector visits; | 323 VisitVector visits; |
381 main_db_->GetVisitsForURL(row.id(), &visits); | 324 main_db_->GetVisitsForURL(row.id(), &visits); |
382 EXPECT_EQ(0U, visits.size()); | 325 EXPECT_EQ(0U, visits.size()); |
383 | 326 |
384 // Thumbnail should be gone. | 327 // Thumbnail should be gone. |
385 // TODO(sky): fix this, see comment in HasThumbnail. | 328 // TODO(sky): fix this, see comment in HasThumbnail. |
386 // EXPECT_FALSE(HasThumbnail(row.id())); | 329 // EXPECT_FALSE(HasThumbnail(row.id())); |
387 | 330 |
388 bool found_delete_notification = false; | 331 bool found_delete_notification = false; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 URLRow last_row; | 407 URLRow last_row; |
465 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &last_row)); | 408 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &last_row)); |
466 chrome::FaviconID favicon_id = GetFavicon(last_row.url(), chrome::FAVICON); | 409 chrome::FaviconID favicon_id = GetFavicon(last_row.url(), chrome::FAVICON); |
467 EXPECT_TRUE(HasFavicon(favicon_id)); | 410 EXPECT_TRUE(HasFavicon(favicon_id)); |
468 // TODO(sky): fix this, see comment in HasThumbnail. | 411 // TODO(sky): fix this, see comment in HasThumbnail. |
469 // EXPECT_TRUE(HasThumbnail(url_ids[2])); | 412 // EXPECT_TRUE(HasThumbnail(url_ids[2])); |
470 | 413 |
471 VisitVector visits; | 414 VisitVector visits; |
472 main_db_->GetVisitsForURL(url_ids[2], &visits); | 415 main_db_->GetVisitsForURL(url_ids[2], &visits); |
473 ASSERT_EQ(1U, visits.size()); | 416 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 | 417 |
495 // Delete the URL and its dependencies. | 418 // Delete the URL and its dependencies. |
496 expirer_.DeleteURL(last_row.url()); | 419 expirer_.DeleteURL(last_row.url()); |
497 | 420 |
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. | 421 // All the normal data + the favicon should be gone. |
515 EnsureURLInfoGone(last_row); | 422 EnsureURLInfoGone(last_row); |
516 EXPECT_FALSE(GetFavicon(last_row.url(), chrome::FAVICON)); | 423 EXPECT_FALSE(GetFavicon(last_row.url(), chrome::FAVICON)); |
517 EXPECT_FALSE(HasFavicon(favicon_id)); | 424 EXPECT_FALSE(HasFavicon(favicon_id)); |
518 } | 425 } |
519 | 426 |
520 // Deletes a URL with a favicon that other URLs reference, so that the favicon | 427 // 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. | 428 // should not get deleted. This also tests deleting more than one visit. |
522 TEST_F(ExpireHistoryTest, DeleteURLWithoutFavicon) { | 429 TEST_F(ExpireHistoryTest, DeleteURLWithoutFavicon) { |
523 URLID url_ids[3]; | 430 URLID url_ids[3]; |
524 Time visit_times[4]; | 431 Time visit_times[4]; |
525 AddExampleData(url_ids, visit_times); | 432 AddExampleData(url_ids, visit_times); |
526 | 433 |
527 // Verify things are the way we expect with a URL row, favicon, thumbnail. | 434 // Verify things are the way we expect with a URL row, favicon, thumbnail. |
528 URLRow last_row; | 435 URLRow last_row; |
529 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &last_row)); | 436 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &last_row)); |
530 chrome::FaviconID favicon_id = GetFavicon(last_row.url(), chrome::FAVICON); | 437 chrome::FaviconID favicon_id = GetFavicon(last_row.url(), chrome::FAVICON); |
531 EXPECT_TRUE(HasFavicon(favicon_id)); | 438 EXPECT_TRUE(HasFavicon(favicon_id)); |
532 // TODO(sky): fix this, see comment in HasThumbnail. | 439 // TODO(sky): fix this, see comment in HasThumbnail. |
533 // EXPECT_TRUE(HasThumbnail(url_ids[1])); | 440 // EXPECT_TRUE(HasThumbnail(url_ids[1])); |
534 | 441 |
535 VisitVector visits; | 442 VisitVector visits; |
536 main_db_->GetVisitsForURL(url_ids[1], &visits); | 443 main_db_->GetVisitsForURL(url_ids[1], &visits); |
537 EXPECT_EQ(2U, visits.size()); | 444 EXPECT_EQ(2U, visits.size()); |
538 EXPECT_EQ(1, CountTextMatchesForURL(last_row.url())); | |
539 | 445 |
540 // Delete the URL and its dependencies. | 446 // Delete the URL and its dependencies. |
541 expirer_.DeleteURL(last_row.url()); | 447 expirer_.DeleteURL(last_row.url()); |
542 | 448 |
543 // All the normal data except the favicon should be gone. | 449 // All the normal data except the favicon should be gone. |
544 EnsureURLInfoGone(last_row); | 450 EnsureURLInfoGone(last_row); |
545 EXPECT_TRUE(HasFavicon(favicon_id)); | 451 EXPECT_TRUE(HasFavicon(favicon_id)); |
546 } | 452 } |
547 | 453 |
548 // DeleteURL should not delete starred urls. | 454 // DeleteURL should not delete starred urls. |
(...skipping 12 matching lines...) Expand all Loading... |
561 expirer_.DeleteURL(url_row.url()); | 467 expirer_.DeleteURL(url_row.url()); |
562 | 468 |
563 // Because the url is starred, it shouldn't be deleted. | 469 // Because the url is starred, it shouldn't be deleted. |
564 GURL url = url_row.url(); | 470 GURL url = url_row.url(); |
565 ASSERT_TRUE(main_db_->GetRowForURL(url, &url_row)); | 471 ASSERT_TRUE(main_db_->GetRowForURL(url, &url_row)); |
566 | 472 |
567 // And the favicon should exist. | 473 // And the favicon should exist. |
568 chrome::FaviconID favicon_id = GetFavicon(url_row.url(), chrome::FAVICON); | 474 chrome::FaviconID favicon_id = GetFavicon(url_row.url(), chrome::FAVICON); |
569 EXPECT_TRUE(HasFavicon(favicon_id)); | 475 EXPECT_TRUE(HasFavicon(favicon_id)); |
570 | 476 |
571 // But there should be no fts. | |
572 ASSERT_EQ(0, CountTextMatchesForURL(url_row.url())); | |
573 | |
574 // And no visits. | 477 // And no visits. |
575 VisitVector visits; | 478 VisitVector visits; |
576 main_db_->GetVisitsForURL(url_row.id(), &visits); | 479 main_db_->GetVisitsForURL(url_row.id(), &visits); |
577 ASSERT_EQ(0U, visits.size()); | 480 ASSERT_EQ(0U, visits.size()); |
578 | 481 |
579 // Should still have the thumbnail. | 482 // Should still have the thumbnail. |
580 // TODO(sky): fix this, see comment in HasThumbnail. | 483 // TODO(sky): fix this, see comment in HasThumbnail. |
581 // ASSERT_TRUE(HasThumbnail(url_row.id())); | 484 // ASSERT_TRUE(HasThumbnail(url_row.id())); |
582 | 485 |
583 // Unstar the URL and delete again. | 486 // Unstar the URL and delete again. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 // the two visits) and one is deleted. | 533 // the two visits) and one is deleted. |
631 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarred) { | 534 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarred) { |
632 URLID url_ids[3]; | 535 URLID url_ids[3]; |
633 Time visit_times[4]; | 536 Time visit_times[4]; |
634 AddExampleData(url_ids, visit_times); | 537 AddExampleData(url_ids, visit_times); |
635 | 538 |
636 URLRow url_row1, url_row2; | 539 URLRow url_row1, url_row2; |
637 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); | 540 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); |
638 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); | 541 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); |
639 | 542 |
640 // In this test we also make sure that any pending entries in the text | |
641 // database manager are removed. | |
642 VisitVector visits; | 543 VisitVector visits; |
643 main_db_->GetVisitsForURL(url_ids[2], &visits); | 544 main_db_->GetVisitsForURL(url_ids[2], &visits); |
644 ASSERT_EQ(1U, visits.size()); | 545 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 | 546 |
648 // This should delete the last two visits. | 547 // This should delete the last two visits. |
649 std::set<GURL> restrict_urls; | 548 std::set<GURL> restrict_urls; |
650 expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time()); | 549 expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time()); |
651 | 550 |
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. | 551 // Verify that the middle URL had its last visit deleted only. |
659 visits.clear(); | 552 visits.clear(); |
660 main_db_->GetVisitsForURL(url_ids[1], &visits); | 553 main_db_->GetVisitsForURL(url_ids[1], &visits); |
661 EXPECT_EQ(1U, visits.size()); | 554 EXPECT_EQ(1U, visits.size()); |
662 EXPECT_EQ(0, CountTextMatchesForURL(url_row1.url())); | |
663 | 555 |
664 // Verify that the middle URL visit time and visit counts were updated. | 556 // Verify that the middle URL visit time and visit counts were updated. |
665 URLRow temp_row; | 557 URLRow temp_row; |
666 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); | 558 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); |
667 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. | 559 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. |
668 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. | 560 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. |
669 EXPECT_EQ(2, url_row1.visit_count()); | 561 EXPECT_EQ(2, url_row1.visit_count()); |
670 EXPECT_EQ(1, temp_row.visit_count()); | 562 EXPECT_EQ(1, temp_row.visit_count()); |
671 EXPECT_EQ(1, url_row1.typed_count()); | 563 EXPECT_EQ(1, url_row1.typed_count()); |
672 EXPECT_EQ(0, temp_row.typed_count()); | 564 EXPECT_EQ(0, temp_row.typed_count()); |
(...skipping 13 matching lines...) Expand all Loading... |
686 // Expires all URLs with times in a given set. | 578 // Expires all URLs with times in a given set. |
687 TEST_F(ExpireHistoryTest, FlushURLsForTimes) { | 579 TEST_F(ExpireHistoryTest, FlushURLsForTimes) { |
688 URLID url_ids[3]; | 580 URLID url_ids[3]; |
689 Time visit_times[4]; | 581 Time visit_times[4]; |
690 AddExampleData(url_ids, visit_times); | 582 AddExampleData(url_ids, visit_times); |
691 | 583 |
692 URLRow url_row1, url_row2; | 584 URLRow url_row1, url_row2; |
693 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); | 585 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); |
694 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); | 586 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); |
695 | 587 |
696 // In this test we also make sure that any pending entries in the text | |
697 // database manager are removed. | |
698 VisitVector visits; | 588 VisitVector visits; |
699 main_db_->GetVisitsForURL(url_ids[2], &visits); | 589 main_db_->GetVisitsForURL(url_ids[2], &visits); |
700 ASSERT_EQ(1U, visits.size()); | 590 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 | 591 |
704 // This should delete the last two visits. | 592 // This should delete the last two visits. |
705 std::vector<base::Time> times; | 593 std::vector<base::Time> times; |
706 times.push_back(visit_times[3]); | 594 times.push_back(visit_times[3]); |
707 times.push_back(visit_times[2]); | 595 times.push_back(visit_times[2]); |
708 expirer_.ExpireHistoryForTimes(times); | 596 expirer_.ExpireHistoryForTimes(times); |
709 | 597 |
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. | 598 // Verify that the middle URL had its last visit deleted only. |
717 visits.clear(); | 599 visits.clear(); |
718 main_db_->GetVisitsForURL(url_ids[1], &visits); | 600 main_db_->GetVisitsForURL(url_ids[1], &visits); |
719 EXPECT_EQ(1U, visits.size()); | 601 EXPECT_EQ(1U, visits.size()); |
720 EXPECT_EQ(0, CountTextMatchesForURL(url_row1.url())); | |
721 | 602 |
722 // Verify that the middle URL visit time and visit counts were updated. | 603 // Verify that the middle URL visit time and visit counts were updated. |
723 URLRow temp_row; | 604 URLRow temp_row; |
724 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); | 605 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); |
725 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. | 606 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. |
726 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. | 607 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. |
727 EXPECT_EQ(2, url_row1.visit_count()); | 608 EXPECT_EQ(2, url_row1.visit_count()); |
728 EXPECT_EQ(1, temp_row.visit_count()); | 609 EXPECT_EQ(1, temp_row.visit_count()); |
729 EXPECT_EQ(1, url_row1.typed_count()); | 610 EXPECT_EQ(1, url_row1.typed_count()); |
730 EXPECT_EQ(0, temp_row.typed_count()); | 611 EXPECT_EQ(0, temp_row.typed_count()); |
(...skipping 15 matching lines...) Expand all Loading... |
746 // one of the two visits). | 627 // one of the two visits). |
747 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarredRestricted) { | 628 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarredRestricted) { |
748 URLID url_ids[3]; | 629 URLID url_ids[3]; |
749 Time visit_times[4]; | 630 Time visit_times[4]; |
750 AddExampleData(url_ids, visit_times); | 631 AddExampleData(url_ids, visit_times); |
751 | 632 |
752 URLRow url_row1, url_row2; | 633 URLRow url_row1, url_row2; |
753 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); | 634 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); |
754 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); | 635 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); |
755 | 636 |
756 // In this test we also make sure that any pending entries in the text | |
757 // database manager are removed. | |
758 VisitVector visits; | 637 VisitVector visits; |
759 main_db_->GetVisitsForURL(url_ids[2], &visits); | 638 main_db_->GetVisitsForURL(url_ids[2], &visits); |
760 ASSERT_EQ(1U, visits.size()); | 639 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 | 640 |
764 // This should delete the last two visits. | 641 // This should delete the last two visits. |
765 std::set<GURL> restrict_urls; | 642 std::set<GURL> restrict_urls; |
766 restrict_urls.insert(url_row1.url()); | 643 restrict_urls.insert(url_row1.url()); |
767 expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time()); | 644 expirer_.ExpireHistoryBetween(restrict_urls, visit_times[2], Time()); |
768 | 645 |
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. | 646 // Verify that the middle URL had its last visit deleted only. |
776 visits.clear(); | 647 visits.clear(); |
777 main_db_->GetVisitsForURL(url_ids[1], &visits); | 648 main_db_->GetVisitsForURL(url_ids[1], &visits); |
778 EXPECT_EQ(1U, visits.size()); | 649 EXPECT_EQ(1U, visits.size()); |
779 EXPECT_EQ(0, CountTextMatchesForURL(url_row1.url())); | |
780 | 650 |
781 // Verify that the middle URL visit time and visit counts were updated. | 651 // Verify that the middle URL visit time and visit counts were updated. |
782 URLRow temp_row; | 652 URLRow temp_row; |
783 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); | 653 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); |
784 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. | 654 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. |
785 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. | 655 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. |
786 EXPECT_EQ(2, url_row1.visit_count()); | 656 EXPECT_EQ(2, url_row1.visit_count()); |
787 EXPECT_EQ(1, temp_row.visit_count()); | 657 EXPECT_EQ(1, temp_row.visit_count()); |
788 EXPECT_EQ(1, url_row1.typed_count()); | 658 EXPECT_EQ(1, url_row1.typed_count()); |
789 EXPECT_EQ(0, temp_row.typed_count()); | 659 EXPECT_EQ(0, temp_row.typed_count()); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 main_db_->GetVisitsForURL(url_id, &archived_visits); | 896 main_db_->GetVisitsForURL(url_id, &archived_visits); |
1027 EXPECT_EQ(0U, archived_visits.size()); | 897 EXPECT_EQ(0U, archived_visits.size()); |
1028 } | 898 } |
1029 | 899 |
1030 // TODO(brettw) add some visits with no URL to make sure everything is updated | 900 // 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. | 901 // properly. Have the visits also refer to nonexistent FTS rows. |
1032 // | 902 // |
1033 // Maybe also refer to invalid favicons. | 903 // Maybe also refer to invalid favicons. |
1034 | 904 |
1035 } // namespace history | 905 } // namespace history |
OLD | NEW |