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 "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 14 matching lines...) Expand all Loading... | |
25 #include "chrome/browser/history/history_notifications.h" | 25 #include "chrome/browser/history/history_notifications.h" |
26 #include "chrome/browser/history/history_service.h" | 26 #include "chrome/browser/history/history_service.h" |
27 #include "chrome/browser/history/history_service_factory.h" | 27 #include "chrome/browser/history/history_service_factory.h" |
28 #include "chrome/browser/history/in_memory_history_backend.h" | 28 #include "chrome/browser/history/in_memory_history_backend.h" |
29 #include "chrome/browser/history/visit_filter.h" | 29 #include "chrome/browser/history/visit_filter.h" |
30 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
31 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
32 #include "chrome/common/importer/imported_favicon_usage.h" | 32 #include "chrome/common/importer/imported_favicon_usage.h" |
33 #include "chrome/test/base/testing_profile.h" | 33 #include "chrome/test/base/testing_profile.h" |
34 #include "components/history/core/browser/history_constants.h" | 34 #include "components/history/core/browser/history_constants.h" |
35 #include "components/history/core/browser/history_service_observer.h" | |
35 #include "components/history/core/browser/in_memory_database.h" | 36 #include "components/history/core/browser/in_memory_database.h" |
36 #include "components/history/core/browser/keyword_search_term.h" | 37 #include "components/history/core/browser/keyword_search_term.h" |
37 #include "components/history/core/test/history_client_fake_bookmarks.h" | 38 #include "components/history/core/test/history_client_fake_bookmarks.h" |
38 #include "content/public/browser/notification_details.h" | 39 #include "content/public/browser/notification_details.h" |
39 #include "content/public/browser/notification_source.h" | 40 #include "content/public/browser/notification_source.h" |
40 #include "content/public/test/test_browser_thread.h" | 41 #include "content/public/test/test_browser_thread.h" |
41 #include "testing/gmock/include/gmock/gmock.h" | 42 #include "testing/gmock/include/gmock/gmock.h" |
42 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
43 #include "third_party/skia/include/core/SkBitmap.h" | 44 #include "third_party/skia/include/core/SkBitmap.h" |
44 #include "ui/gfx/codec/png_codec.h" | 45 #include "ui/gfx/codec/png_codec.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 | 120 |
120 void NotifyProfileError(sql::InitStatus init_status) override {} | 121 void NotifyProfileError(sql::InitStatus init_status) override {} |
121 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) override; | 122 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) override; |
122 void NotifyAddVisit(const BriefVisitInfo& info) override {} | 123 void NotifyAddVisit(const BriefVisitInfo& info) override {} |
123 void NotifyFaviconChanged(const std::set<GURL>& urls) override; | 124 void NotifyFaviconChanged(const std::set<GURL>& urls) override; |
124 void NotifyURLVisited(ui::PageTransition transition, | 125 void NotifyURLVisited(ui::PageTransition transition, |
125 const URLRow& row, | 126 const URLRow& row, |
126 const RedirectList& redirects, | 127 const RedirectList& redirects, |
127 base::Time visit_time) override; | 128 base::Time visit_time) override; |
128 void NotifyURLsModified(const URLRows& changed_urls) override; | 129 void NotifyURLsModified(const URLRows& changed_urls) override; |
130 void NotifyURLsDeleted( | |
131 const history::URLsDeletedDetails& deleted_details) override; | |
129 void BroadcastNotifications(int type, | 132 void BroadcastNotifications(int type, |
130 scoped_ptr<HistoryDetails> details) override; | 133 scoped_ptr<HistoryDetails> details) override; |
131 void DBLoaded() override; | 134 void DBLoaded() override; |
132 | 135 |
133 private: | 136 private: |
134 // Not owned by us. | 137 // Not owned by us. |
135 HistoryBackendTestBase* test_; | 138 HistoryBackendTestBase* test_; |
136 | 139 |
137 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestDelegate); | 140 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestDelegate); |
138 }; | 141 }; |
139 | 142 |
140 class HistoryBackendTestBase : public testing::Test { | 143 class HistoryBackendTestBase : public testing::Test { |
141 public: | 144 public: |
142 typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList; | 145 typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList; |
sdefresne
2014/12/04 17:21:13
This is no longer used, remove.
nshaik
2014/12/07 09:34:49
Done.
| |
143 typedef std::vector<std::pair<ui::PageTransition, URLRow>> URLVisitedList; | 146 typedef std::vector<std::pair<ui::PageTransition, URLRow>> URLVisitedList; |
144 typedef std::vector<URLRows> URLsModifiedList; | 147 typedef std::vector<URLRows> URLsModifiedList; |
148 typedef std::vector<history::URLsDeletedDetails> URLsDeletedList; | |
145 | 149 |
146 HistoryBackendTestBase() | 150 HistoryBackendTestBase() |
147 : loaded_(false), | 151 : loaded_(false), |
148 favicon_changed_notifications_(0), | 152 favicon_changed_notifications_(0), |
149 ui_thread_(content::BrowserThread::UI, &message_loop_) {} | 153 ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
150 | 154 |
151 ~HistoryBackendTestBase() override { | 155 ~HistoryBackendTestBase() override { |
152 STLDeleteValues(&broadcasted_notifications_); | 156 STLDeleteValues(&broadcasted_notifications_); |
sdefresne
2014/12/04 17:21:12
This is no longer used, remove.
nshaik
2014/12/07 09:34:49
Done.
| |
153 } | 157 } |
154 | 158 |
155 protected: | 159 protected: |
156 int favicon_changed_notifications() const { | 160 int favicon_changed_notifications() const { |
157 return favicon_changed_notifications_; | 161 return favicon_changed_notifications_; |
158 } | 162 } |
159 | 163 |
160 void ClearFaviconChangedNotificationCounter() { | 164 void ClearFaviconChangedNotificationCounter() { |
161 favicon_changed_notifications_ = 0; | 165 favicon_changed_notifications_ = 0; |
162 } | 166 } |
163 | 167 |
164 int num_url_visited_notifications() const { | 168 int num_url_visited_notifications() const { |
165 return url_visited_notifications_.size(); | 169 return url_visited_notifications_.size(); |
166 } | 170 } |
167 | 171 |
168 const URLVisitedList& url_visited_notifications() const { | 172 const URLVisitedList& url_visited_notifications() const { |
169 return url_visited_notifications_; | 173 return url_visited_notifications_; |
170 } | 174 } |
171 | 175 |
172 int num_urls_modified_notifications() const { | 176 int num_urls_modified_notifications() const { |
173 return urls_modified_notifications_.size(); | 177 return urls_modified_notifications_.size(); |
174 } | 178 } |
175 | 179 |
176 const URLsModifiedList& urls_modified_notifications() const { | 180 const URLsModifiedList& urls_modified_notifications() const { |
177 return urls_modified_notifications_; | 181 return urls_modified_notifications_; |
178 } | 182 } |
179 | 183 |
184 const URLsDeletedList& urls_deleted_notifications() const { | |
185 return urls_deleted_notifications_; | |
186 } | |
187 | |
180 int num_broadcasted_notifications() const { | 188 int num_broadcasted_notifications() const { |
sdefresne
2014/12/04 17:21:12
This is no longer used, remove.
nshaik
2014/12/07 09:34:49
Done.
| |
181 return broadcasted_notifications_.size(); | 189 return broadcasted_notifications_.size(); |
182 } | 190 } |
183 | 191 |
184 const NotificationList& broadcasted_notifications() const { | 192 const NotificationList& broadcasted_notifications() const { |
sdefresne
2014/12/04 17:21:12
This is no longer used, remove.
sdefresne
2014/12/04 17:21:12
This is no longer used, remove.
nshaik
2014/12/07 09:34:49
Done.
nshaik
2014/12/07 09:34:49
Done.
| |
185 return broadcasted_notifications_; | 193 return broadcasted_notifications_; |
186 } | 194 } |
187 | 195 |
188 void ClearBroadcastedNotifications() { | 196 void ClearBroadcastedNotifications() { |
189 url_visited_notifications_.clear(); | 197 url_visited_notifications_.clear(); |
sdefresne
2014/12/04 17:21:12
Please clear urls_deleted_notifications_ here too.
nshaik
2014/12/07 09:34:49
sorry missed it. done.
| |
190 urls_modified_notifications_.clear(); | 198 urls_modified_notifications_.clear(); |
191 STLDeleteValues(&broadcasted_notifications_); | 199 STLDeleteValues(&broadcasted_notifications_); |
sdefresne
2014/12/04 17:21:12
This is no longer used, remove.
nshaik
2014/12/07 09:34:49
Done.
| |
192 } | 200 } |
193 | 201 |
194 base::FilePath test_dir() { | 202 base::FilePath test_dir() { |
195 return test_dir_; | 203 return test_dir_; |
196 } | 204 } |
197 | 205 |
198 void NotifyFaviconChanged(const std::set<GURL>& changed_favicons) { | 206 void NotifyFaviconChanged(const std::set<GURL>& changed_favicons) { |
199 ++favicon_changed_notifications_; | 207 ++favicon_changed_notifications_; |
200 } | 208 } |
201 | 209 |
202 void NotifyURLVisited(ui::PageTransition transition, | 210 void NotifyURLVisited(ui::PageTransition transition, |
203 const URLRow& row, | 211 const URLRow& row, |
204 const RedirectList& redirects, | 212 const RedirectList& redirects, |
205 base::Time visit_time) { | 213 base::Time visit_time) { |
206 // Send the notifications directly to the in-memory database. | 214 // Send the notifications directly to the in-memory database. |
207 mem_backend_->OnURLVisited(nullptr, transition, row, redirects, visit_time); | 215 mem_backend_->OnURLVisited(nullptr, transition, row, redirects, visit_time); |
208 url_visited_notifications_.push_back(std::make_pair(transition, row)); | 216 url_visited_notifications_.push_back(std::make_pair(transition, row)); |
209 } | 217 } |
210 | 218 |
211 void NotifyURLsModified(const URLRows& changed_urls) { | 219 void NotifyURLsModified(const URLRows& changed_urls) { |
212 // Send the notifications directly to the in-memory database. | 220 // Send the notifications directly to the in-memory database. |
213 mem_backend_->OnURLsModified(nullptr, changed_urls); | 221 mem_backend_->OnURLsModified(nullptr, changed_urls); |
214 urls_modified_notifications_.push_back(changed_urls); | 222 urls_modified_notifications_.push_back(changed_urls); |
215 } | 223 } |
216 | 224 |
225 void NotifyURLsDeleted(const history::URLsDeletedDetails& deleted_details) { | |
226 mem_backend_->OnURLsDeleted(nullptr, deleted_details); | |
227 urls_deleted_notifications_.push_back(deleted_details); | |
228 } | |
229 | |
217 void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) { | 230 void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) { |
218 // Send the notifications directly to the in-memory database. | 231 // Send the notifications directly to the in-memory database. |
219 content::Details<HistoryDetails> det(details.get()); | 232 content::Details<HistoryDetails> det(details.get()); |
sdefresne
2014/12/04 17:21:12
This method should not longer be called, please de
nshaik
2014/12/07 09:34:50
I think this is still needed for chrome::NOTIFICAT
| |
220 mem_backend_->Observe( | 233 mem_backend_->Observe( |
221 type, content::Source<HistoryBackendTestBase>(NULL), det); | 234 type, content::Source<HistoryBackendTestBase>(NULL), det); |
222 | 235 |
223 // The backend passes ownership of the details pointer to us. | 236 // The backend passes ownership of the details pointer to us. |
224 broadcasted_notifications_.push_back( | 237 broadcasted_notifications_.push_back( |
225 std::make_pair(type, details.release())); | 238 std::make_pair(type, details.release())); |
226 } | 239 } |
227 | 240 |
228 history::HistoryClientFakeBookmarks history_client_; | 241 history::HistoryClientFakeBookmarks history_client_; |
229 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. | 242 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. |
(...skipping 22 matching lines...) Expand all Loading... | |
252 base::DeleteFile(test_dir_, true); | 265 base::DeleteFile(test_dir_, true); |
253 base::RunLoop().RunUntilIdle(); | 266 base::RunLoop().RunUntilIdle(); |
254 history_client_.ClearAllBookmarks(); | 267 history_client_.ClearAllBookmarks(); |
255 } | 268 } |
256 | 269 |
257 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) { | 270 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) { |
258 mem_backend_.swap(backend); | 271 mem_backend_.swap(backend); |
259 } | 272 } |
260 | 273 |
261 // The types and details of notifications which were broadcasted. | 274 // The types and details of notifications which were broadcasted. |
262 NotificationList broadcasted_notifications_; | 275 NotificationList broadcasted_notifications_; |
sdefresne
2014/12/04 17:21:13
This is no longer used, remove.
nshaik
2014/12/07 09:34:49
Done.
| |
263 int favicon_changed_notifications_; | 276 int favicon_changed_notifications_; |
264 URLVisitedList url_visited_notifications_; | 277 URLVisitedList url_visited_notifications_; |
265 URLsModifiedList urls_modified_notifications_; | 278 URLsModifiedList urls_modified_notifications_; |
279 URLsDeletedList urls_deleted_notifications_; | |
266 | 280 |
267 base::MessageLoop message_loop_; | 281 base::MessageLoop message_loop_; |
268 base::FilePath test_dir_; | 282 base::FilePath test_dir_; |
269 content::TestBrowserThread ui_thread_; | 283 content::TestBrowserThread ui_thread_; |
270 | 284 |
271 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestBase); | 285 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestBase); |
272 }; | 286 }; |
273 | 287 |
274 void HistoryBackendTestDelegate::SetInMemoryBackend( | 288 void HistoryBackendTestDelegate::SetInMemoryBackend( |
275 scoped_ptr<InMemoryHistoryBackend> backend) { | 289 scoped_ptr<InMemoryHistoryBackend> backend) { |
(...skipping 10 matching lines...) Expand all Loading... | |
286 const RedirectList& redirects, | 300 const RedirectList& redirects, |
287 base::Time visit_time) { | 301 base::Time visit_time) { |
288 test_->NotifyURLVisited(transition, row, redirects, visit_time); | 302 test_->NotifyURLVisited(transition, row, redirects, visit_time); |
289 } | 303 } |
290 | 304 |
291 void HistoryBackendTestDelegate::NotifyURLsModified( | 305 void HistoryBackendTestDelegate::NotifyURLsModified( |
292 const URLRows& changed_urls) { | 306 const URLRows& changed_urls) { |
293 test_->NotifyURLsModified(changed_urls); | 307 test_->NotifyURLsModified(changed_urls); |
294 } | 308 } |
295 | 309 |
310 void HistoryBackendTestDelegate::NotifyURLsDeleted( | |
311 const history::URLsDeletedDetails& deleted_details) { | |
312 test_->NotifyURLsDeleted(deleted_details); | |
313 } | |
314 | |
296 void HistoryBackendTestDelegate::BroadcastNotifications( | 315 void HistoryBackendTestDelegate::BroadcastNotifications( |
297 int type, | 316 int type, |
298 scoped_ptr<HistoryDetails> details) { | 317 scoped_ptr<HistoryDetails> details) { |
299 test_->BroadcastNotifications(type, details.Pass()); | 318 test_->BroadcastNotifications(type, details.Pass()); |
300 } | 319 } |
301 | 320 |
302 void HistoryBackendTestDelegate::DBLoaded() { | 321 void HistoryBackendTestDelegate::DBLoaded() { |
303 test_->loaded_ = true; | 322 test_->loaded_ = true; |
304 } | 323 } |
305 | 324 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 private: | 478 private: |
460 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTest); | 479 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTest); |
461 }; | 480 }; |
462 | 481 |
463 class InMemoryHistoryBackendTest : public HistoryBackendTestBase { | 482 class InMemoryHistoryBackendTest : public HistoryBackendTestBase { |
464 public: | 483 public: |
465 InMemoryHistoryBackendTest() {} | 484 InMemoryHistoryBackendTest() {} |
466 ~InMemoryHistoryBackendTest() override {} | 485 ~InMemoryHistoryBackendTest() override {} |
467 | 486 |
468 protected: | 487 protected: |
469 void SimulateNotification(int type, | 488 void SimulateNotificationURLsDeleted(const URLRow* row1, |
470 const URLRow* row1, | 489 const URLRow* row2 = NULL, |
471 const URLRow* row2 = NULL, | 490 const URLRow* row3 = NULL) { |
472 const URLRow* row3 = NULL) { | |
473 DCHECK(type == chrome::NOTIFICATION_HISTORY_URLS_DELETED); | |
474 | |
475 URLRows rows; | 491 URLRows rows; |
476 rows.push_back(*row1); | 492 rows.push_back(*row1); |
477 if (row2) rows.push_back(*row2); | 493 if (row2) rows.push_back(*row2); |
478 if (row3) rows.push_back(*row3); | 494 if (row3) rows.push_back(*row3); |
479 | 495 |
480 scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails()); | 496 URLsDeletedDetails details; |
481 details->rows = rows; | 497 details.rows = rows; |
482 BroadcastNotifications(type, details.Pass()); | 498 NotifyURLsDeleted(details); |
483 } | 499 } |
484 | 500 |
485 size_t GetNumberOfMatchingSearchTerms(const int keyword_id, | 501 size_t GetNumberOfMatchingSearchTerms(const int keyword_id, |
486 const base::string16& prefix) { | 502 const base::string16& prefix) { |
487 std::vector<KeywordSearchTermVisit> matching_terms; | 503 std::vector<KeywordSearchTermVisit> matching_terms; |
488 mem_backend_->db()->GetMostRecentKeywordSearchTerms( | 504 mem_backend_->db()->GetMostRecentKeywordSearchTerms( |
489 keyword_id, prefix, 1, &matching_terms); | 505 keyword_id, prefix, 1, &matching_terms); |
490 return matching_terms.size(); | 506 return matching_terms.size(); |
491 } | 507 } |
492 | 508 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 std::vector<IconMapping> mappings; | 691 std::vector<IconMapping> mappings; |
676 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 692 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
677 outrow1.url(), favicon_base::FAVICON, &mappings)); | 693 outrow1.url(), favicon_base::FAVICON, &mappings)); |
678 EXPECT_EQ(1u, mappings.size()); | 694 EXPECT_EQ(1u, mappings.size()); |
679 EXPECT_EQ(out_favicon1, mappings[0].icon_id); | 695 EXPECT_EQ(out_favicon1, mappings[0].icon_id); |
680 | 696 |
681 // The first URL should still be bookmarked. | 697 // The first URL should still be bookmarked. |
682 EXPECT_TRUE(history_client_.IsBookmarked(row1.url())); | 698 EXPECT_TRUE(history_client_.IsBookmarked(row1.url())); |
683 | 699 |
684 // Check that we fire the notification about all history having been deleted. | 700 // Check that we fire the notification about all history having been deleted. |
685 ASSERT_EQ(1u, broadcasted_notifications().size()); | 701 ASSERT_EQ(1u, urls_deleted_notifications().size()); |
686 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 702 const URLsDeletedDetails& details = urls_deleted_notifications()[0]; |
687 broadcasted_notifications()[0].first); | 703 EXPECT_TRUE(details.all_history); |
688 const URLsDeletedDetails* details = static_cast<const URLsDeletedDetails*>( | 704 EXPECT_FALSE(details.expired); |
689 broadcasted_notifications()[0].second); | |
690 EXPECT_TRUE(details->all_history); | |
691 EXPECT_FALSE(details->expired); | |
692 } | 705 } |
693 | 706 |
694 // Checks that adding a visit, then calling DeleteAll, and then trying to add | 707 // Checks that adding a visit, then calling DeleteAll, and then trying to add |
695 // data for the visited page works. This can happen when clearing the history | 708 // data for the visited page works. This can happen when clearing the history |
696 // immediately after visiting a page. | 709 // immediately after visiting a page. |
697 TEST_F(HistoryBackendTest, DeleteAllThenAddData) { | 710 TEST_F(HistoryBackendTest, DeleteAllThenAddData) { |
698 ASSERT_TRUE(backend_.get()); | 711 ASSERT_TRUE(backend_.get()); |
699 | 712 |
700 Time visit_time = Time::Now(); | 713 Time visit_time = Time::Now(); |
701 GURL url("http://www.google.com/"); | 714 GURL url("http://www.google.com/"); |
(...skipping 2426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3128 | 3141 |
3129 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedPiecewise) { | 3142 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedPiecewise) { |
3130 // Add two typed and one non-typed URLRow to the in-memory database. | 3143 // Add two typed and one non-typed URLRow to the in-memory database. |
3131 URLRow row1(CreateTestTypedURL()); | 3144 URLRow row1(CreateTestTypedURL()); |
3132 URLRow row2(CreateAnotherTestTypedURL()); | 3145 URLRow row2(CreateAnotherTestTypedURL()); |
3133 URLRow row3(CreateTestNonTypedURL()); | 3146 URLRow row3(CreateTestNonTypedURL()); |
3134 SimulateNotificationURLsModified(mem_backend_.get(), &row1, &row2, &row3); | 3147 SimulateNotificationURLsModified(mem_backend_.get(), &row1, &row2, &row3); |
3135 | 3148 |
3136 // Notify the in-memory database that the second typed URL and the non-typed | 3149 // Notify the in-memory database that the second typed URL and the non-typed |
3137 // URL has been deleted. | 3150 // URL has been deleted. |
3138 SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 3151 SimulateNotificationURLsDeleted(&row2, &row3); |
3139 &row2, &row3); | |
3140 | 3152 |
3141 // Expect that the first typed URL remains intact, the second typed URL is | 3153 // Expect that the first typed URL remains intact, the second typed URL is |
3142 // correctly removed, and the non-typed URL does not magically appear. | 3154 // correctly removed, and the non-typed URL does not magically appear. |
3143 URLRow cached_row1; | 3155 URLRow cached_row1; |
3144 EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1)); | 3156 EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1)); |
3145 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL)); | 3157 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL)); |
3146 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL)); | 3158 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL)); |
3147 EXPECT_EQ(row1.id(), cached_row1.id()); | 3159 EXPECT_EQ(row1.id(), cached_row1.id()); |
3148 } | 3160 } |
3149 | 3161 |
3150 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedEnMasse) { | 3162 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedEnMasse) { |
3151 // Add two typed and one non-typed URLRow to the in-memory database. | 3163 // Add two typed and one non-typed URLRow to the in-memory database. |
3152 URLRow row1(CreateTestTypedURL()); | 3164 URLRow row1(CreateTestTypedURL()); |
3153 URLRow row2(CreateAnotherTestTypedURL()); | 3165 URLRow row2(CreateAnotherTestTypedURL()); |
3154 URLRow row3(CreateTestNonTypedURL()); | 3166 URLRow row3(CreateTestNonTypedURL()); |
3155 SimulateNotificationURLsModified(mem_backend_.get(), &row1, &row2, &row3); | 3167 SimulateNotificationURLsModified(mem_backend_.get(), &row1, &row2, &row3); |
3156 | 3168 |
3157 // Now notify the in-memory database that all history has been deleted. | 3169 // Now notify the in-memory database that all history has been deleted. |
3158 scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails()); | 3170 URLsDeletedDetails details; |
3159 details->all_history = true; | 3171 details.all_history = true; |
3160 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 3172 mem_backend_->OnURLsDeleted(nullptr, details); |
3161 details.Pass()); | |
3162 | 3173 |
3163 // Expect that everything goes away. | 3174 // Expect that everything goes away. |
3164 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), NULL)); | 3175 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), NULL)); |
3165 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL)); | 3176 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL)); |
3166 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL)); | 3177 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL)); |
3167 } | 3178 } |
3168 | 3179 |
3169 void InMemoryHistoryBackendTest::PopulateTestURLsAndSearchTerms( | 3180 void InMemoryHistoryBackendTest::PopulateTestURLsAndSearchTerms( |
3170 URLRow* row1, | 3181 URLRow* row1, |
3171 URLRow* row2, | 3182 URLRow* row2, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3261 } | 3272 } |
3262 | 3273 |
3263 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedWithSearchTerms) { | 3274 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedWithSearchTerms) { |
3264 URLRow row1(CreateTestTypedURL()); | 3275 URLRow row1(CreateTestTypedURL()); |
3265 URLRow row2(CreateTestNonTypedURL()); | 3276 URLRow row2(CreateTestNonTypedURL()); |
3266 base::string16 term1(base::UTF8ToUTF16(kTestSearchTerm1)); | 3277 base::string16 term1(base::UTF8ToUTF16(kTestSearchTerm1)); |
3267 base::string16 term2(base::UTF8ToUTF16(kTestSearchTerm2)); | 3278 base::string16 term2(base::UTF8ToUTF16(kTestSearchTerm2)); |
3268 PopulateTestURLsAndSearchTerms(&row1, &row2, term1, term2); | 3279 PopulateTestURLsAndSearchTerms(&row1, &row2, term1, term2); |
3269 | 3280 |
3270 // Notify the in-memory database that the second typed URL has been deleted. | 3281 // Notify the in-memory database that the second typed URL has been deleted. |
3271 SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_DELETED, &row2); | 3282 SimulateNotificationURLsDeleted(&row2); |
3272 | 3283 |
3273 // Verify that the second term is no longer returned as result, and also check | 3284 // Verify that the second term is no longer returned as result, and also check |
3274 // at the low level that it is gone for good. The term corresponding to the | 3285 // at the low level that it is gone for good. The term corresponding to the |
3275 // first URLRow should not be affected. | 3286 // first URLRow should not be affected. |
3276 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); | 3287 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); |
3277 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); | 3288 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); |
3278 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); | 3289 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); |
3279 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); | 3290 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); |
3280 } | 3291 } |
3281 | 3292 |
3282 } // namespace history | 3293 } // namespace history |
OLD | NEW |