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

Unified 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: Rebase to tip Created 5 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_details.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/history_backend_unittest.cc
diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc
index 21d67c00ff9e0f7cc4feee695366b0c7457e6f9d..cbf82bf8fd29a89d0ce2b7cb9a3f9cf37572c60c 100644
--- a/chrome/browser/history/history_backend_unittest.cc
+++ b/chrome/browser/history/history_backend_unittest.cc
@@ -21,8 +21,6 @@
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/in_memory_history_backend.h"
@@ -32,13 +30,12 @@
#include "chrome/test/base/testing_profile.h"
#include "components/history/core/browser/history_constants.h"
#include "components/history/core/browser/history_database_params.h"
+#include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/in_memory_database.h"
#include "components/history/core/browser/keyword_search_term.h"
#include "components/history/core/browser/visit_filter.h"
#include "components/history/core/test/history_client_fake_bookmarks.h"
#include "components/history/core/test/test_history_database.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_source.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -128,12 +125,14 @@ class HistoryBackendTestDelegate : public HistoryBackend::Delegate {
const RedirectList& redirects,
base::Time visit_time) override;
void NotifyURLsModified(const URLRows& changed_urls) override;
+ void NotifyURLsDeleted(bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) override;
void NotifyKeywordSearchTermUpdated(const URLRow& row,
KeywordID keyword_id,
const base::string16& term) override;
void NotifyKeywordSearchTermDeleted(URLID url_id) override;
- void BroadcastNotifications(int type,
- scoped_ptr<HistoryDetails> details) override;
void DBLoaded() override;
private:
@@ -145,9 +144,9 @@ class HistoryBackendTestDelegate : public HistoryBackend::Delegate {
class HistoryBackendTestBase : public testing::Test {
public:
- typedef std::vector<std::pair<int, HistoryDetails*> > NotificationList;
typedef std::vector<std::pair<ui::PageTransition, URLRow>> URLVisitedList;
typedef std::vector<URLRows> URLsModifiedList;
+ typedef std::vector<std::pair<bool, bool>> URLsDeletedList;
HistoryBackendTestBase()
: loaded_(false),
@@ -155,7 +154,6 @@ class HistoryBackendTestBase : public testing::Test {
ui_thread_(content::BrowserThread::UI, &message_loop_) {}
~HistoryBackendTestBase() override {
- STLDeleteValues(&broadcasted_notifications_);
}
protected:
@@ -183,18 +181,14 @@ class HistoryBackendTestBase : public testing::Test {
return urls_modified_notifications_;
}
- int num_broadcasted_notifications() const {
- return broadcasted_notifications_.size();
- }
-
- const NotificationList& broadcasted_notifications() const {
- return broadcasted_notifications_;
+ const URLsDeletedList& urls_deleted_notifications() const {
+ return urls_deleted_notifications_;
}
void ClearBroadcastedNotifications() {
url_visited_notifications_.clear();
urls_modified_notifications_.clear();
- STLDeleteValues(&broadcasted_notifications_);
+ urls_deleted_notifications_.clear();
}
base::FilePath test_dir() {
@@ -220,6 +214,15 @@ class HistoryBackendTestBase : public testing::Test {
urls_modified_notifications_.push_back(changed_urls);
}
+ void NotifyURLsDeleted(bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ mem_backend_->OnURLsDeleted(nullptr, all_history, expired, deleted_rows,
+ favicon_urls);
+ urls_deleted_notifications_.push_back(std::make_pair(all_history, expired));
+ }
+
void NotifyKeywordSearchTermUpdated(const URLRow& row,
KeywordID keyword_id,
const base::string16& term) {
@@ -230,17 +233,6 @@ class HistoryBackendTestBase : public testing::Test {
mem_backend_->OnKeywordSearchTermDeleted(nullptr, url_id);
}
- void BroadcastNotifications(int type, scoped_ptr<HistoryDetails> details) {
- // Send the notifications directly to the in-memory database.
- content::Details<HistoryDetails> det(details.get());
- mem_backend_->Observe(
- type, content::Source<HistoryBackendTestBase>(NULL), det);
-
- // The backend passes ownership of the details pointer to us.
- broadcasted_notifications_.push_back(
- std::make_pair(type, details.release()));
- }
-
history::HistoryClientFakeBookmarks history_client_;
scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure.
scoped_ptr<InMemoryHistoryBackend> mem_backend_;
@@ -276,10 +268,10 @@ class HistoryBackendTestBase : public testing::Test {
}
// The types and details of notifications which were broadcasted.
- NotificationList broadcasted_notifications_;
int favicon_changed_notifications_;
URLVisitedList url_visited_notifications_;
URLsModifiedList urls_modified_notifications_;
+ URLsDeletedList urls_deleted_notifications_;
base::MessageLoop message_loop_;
base::FilePath test_dir_;
@@ -310,6 +302,14 @@ void HistoryBackendTestDelegate::NotifyURLsModified(
test_->NotifyURLsModified(changed_urls);
}
+void HistoryBackendTestDelegate::NotifyURLsDeleted(
+ bool all_history,
+ bool expired,
+ const URLRows& deleted_rows,
+ const std::set<GURL>& favicon_urls) {
+ test_->NotifyURLsDeleted(all_history, expired, deleted_rows, favicon_urls);
+}
+
void HistoryBackendTestDelegate::NotifyKeywordSearchTermUpdated(
const URLRow& row,
KeywordID keyword_id,
@@ -321,12 +321,6 @@ void HistoryBackendTestDelegate::NotifyKeywordSearchTermDeleted(URLID url_id) {
test_->NotifyKeywordSearchTermDeleted(url_id);
}
-void HistoryBackendTestDelegate::BroadcastNotifications(
- int type,
- scoped_ptr<HistoryDetails> details) {
- test_->BroadcastNotifications(type, details.Pass());
-}
-
void HistoryBackendTestDelegate::DBLoaded() {
test_->loaded_ = true;
}
@@ -494,20 +488,15 @@ class InMemoryHistoryBackendTest : public HistoryBackendTestBase {
~InMemoryHistoryBackendTest() override {}
protected:
- void SimulateNotification(int type,
- const URLRow* row1,
- const URLRow* row2 = NULL,
- const URLRow* row3 = NULL) {
- DCHECK(type == chrome::NOTIFICATION_HISTORY_URLS_DELETED);
-
+ void SimulateNotificationURLsDeleted(const URLRow* row1,
+ const URLRow* row2 = NULL,
+ const URLRow* row3 = NULL) {
URLRows rows;
rows.push_back(*row1);
if (row2) rows.push_back(*row2);
if (row3) rows.push_back(*row3);
- scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails());
- details->rows = rows;
- BroadcastNotifications(type, details.Pass());
+ NotifyURLsDeleted(false, false, rows, std::set<GURL>());
}
size_t GetNumberOfMatchingSearchTerms(const int keyword_id,
@@ -710,13 +699,9 @@ TEST_F(HistoryBackendTest, DeleteAll) {
EXPECT_TRUE(history_client_.IsBookmarked(row1.url()));
// Check that we fire the notification about all history having been deleted.
- ASSERT_EQ(1u, broadcasted_notifications().size());
- ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- broadcasted_notifications()[0].first);
- const URLsDeletedDetails* details = static_cast<const URLsDeletedDetails*>(
- broadcasted_notifications()[0].second);
- EXPECT_TRUE(details->all_history);
- EXPECT_FALSE(details->expired);
+ ASSERT_EQ(1u, urls_deleted_notifications().size());
+ EXPECT_TRUE(urls_deleted_notifications()[0].first);
+ EXPECT_FALSE(urls_deleted_notifications()[0].second);
}
// Checks that adding a visit, then calling DeleteAll, and then trying to add
@@ -3166,8 +3151,7 @@ TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedPiecewise) {
// Notify the in-memory database that the second typed URL and the non-typed
// URL has been deleted.
- SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- &row2, &row3);
+ SimulateNotificationURLsDeleted(&row2, &row3);
// Expect that the first typed URL remains intact, the second typed URL is
// correctly removed, and the non-typed URL does not magically appear.
@@ -3186,10 +3170,8 @@ TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedEnMasse) {
SimulateNotificationURLsModified(mem_backend_.get(), &row1, &row2, &row3);
// Now notify the in-memory database that all history has been deleted.
- scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails());
- details->all_history = true;
- BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
- details.Pass());
+ mem_backend_->OnURLsDeleted(nullptr, true, false, URLRows(),
+ std::set<GURL>());
// Expect that everything goes away.
EXPECT_EQ(0, mem_backend_->db()->GetRowForURL(row1.url(), NULL));
@@ -3299,7 +3281,7 @@ TEST_F(InMemoryHistoryBackendTest, OnURLsDeletedWithSearchTerms) {
PopulateTestURLsAndSearchTerms(&row1, &row2, term1, term2);
// Notify the in-memory database that the second typed URL has been deleted.
- SimulateNotification(chrome::NOTIFICATION_HISTORY_URLS_DELETED, &row2);
+ SimulateNotificationURLsDeleted(&row2);
// Verify that the second term is no longer returned as result, and also check
// at the low level that it is gone for good. The term corresponding to the
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_details.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698