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/bookmarks/test_bookmark_client.h" |
21 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
22 #include "chrome/browser/history/archived_database.h" | 23 #include "chrome/browser/history/archived_database.h" |
23 #include "chrome/browser/history/expire_history_backend.h" | 24 #include "chrome/browser/history/expire_history_backend.h" |
24 #include "chrome/browser/history/history_database.h" | 25 #include "chrome/browser/history/history_database.h" |
25 #include "chrome/browser/history/history_notifications.h" | 26 #include "chrome/browser/history/history_notifications.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" |
(...skipping 18 matching lines...) Expand all Loading... |
49 // The test must be in the history namespace for the gtest forward declarations | 50 // The test must be in the history namespace for the gtest forward declarations |
50 // to work. It also eliminates a bunch of ugly "history::". | 51 // to work. It also eliminates a bunch of ugly "history::". |
51 namespace history { | 52 namespace history { |
52 | 53 |
53 // ExpireHistoryTest ----------------------------------------------------------- | 54 // ExpireHistoryTest ----------------------------------------------------------- |
54 | 55 |
55 class ExpireHistoryTest : public testing::Test, | 56 class ExpireHistoryTest : public testing::Test, |
56 public BroadcastNotificationDelegate { | 57 public BroadcastNotificationDelegate { |
57 public: | 58 public: |
58 ExpireHistoryTest() | 59 ExpireHistoryTest() |
59 : bookmark_model_(NULL, false), | 60 : bookmark_model_(bookmark_client_.CreateModel(false)), |
60 ui_thread_(BrowserThread::UI, &message_loop_), | 61 ui_thread_(BrowserThread::UI, &message_loop_), |
61 db_thread_(BrowserThread::DB, &message_loop_), | 62 db_thread_(BrowserThread::DB, &message_loop_), |
62 expirer_(this, &bookmark_model_), | 63 expirer_(this, bookmark_model_.get()), |
63 now_(Time::Now()) { | 64 now_(Time::Now()) {} |
64 } | |
65 | 65 |
66 protected: | 66 protected: |
67 // Called by individual tests when they want data populated. | 67 // Called by individual tests when they want data populated. |
68 void AddExampleData(URLID url_ids[3], Time visit_times[4]); | 68 void AddExampleData(URLID url_ids[3], Time visit_times[4]); |
69 // Add visits with source information. | 69 // Add visits with source information. |
70 void AddExampleSourceData(const GURL& url, URLID* id); | 70 void AddExampleSourceData(const GURL& url, URLID* id); |
71 | 71 |
72 // 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. |
73 bool HasFavicon(favicon_base::FaviconID favicon_id); | 73 bool HasFavicon(favicon_base::FaviconID favicon_id); |
74 bool HasThumbnail(URLID url_id); | 74 bool HasThumbnail(URLID url_id); |
75 | 75 |
76 favicon_base::FaviconID GetFavicon(const GURL& page_url, | 76 favicon_base::FaviconID GetFavicon(const GURL& page_url, |
77 favicon_base::IconType icon_type); | 77 favicon_base::IconType icon_type); |
78 | 78 |
79 // EXPECTs that each URL-specific history thing (basically, everything but | 79 // EXPECTs that each URL-specific history thing (basically, everything but |
80 // favicons) is gone, the reason being either that it was |archived|, or | 80 // favicons) is gone, the reason being either that it was |archived|, or |
81 // manually deleted. | 81 // manually deleted. |
82 void EnsureURLInfoGone(const URLRow& row, bool archived); | 82 void EnsureURLInfoGone(const URLRow& row, bool archived); |
83 | 83 |
84 // Returns whether a NOTIFICATION_HISTORY_URLS_MODIFIED was sent for |url|. | 84 // Returns whether a NOTIFICATION_HISTORY_URLS_MODIFIED was sent for |url|. |
85 bool ModifiedNotificationSent(const GURL& url); | 85 bool ModifiedNotificationSent(const GURL& url); |
86 | 86 |
87 // Clears the list of notifications received. | 87 // Clears the list of notifications received. |
88 void ClearLastNotifications() { | 88 void ClearLastNotifications() { |
89 STLDeleteValues(¬ifications_); | 89 STLDeleteValues(¬ifications_); |
90 } | 90 } |
91 | 91 |
92 void StarURL(const GURL& url) { | 92 void StarURL(const GURL& url) { |
93 bookmark_model_.AddURL( | 93 bookmark_model_->AddURL( |
94 bookmark_model_.bookmark_bar_node(), 0, base::string16(), url); | 94 bookmark_model_->bookmark_bar_node(), 0, base::string16(), url); |
95 } | 95 } |
96 | 96 |
97 static bool IsStringInFile(const base::FilePath& filename, const char* str); | 97 static bool IsStringInFile(const base::FilePath& filename, const char* str); |
98 | 98 |
99 // Returns the path the db files are created in. | 99 // Returns the path the db files are created in. |
100 const base::FilePath& path() const { return tmp_dir_.path(); } | 100 const base::FilePath& path() const { return tmp_dir_.path(); } |
101 | 101 |
102 // This must be destroyed last. | 102 // This must be destroyed last. |
103 base::ScopedTempDir tmp_dir_; | 103 base::ScopedTempDir tmp_dir_; |
104 | 104 |
105 BookmarkModel bookmark_model_; | 105 test::TestBookmarkClient bookmark_client_; |
| 106 scoped_ptr<BookmarkModel> bookmark_model_; |
106 | 107 |
107 base::MessageLoopForUI message_loop_; | 108 base::MessageLoopForUI message_loop_; |
108 content::TestBrowserThread ui_thread_; | 109 content::TestBrowserThread ui_thread_; |
109 content::TestBrowserThread db_thread_; | 110 content::TestBrowserThread db_thread_; |
110 | 111 |
111 ExpireHistoryBackend expirer_; | 112 ExpireHistoryBackend expirer_; |
112 | 113 |
113 scoped_ptr<HistoryDatabase> main_db_; | 114 scoped_ptr<HistoryDatabase> main_db_; |
114 scoped_ptr<ArchivedDatabase> archived_db_; | 115 scoped_ptr<ArchivedDatabase> archived_db_; |
115 scoped_ptr<ThumbnailDatabase> thumb_db_; | 116 scoped_ptr<ThumbnailDatabase> thumb_db_; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 // And no visits. | 514 // And no visits. |
514 VisitVector visits; | 515 VisitVector visits; |
515 main_db_->GetVisitsForURL(url_row.id(), &visits); | 516 main_db_->GetVisitsForURL(url_row.id(), &visits); |
516 ASSERT_EQ(0U, visits.size()); | 517 ASSERT_EQ(0U, visits.size()); |
517 | 518 |
518 // Should still have the thumbnail. | 519 // Should still have the thumbnail. |
519 // TODO(sky): fix this, see comment in HasThumbnail. | 520 // TODO(sky): fix this, see comment in HasThumbnail. |
520 // ASSERT_TRUE(HasThumbnail(url_row.id())); | 521 // ASSERT_TRUE(HasThumbnail(url_row.id())); |
521 | 522 |
522 // Unstar the URL and delete again. | 523 // Unstar the URL and delete again. |
523 bookmark_utils::RemoveAllBookmarks(&bookmark_model_, url); | 524 bookmark_utils::RemoveAllBookmarks(bookmark_model_.get(), url); |
524 ClearLastNotifications(); | 525 ClearLastNotifications(); |
525 expirer_.DeleteURL(url); | 526 expirer_.DeleteURL(url); |
526 | 527 |
527 // Now it should be completely deleted. | 528 // Now it should be completely deleted. |
528 EnsureURLInfoGone(url_row, false); | 529 EnsureURLInfoGone(url_row, false); |
529 } | 530 } |
530 | 531 |
531 // Deletes multiple URLs at once. The favicon for the third one but | 532 // Deletes multiple URLs at once. The favicon for the third one but |
532 // not the first two should be deleted. | 533 // not the first two should be deleted. |
533 TEST_F(ExpireHistoryTest, DeleteURLs) { | 534 TEST_F(ExpireHistoryTest, DeleteURLs) { |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 main_db_->GetVisitsForURL(url_id, &archived_visits); | 951 main_db_->GetVisitsForURL(url_id, &archived_visits); |
951 EXPECT_EQ(0U, archived_visits.size()); | 952 EXPECT_EQ(0U, archived_visits.size()); |
952 } | 953 } |
953 | 954 |
954 // TODO(brettw) add some visits with no URL to make sure everything is updated | 955 // TODO(brettw) add some visits with no URL to make sure everything is updated |
955 // properly. Have the visits also refer to nonexistent FTS rows. | 956 // properly. Have the visits also refer to nonexistent FTS rows. |
956 // | 957 // |
957 // Maybe also refer to invalid favicons. | 958 // Maybe also refer to invalid favicons. |
958 | 959 |
959 } // namespace history | 960 } // namespace history |
OLD | NEW |