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

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

Issue 2338133006: [NTP] Fix article suggestion clicks contributing to Most Visited tiles (Closed)
Patch Set: Updated trivial occurrence in unit test. Created 4 years, 3 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 (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 "components/history/core/browser/history_backend.h" 5 #include "components/history/core/browser/history_backend.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 ui::PageTransition transition, 350 ui::PageTransition transition,
351 base::Time time) { 351 base::Time time) {
352 history::RedirectList redirects; 352 history::RedirectList redirects;
353 for (int i = 0; sequence[i] != NULL; ++i) 353 for (int i = 0; sequence[i] != NULL; ++i)
354 redirects.push_back(GURL(sequence[i])); 354 redirects.push_back(GURL(sequence[i]));
355 355
356 ContextID context_id = reinterpret_cast<ContextID>(1); 356 ContextID context_id = reinterpret_cast<ContextID>(1);
357 history::HistoryAddPageArgs request( 357 history::HistoryAddPageArgs request(
358 redirects.back(), time, context_id, nav_entry_id, GURL(), 358 redirects.back(), time, context_id, nav_entry_id, GURL(),
359 redirects, transition, history::SOURCE_BROWSED, 359 redirects, transition, history::SOURCE_BROWSED,
360 true); 360 true, true);
361 backend_->AddPage(request); 361 backend_->AddPage(request);
362 } 362 }
363 363
364 // Adds CLIENT_REDIRECT page transition. 364 // Adds CLIENT_REDIRECT page transition.
365 // |url1| is the source URL and |url2| is the destination. 365 // |url1| is the source URL and |url2| is the destination.
366 // |did_replace| is true if the transition is non-user initiated and the 366 // |did_replace| is true if the transition is non-user initiated and the
367 // navigation entry for |url2| has replaced that for |url1|. The possibly 367 // navigation entry for |url2| has replaced that for |url1|. The possibly
368 // updated transition code of the visit records for |url1| and |url2| is 368 // updated transition code of the visit records for |url1| and |url2| is
369 // returned by filling in |*transition1| and |*transition2|, respectively. 369 // returned by filling in |*transition1| and |*transition2|, respectively.
370 // |time| is a time of the redirect. 370 // |time| is a time of the redirect.
371 void AddClientRedirect(const GURL& url1, 371 void AddClientRedirect(const GURL& url1,
372 const GURL& url2, 372 const GURL& url2,
373 bool did_replace, 373 bool did_replace,
374 base::Time time, 374 base::Time time,
375 int* transition1, 375 int* transition1,
376 int* transition2) { 376 int* transition2) {
377 ContextID dummy_context_id = reinterpret_cast<ContextID>(0x87654321); 377 ContextID dummy_context_id = reinterpret_cast<ContextID>(0x87654321);
378 history::RedirectList redirects; 378 history::RedirectList redirects;
379 if (url1.is_valid()) 379 if (url1.is_valid())
380 redirects.push_back(url1); 380 redirects.push_back(url1);
381 if (url2.is_valid()) 381 if (url2.is_valid())
382 redirects.push_back(url2); 382 redirects.push_back(url2);
383 HistoryAddPageArgs request( 383 HistoryAddPageArgs request(
384 url2, time, dummy_context_id, 0, url1, 384 url2, time, dummy_context_id, 0, url1,
385 redirects, ui::PAGE_TRANSITION_CLIENT_REDIRECT, 385 redirects, ui::PAGE_TRANSITION_CLIENT_REDIRECT,
386 history::SOURCE_BROWSED, did_replace); 386 history::SOURCE_BROWSED, did_replace, true);
387 backend_->AddPage(request); 387 backend_->AddPage(request);
388 388
389 *transition1 = GetTransition(url1); 389 *transition1 = GetTransition(url1);
390 *transition2 = GetTransition(url2); 390 *transition2 = GetTransition(url2);
391 } 391 }
392 392
393 int GetTransition(const GURL& url) { 393 int GetTransition(const GURL& url) {
394 if (!url.is_valid()) 394 if (!url.is_valid())
395 return 0; 395 return 0;
396 URLRow row; 396 URLRow row;
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 // data for the visited page works. This can happen when clearing the history 772 // data for the visited page works. This can happen when clearing the history
773 // immediately after visiting a page. 773 // immediately after visiting a page.
774 TEST_F(HistoryBackendTest, DeleteAllThenAddData) { 774 TEST_F(HistoryBackendTest, DeleteAllThenAddData) {
775 ASSERT_TRUE(backend_.get()); 775 ASSERT_TRUE(backend_.get());
776 776
777 base::Time visit_time = base::Time::Now(); 777 base::Time visit_time = base::Time::Now();
778 GURL url("http://www.google.com/"); 778 GURL url("http://www.google.com/");
779 HistoryAddPageArgs request(url, visit_time, NULL, 0, GURL(), 779 HistoryAddPageArgs request(url, visit_time, NULL, 0, GURL(),
780 history::RedirectList(), 780 history::RedirectList(),
781 ui::PAGE_TRANSITION_KEYWORD_GENERATED, 781 ui::PAGE_TRANSITION_KEYWORD_GENERATED,
782 history::SOURCE_BROWSED, false); 782 history::SOURCE_BROWSED, false, true);
783 backend_->AddPage(request); 783 backend_->AddPage(request);
784 784
785 // Check that a row was added. 785 // Check that a row was added.
786 URLRow outrow; 786 URLRow outrow;
787 EXPECT_TRUE(backend_->db_->GetRowForURL(url, &outrow)); 787 EXPECT_TRUE(backend_->db_->GetRowForURL(url, &outrow));
788 788
789 // Check that the visit was added. 789 // Check that the visit was added.
790 VisitVector all_visits; 790 VisitVector all_visits;
791 backend_->db_->GetAllVisitsInRange(base::Time(), base::Time(), 0, 791 backend_->db_->GetAllVisitsInRange(base::Time(), base::Time(), 0,
792 &all_visits); 792 &all_visits);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 // KEYWORD_GENERATED. 914 // KEYWORD_GENERATED.
915 TEST_F(HistoryBackendTest, KeywordGenerated) { 915 TEST_F(HistoryBackendTest, KeywordGenerated) {
916 ASSERT_TRUE(backend_.get()); 916 ASSERT_TRUE(backend_.get());
917 917
918 GURL url("http://google.com"); 918 GURL url("http://google.com");
919 919
920 base::Time visit_time = base::Time::Now() - base::TimeDelta::FromDays(1); 920 base::Time visit_time = base::Time::Now() - base::TimeDelta::FromDays(1);
921 HistoryAddPageArgs request(url, visit_time, NULL, 0, GURL(), 921 HistoryAddPageArgs request(url, visit_time, NULL, 0, GURL(),
922 history::RedirectList(), 922 history::RedirectList(),
923 ui::PAGE_TRANSITION_KEYWORD_GENERATED, 923 ui::PAGE_TRANSITION_KEYWORD_GENERATED,
924 history::SOURCE_BROWSED, false); 924 history::SOURCE_BROWSED, false, true);
925 backend_->AddPage(request); 925 backend_->AddPage(request);
926 926
927 // A row should have been added for the url. 927 // A row should have been added for the url.
928 URLRow row; 928 URLRow row;
929 URLID url_id = backend_->db()->GetRowForURL(url, &row); 929 URLID url_id = backend_->db()->GetRowForURL(url, &row);
930 ASSERT_NE(0, url_id); 930 ASSERT_NE(0, url_id);
931 931
932 // The typed count should be 1. 932 // The typed count should be 1.
933 ASSERT_EQ(1, row.typed_count()); 933 ASSERT_EQ(1, row.typed_count());
934 934
(...skipping 11 matching lines...) Expand all
946 QueryOptions query_options; 946 QueryOptions query_options;
947 query_options.max_count = 1; 947 query_options.max_count = 1;
948 backend_->db()->GetVisibleVisitsInRange(query_options, &visits); 948 backend_->db()->GetVisibleVisitsInRange(query_options, &visits);
949 EXPECT_TRUE(visits.empty()); 949 EXPECT_TRUE(visits.empty());
950 950
951 // Going back to the same entry should not increment the typed count. 951 // Going back to the same entry should not increment the typed count.
952 ui::PageTransition back_transition = ui::PageTransitionFromInt( 952 ui::PageTransition back_transition = ui::PageTransitionFromInt(
953 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FORWARD_BACK); 953 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FORWARD_BACK);
954 HistoryAddPageArgs back_request(url, visit_time, NULL, 0, GURL(), 954 HistoryAddPageArgs back_request(url, visit_time, NULL, 0, GURL(),
955 history::RedirectList(), back_transition, 955 history::RedirectList(), back_transition,
956 history::SOURCE_BROWSED, false); 956 history::SOURCE_BROWSED, false, true);
957 backend_->AddPage(back_request); 957 backend_->AddPage(back_request);
958 url_id = backend_->db()->GetRowForURL(url, &row); 958 url_id = backend_->db()->GetRowForURL(url, &row);
959 ASSERT_NE(0, url_id); 959 ASSERT_NE(0, url_id);
960 ASSERT_EQ(1, row.typed_count()); 960 ASSERT_EQ(1, row.typed_count());
961 961
962 // Expire the visits. 962 // Expire the visits.
963 std::set<GURL> restrict_urls; 963 std::set<GURL> restrict_urls;
964 backend_->expire_backend()->ExpireHistoryBetween(restrict_urls, visit_time, 964 backend_->expire_backend()->ExpireHistoryBetween(restrict_urls, visit_time,
965 base::Time::Now()); 965 base::Time::Now());
966 966
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 1475
1476 TEST_F(HistoryBackendTest, AddPageArgsSource) { 1476 TEST_F(HistoryBackendTest, AddPageArgsSource) {
1477 ASSERT_TRUE(backend_.get()); 1477 ASSERT_TRUE(backend_.get());
1478 1478
1479 GURL url("http://testpageargs.com"); 1479 GURL url("http://testpageargs.com");
1480 1480
1481 // Assume this page is browsed by user. 1481 // Assume this page is browsed by user.
1482 HistoryAddPageArgs request1(url, base::Time::Now(), NULL, 0, GURL(), 1482 HistoryAddPageArgs request1(url, base::Time::Now(), NULL, 0, GURL(),
1483 history::RedirectList(), 1483 history::RedirectList(),
1484 ui::PAGE_TRANSITION_KEYWORD_GENERATED, 1484 ui::PAGE_TRANSITION_KEYWORD_GENERATED,
1485 history::SOURCE_BROWSED, false); 1485 history::SOURCE_BROWSED, false, true);
1486 backend_->AddPage(request1); 1486 backend_->AddPage(request1);
1487 // Assume this page is synced. 1487 // Assume this page is synced.
1488 HistoryAddPageArgs request2(url, base::Time::Now(), NULL, 0, GURL(), 1488 HistoryAddPageArgs request2(url, base::Time::Now(), NULL, 0, GURL(),
1489 history::RedirectList(), 1489 history::RedirectList(),
1490 ui::PAGE_TRANSITION_LINK, 1490 ui::PAGE_TRANSITION_LINK,
1491 history::SOURCE_SYNCED, false); 1491 history::SOURCE_SYNCED, false, true);
1492 backend_->AddPage(request2); 1492 backend_->AddPage(request2);
1493 // Assume this page is browsed again. 1493 // Assume this page is browsed again.
1494 HistoryAddPageArgs request3(url, base::Time::Now(), NULL, 0, GURL(), 1494 HistoryAddPageArgs request3(url, base::Time::Now(), NULL, 0, GURL(),
1495 history::RedirectList(), 1495 history::RedirectList(),
1496 ui::PAGE_TRANSITION_TYPED, 1496 ui::PAGE_TRANSITION_TYPED,
1497 history::SOURCE_BROWSED, false); 1497 history::SOURCE_BROWSED, false, true);
1498 backend_->AddPage(request3); 1498 backend_->AddPage(request3);
1499 1499
1500 // Three visits should be added with proper sources. 1500 // Three visits should be added with proper sources.
1501 VisitVector visits; 1501 VisitVector visits;
1502 URLRow row; 1502 URLRow row;
1503 URLID id = backend_->db()->GetRowForURL(url, &row); 1503 URLID id = backend_->db()->GetRowForURL(url, &row);
1504 ASSERT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); 1504 ASSERT_TRUE(backend_->db()->GetVisitsForURL(id, &visits));
1505 ASSERT_EQ(3U, visits.size()); 1505 ASSERT_EQ(3U, visits.size());
1506 VisitSourceMap visit_sources; 1506 VisitSourceMap visit_sources;
1507 ASSERT_TRUE(backend_->GetVisitsSource(visits, &visit_sources)); 1507 ASSERT_TRUE(backend_->GetVisitsSource(visits, &visit_sources));
(...skipping 2291 matching lines...) Expand 10 before | Expand all | Expand 10 after
3799 3799
3800 // Verify that the second term is no longer returned as result, and also check 3800 // Verify that the second term is no longer returned as result, and also check
3801 // at the low level that it is gone for good. The term corresponding to the 3801 // at the low level that it is gone for good. The term corresponding to the
3802 // first URLRow should not be affected. 3802 // first URLRow should not be affected.
3803 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); 3803 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
3804 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); 3804 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
3805 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); 3805 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
3806 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); 3806 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
3807 } 3807 }
3808 3808
3809 TEST_F(HistoryBackendTest, QueryMostVisitedURLs) {
3810 ASSERT_TRUE(backend_.get());
3811
3812 // Pairs from page transitions to consider_for_ntp_most_visited.
3813 std::vector<std::pair<ui::PageTransition, bool>> pages;
3814 pages.emplace_back(ui::PAGE_TRANSITION_AUTO_BOOKMARK, true); // good.
3815 pages.emplace_back(ui::PAGE_TRANSITION_AUTO_BOOKMARK, false); // bad.
3816 pages.emplace_back(ui::PAGE_TRANSITION_LINK, true); // bad.
3817 pages.emplace_back(ui::PAGE_TRANSITION_TYPED, false); // bad.
3818 pages.emplace_back(ui::PAGE_TRANSITION_TYPED, true); // good.
3819
3820 for (size_t i = 0; i < pages.size(); ++i) {
3821 HistoryAddPageArgs args;
3822 args.url = GURL("http://example" + base::SizeTToString(i + 1) + ".com");
3823 args.time = base::Time::Now() - base::TimeDelta::FromDays(i + 1);
3824 args.transition = pages[i].first;
3825 args.consider_for_ntp_most_visited = pages[i].second;
3826 backend_->AddPage(args);
3827 }
3828
3829 MostVisitedURLList most_visited;
3830 backend_->QueryMostVisitedURLs(100, 100, &most_visited);
3831
3832 const base::string16 kSomeTitle; // Ignored by equality operator.
3833 EXPECT_THAT(
3834 most_visited,
3835 ElementsAre(MostVisitedURL(GURL("http://example1.com"), kSomeTitle),
3836 MostVisitedURL(GURL("http://example5.com"), kSomeTitle)));
3837 }
3838
3809 } // namespace history 3839 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/history_backend.cc ('k') | components/history/core/browser/history_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698