Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: chrome/browser/history/history_backend_unittest.cc

Issue 694843002: Remove NOTIFICATION_HISTORY_URLS_MODIFIED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/history/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 rows.push_back(*row3); 82 rows.push_back(*row3);
83 83
84 base::Time visit_time; 84 base::Time visit_time;
85 history::RedirectList redirects; 85 history::RedirectList redirects;
86 for (const auto& row : rows) { 86 for (const auto& row : rows) {
87 observer->OnURLVisited( 87 observer->OnURLVisited(
88 nullptr, ui::PAGE_TRANSITION_LINK, row, redirects, visit_time); 88 nullptr, ui::PAGE_TRANSITION_LINK, row, redirects, visit_time);
89 } 89 }
90 } 90 }
91 91
92 void SimulateNotificationURLsModified(history::HistoryServiceObserver* observer,
93 const history::URLRow* row1,
94 const history::URLRow* row2,
95 const history::URLRow* row3) {
96 history::URLRows rows;
97 rows.push_back(*row1);
98 if (row2)
99 rows.push_back(*row2);
100 if (row3)
101 rows.push_back(*row3);
102
103 observer->OnURLsModified(nullptr, rows);
104 }
105
92 } // namespace 106 } // namespace
93 107
94 namespace history { 108 namespace history {
95 109
96 class HistoryBackendTestBase; 110 class HistoryBackendTestBase;
97 111
98 // This must be a separate object since HistoryBackend manages its lifetime. 112 // This must be a separate object since HistoryBackend manages its lifetime.
99 // This just forwards the messages we're interested in to the test object. 113 // This just forwards the messages we're interested in to the test object.
100 class HistoryBackendTestDelegate : public HistoryBackend::Delegate { 114 class HistoryBackendTestDelegate : public HistoryBackend::Delegate {
101 public: 115 public:
102 explicit HistoryBackendTestDelegate(HistoryBackendTestBase* test) 116 explicit HistoryBackendTestDelegate(HistoryBackendTestBase* test)
103 : test_(test) {} 117 : test_(test) {}
104 118
105 void NotifyProfileError(sql::InitStatus init_status) override {} 119 void NotifyProfileError(sql::InitStatus init_status) override {}
106 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) override; 120 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) override;
107 void NotifyAddVisit(const BriefVisitInfo& info) override {} 121 void NotifyAddVisit(const BriefVisitInfo& info) override {}
108 void NotifyFaviconChanged(const std::set<GURL>& urls) override; 122 void NotifyFaviconChanged(const std::set<GURL>& urls) override;
109 void NotifyURLVisited(ui::PageTransition transition, 123 void NotifyURLVisited(ui::PageTransition transition,
110 const URLRow& row, 124 const URLRow& row,
111 const RedirectList& redirects, 125 const RedirectList& redirects,
112 base::Time visit_time) override; 126 base::Time visit_time) override;
127 void NotifyURLsModified(const URLRows& changed_urls) override;
113 void BroadcastNotifications(int type, 128 void BroadcastNotifications(int type,
114 scoped_ptr<HistoryDetails> details) override; 129 scoped_ptr<HistoryDetails> details) override;
115 void DBLoaded() override; 130 void DBLoaded() override;
116 131
117 private: 132 private:
118 // Not owned by us. 133 // Not owned by us.
119 HistoryBackendTestBase* test_; 134 HistoryBackendTestBase* test_;
120 135
121 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestDelegate); 136 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestDelegate);
122 }; 137 };
123 138
124 class HistoryBackendTestBase : public testing::Test { 139 class HistoryBackendTestBase : public testing::Test {
125 public: 140 public:
126 typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList; 141 typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList;
127 typedef std::vector<std::pair<ui::PageTransition, URLRow>> URLVisitedList; 142 typedef std::vector<std::pair<ui::PageTransition, URLRow>> URLVisitedList;
143 typedef std::vector<URLRows> URLsModifiedList;
128 144
129 HistoryBackendTestBase() 145 HistoryBackendTestBase()
130 : loaded_(false), 146 : loaded_(false),
131 favicon_changed_notifications_(0), 147 favicon_changed_notifications_(0),
132 ui_thread_(content::BrowserThread::UI, &message_loop_) {} 148 ui_thread_(content::BrowserThread::UI, &message_loop_) {}
133 149
134 ~HistoryBackendTestBase() override { 150 ~HistoryBackendTestBase() override {
135 STLDeleteValues(&broadcasted_notifications_); 151 STLDeleteValues(&broadcasted_notifications_);
136 } 152 }
137 153
138 protected: 154 protected:
139 int favicon_changed_notifications() const { 155 int favicon_changed_notifications() const {
140 return favicon_changed_notifications_; 156 return favicon_changed_notifications_;
141 } 157 }
142 158
143 void ClearFaviconChangedNotificationCounter() { 159 void ClearFaviconChangedNotificationCounter() {
144 favicon_changed_notifications_ = 0; 160 favicon_changed_notifications_ = 0;
145 } 161 }
146 162
147 int num_url_visited_notifications() const { 163 int num_url_visited_notifications() const {
148 return url_visited_notifications_.size(); 164 return url_visited_notifications_.size();
149 } 165 }
150 166
151 const URLVisitedList& url_visited_notifications() const { 167 const URLVisitedList& url_visited_notifications() const {
152 return url_visited_notifications_; 168 return url_visited_notifications_;
153 } 169 }
154 170
171 int num_urls_modified_notifications() const {
172 return urls_modified_notifications_.size();
173 }
174
175 const URLsModifiedList& urls_modified_notifications() const {
176 return urls_modified_notifications_;
177 }
178
155 int num_broadcasted_notifications() const { 179 int num_broadcasted_notifications() const {
156 return broadcasted_notifications_.size(); 180 return broadcasted_notifications_.size();
157 } 181 }
158 182
159 const NotificationList& broadcasted_notifications() const { 183 const NotificationList& broadcasted_notifications() const {
160 return broadcasted_notifications_; 184 return broadcasted_notifications_;
161 } 185 }
162 186
163 void ClearBroadcastedNotifications() { 187 void ClearBroadcastedNotifications() {
164 url_visited_notifications_.clear(); 188 url_visited_notifications_.clear();
189 urls_modified_notifications_.clear();
165 STLDeleteValues(&broadcasted_notifications_); 190 STLDeleteValues(&broadcasted_notifications_);
166 } 191 }
167 192
168 base::FilePath test_dir() { 193 base::FilePath test_dir() {
169 return test_dir_; 194 return test_dir_;
170 } 195 }
171 196
172 void NotifyFaviconChanged(const std::set<GURL>& changed_favicons) { 197 void NotifyFaviconChanged(const std::set<GURL>& changed_favicons) {
173 ++favicon_changed_notifications_; 198 ++favicon_changed_notifications_;
174 } 199 }
175 200
176 void NotifyURLVisited(ui::PageTransition transition, 201 void NotifyURLVisited(ui::PageTransition transition,
177 const URLRow& row, 202 const URLRow& row,
178 const RedirectList& redirects, 203 const RedirectList& redirects,
179 base::Time visit_time) { 204 base::Time visit_time) {
205 // Send the notifications directly to the in-memory database.
206 mem_backend_->OnURLVisited(nullptr, transition, row, redirects, visit_time);
180 url_visited_notifications_.push_back(std::make_pair(transition, row)); 207 url_visited_notifications_.push_back(std::make_pair(transition, row));
181 } 208 }
182 209
210 void NotifyURLsModified(const URLRows& changed_urls) {
211 // Send the notifications directly to the in-memory database.
212 mem_backend_->OnURLsModified(nullptr, changed_urls);
213 urls_modified_notifications_.push_back(changed_urls);
214 }
215
183 void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) { 216 void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) {
184 // Send the notifications directly to the in-memory database. 217 // Send the notifications directly to the in-memory database.
185 content::Details<HistoryDetails> det(details.get()); 218 content::Details<HistoryDetails> det(details.get());
186 mem_backend_->Observe( 219 mem_backend_->Observe(
187 type, content::Source<HistoryBackendTestBase>(NULL), det); 220 type, content::Source<HistoryBackendTestBase>(NULL), det);
188 221
189 // The backend passes ownership of the details pointer to us. 222 // The backend passes ownership of the details pointer to us.
190 broadcasted_notifications_.push_back( 223 broadcasted_notifications_.push_back(
191 std::make_pair(type, details.release())); 224 std::make_pair(type, details.release()));
192 } 225 }
(...skipping 28 matching lines...) Expand all
221 } 254 }
222 255
223 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) { 256 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) {
224 mem_backend_.swap(backend); 257 mem_backend_.swap(backend);
225 } 258 }
226 259
227 // The types and details of notifications which were broadcasted. 260 // The types and details of notifications which were broadcasted.
228 NotificationList broadcasted_notifications_; 261 NotificationList broadcasted_notifications_;
229 int favicon_changed_notifications_; 262 int favicon_changed_notifications_;
230 URLVisitedList url_visited_notifications_; 263 URLVisitedList url_visited_notifications_;
264 URLsModifiedList urls_modified_notifications_;
231 265
232 base::MessageLoop message_loop_; 266 base::MessageLoop message_loop_;
233 base::FilePath test_dir_; 267 base::FilePath test_dir_;
234 content::TestBrowserThread ui_thread_; 268 content::TestBrowserThread ui_thread_;
235 269
236 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestBase); 270 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestBase);
237 }; 271 };
238 272
239 void HistoryBackendTestDelegate::SetInMemoryBackend( 273 void HistoryBackendTestDelegate::SetInMemoryBackend(
240 scoped_ptr<InMemoryHistoryBackend> backend) { 274 scoped_ptr<InMemoryHistoryBackend> backend) {
241 test_->SetInMemoryBackend(backend.Pass()); 275 test_->SetInMemoryBackend(backend.Pass());
242 } 276 }
243 277
244 void HistoryBackendTestDelegate::NotifyFaviconChanged( 278 void HistoryBackendTestDelegate::NotifyFaviconChanged(
245 const std::set<GURL>& changed_favicons) { 279 const std::set<GURL>& changed_favicons) {
246 test_->NotifyFaviconChanged(changed_favicons); 280 test_->NotifyFaviconChanged(changed_favicons);
247 } 281 }
248 282
249 void HistoryBackendTestDelegate::NotifyURLVisited(ui::PageTransition transition, 283 void HistoryBackendTestDelegate::NotifyURLVisited(ui::PageTransition transition,
250 const URLRow& row, 284 const URLRow& row,
251 const RedirectList& redirects, 285 const RedirectList& redirects,
252 base::Time visit_time) { 286 base::Time visit_time) {
253 test_->NotifyURLVisited(transition, row, redirects, visit_time); 287 test_->NotifyURLVisited(transition, row, redirects, visit_time);
254 } 288 }
255 289
290 void HistoryBackendTestDelegate::NotifyURLsModified(
291 const URLRows& changed_urls) {
292 test_->NotifyURLsModified(changed_urls);
293 }
294
256 void HistoryBackendTestDelegate::BroadcastNotifications( 295 void HistoryBackendTestDelegate::BroadcastNotifications(
257 int type, 296 int type,
258 scoped_ptr<HistoryDetails> details) { 297 scoped_ptr<HistoryDetails> details) {
259 test_->BroadcastNotifications(type, details.Pass()); 298 test_->BroadcastNotifications(type, details.Pass());
260 } 299 }
261 300
262 void HistoryBackendTestDelegate::DBLoaded() { 301 void HistoryBackendTestDelegate::DBLoaded() {
263 test_->loaded_ = true; 302 test_->loaded_ = true;
264 } 303 }
265 304
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 457
419 private: 458 private:
420 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTest); 459 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTest);
421 }; 460 };
422 461
423 class InMemoryHistoryBackendTest : public HistoryBackendTestBase { 462 class InMemoryHistoryBackendTest : public HistoryBackendTestBase {
424 public: 463 public:
425 InMemoryHistoryBackendTest() {} 464 InMemoryHistoryBackendTest() {}
426 ~InMemoryHistoryBackendTest() override {} 465 ~InMemoryHistoryBackendTest() override {}
427 466
428 // Public so that the method can be bound in test fixture using 467 protected:
429 // base::Bind(&InMemoryHistoryBackendTest::SimulateNotification, ...).
430 void SimulateNotification(int type, 468 void SimulateNotification(int type,
431 const URLRow* row1, 469 const URLRow* row1,
432 const URLRow* row2 = NULL, 470 const URLRow* row2 = NULL,
433 const URLRow* row3 = NULL) { 471 const URLRow* row3 = NULL) {
472 DCHECK(type == chrome::NOTIFICATION_HISTORY_URLS_DELETED);
473
434 URLRows rows; 474 URLRows rows;
435 rows.push_back(*row1); 475 rows.push_back(*row1);
436 if (row2) rows.push_back(*row2); 476 if (row2) rows.push_back(*row2);
437 if (row3) rows.push_back(*row3); 477 if (row3) rows.push_back(*row3);
438 478
439 if (type == chrome::NOTIFICATION_HISTORY_URLS_MODIFIED) { 479 scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails());
440 scoped_ptr<URLsModifiedDetails> details(new URLsModifiedDetails()); 480 details->rows = rows;
441 details->changed_urls.swap(rows); 481 BroadcastNotifications(type, details.Pass());
442 BroadcastNotifications(type, details.Pass());
443 } else if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) {
444 scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails());
445 details->rows = rows;
446 BroadcastNotifications(type, details.Pass());
447 } else {
448 NOTREACHED();
449 }
450 } 482 }
451 483
452 protected:
453 size_t GetNumberOfMatchingSearchTerms(const int keyword_id, 484 size_t GetNumberOfMatchingSearchTerms(const int keyword_id,
454 const base::string16& prefix) { 485 const base::string16& prefix) {
455 std::vector<KeywordSearchTermVisit> matching_terms; 486 std::vector<KeywordSearchTermVisit> matching_terms;
456 mem_backend_->db()->GetMostRecentKeywordSearchTerms( 487 mem_backend_->db()->GetMostRecentKeywordSearchTerms(
457 keyword_id, prefix, 1, &matching_terms); 488 keyword_id, prefix, 1, &matching_terms);
458 return matching_terms.size(); 489 return matching_terms.size();
459 } 490 }
460 491
461 static URLRow CreateTestTypedURL() { 492 static URLRow CreateTestTypedURL() {
462 URLRow url_row(GURL("https://www.google.com/")); 493 URLRow url_row(GURL("https://www.google.com/"));
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 URLRow stored_row1, stored_row2, stored_row3, stored_row4; 943 URLRow stored_row1, stored_row2, stored_row3, stored_row4;
913 EXPECT_NE(0, backend_->db_->GetRowForURL(row1.url(), &stored_row1)); 944 EXPECT_NE(0, backend_->db_->GetRowForURL(row1.url(), &stored_row1));
914 EXPECT_NE(0, backend_->db_->GetRowForURL(row2.url(), &stored_row2)); 945 EXPECT_NE(0, backend_->db_->GetRowForURL(row2.url(), &stored_row2));
915 EXPECT_NE(0, backend_->db_->GetRowForURL(row3.url(), &stored_row3)); 946 EXPECT_NE(0, backend_->db_->GetRowForURL(row3.url(), &stored_row3));
916 EXPECT_EQ(0, backend_->db_->GetRowForURL(row4.url(), &stored_row4)); 947 EXPECT_EQ(0, backend_->db_->GetRowForURL(row4.url(), &stored_row4));
917 948
918 // Ensure that a notification was fired for both typed and non-typed URLs. 949 // Ensure that a notification was fired for both typed and non-typed URLs.
919 // Further verify that the IDs in the notification are set to those that are 950 // Further verify that the IDs in the notification are set to those that are
920 // in effect in the main database. The InMemoryHistoryBackend relies on this 951 // in effect in the main database. The InMemoryHistoryBackend relies on this
921 // for caching. 952 // for caching.
922 ASSERT_EQ(1u, broadcasted_notifications().size()); 953 ASSERT_EQ(1, num_urls_modified_notifications());
923 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
924 broadcasted_notifications()[0].first);
925 const URLsModifiedDetails* details = static_cast<const URLsModifiedDetails*>(
926 broadcasted_notifications()[0].second);
927 EXPECT_EQ(3u, details->changed_urls.size());
928 954
929 URLRows::const_iterator it_row1 = std::find_if( 955 const URLRows& changed_urls = urls_modified_notifications()[0];
930 details->changed_urls.begin(), 956 EXPECT_EQ(3u, changed_urls.size());
931 details->changed_urls.end(), 957
932 history::URLRow::URLRowHasURL(row1.url())); 958 URLRows::const_iterator it_row1 =
933 ASSERT_NE(details->changed_urls.end(), it_row1); 959 std::find_if(changed_urls.begin(),
960 changed_urls.end(),
961 history::URLRow::URLRowHasURL(row1.url()));
962 ASSERT_NE(changed_urls.end(), it_row1);
934 EXPECT_EQ(stored_row1.id(), it_row1->id()); 963 EXPECT_EQ(stored_row1.id(), it_row1->id());
935 964
936 URLRows::const_iterator it_row2 = std::find_if( 965 URLRows::const_iterator it_row2 =
937 details->changed_urls.begin(), 966 std::find_if(changed_urls.begin(),
938 details->changed_urls.end(), 967 changed_urls.end(),
939 history::URLRow::URLRowHasURL(row2.url())); 968 history::URLRow::URLRowHasURL(row2.url()));
940 ASSERT_NE(details->changed_urls.end(), it_row2); 969 ASSERT_NE(changed_urls.end(), it_row2);
941 EXPECT_EQ(stored_row2.id(), it_row2->id()); 970 EXPECT_EQ(stored_row2.id(), it_row2->id());
942 971
943 URLRows::const_iterator it_row3 = std::find_if( 972 URLRows::const_iterator it_row3 =
944 details->changed_urls.begin(), 973 std::find_if(changed_urls.begin(),
945 details->changed_urls.end(), 974 changed_urls.end(),
946 history::URLRow::URLRowHasURL(row3.url())); 975 history::URLRow::URLRowHasURL(row3.url()));
947 ASSERT_NE(details->changed_urls.end(), it_row3); 976 ASSERT_NE(changed_urls.end(), it_row3);
948 EXPECT_EQ(stored_row3.id(), it_row3->id()); 977 EXPECT_EQ(stored_row3.id(), it_row3->id());
949 } 978 }
950 979
951 TEST_F(HistoryBackendTest, UpdateURLs) { 980 TEST_F(HistoryBackendTest, UpdateURLs) {
952 ASSERT_TRUE(backend_.get()); 981 ASSERT_TRUE(backend_.get());
953 982
954 // Add three pages directly to the database. 983 // Add three pages directly to the database.
955 URLRow row1(GURL("https://news.google.com/")); 984 URLRow row1(GURL("https://news.google.com/"));
956 row1.set_visit_count(1); 985 row1.set_visit_count(1);
957 row1.set_last_visit(Time::Now()); 986 row1.set_last_visit(Time::Now());
(...skipping 30 matching lines...) Expand all
988 1017
989 URLRow stored_row1, stored_row3; 1018 URLRow stored_row1, stored_row3;
990 EXPECT_NE(0, backend_->db_->GetRowForURL(row1.url(), &stored_row1)); 1019 EXPECT_NE(0, backend_->db_->GetRowForURL(row1.url(), &stored_row1));
991 EXPECT_NE(0, backend_->db_->GetRowForURL(row3.url(), &stored_row3)); 1020 EXPECT_NE(0, backend_->db_->GetRowForURL(row3.url(), &stored_row3));
992 EXPECT_EQ(altered_row1.visit_count(), stored_row1.visit_count()); 1021 EXPECT_EQ(altered_row1.visit_count(), stored_row1.visit_count());
993 EXPECT_EQ(altered_row3.visit_count(), stored_row3.visit_count()); 1022 EXPECT_EQ(altered_row3.visit_count(), stored_row3.visit_count());
994 1023
995 // Ensure that a notification was fired, and further verify that the IDs in 1024 // Ensure that a notification was fired, and further verify that the IDs in
996 // the notification are set to those that are in effect in the main database. 1025 // the notification are set to those that are in effect in the main database.
997 // The InMemoryHistoryBackend relies on this for caching. 1026 // The InMemoryHistoryBackend relies on this for caching.
998 ASSERT_EQ(1u, broadcasted_notifications().size()); 1027 ASSERT_EQ(1, num_urls_modified_notifications());
999 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, 1028
1000 broadcasted_notifications()[0].first); 1029 const URLRows& changed_urls = urls_modified_notifications()[0];
1001 const URLsModifiedDetails* details = static_cast<const URLsModifiedDetails*>( 1030 EXPECT_EQ(2u, changed_urls.size());
1002 broadcasted_notifications()[0].second);
1003 EXPECT_EQ(2u, details->changed_urls.size());
1004 1031
1005 URLRows::const_iterator it_row1 = 1032 URLRows::const_iterator it_row1 =
1006 std::find_if(details->changed_urls.begin(), 1033 std::find_if(changed_urls.begin(),
1007 details->changed_urls.end(), 1034 changed_urls.end(),
1008 history::URLRow::URLRowHasURL(row1.url())); 1035 history::URLRow::URLRowHasURL(row1.url()));
1009 ASSERT_NE(details->changed_urls.end(), it_row1); 1036 ASSERT_NE(changed_urls.end(), it_row1);
1010 EXPECT_EQ(altered_row1.id(), it_row1->id()); 1037 EXPECT_EQ(altered_row1.id(), it_row1->id());
1011 EXPECT_EQ(altered_row1.visit_count(), it_row1->visit_count()); 1038 EXPECT_EQ(altered_row1.visit_count(), it_row1->visit_count());
1012 1039
1013 URLRows::const_iterator it_row3 = 1040 URLRows::const_iterator it_row3 =
1014 std::find_if(details->changed_urls.begin(), 1041 std::find_if(changed_urls.begin(),
1015 details->changed_urls.end(), 1042 changed_urls.end(),
1016 history::URLRow::URLRowHasURL(row3.url())); 1043 history::URLRow::URLRowHasURL(row3.url()));
1017 ASSERT_NE(details->changed_urls.end(), it_row3); 1044 ASSERT_NE(changed_urls.end(), it_row3);
1018 EXPECT_EQ(altered_row3.id(), it_row3->id()); 1045 EXPECT_EQ(altered_row3.id(), it_row3->id());
1019 EXPECT_EQ(altered_row3.visit_count(), it_row3->visit_count()); 1046 EXPECT_EQ(altered_row3.visit_count(), it_row3->visit_count());
1020 } 1047 }
1021 1048
1022 // This verifies that a notification is fired. In-depth testing of logic should 1049 // This verifies that a notification is fired. In-depth testing of logic should
1023 // be done in HistoryTest.SetTitle. 1050 // be done in HistoryTest.SetTitle.
1024 TEST_F(HistoryBackendTest, SetPageTitleFiresNotificationWithCorrectDetails) { 1051 TEST_F(HistoryBackendTest, SetPageTitleFiresNotificationWithCorrectDetails) {
1025 const char kTestUrlTitle[] = "Google Search"; 1052 const char kTestUrlTitle[] = "Google Search";
1026 1053
1027 ASSERT_TRUE(backend_.get()); 1054 ASSERT_TRUE(backend_.get());
(...skipping 12 matching lines...) Expand all
1040 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); 1067 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED);
1041 1068
1042 ClearBroadcastedNotifications(); 1069 ClearBroadcastedNotifications();
1043 backend_->SetPageTitle(row2.url(), base::UTF8ToUTF16(kTestUrlTitle)); 1070 backend_->SetPageTitle(row2.url(), base::UTF8ToUTF16(kTestUrlTitle));
1044 1071
1045 // Ensure that a notification was fired, and further verify that the IDs in 1072 // Ensure that a notification was fired, and further verify that the IDs in
1046 // the notification are set to those that are in effect in the main database. 1073 // the notification are set to those that are in effect in the main database.
1047 // The InMemoryHistoryBackend relies on this for caching. 1074 // The InMemoryHistoryBackend relies on this for caching.
1048 URLRow stored_row2; 1075 URLRow stored_row2;
1049 EXPECT_TRUE(backend_->GetURL(row2.url(), &stored_row2)); 1076 EXPECT_TRUE(backend_->GetURL(row2.url(), &stored_row2));
1050 ASSERT_EQ(1u, broadcasted_notifications().size()); 1077 ASSERT_EQ(1, num_urls_modified_notifications());
1051 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, 1078
1052 broadcasted_notifications()[0].first); 1079 const URLRows& changed_urls = urls_modified_notifications()[0];
1053 const URLsModifiedDetails* details = static_cast<const URLsModifiedDetails*>( 1080 ASSERT_EQ(1u, changed_urls.size());
1054 broadcasted_notifications()[0].second); 1081 EXPECT_EQ(base::UTF8ToUTF16(kTestUrlTitle), changed_urls[0].title());
1055 ASSERT_EQ(1u, details->changed_urls.size()); 1082 EXPECT_EQ(stored_row2.id(), changed_urls[0].id());
1056 EXPECT_EQ(base::UTF8ToUTF16(kTestUrlTitle), details->changed_urls[0].title());
1057 EXPECT_EQ(stored_row2.id(), details->changed_urls[0].id());
1058 } 1083 }
1059 1084
1060 // There's no importer on Android. 1085 // There's no importer on Android.
1061 #if !defined(OS_ANDROID) 1086 #if !defined(OS_ANDROID)
1062 TEST_F(HistoryBackendTest, ImportedFaviconsTest) { 1087 TEST_F(HistoryBackendTest, ImportedFaviconsTest) {
1063 // Setup test data - two Urls in the history, one with favicon assigned and 1088 // Setup test data - two Urls in the history, one with favicon assigned and
1064 // one without. 1089 // one without.
1065 GURL favicon_url1("http://www.google.com/favicon.ico"); 1090 GURL favicon_url1("http://www.google.com/favicon.ico");
1066 std::vector<unsigned char> data; 1091 std::vector<unsigned char> data;
1067 data.push_back('1'); 1092 data.push_back('1');
(...skipping 2018 matching lines...) Expand 10 before | Expand all | Expand 10 after
3086 // The in-memory database should stop caching the first URLRow, and start 3111 // The in-memory database should stop caching the first URLRow, and start
3087 // caching the second URLRow. 3112 // caching the second URLRow.
3088 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1)); 3113 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1));
3089 EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row2.url(), &cached_row2)); 3114 EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row2.url(), &cached_row2));
3090 EXPECT_EQ(row2.id(), cached_row2.id()); 3115 EXPECT_EQ(row2.id(), cached_row2.id());
3091 EXPECT_EQ(base::UTF8ToUTF16(kTestNonTypedURLAlternativeTitle), 3116 EXPECT_EQ(base::UTF8ToUTF16(kTestNonTypedURLAlternativeTitle),
3092 cached_row2.title()); 3117 cached_row2.title());
3093 } 3118 }
3094 3119
3095 TEST_F(InMemoryHistoryBackendTest, OnURLsModified) { 3120 TEST_F(InMemoryHistoryBackendTest, OnURLsModified) {
3096 TestAddingAndChangingURLRows( 3121 TestAddingAndChangingURLRows(base::Bind(
3097 base::Bind(&InMemoryHistoryBackendTest::SimulateNotification, 3122 &SimulateNotificationURLsModified, base::Unretained(mem_backend_.get())));
3098 base::Unretained(this),
3099 chrome::NOTIFICATION_HISTORY_URLS_MODIFIED));
3100 } 3123 }
3101 3124
3102 TEST_F(InMemoryHistoryBackendTest, OnURLsVisisted) { 3125 TEST_F(InMemoryHistoryBackendTest, OnURLsVisisted) {
3103 TestAddingAndChangingURLRows(base::Bind( 3126 TestAddingAndChangingURLRows(base::Bind(
3104 &SimulateNotificationURLVisited, base::Unretained(mem_backend_.get()))); 3127 &SimulateNotificationURLVisited, base::Unretained(mem_backend_.get())));
3105 } 3128 }
3106 3129
3107 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedPiecewise) { 3130 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedPiecewise) {
3108 // Add two typed and one non-typed URLRow to the in-memory database. 3131 // Add two typed and one non-typed URLRow to the in-memory database.
3109 URLRow row1(CreateTestTypedURL()); 3132 URLRow row1(CreateTestTypedURL());
3110 URLRow row2(CreateAnotherTestTypedURL()); 3133 URLRow row2(CreateAnotherTestTypedURL());
3111 URLRow row3(CreateTestNonTypedURL()); 3134 URLRow row3(CreateTestNonTypedURL());
3112 SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, 3135 SimulateNotificationURLsModified(mem_backend_.get(), &row1, &row2, &row3);
3113 &row1, &row2, &row3);
3114 3136
3115 // Notify the in-memory database that the second typed URL and the non-typed 3137 // Notify the in-memory database that the second typed URL and the non-typed
3116 // URL has been deleted. 3138 // URL has been deleted.
3117 SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_DELETED, 3139 SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
3118 &row2, &row3); 3140 &row2, &row3);
3119 3141
3120 // Expect that the first typed URL remains intact, the second typed URL is 3142 // Expect that the first typed URL remains intact, the second typed URL is
3121 // correctly removed, and the non-typed URL does not magically appear. 3143 // correctly removed, and the non-typed URL does not magically appear.
3122 URLRow cached_row1; 3144 URLRow cached_row1;
3123 EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1)); 3145 EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1));
3124 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL)); 3146 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL));
3125 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL)); 3147 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL));
3126 EXPECT_EQ(row1.id(), cached_row1.id()); 3148 EXPECT_EQ(row1.id(), cached_row1.id());
3127 } 3149 }
3128 3150
3129 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedEnMasse) { 3151 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedEnMasse) {
3130 // Add two typed and one non-typed URLRow to the in-memory database. 3152 // Add two typed and one non-typed URLRow to the in-memory database.
3131 URLRow row1(CreateTestTypedURL()); 3153 URLRow row1(CreateTestTypedURL());
3132 URLRow row2(CreateAnotherTestTypedURL()); 3154 URLRow row2(CreateAnotherTestTypedURL());
3133 URLRow row3(CreateTestNonTypedURL()); 3155 URLRow row3(CreateTestNonTypedURL());
3134 SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, 3156 SimulateNotificationURLsModified(mem_backend_.get(), &row1, &row2, &row3);
3135 &row1, &row2, &row3);
3136 3157
3137 // Now notify the in-memory database that all history has been deleted. 3158 // Now notify the in-memory database that all history has been deleted.
3138 scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails()); 3159 scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails());
3139 details->all_history = true; 3160 details->all_history = true;
3140 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED, 3161 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
3141 details.Pass()); 3162 details.Pass());
3142 3163
3143 // Expect that everything goes away. 3164 // Expect that everything goes away.
3144 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), NULL)); 3165 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), NULL));
3145 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL)); 3166 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
3253 // Verify that the second term is no longer returned as result, and also check 3274 // Verify that the second term is no longer returned as result, and also check
3254 // at the low level that it is gone for good. The term corresponding to the 3275 // at the low level that it is gone for good. The term corresponding to the
3255 // first URLRow should not be affected. 3276 // first URLRow should not be affected.
3256 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); 3277 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
3257 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); 3278 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
3258 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); 3279 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
3259 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); 3280 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
3260 } 3281 }
3261 3282
3262 } // namespace history 3283 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698