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

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

Issue 773103004: Remove NOTIFICATION_HISTORY_URLS_DELETED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove NotificationObserver from InMemoryURLIndex 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 <algorithm> 5 #include <algorithm>
6 #include <fstream> 6 #include <fstream>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
18 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
sdefresne 2014/12/04 17:21:13 This #include can be removed.
nshaik 2014/12/07 09:34:50 Done.
19 #include "chrome/browser/history/history_backend.h" 19 #include "chrome/browser/history/history_backend.h"
20 #include "chrome/browser/history/history_database.h" 20 #include "chrome/browser/history/history_database.h"
21 #include "chrome/browser/history/history_notifications.h" 21 #include "chrome/browser/history/history_notifications.h"
22 #include "chrome/browser/history/history_service.h" 22 #include "chrome/browser/history/history_service.h"
23 #include "chrome/browser/history/history_service_factory.h" 23 #include "chrome/browser/history/history_service_factory.h"
24 #include "chrome/browser/history/in_memory_url_index.h" 24 #include "chrome/browser/history/in_memory_url_index.h"
25 #include "chrome/browser/history/in_memory_url_index_types.h" 25 #include "chrome/browser/history/in_memory_url_index_types.h"
26 #include "chrome/browser/history/url_index_private_data.h" 26 #include "chrome/browser/history/url_index_private_data.h"
27 #include "chrome/common/chrome_paths.h" 27 #include "chrome/common/chrome_paths.h"
28 #include "chrome/test/base/history_index_restore_observer.h" 28 #include "chrome/test/base/history_index_restore_observer.h"
29 #include "chrome/test/base/testing_profile.h" 29 #include "chrome/test/base/testing_profile.h"
30 #include "components/bookmarks/test/bookmark_test_helpers.h" 30 #include "components/bookmarks/test/bookmark_test_helpers.h"
31 #include "components/history/core/browser/history_client.h" 31 #include "components/history/core/browser/history_client.h"
32 #include "content/public/browser/notification_details.h"
33 #include "content/public/browser/notification_source.h"
34 #include "content/public/test/test_browser_thread_bundle.h" 32 #include "content/public/test/test_browser_thread_bundle.h"
35 #include "sql/transaction.h" 33 #include "sql/transaction.h"
36 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
37 35
38 using base::ASCIIToUTF16; 36 using base::ASCIIToUTF16;
39 37
40 namespace { 38 namespace {
41 const size_t kMaxMatches = 3; 39 const size_t kMaxMatches = 3;
42 } // namespace 40 } // namespace
43 41
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 sql::Connection& GetDB(); 104 sql::Connection& GetDB();
107 105
108 // Pass-through functions to simplify our friendship with InMemoryURLIndex. 106 // Pass-through functions to simplify our friendship with InMemoryURLIndex.
109 URLIndexPrivateData* GetPrivateData() const; 107 URLIndexPrivateData* GetPrivateData() const;
110 base::CancelableTaskTracker* GetPrivateDataTracker() const; 108 base::CancelableTaskTracker* GetPrivateDataTracker() const;
111 void ClearPrivateData(); 109 void ClearPrivateData();
112 void set_history_dir(const base::FilePath& dir_path); 110 void set_history_dir(const base::FilePath& dir_path);
113 bool GetCacheFilePath(base::FilePath* file_path) const; 111 bool GetCacheFilePath(base::FilePath* file_path) const;
114 void PostRestoreFromCacheFileTask(); 112 void PostRestoreFromCacheFileTask();
115 void PostSaveToCacheFileTask(); 113 void PostSaveToCacheFileTask();
116 void Observe(int notification_type,
117 const content::NotificationSource& source,
118 const content::NotificationDetails& details);
119 const std::set<std::string>& scheme_whitelist(); 114 const std::set<std::string>& scheme_whitelist();
120 115
121 116
122 // Pass-through functions to simplify our friendship with URLIndexPrivateData. 117 // Pass-through functions to simplify our friendship with URLIndexPrivateData.
123 bool UpdateURL(const URLRow& row); 118 bool UpdateURL(const URLRow& row);
124 bool DeleteURL(const GURL& url); 119 bool DeleteURL(const GURL& url);
125 120
126 // Data verification helper functions. 121 // Data verification helper functions.
127 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data); 122 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data);
128 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data); 123 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 164 }
170 165
171 void InMemoryURLIndexTest::PostRestoreFromCacheFileTask() { 166 void InMemoryURLIndexTest::PostRestoreFromCacheFileTask() {
172 url_index_->PostRestoreFromCacheFileTask(); 167 url_index_->PostRestoreFromCacheFileTask();
173 } 168 }
174 169
175 void InMemoryURLIndexTest::PostSaveToCacheFileTask() { 170 void InMemoryURLIndexTest::PostSaveToCacheFileTask() {
176 url_index_->PostSaveToCacheFileTask(); 171 url_index_->PostSaveToCacheFileTask();
177 } 172 }
178 173
179 void InMemoryURLIndexTest::Observe(
180 int notification_type,
181 const content::NotificationSource& source,
182 const content::NotificationDetails& details) {
183 url_index_->Observe(notification_type, source, details);
184 }
185
186 const std::set<std::string>& InMemoryURLIndexTest::scheme_whitelist() { 174 const std::set<std::string>& InMemoryURLIndexTest::scheme_whitelist() {
187 return url_index_->scheme_whitelist(); 175 return url_index_->scheme_whitelist();
188 } 176 }
189 177
190 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) { 178 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) {
191 return GetPrivateData()->UpdateURL(history_service_, 179 return GetPrivateData()->UpdateURL(history_service_,
192 row, 180 row,
193 url_index_->languages_, 181 url_index_->languages_,
194 url_index_->scheme_whitelist_, 182 url_index_->scheme_whitelist_,
195 GetPrivateDataTracker()); 183 GetPrivateDataTracker());
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 TEST_F(InMemoryURLIndexTest, ExpireRow) { 883 TEST_F(InMemoryURLIndexTest, ExpireRow) {
896 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( 884 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
897 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches); 885 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches);
898 ASSERT_EQ(1U, matches.size()); 886 ASSERT_EQ(1U, matches.size());
899 887
900 // Determine the row id for the result, remember that id, broadcast a 888 // Determine the row id for the result, remember that id, broadcast a
901 // delete notification, then ensure that the row has been deleted. 889 // delete notification, then ensure that the row has been deleted.
902 URLsDeletedDetails deleted_details; 890 URLsDeletedDetails deleted_details;
903 deleted_details.all_history = false; 891 deleted_details.all_history = false;
904 deleted_details.rows.push_back(matches[0].url_info); 892 deleted_details.rows.push_back(matches[0].url_info);
905 Observe(chrome::NOTIFICATION_HISTORY_URLS_DELETED, 893 url_index_->OnURLsDeleted(nullptr, deleted_details);
906 content::Source<InMemoryURLIndexTest>(this),
907 content::Details<history::HistoryDetails>(&deleted_details));
908 EXPECT_TRUE(url_index_->HistoryItemsForTerms( 894 EXPECT_TRUE(url_index_->HistoryItemsForTerms(
909 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches).empty()); 895 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches).empty());
910 } 896 }
911 897
912 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { 898 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) {
913 struct TestData { 899 struct TestData {
914 const std::string url_spec; 900 const std::string url_spec;
915 const bool expected_is_whitelisted; 901 const bool expected_is_whitelisted;
916 } data[] = { 902 } data[] = {
917 // URLs with whitelisted schemes. 903 // URLs with whitelisted schemes.
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 full_file_path.GetComponents(&actual_parts); 1214 full_file_path.GetComponents(&actual_parts);
1229 ASSERT_EQ(expected_parts.size(), actual_parts.size()); 1215 ASSERT_EQ(expected_parts.size(), actual_parts.size());
1230 size_t count = expected_parts.size(); 1216 size_t count = expected_parts.size();
1231 for (size_t i = 0; i < count; ++i) 1217 for (size_t i = 0; i < count; ++i)
1232 EXPECT_EQ(expected_parts[i], actual_parts[i]); 1218 EXPECT_EQ(expected_parts[i], actual_parts[i]);
1233 // Must clear the history_dir_ to satisfy the dtor's DCHECK. 1219 // Must clear the history_dir_ to satisfy the dtor's DCHECK.
1234 set_history_dir(base::FilePath()); 1220 set_history_dir(base::FilePath());
1235 } 1221 }
1236 1222
1237 } // namespace history 1223 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698