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/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.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/stl_util.h" | |
16 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
17 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
18 #include "chrome/browser/history/expire_history_backend.h" | |
19 #include "chrome/browser/history/history_details.h" | |
20 #include "chrome/browser/history/top_sites.h" | 17 #include "chrome/browser/history/top_sites.h" |
21 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
22 #include "chrome/tools/profiles/thumbnail-inl.h" | 19 #include "chrome/tools/profiles/thumbnail-inl.h" |
| 20 #include "components/history/core/browser/expire_history_backend.h" |
23 #include "components/history/core/browser/history_backend_notifier.h" | 21 #include "components/history/core/browser/history_backend_notifier.h" |
24 #include "components/history/core/browser/history_database.h" | 22 #include "components/history/core/browser/history_database.h" |
25 #include "components/history/core/browser/thumbnail_database.h" | 23 #include "components/history/core/browser/thumbnail_database.h" |
26 #include "components/history/core/common/thumbnail_score.h" | 24 #include "components/history/core/common/thumbnail_score.h" |
27 #include "components/history/core/test/history_client_fake_bookmarks.h" | 25 #include "components/history/core/test/history_client_fake_bookmarks.h" |
28 #include "components/history/core/test/test_history_database.h" | 26 #include "components/history/core/test/test_history_database.h" |
29 #include "content/public/test/test_browser_thread.h" | 27 #include "content/public/test/test_browser_thread.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
32 #include "ui/gfx/codec/jpeg_codec.h" | 30 #include "ui/gfx/codec/jpeg_codec.h" |
(...skipping 23 matching lines...) Expand all Loading... |
56 db_thread_(BrowserThread::DB, &message_loop_), | 54 db_thread_(BrowserThread::DB, &message_loop_), |
57 expirer_(this, &history_client_), | 55 expirer_(this, &history_client_), |
58 now_(Time::Now()) {} | 56 now_(Time::Now()) {} |
59 | 57 |
60 protected: | 58 protected: |
61 // Called by individual tests when they want data populated. | 59 // Called by individual tests when they want data populated. |
62 void AddExampleData(URLID url_ids[3], Time visit_times[4]); | 60 void AddExampleData(URLID url_ids[3], Time visit_times[4]); |
63 // Add visits with source information. | 61 // Add visits with source information. |
64 void AddExampleSourceData(const GURL& url, URLID* id); | 62 void AddExampleSourceData(const GURL& url, URLID* id); |
65 | 63 |
66 // Returns true if the given favicon/thumanil has an entry in the DB. | 64 // Returns true if the given favicon/thumbnail has an entry in the DB. |
67 bool HasFavicon(favicon_base::FaviconID favicon_id); | 65 bool HasFavicon(favicon_base::FaviconID favicon_id); |
68 bool HasThumbnail(URLID url_id); | 66 bool HasThumbnail(URLID url_id); |
69 | 67 |
70 favicon_base::FaviconID GetFavicon(const GURL& page_url, | 68 favicon_base::FaviconID GetFavicon(const GURL& page_url, |
71 favicon_base::IconType icon_type); | 69 favicon_base::IconType icon_type); |
72 | 70 |
73 // EXPECTs that each URL-specific history thing (basically, everything but | 71 // EXPECTs that each URL-specific history thing (basically, everything but |
74 // favicons) is gone, the reason being either that it was automatically | 72 // favicons) is gone, the reason being either that it was automatically |
75 // |expired|, or manually deleted. | 73 // |expired|, or manually deleted. |
76 void EnsureURLInfoGone(const URLRow& row, bool expired); | 74 void EnsureURLInfoGone(const URLRow& row, bool expired); |
77 | 75 |
78 // Returns whether HistoryBackendNotifier::NotifyURLsModified was | 76 // Returns whether HistoryBackendNotifier::NotifyURLsModified was |
79 // called for |url|. | 77 // called for |url|. |
80 bool ModifiedNotificationSent(const GURL& url); | 78 bool ModifiedNotificationSent(const GURL& url); |
81 | 79 |
82 // Clears the list of notifications received. | 80 // Clears the list of notifications received. |
83 void ClearLastNotifications() { | 81 void ClearLastNotifications() { |
84 STLDeleteValues(¬ifications_); | |
85 urls_modified_notifications_.clear(); | 82 urls_modified_notifications_.clear(); |
86 urls_deleted_notifications_.clear(); | 83 urls_deleted_notifications_.clear(); |
87 } | 84 } |
88 | 85 |
89 void StarURL(const GURL& url) { history_client_.AddBookmark(url); } | 86 void StarURL(const GURL& url) { history_client_.AddBookmark(url); } |
90 | 87 |
91 static bool IsStringInFile(const base::FilePath& filename, const char* str); | 88 static bool IsStringInFile(const base::FilePath& filename, const char* str); |
92 | 89 |
93 // Returns the path the db files are created in. | 90 // Returns the path the db files are created in. |
94 const base::FilePath& path() const { return tmp_dir_.path(); } | 91 const base::FilePath& path() const { return tmp_dir_.path(); } |
(...skipping 10 matching lines...) Expand all Loading... |
105 ExpireHistoryBackend expirer_; | 102 ExpireHistoryBackend expirer_; |
106 | 103 |
107 scoped_ptr<HistoryDatabase> main_db_; | 104 scoped_ptr<HistoryDatabase> main_db_; |
108 scoped_ptr<ThumbnailDatabase> thumb_db_; | 105 scoped_ptr<ThumbnailDatabase> thumb_db_; |
109 TestingProfile profile_; | 106 TestingProfile profile_; |
110 scoped_refptr<TopSites> top_sites_; | 107 scoped_refptr<TopSites> top_sites_; |
111 | 108 |
112 // Time at the beginning of the test, so everybody agrees what "now" is. | 109 // Time at the beginning of the test, so everybody agrees what "now" is. |
113 const Time now_; | 110 const Time now_; |
114 | 111 |
115 // Notifications intended to be broadcast, we can check these values to make | 112 // Details received from HistoryObserver events. |
116 // sure that the deletor is doing the correct broadcasts. We own the details | |
117 // pointers. | |
118 typedef std::vector< std::pair<int, HistoryDetails*> > | |
119 NotificationList; | |
120 NotificationList notifications_; | |
121 | |
122 typedef std::vector<URLRows> URLsModifiedNotificationList; | 113 typedef std::vector<URLRows> URLsModifiedNotificationList; |
123 URLsModifiedNotificationList urls_modified_notifications_; | 114 URLsModifiedNotificationList urls_modified_notifications_; |
124 | 115 |
125 typedef std::vector<std::pair<bool, URLRows>> URLsDeletedNotificationList; | 116 typedef std::vector<std::pair<bool, URLRows>> URLsDeletedNotificationList; |
126 URLsDeletedNotificationList urls_deleted_notifications_; | 117 URLsDeletedNotificationList urls_deleted_notifications_; |
127 | 118 |
128 private: | 119 private: |
129 void SetUp() override { | 120 void SetUp() override { |
130 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); | 121 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); |
131 | 122 |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1)); | 866 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1)); |
876 EXPECT_EQ(1U, visits.size()); | 867 EXPECT_EQ(1U, visits.size()); |
877 } | 868 } |
878 | 869 |
879 // TODO(brettw) add some visits with no URL to make sure everything is updated | 870 // TODO(brettw) add some visits with no URL to make sure everything is updated |
880 // properly. Have the visits also refer to nonexistent FTS rows. | 871 // properly. Have the visits also refer to nonexistent FTS rows. |
881 // | 872 // |
882 // Maybe also refer to invalid favicons. | 873 // Maybe also refer to invalid favicons. |
883 | 874 |
884 } // namespace history | 875 } // namespace history |
OLD | NEW |