Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 | 227 |
| 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) { |
|
Mark P
2017/05/08 22:39:17
Please restructure this test a bit. Right now, fo
ssid
2017/05/10 01:01:35
good point. Done.
| |
| 238 std::set<std::string> good_urls; | 238 // Vector contains urls in order of significance. |
| 239 std::vector<std::string> good_urls; | |
| 240 | |
| 239 // Add URLs which do and don't meet the criteria. | 241 // Add URLs which do and don't meet the criteria. |
| 240 URLRow url_no_match(GURL("http://www.url_no_match.com/")); | 242 URLRow url_no_match(GURL("http://www.url_no_match.com/")); |
| 241 EXPECT_TRUE(AddURL(url_no_match)); | 243 EXPECT_TRUE(AddURL(url_no_match)); |
| 242 | 244 |
| 243 std::string url_string2("http://www.url_match_visit_count.com/"); | 245 good_urls.push_back("http://www.url_match_higher_typed_count.com/"); |
| 244 good_urls.insert("http://www.url_match_visit_count.com/"); | 246 URLRow url_match_typed_count1( |
| 245 URLRow url_match_visit_count(GURL("http://www.url_match_visit_count.com/")); | 247 GURL("http://www.url_match_higher_typed_count.com/")); |
| 246 url_match_visit_count.set_visit_count(kLowQualityMatchVisitLimit); | 248 url_match_typed_count1.set_typed_count(kLowQualityMatchTypedLimit + 1); |
| 247 EXPECT_TRUE(AddURL(url_match_visit_count)); | 249 EXPECT_TRUE(AddURL(url_match_typed_count1)); |
| 248 | 250 |
| 249 good_urls.insert("http://www.url_match_typed_count.com/"); | 251 good_urls.push_back("http://www.url_match_typed_count.com/"); |
| 250 URLRow url_match_typed_count(GURL("http://www.url_match_typed_count.com/")); | 252 URLRow url_match_typed_count2(GURL("http://www.url_match_typed_count.com/")); |
| 251 url_match_typed_count.set_typed_count(kLowQualityMatchTypedLimit); | 253 url_match_typed_count2.set_typed_count(kLowQualityMatchTypedLimit); |
| 252 EXPECT_TRUE(AddURL(url_match_typed_count)); | 254 EXPECT_TRUE(AddURL(url_match_typed_count2)); |
| 253 | 255 |
| 254 good_urls.insert("http://www.url_match_last_visit.com/"); | 256 good_urls.push_back("http://www.url_match_last_visit.com/"); |
| 255 URLRow url_match_last_visit(GURL("http://www.url_match_last_visit.com/")); | 257 URLRow url_match_last_visit1(GURL("http://www.url_match_last_visit.com/")); |
| 256 url_match_last_visit.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); | 258 url_match_last_visit1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); |
| 257 EXPECT_TRUE(AddURL(url_match_last_visit)); | 259 EXPECT_TRUE(AddURL(url_match_last_visit1)); |
| 260 | |
| 261 good_urls.push_back("http://www.url_match_last_visit2.com/"); | |
| 262 URLRow url_match_last_visit2(GURL("http://www.url_match_last_visit2.com/")); | |
| 263 url_match_last_visit2.set_last_visit(Time::Now() - TimeDelta::FromDays(2)); | |
| 264 EXPECT_TRUE(AddURL(url_match_last_visit2)); | |
| 265 | |
| 266 good_urls.push_back("http://www.url_match_higher_visit_count.com/"); | |
| 267 URLRow url_match_visit_count1( | |
| 268 GURL("http://www.url_match_higher_visit_count.com/")); | |
| 269 url_match_visit_count1.set_visit_count(kLowQualityMatchVisitLimit + 1); | |
| 270 EXPECT_TRUE(AddURL(url_match_visit_count1)); | |
| 271 | |
| 272 good_urls.push_back("http://www.url_match_visit_count.com/"); | |
| 273 URLRow url_match_visit_count2(GURL("http://www.url_match_visit_count.com/")); | |
| 274 url_match_visit_count2.set_visit_count(kLowQualityMatchVisitLimit); | |
| 275 EXPECT_TRUE(AddURL(url_match_visit_count2)); | |
| 258 | 276 |
| 259 URLRow url_no_match_last_visit(GURL( | 277 URLRow url_no_match_last_visit(GURL( |
| 260 "http://www.url_no_match_last_visit.com/")); | 278 "http://www.url_no_match_last_visit.com/")); |
| 261 url_no_match_last_visit.set_last_visit(Time::Now() - | 279 url_no_match_last_visit.set_last_visit(Time::Now() - |
| 262 TimeDelta::FromDays(kLowQualityMatchAgeLimitInDays + 1)); | 280 TimeDelta::FromDays(kLowQualityMatchAgeLimitInDays + 1)); |
| 263 EXPECT_TRUE(AddURL(url_no_match_last_visit)); | 281 EXPECT_TRUE(AddURL(url_no_match_last_visit)); |
| 264 | 282 |
| 265 URLDatabase::URLEnumerator history_enum; | 283 URLDatabase::URLEnumerator history_enum; |
| 266 EXPECT_TRUE(InitURLEnumeratorForSignificant(&history_enum)); | 284 EXPECT_TRUE(InitURLEnumeratorForSignificant(&history_enum)); |
| 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 Loading... | |
| 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 |
| OLD | NEW |