| 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 |
| 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/common/chrome_constants.h" | 27 #include "chrome/common/chrome_constants.h" |
| 30 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
| 31 #include "chrome/common/importer/imported_favicon_usage.h" | 29 #include "chrome/common/importer/imported_favicon_usage.h" |
| 32 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
| 33 #include "components/history/core/browser/history_constants.h" | 31 #include "components/history/core/browser/history_constants.h" |
| 34 #include "components/history/core/browser/history_database_params.h" | 32 #include "components/history/core/browser/history_database_params.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/browser/visit_filter.h" | 36 #include "components/history/core/browser/visit_filter.h" |
| 38 #include "components/history/core/test/history_client_fake_bookmarks.h" | 37 #include "components/history/core/test/history_client_fake_bookmarks.h" |
| 39 #include "components/history/core/test/test_history_database.h" | 38 #include "components/history/core/test/test_history_database.h" |
| 40 #include "content/public/browser/notification_details.h" | |
| 41 #include "content/public/browser/notification_source.h" | |
| 42 #include "content/public/test/test_browser_thread.h" | 39 #include "content/public/test/test_browser_thread.h" |
| 43 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
| 44 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 45 #include "third_party/skia/include/core/SkBitmap.h" | 42 #include "third_party/skia/include/core/SkBitmap.h" |
| 46 #include "ui/gfx/codec/png_codec.h" | 43 #include "ui/gfx/codec/png_codec.h" |
| 47 #include "url/gurl.h" | 44 #include "url/gurl.h" |
| 48 | 45 |
| 49 using base::Time; | 46 using base::Time; |
| 50 | 47 |
| 51 // This file only tests functionality where it is most convenient to call the | 48 // This file only tests functionality where it is most convenient to call the |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 118 |
| 122 void NotifyProfileError(sql::InitStatus init_status) override {} | 119 void NotifyProfileError(sql::InitStatus init_status) override {} |
| 123 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) override; | 120 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) override; |
| 124 void NotifyAddVisit(const BriefVisitInfo& info) override {} | 121 void NotifyAddVisit(const BriefVisitInfo& info) override {} |
| 125 void NotifyFaviconChanged(const std::set<GURL>& urls) override; | 122 void NotifyFaviconChanged(const std::set<GURL>& urls) override; |
| 126 void NotifyURLVisited(ui::PageTransition transition, | 123 void NotifyURLVisited(ui::PageTransition transition, |
| 127 const URLRow& row, | 124 const URLRow& row, |
| 128 const RedirectList& redirects, | 125 const RedirectList& redirects, |
| 129 base::Time visit_time) override; | 126 base::Time visit_time) override; |
| 130 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; |
| 131 void NotifyKeywordSearchTermUpdated(const URLRow& row, | 132 void NotifyKeywordSearchTermUpdated(const URLRow& row, |
| 132 KeywordID keyword_id, | 133 KeywordID keyword_id, |
| 133 const base::string16& term) override; | 134 const base::string16& term) override; |
| 134 void NotifyKeywordSearchTermDeleted(URLID url_id) override; | 135 void NotifyKeywordSearchTermDeleted(URLID url_id) override; |
| 135 void BroadcastNotifications(int type, | |
| 136 scoped_ptr<HistoryDetails> details) override; | |
| 137 void DBLoaded() override; | 136 void DBLoaded() override; |
| 138 | 137 |
| 139 private: | 138 private: |
| 140 // Not owned by us. | 139 // Not owned by us. |
| 141 HistoryBackendTestBase* test_; | 140 HistoryBackendTestBase* test_; |
| 142 | 141 |
| 143 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestDelegate); | 142 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestDelegate); |
| 144 }; | 143 }; |
| 145 | 144 |
| 146 class HistoryBackendTestBase : public testing::Test { | 145 class HistoryBackendTestBase : public testing::Test { |
| 147 public: | 146 public: |
| 148 typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList; | |
| 149 typedef std::vector<std::pair<ui::PageTransition, URLRow>> URLVisitedList; | 147 typedef std::vector<std::pair<ui::PageTransition, URLRow>> URLVisitedList; |
| 150 typedef std::vector<URLRows> URLsModifiedList; | 148 typedef std::vector<URLRows> URLsModifiedList; |
| 149 typedef std::vector<std::pair<bool, bool>> URLsDeletedList; |
| 151 | 150 |
| 152 HistoryBackendTestBase() | 151 HistoryBackendTestBase() |
| 153 : loaded_(false), | 152 : loaded_(false), |
| 154 favicon_changed_notifications_(0), | 153 favicon_changed_notifications_(0), |
| 155 ui_thread_(content::BrowserThread::UI, &message_loop_) {} | 154 ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
| 156 | 155 |
| 157 ~HistoryBackendTestBase() override { | 156 ~HistoryBackendTestBase() override { |
| 158 STLDeleteValues(&broadcasted_notifications_); | |
| 159 } | 157 } |
| 160 | 158 |
| 161 protected: | 159 protected: |
| 162 int favicon_changed_notifications() const { | 160 int favicon_changed_notifications() const { |
| 163 return favicon_changed_notifications_; | 161 return favicon_changed_notifications_; |
| 164 } | 162 } |
| 165 | 163 |
| 166 void ClearFaviconChangedNotificationCounter() { | 164 void ClearFaviconChangedNotificationCounter() { |
| 167 favicon_changed_notifications_ = 0; | 165 favicon_changed_notifications_ = 0; |
| 168 } | 166 } |
| 169 | 167 |
| 170 int num_url_visited_notifications() const { | 168 int num_url_visited_notifications() const { |
| 171 return url_visited_notifications_.size(); | 169 return url_visited_notifications_.size(); |
| 172 } | 170 } |
| 173 | 171 |
| 174 const URLVisitedList& url_visited_notifications() const { | 172 const URLVisitedList& url_visited_notifications() const { |
| 175 return url_visited_notifications_; | 173 return url_visited_notifications_; |
| 176 } | 174 } |
| 177 | 175 |
| 178 int num_urls_modified_notifications() const { | 176 int num_urls_modified_notifications() const { |
| 179 return urls_modified_notifications_.size(); | 177 return urls_modified_notifications_.size(); |
| 180 } | 178 } |
| 181 | 179 |
| 182 const URLsModifiedList& urls_modified_notifications() const { | 180 const URLsModifiedList& urls_modified_notifications() const { |
| 183 return urls_modified_notifications_; | 181 return urls_modified_notifications_; |
| 184 } | 182 } |
| 185 | 183 |
| 186 int num_broadcasted_notifications() const { | 184 const URLsDeletedList& urls_deleted_notifications() const { |
| 187 return broadcasted_notifications_.size(); | 185 return urls_deleted_notifications_; |
| 188 } | |
| 189 | |
| 190 const NotificationList& broadcasted_notifications() const { | |
| 191 return broadcasted_notifications_; | |
| 192 } | 186 } |
| 193 | 187 |
| 194 void ClearBroadcastedNotifications() { | 188 void ClearBroadcastedNotifications() { |
| 195 url_visited_notifications_.clear(); | 189 url_visited_notifications_.clear(); |
| 196 urls_modified_notifications_.clear(); | 190 urls_modified_notifications_.clear(); |
| 197 STLDeleteValues(&broadcasted_notifications_); | 191 urls_deleted_notifications_.clear(); |
| 198 } | 192 } |
| 199 | 193 |
| 200 base::FilePath test_dir() { | 194 base::FilePath test_dir() { |
| 201 return test_dir_; | 195 return test_dir_; |
| 202 } | 196 } |
| 203 | 197 |
| 204 void NotifyFaviconChanged(const std::set<GURL>& changed_favicons) { | 198 void NotifyFaviconChanged(const std::set<GURL>& changed_favicons) { |
| 205 ++favicon_changed_notifications_; | 199 ++favicon_changed_notifications_; |
| 206 } | 200 } |
| 207 | 201 |
| 208 void NotifyURLVisited(ui::PageTransition transition, | 202 void NotifyURLVisited(ui::PageTransition transition, |
| 209 const URLRow& row, | 203 const URLRow& row, |
| 210 const RedirectList& redirects, | 204 const RedirectList& redirects, |
| 211 base::Time visit_time) { | 205 base::Time visit_time) { |
| 212 // Send the notifications directly to the in-memory database. | 206 // Send the notifications directly to the in-memory database. |
| 213 mem_backend_->OnURLVisited(nullptr, transition, row, redirects, visit_time); | 207 mem_backend_->OnURLVisited(nullptr, transition, row, redirects, visit_time); |
| 214 url_visited_notifications_.push_back(std::make_pair(transition, row)); | 208 url_visited_notifications_.push_back(std::make_pair(transition, row)); |
| 215 } | 209 } |
| 216 | 210 |
| 217 void NotifyURLsModified(const URLRows& changed_urls) { | 211 void NotifyURLsModified(const URLRows& changed_urls) { |
| 218 // Send the notifications directly to the in-memory database. | 212 // Send the notifications directly to the in-memory database. |
| 219 mem_backend_->OnURLsModified(nullptr, changed_urls); | 213 mem_backend_->OnURLsModified(nullptr, changed_urls); |
| 220 urls_modified_notifications_.push_back(changed_urls); | 214 urls_modified_notifications_.push_back(changed_urls); |
| 221 } | 215 } |
| 222 | 216 |
| 217 void NotifyURLsDeleted(bool all_history, |
| 218 bool expired, |
| 219 const URLRows& deleted_rows, |
| 220 const std::set<GURL>& favicon_urls) { |
| 221 mem_backend_->OnURLsDeleted(nullptr, all_history, expired, deleted_rows, |
| 222 favicon_urls); |
| 223 urls_deleted_notifications_.push_back(std::make_pair(all_history, expired)); |
| 224 } |
| 225 |
| 223 void NotifyKeywordSearchTermUpdated(const URLRow& row, | 226 void NotifyKeywordSearchTermUpdated(const URLRow& row, |
| 224 KeywordID keyword_id, | 227 KeywordID keyword_id, |
| 225 const base::string16& term) { | 228 const base::string16& term) { |
| 226 mem_backend_->OnKeywordSearchTermUpdated(nullptr, row, keyword_id, term); | 229 mem_backend_->OnKeywordSearchTermUpdated(nullptr, row, keyword_id, term); |
| 227 } | 230 } |
| 228 | 231 |
| 229 void NotifyKeywordSearchTermDeleted(URLID url_id) { | 232 void NotifyKeywordSearchTermDeleted(URLID url_id) { |
| 230 mem_backend_->OnKeywordSearchTermDeleted(nullptr, url_id); | 233 mem_backend_->OnKeywordSearchTermDeleted(nullptr, url_id); |
| 231 } | 234 } |
| 232 | 235 |
| 233 void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) { | |
| 234 // Send the notifications directly to the in-memory database. | |
| 235 content::Details<HistoryDetails> det(details.get()); | |
| 236 mem_backend_->Observe( | |
| 237 type, content::Source<HistoryBackendTestBase>(NULL), det); | |
| 238 | |
| 239 // The backend passes ownership of the details pointer to us. | |
| 240 broadcasted_notifications_.push_back( | |
| 241 std::make_pair(type, details.release())); | |
| 242 } | |
| 243 | |
| 244 history::HistoryClientFakeBookmarks history_client_; | 236 history::HistoryClientFakeBookmarks history_client_; |
| 245 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. | 237 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. |
| 246 scoped_ptr<InMemoryHistoryBackend> mem_backend_; | 238 scoped_ptr<InMemoryHistoryBackend> mem_backend_; |
| 247 bool loaded_; | 239 bool loaded_; |
| 248 | 240 |
| 249 private: | 241 private: |
| 250 friend class HistoryBackendTestDelegate; | 242 friend class HistoryBackendTestDelegate; |
| 251 | 243 |
| 252 // testing::Test | 244 // testing::Test |
| 253 void SetUp() override { | 245 void SetUp() override { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 269 base::DeleteFile(test_dir_, true); | 261 base::DeleteFile(test_dir_, true); |
| 270 base::RunLoop().RunUntilIdle(); | 262 base::RunLoop().RunUntilIdle(); |
| 271 history_client_.ClearAllBookmarks(); | 263 history_client_.ClearAllBookmarks(); |
| 272 } | 264 } |
| 273 | 265 |
| 274 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) { | 266 void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) { |
| 275 mem_backend_.swap(backend); | 267 mem_backend_.swap(backend); |
| 276 } | 268 } |
| 277 | 269 |
| 278 // The types and details of notifications which were broadcasted. | 270 // The types and details of notifications which were broadcasted. |
| 279 NotificationList broadcasted_notifications_; | |
| 280 int favicon_changed_notifications_; | 271 int favicon_changed_notifications_; |
| 281 URLVisitedList url_visited_notifications_; | 272 URLVisitedList url_visited_notifications_; |
| 282 URLsModifiedList urls_modified_notifications_; | 273 URLsModifiedList urls_modified_notifications_; |
| 274 URLsDeletedList urls_deleted_notifications_; |
| 283 | 275 |
| 284 base::MessageLoop message_loop_; | 276 base::MessageLoop message_loop_; |
| 285 base::FilePath test_dir_; | 277 base::FilePath test_dir_; |
| 286 content::TestBrowserThread ui_thread_; | 278 content::TestBrowserThread ui_thread_; |
| 287 | 279 |
| 288 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestBase); | 280 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTestBase); |
| 289 }; | 281 }; |
| 290 | 282 |
| 291 void HistoryBackendTestDelegate::SetInMemoryBackend( | 283 void HistoryBackendTestDelegate::SetInMemoryBackend( |
| 292 scoped_ptr<InMemoryHistoryBackend> backend) { | 284 scoped_ptr<InMemoryHistoryBackend> backend) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 303 const RedirectList& redirects, | 295 const RedirectList& redirects, |
| 304 base::Time visit_time) { | 296 base::Time visit_time) { |
| 305 test_->NotifyURLVisited(transition, row, redirects, visit_time); | 297 test_->NotifyURLVisited(transition, row, redirects, visit_time); |
| 306 } | 298 } |
| 307 | 299 |
| 308 void HistoryBackendTestDelegate::NotifyURLsModified( | 300 void HistoryBackendTestDelegate::NotifyURLsModified( |
| 309 const URLRows& changed_urls) { | 301 const URLRows& changed_urls) { |
| 310 test_->NotifyURLsModified(changed_urls); | 302 test_->NotifyURLsModified(changed_urls); |
| 311 } | 303 } |
| 312 | 304 |
| 305 void HistoryBackendTestDelegate::NotifyURLsDeleted( |
| 306 bool all_history, |
| 307 bool expired, |
| 308 const URLRows& deleted_rows, |
| 309 const std::set<GURL>& favicon_urls) { |
| 310 test_->NotifyURLsDeleted(all_history, expired, deleted_rows, favicon_urls); |
| 311 } |
| 312 |
| 313 void HistoryBackendTestDelegate::NotifyKeywordSearchTermUpdated( | 313 void HistoryBackendTestDelegate::NotifyKeywordSearchTermUpdated( |
| 314 const URLRow& row, | 314 const URLRow& row, |
| 315 KeywordID keyword_id, | 315 KeywordID keyword_id, |
| 316 const base::string16& term) { | 316 const base::string16& term) { |
| 317 test_->NotifyKeywordSearchTermUpdated(row, keyword_id, term); | 317 test_->NotifyKeywordSearchTermUpdated(row, keyword_id, term); |
| 318 } | 318 } |
| 319 | 319 |
| 320 void HistoryBackendTestDelegate::NotifyKeywordSearchTermDeleted(URLID url_id) { | 320 void HistoryBackendTestDelegate::NotifyKeywordSearchTermDeleted(URLID url_id) { |
| 321 test_->NotifyKeywordSearchTermDeleted(url_id); | 321 test_->NotifyKeywordSearchTermDeleted(url_id); |
| 322 } | 322 } |
| 323 | 323 |
| 324 void HistoryBackendTestDelegate::BroadcastNotifications( | |
| 325 int type, | |
| 326 scoped_ptr<HistoryDetails> details) { | |
| 327 test_->BroadcastNotifications(type, details.Pass()); | |
| 328 } | |
| 329 | |
| 330 void HistoryBackendTestDelegate::DBLoaded() { | 324 void HistoryBackendTestDelegate::DBLoaded() { |
| 331 test_->loaded_ = true; | 325 test_->loaded_ = true; |
| 332 } | 326 } |
| 333 | 327 |
| 334 class HistoryBackendTest : public HistoryBackendTestBase { | 328 class HistoryBackendTest : public HistoryBackendTestBase { |
| 335 public: | 329 public: |
| 336 HistoryBackendTest() {} | 330 HistoryBackendTest() {} |
| 337 ~HistoryBackendTest() override {} | 331 ~HistoryBackendTest() override {} |
| 338 | 332 |
| 339 protected: | 333 protected: |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 private: | 481 private: |
| 488 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTest); | 482 DISALLOW_COPY_AND_ASSIGN(HistoryBackendTest); |
| 489 }; | 483 }; |
| 490 | 484 |
| 491 class InMemoryHistoryBackendTest : public HistoryBackendTestBase { | 485 class InMemoryHistoryBackendTest : public HistoryBackendTestBase { |
| 492 public: | 486 public: |
| 493 InMemoryHistoryBackendTest() {} | 487 InMemoryHistoryBackendTest() {} |
| 494 ~InMemoryHistoryBackendTest() override {} | 488 ~InMemoryHistoryBackendTest() override {} |
| 495 | 489 |
| 496 protected: | 490 protected: |
| 497 void SimulateNotification(int type, | 491 void SimulateNotificationURLsDeleted(const URLRow* row1, |
| 498 const URLRow* row1, | 492 const URLRow* row2 = NULL, |
| 499 const URLRow* row2 = NULL, | 493 const URLRow* row3 = NULL) { |
| 500 const URLRow* row3 = NULL) { | |
| 501 DCHECK(type == chrome::NOTIFICATION_HISTORY_URLS_DELETED); | |
| 502 | |
| 503 URLRows rows; | 494 URLRows rows; |
| 504 rows.push_back(*row1); | 495 rows.push_back(*row1); |
| 505 if (row2) rows.push_back(*row2); | 496 if (row2) rows.push_back(*row2); |
| 506 if (row3) rows.push_back(*row3); | 497 if (row3) rows.push_back(*row3); |
| 507 | 498 |
| 508 scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails()); | 499 NotifyURLsDeleted(false, false, rows, std::set<GURL>()); |
| 509 details->rows = rows; | |
| 510 BroadcastNotifications(type, details.Pass()); | |
| 511 } | 500 } |
| 512 | 501 |
| 513 size_t GetNumberOfMatchingSearchTerms(const int keyword_id, | 502 size_t GetNumberOfMatchingSearchTerms(const int keyword_id, |
| 514 const base::string16& prefix) { | 503 const base::string16& prefix) { |
| 515 std::vector<KeywordSearchTermVisit> matching_terms; | 504 std::vector<KeywordSearchTermVisit> matching_terms; |
| 516 mem_backend_->db()->GetMostRecentKeywordSearchTerms( | 505 mem_backend_->db()->GetMostRecentKeywordSearchTerms( |
| 517 keyword_id, prefix, 1, &matching_terms); | 506 keyword_id, prefix, 1, &matching_terms); |
| 518 return matching_terms.size(); | 507 return matching_terms.size(); |
| 519 } | 508 } |
| 520 | 509 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 std::vector<IconMapping> mappings; | 692 std::vector<IconMapping> mappings; |
| 704 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 693 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
| 705 outrow1.url(), favicon_base::FAVICON, &mappings)); | 694 outrow1.url(), favicon_base::FAVICON, &mappings)); |
| 706 EXPECT_EQ(1u, mappings.size()); | 695 EXPECT_EQ(1u, mappings.size()); |
| 707 EXPECT_EQ(out_favicon1, mappings[0].icon_id); | 696 EXPECT_EQ(out_favicon1, mappings[0].icon_id); |
| 708 | 697 |
| 709 // The first URL should still be bookmarked. | 698 // The first URL should still be bookmarked. |
| 710 EXPECT_TRUE(history_client_.IsBookmarked(row1.url())); | 699 EXPECT_TRUE(history_client_.IsBookmarked(row1.url())); |
| 711 | 700 |
| 712 // Check that we fire the notification about all history having been deleted. | 701 // Check that we fire the notification about all history having been deleted. |
| 713 ASSERT_EQ(1u, broadcasted_notifications().size()); | 702 ASSERT_EQ(1u, urls_deleted_notifications().size()); |
| 714 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 703 EXPECT_TRUE(urls_deleted_notifications()[0].first); |
| 715 broadcasted_notifications()[0].first); | 704 EXPECT_FALSE(urls_deleted_notifications()[0].second); |
| 716 const URLsDeletedDetails* details = static_cast<const URLsDeletedDetails*>( | |
| 717 broadcasted_notifications()[0].second); | |
| 718 EXPECT_TRUE(details->all_history); | |
| 719 EXPECT_FALSE(details->expired); | |
| 720 } | 705 } |
| 721 | 706 |
| 722 // 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 |
| 723 // 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 |
| 724 // immediately after visiting a page. | 709 // immediately after visiting a page. |
| 725 TEST_F(HistoryBackendTest, DeleteAllThenAddData) { | 710 TEST_F(HistoryBackendTest, DeleteAllThenAddData) { |
| 726 ASSERT_TRUE(backend_.get()); | 711 ASSERT_TRUE(backend_.get()); |
| 727 | 712 |
| 728 Time visit_time = Time::Now(); | 713 Time visit_time = Time::Now(); |
| 729 GURL url("http://www.google.com/"); | 714 GURL url("http://www.google.com/"); |
| (...skipping 2429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3159 | 3144 |
| 3160 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedPiecewise) { | 3145 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedPiecewise) { |
| 3161 // Add two typed and one non-typed URLRow to the in-memory database. | 3146 // Add two typed and one non-typed URLRow to the in-memory database. |
| 3162 URLRow row1(CreateTestTypedURL()); | 3147 URLRow row1(CreateTestTypedURL()); |
| 3163 URLRow row2(CreateAnotherTestTypedURL()); | 3148 URLRow row2(CreateAnotherTestTypedURL()); |
| 3164 URLRow row3(CreateTestNonTypedURL()); | 3149 URLRow row3(CreateTestNonTypedURL()); |
| 3165 SimulateNotificationURLsModified(mem_backend_.get(), &row1, &row2, &row3); | 3150 SimulateNotificationURLsModified(mem_backend_.get(), &row1, &row2, &row3); |
| 3166 | 3151 |
| 3167 // Notify the in-memory database that the second typed URL and the non-typed | 3152 // Notify the in-memory database that the second typed URL and the non-typed |
| 3168 // URL has been deleted. | 3153 // URL has been deleted. |
| 3169 SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 3154 SimulateNotificationURLsDeleted(&row2, &row3); |
| 3170 &row2, &row3); | |
| 3171 | 3155 |
| 3172 // Expect that the first typed URL remains intact, the second typed URL is | 3156 // Expect that the first typed URL remains intact, the second typed URL is |
| 3173 // correctly removed, and the non-typed URL does not magically appear. | 3157 // correctly removed, and the non-typed URL does not magically appear. |
| 3174 URLRow cached_row1; | 3158 URLRow cached_row1; |
| 3175 EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1)); | 3159 EXPECT_NE(0, mem_backend_->db()->GetRowForURL(row1.url(), &cached_row1)); |
| 3176 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL)); | 3160 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL)); |
| 3177 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL)); | 3161 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL)); |
| 3178 EXPECT_EQ(row1.id(), cached_row1.id()); | 3162 EXPECT_EQ(row1.id(), cached_row1.id()); |
| 3179 } | 3163 } |
| 3180 | 3164 |
| 3181 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedEnMasse) { | 3165 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedEnMasse) { |
| 3182 // Add two typed and one non-typed URLRow to the in-memory database. | 3166 // Add two typed and one non-typed URLRow to the in-memory database. |
| 3183 URLRow row1(CreateTestTypedURL()); | 3167 URLRow row1(CreateTestTypedURL()); |
| 3184 URLRow row2(CreateAnotherTestTypedURL()); | 3168 URLRow row2(CreateAnotherTestTypedURL()); |
| 3185 URLRow row3(CreateTestNonTypedURL()); | 3169 URLRow row3(CreateTestNonTypedURL()); |
| 3186 SimulateNotificationURLsModified(mem_backend_.get(), &row1, &row2, &row3); | 3170 SimulateNotificationURLsModified(mem_backend_.get(), &row1, &row2, &row3); |
| 3187 | 3171 |
| 3188 // Now notify the in-memory database that all history has been deleted. | 3172 // Now notify the in-memory database that all history has been deleted. |
| 3189 scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails()); | 3173 mem_backend_->OnURLsDeleted(nullptr, true, false, URLRows(), |
| 3190 details->all_history = true; | 3174 std::set<GURL>()); |
| 3191 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | |
| 3192 details.Pass()); | |
| 3193 | 3175 |
| 3194 // Expect that everything goes away. | 3176 // Expect that everything goes away. |
| 3195 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), NULL)); | 3177 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), NULL)); |
| 3196 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL)); | 3178 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row2.url(), NULL)); |
| 3197 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL)); | 3179 EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row3.url(), NULL)); |
| 3198 } | 3180 } |
| 3199 | 3181 |
| 3200 void InMemoryHistoryBackendTest::PopulateTestURLsAndSearchTerms( | 3182 void InMemoryHistoryBackendTest::PopulateTestURLsAndSearchTerms( |
| 3201 URLRow* row1, | 3183 URLRow* row1, |
| 3202 URLRow* row2, | 3184 URLRow* row2, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3292 } | 3274 } |
| 3293 | 3275 |
| 3294 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedWithSearchTerms) { | 3276 TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedWithSearchTerms) { |
| 3295 URLRow row1(CreateTestTypedURL()); | 3277 URLRow row1(CreateTestTypedURL()); |
| 3296 URLRow row2(CreateTestNonTypedURL()); | 3278 URLRow row2(CreateTestNonTypedURL()); |
| 3297 base::string16 term1(base::UTF8ToUTF16(kTestSearchTerm1)); | 3279 base::string16 term1(base::UTF8ToUTF16(kTestSearchTerm1)); |
| 3298 base::string16 term2(base::UTF8ToUTF16(kTestSearchTerm2)); | 3280 base::string16 term2(base::UTF8ToUTF16(kTestSearchTerm2)); |
| 3299 PopulateTestURLsAndSearchTerms(&row1, &row2, term1, term2); | 3281 PopulateTestURLsAndSearchTerms(&row1, &row2, term1, term2); |
| 3300 | 3282 |
| 3301 // Notify the in-memory database that the second typed URL has been deleted. | 3283 // Notify the in-memory database that the second typed URL has been deleted. |
| 3302 SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_DELETED, &row2); | 3284 SimulateNotificationURLsDeleted(&row2); |
| 3303 | 3285 |
| 3304 // Verify that the second term is no longer returned as result, and also check | 3286 // Verify that the second term is no longer returned as result, and also check |
| 3305 // at the low level that it is gone for good. The term corresponding to the | 3287 // at the low level that it is gone for good. The term corresponding to the |
| 3306 // first URLRow should not be affected. | 3288 // first URLRow should not be affected. |
| 3307 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); | 3289 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); |
| 3308 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); | 3290 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); |
| 3309 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); | 3291 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); |
| 3310 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); | 3292 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); |
| 3311 } | 3293 } |
| 3312 | 3294 |
| 3313 } // namespace history | 3295 } // namespace history |
| OLD | NEW |