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

Side by Side Diff: components/history/core/browser/url_database_unittest.cc

Issue 2864103003: Limit the number of history urls indexed for omnibox suggestions. (Closed)
Patch Set: Address comments. Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "components/history/core/browser/keyword_search_term.h" 9 #include "components/history/core/browser/keyword_search_term.h"
10 #include "components/history/core/browser/url_database.h" 10 #include "components/history/core/browser/url_database.h"
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 // Delete the url. 228 // Delete the url.
229 ASSERT_TRUE(DeleteURLRow(url_id)); 229 ASSERT_TRUE(DeleteURLRow(url_id));
230 230
231 // Make sure the keyword visit was deleted. 231 // Make sure the keyword visit was deleted.
232 std::vector<KeywordSearchTermVisit> matches; 232 std::vector<KeywordSearchTermVisit> matches;
233 GetMostRecentKeywordSearchTerms(1, base::UTF8ToUTF16("visit"), 10, &matches); 233 GetMostRecentKeywordSearchTerms(1, base::UTF8ToUTF16("visit"), 10, &matches);
234 ASSERT_EQ(0U, matches.size()); 234 ASSERT_EQ(0U, matches.size());
235 } 235 }
236 236
237 TEST_F(URLDatabaseTest, EnumeratorForSignificant) { 237 TEST_F(URLDatabaseTest, EnumeratorForSignificant) {
238 std::set<std::string> good_urls;
239 // Add URLs which do and don't meet the criteria. 238 // Add URLs which do and don't meet the criteria.
240 URLRow url_no_match(GURL("http://www.url_no_match.com/")); 239 URLRow url_no_match(GURL("http://www.url_no_match.com/"));
241 EXPECT_TRUE(AddURL(url_no_match)); 240 EXPECT_TRUE(AddURL(url_no_match));
242 241
243 std::string url_string2("http://www.url_match_visit_count.com/"); 242 URLRow url_match_visit_count2(GURL("http://www.url_match_visit_count.com/"));
244 good_urls.insert("http://www.url_match_visit_count.com/"); 243 url_match_visit_count2.set_visit_count(kLowQualityMatchVisitLimit);
245 URLRow url_match_visit_count(GURL("http://www.url_match_visit_count.com/")); 244 EXPECT_TRUE(AddURL(url_match_visit_count2));
246 url_match_visit_count.set_visit_count(kLowQualityMatchVisitLimit);
247 EXPECT_TRUE(AddURL(url_match_visit_count));
248 245
249 good_urls.insert("http://www.url_match_typed_count.com/"); 246 URLRow url_match_typed_count2(GURL("http://www.url_match_typed_count.com/"));
250 URLRow url_match_typed_count(GURL("http://www.url_match_typed_count.com/")); 247 url_match_typed_count2.set_typed_count(kLowQualityMatchTypedLimit);
251 url_match_typed_count.set_typed_count(kLowQualityMatchTypedLimit); 248 EXPECT_TRUE(AddURL(url_match_typed_count2));
252 EXPECT_TRUE(AddURL(url_match_typed_count));
253 249
254 good_urls.insert("http://www.url_match_last_visit.com/"); 250 URLRow url_match_last_visit2(GURL("http://www.url_match_last_visit2.com/"));
255 URLRow url_match_last_visit(GURL("http://www.url_match_last_visit.com/")); 251 url_match_last_visit2.set_last_visit(Time::Now() - TimeDelta::FromDays(2));
256 url_match_last_visit.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); 252 EXPECT_TRUE(AddURL(url_match_last_visit2));
257 EXPECT_TRUE(AddURL(url_match_last_visit)); 253
254 URLRow url_match_typed_count1(
255 GURL("http://www.url_match_higher_typed_count.com/"));
256 url_match_typed_count1.set_typed_count(kLowQualityMatchTypedLimit + 1);
257 EXPECT_TRUE(AddURL(url_match_typed_count1));
258
259 URLRow url_match_visit_count1(
260 GURL("http://www.url_match_higher_visit_count.com/"));
261 url_match_visit_count1.set_visit_count(kLowQualityMatchVisitLimit + 1);
262 EXPECT_TRUE(AddURL(url_match_visit_count1));
263
264 URLRow url_match_last_visit1(GURL("http://www.url_match_last_visit.com/"));
265 url_match_last_visit1.set_last_visit(Time::Now() - TimeDelta::FromDays(1));
266 EXPECT_TRUE(AddURL(url_match_last_visit1));
258 267
259 URLRow url_no_match_last_visit(GURL( 268 URLRow url_no_match_last_visit(GURL(
260 "http://www.url_no_match_last_visit.com/")); 269 "http://www.url_no_match_last_visit.com/"));
261 url_no_match_last_visit.set_last_visit(Time::Now() - 270 url_no_match_last_visit.set_last_visit(Time::Now() -
262 TimeDelta::FromDays(kLowQualityMatchAgeLimitInDays + 1)); 271 TimeDelta::FromDays(kLowQualityMatchAgeLimitInDays + 1));
263 EXPECT_TRUE(AddURL(url_no_match_last_visit)); 272 EXPECT_TRUE(AddURL(url_no_match_last_visit));
264 273
265 URLDatabase::URLEnumerator history_enum; 274 URLDatabase::URLEnumerator history_enum;
266 EXPECT_TRUE(InitURLEnumeratorForSignificant(&history_enum)); 275 EXPECT_TRUE(InitURLEnumeratorForSignificant(&history_enum));
276
277 // Vector contains urls in order of significance.
278 std::vector<std::string> good_urls;
279 good_urls.push_back("http://www.url_match_higher_typed_count.com/");
280 good_urls.push_back("http://www.url_match_typed_count.com/");
281 good_urls.push_back("http://www.url_match_last_visit.com/");
282 good_urls.push_back("http://www.url_match_last_visit2.com/");
283 good_urls.push_back("http://www.url_match_higher_visit_count.com/");
284 good_urls.push_back("http://www.url_match_visit_count.com/");
267 URLRow row; 285 URLRow row;
268 int row_count = 0; 286 int row_count = 0;
269 for (; history_enum.GetNextURL(&row); ++row_count) 287 for (; history_enum.GetNextURL(&row); ++row_count)
270 EXPECT_EQ(1U, good_urls.count(row.url().spec())); 288 EXPECT_EQ(good_urls[row_count], row.url().spec());
271 EXPECT_EQ(3, row_count); 289 EXPECT_EQ(6, row_count);
272 } 290 }
273 291
274 // Test GetKeywordSearchTermRows and DeleteSearchTerm 292 // Test GetKeywordSearchTermRows and DeleteSearchTerm
275 TEST_F(URLDatabaseTest, GetAndDeleteKeywordSearchTermByTerm) { 293 TEST_F(URLDatabaseTest, GetAndDeleteKeywordSearchTermByTerm) {
276 URLRow url_info1(GURL("http://www.google.com/")); 294 URLRow url_info1(GURL("http://www.google.com/"));
277 url_info1.set_title(base::UTF8ToUTF16("Google")); 295 url_info1.set_title(base::UTF8ToUTF16("Google"));
278 url_info1.set_visit_count(4); 296 url_info1.set_visit_count(4);
279 url_info1.set_typed_count(2); 297 url_info1.set_typed_count(2);
280 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); 298 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1));
281 url_info1.set_hidden(false); 299 url_info1.set_hidden(false);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 EXPECT_TRUE(AddURL(url_info5)); 453 EXPECT_TRUE(AddURL(url_info5));
436 454
437 URLRow info5; 455 URLRow info5;
438 EXPECT_TRUE(GetRowForURL(url5, &info5)); 456 EXPECT_TRUE(GetRowForURL(url5, &info5));
439 EXPECT_TRUE(IsURLRowEqual(url_info5, info5)); 457 EXPECT_TRUE(IsURLRowEqual(url_info5, info5));
440 // Verify the id is not re-used. 458 // Verify the id is not re-used.
441 EXPECT_NE(info4.id(), info5.id()); 459 EXPECT_NE(info4.id(), info5.id());
442 } 460 }
443 461
444 } // namespace history 462 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/url_database.cc ('k') | components/omnibox/browser/omnibox_field_trial.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698