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

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

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

Powered by Google App Engine
This is Rietveld 408576698