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

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

Issue 352623002: Port History::QueryMostVisitedURLs to use CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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 // History unit tests come in two flavors: 5 // History unit tests come in two flavors:
6 // 6 //
7 // 1. The more complicated style is that the unit test creates a full history 7 // 1. The more complicated style is that the unit test creates a full history
8 // service. This spawns a background thread for the history backend, and 8 // service. This spawns a background thread for the history backend, and
9 // all communication is asynchronous. This is useful for testing more 9 // all communication is asynchronous. This is useful for testing more
10 // complicated things or end-to-end behavior. 10 // complicated things or end-to-end behavior.
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle, 987 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle,
988 std::vector<PageUsageData*>* data) { 988 std::vector<PageUsageData*>* data) {
989 page_usage_data_.swap(*data); 989 page_usage_data_.swap(*data);
990 base::MessageLoop::current()->Quit(); 990 base::MessageLoop::current()->Quit();
991 } 991 }
992 992
993 void OnDeleteURLsDone(CancelableRequestProvider::Handle handle) { 993 void OnDeleteURLsDone(CancelableRequestProvider::Handle handle) {
994 base::MessageLoop::current()->Quit(); 994 base::MessageLoop::current()->Quit();
995 } 995 }
996 996
997 void OnMostVisitedURLsAvailable(CancelableRequestProvider::Handle handle, 997 void OnMostVisitedURLsAvailable(const MostVisitedURLList* url_list) {
998 MostVisitedURLList url_list) { 998 most_visited_urls_ = *url_list;
999 most_visited_urls_.swap(url_list);
1000 base::MessageLoop::current()->Quit(); 999 base::MessageLoop::current()->Quit();
1001 } 1000 }
1002 1001
1003 protected: 1002 protected:
1004 friend class BackendDelegate; 1003 friend class BackendDelegate;
1005 1004
1006 // testing::Test 1005 // testing::Test
1007 virtual void SetUp() { 1006 virtual void SetUp() {
1008 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 1007 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
1009 history_dir_ = temp_dir_.path().AppendASCII("HistoryTest"); 1008 history_dir_ = temp_dir_.path().AppendASCII("HistoryTest");
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 // Add two pages. 1476 // Add two pages.
1478 history_service_->AddPage( 1477 history_service_->AddPage(
1479 url0, base::Time::Now(), context_id, 0, GURL(), 1478 url0, base::Time::Now(), context_id, 0, GURL(),
1480 history::RedirectList(), content::PAGE_TRANSITION_TYPED, 1479 history::RedirectList(), content::PAGE_TRANSITION_TYPED,
1481 history::SOURCE_BROWSED, false); 1480 history::SOURCE_BROWSED, false);
1482 history_service_->AddPage( 1481 history_service_->AddPage(
1483 url1, base::Time::Now(), context_id, 0, GURL(), 1482 url1, base::Time::Now(), context_id, 0, GURL(),
1484 history::RedirectList(), content::PAGE_TRANSITION_TYPED, 1483 history::RedirectList(), content::PAGE_TRANSITION_TYPED,
1485 history::SOURCE_BROWSED, false); 1484 history::SOURCE_BROWSED, false);
1486 history_service_->QueryMostVisitedURLs( 1485 history_service_->QueryMostVisitedURLs(
1487 20, 90, &consumer_, 1486 20, 90,
1488 base::Bind( 1487 base::Bind(
1489 &HistoryTest::OnMostVisitedURLsAvailable, 1488 &HistoryTest::OnMostVisitedURLsAvailable,
1490 base::Unretained(this))); 1489 base::Unretained(this)),
1490 &tracker_);
1491 base::MessageLoop::current()->Run(); 1491 base::MessageLoop::current()->Run();
1492 1492
1493 EXPECT_EQ(2U, most_visited_urls_.size()); 1493 EXPECT_EQ(2U, most_visited_urls_.size());
1494 EXPECT_EQ(url0, most_visited_urls_[0].url); 1494 EXPECT_EQ(url0, most_visited_urls_[0].url);
1495 EXPECT_EQ(url1, most_visited_urls_[1].url); 1495 EXPECT_EQ(url1, most_visited_urls_[1].url);
1496 1496
1497 // Add another page. 1497 // Add another page.
1498 history_service_->AddPage( 1498 history_service_->AddPage(
1499 url2, base::Time::Now(), context_id, 0, GURL(), 1499 url2, base::Time::Now(), context_id, 0, GURL(),
1500 history::RedirectList(), content::PAGE_TRANSITION_TYPED, 1500 history::RedirectList(), content::PAGE_TRANSITION_TYPED,
1501 history::SOURCE_BROWSED, false); 1501 history::SOURCE_BROWSED, false);
1502 history_service_->QueryMostVisitedURLs( 1502 history_service_->QueryMostVisitedURLs(
1503 20, 90, &consumer_, 1503 20, 90,
1504 base::Bind( 1504 base::Bind(
1505 &HistoryTest::OnMostVisitedURLsAvailable, 1505 &HistoryTest::OnMostVisitedURLsAvailable,
1506 base::Unretained(this))); 1506 base::Unretained(this)),
1507 &tracker_);
1507 base::MessageLoop::current()->Run(); 1508 base::MessageLoop::current()->Run();
1508 1509
1509 EXPECT_EQ(3U, most_visited_urls_.size()); 1510 EXPECT_EQ(3U, most_visited_urls_.size());
1510 EXPECT_EQ(url0, most_visited_urls_[0].url); 1511 EXPECT_EQ(url0, most_visited_urls_[0].url);
1511 EXPECT_EQ(url1, most_visited_urls_[1].url); 1512 EXPECT_EQ(url1, most_visited_urls_[1].url);
1512 EXPECT_EQ(url2, most_visited_urls_[2].url); 1513 EXPECT_EQ(url2, most_visited_urls_[2].url);
1513 1514
1514 // Revisit url2, making it the top URL. 1515 // Revisit url2, making it the top URL.
1515 history_service_->AddPage( 1516 history_service_->AddPage(
1516 url2, base::Time::Now(), context_id, 0, GURL(), 1517 url2, base::Time::Now(), context_id, 0, GURL(),
1517 history::RedirectList(), content::PAGE_TRANSITION_TYPED, 1518 history::RedirectList(), content::PAGE_TRANSITION_TYPED,
1518 history::SOURCE_BROWSED, false); 1519 history::SOURCE_BROWSED, false);
1519 history_service_->QueryMostVisitedURLs( 1520 history_service_->QueryMostVisitedURLs(
1520 20, 90, &consumer_, 1521 20, 90,
1521 base::Bind( 1522 base::Bind(
1522 &HistoryTest::OnMostVisitedURLsAvailable, 1523 &HistoryTest::OnMostVisitedURLsAvailable,
1523 base::Unretained(this))); 1524 base::Unretained(this)),
1525 &tracker_);
1524 base::MessageLoop::current()->Run(); 1526 base::MessageLoop::current()->Run();
1525 1527
1526 EXPECT_EQ(3U, most_visited_urls_.size()); 1528 EXPECT_EQ(3U, most_visited_urls_.size());
1527 EXPECT_EQ(url2, most_visited_urls_[0].url); 1529 EXPECT_EQ(url2, most_visited_urls_[0].url);
1528 EXPECT_EQ(url0, most_visited_urls_[1].url); 1530 EXPECT_EQ(url0, most_visited_urls_[1].url);
1529 EXPECT_EQ(url1, most_visited_urls_[2].url); 1531 EXPECT_EQ(url1, most_visited_urls_[2].url);
1530 1532
1531 // Revisit url1, making it the top URL. 1533 // Revisit url1, making it the top URL.
1532 history_service_->AddPage( 1534 history_service_->AddPage(
1533 url1, base::Time::Now(), context_id, 0, GURL(), 1535 url1, base::Time::Now(), context_id, 0, GURL(),
1534 history::RedirectList(), content::PAGE_TRANSITION_TYPED, 1536 history::RedirectList(), content::PAGE_TRANSITION_TYPED,
1535 history::SOURCE_BROWSED, false); 1537 history::SOURCE_BROWSED, false);
1536 history_service_->QueryMostVisitedURLs( 1538 history_service_->QueryMostVisitedURLs(
1537 20, 90, &consumer_, 1539 20, 90,
1538 base::Bind( 1540 base::Bind(
1539 &HistoryTest::OnMostVisitedURLsAvailable, 1541 &HistoryTest::OnMostVisitedURLsAvailable,
1540 base::Unretained(this))); 1542 base::Unretained(this)),
1543 &tracker_);
1541 base::MessageLoop::current()->Run(); 1544 base::MessageLoop::current()->Run();
1542 1545
1543 EXPECT_EQ(3U, most_visited_urls_.size()); 1546 EXPECT_EQ(3U, most_visited_urls_.size());
1544 EXPECT_EQ(url1, most_visited_urls_[0].url); 1547 EXPECT_EQ(url1, most_visited_urls_[0].url);
1545 EXPECT_EQ(url2, most_visited_urls_[1].url); 1548 EXPECT_EQ(url2, most_visited_urls_[1].url);
1546 EXPECT_EQ(url0, most_visited_urls_[2].url); 1549 EXPECT_EQ(url0, most_visited_urls_[2].url);
1547 1550
1548 // Redirects 1551 // Redirects
1549 history::RedirectList redirects; 1552 history::RedirectList redirects;
1550 redirects.push_back(url3); 1553 redirects.push_back(url3);
1551 redirects.push_back(url4); 1554 redirects.push_back(url4);
1552 1555
1553 // Visit url4 using redirects. 1556 // Visit url4 using redirects.
1554 history_service_->AddPage( 1557 history_service_->AddPage(
1555 url4, base::Time::Now(), context_id, 0, GURL(), 1558 url4, base::Time::Now(), context_id, 0, GURL(),
1556 redirects, content::PAGE_TRANSITION_TYPED, 1559 redirects, content::PAGE_TRANSITION_TYPED,
1557 history::SOURCE_BROWSED, false); 1560 history::SOURCE_BROWSED, false);
1558 history_service_->QueryMostVisitedURLs( 1561 history_service_->QueryMostVisitedURLs(
1559 20, 90, &consumer_, 1562 20, 90,
1560 base::Bind( 1563 base::Bind(
1561 &HistoryTest::OnMostVisitedURLsAvailable, 1564 &HistoryTest::OnMostVisitedURLsAvailable,
1562 base::Unretained(this))); 1565 base::Unretained(this)),
1566 &tracker_);
1563 base::MessageLoop::current()->Run(); 1567 base::MessageLoop::current()->Run();
1564 1568
1565 EXPECT_EQ(4U, most_visited_urls_.size()); 1569 EXPECT_EQ(4U, most_visited_urls_.size());
1566 EXPECT_EQ(url1, most_visited_urls_[0].url); 1570 EXPECT_EQ(url1, most_visited_urls_[0].url);
1567 EXPECT_EQ(url2, most_visited_urls_[1].url); 1571 EXPECT_EQ(url2, most_visited_urls_[1].url);
1568 EXPECT_EQ(url0, most_visited_urls_[2].url); 1572 EXPECT_EQ(url0, most_visited_urls_[2].url);
1569 EXPECT_EQ(url3, most_visited_urls_[3].url); 1573 EXPECT_EQ(url3, most_visited_urls_[3].url);
1570 EXPECT_EQ(2U, most_visited_urls_[3].redirects.size()); 1574 EXPECT_EQ(2U, most_visited_urls_[3].redirects.size());
1571 } 1575 }
1572 1576
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 std::vector<PageUsageData*> results; 1942 std::vector<PageUsageData*> results;
1939 db_->QuerySegmentUsage(segment_time, 10, &results); 1943 db_->QuerySegmentUsage(segment_time, 10, &results);
1940 ASSERT_EQ(1u, results.size()); 1944 ASSERT_EQ(1u, results.size());
1941 EXPECT_EQ(url, results[0]->GetURL()); 1945 EXPECT_EQ(url, results[0]->GetURL());
1942 EXPECT_EQ(segment_id, results[0]->GetID()); 1946 EXPECT_EQ(segment_id, results[0]->GetID());
1943 EXPECT_EQ(title, results[0]->GetTitle()); 1947 EXPECT_EQ(title, results[0]->GetTitle());
1944 STLDeleteElements(&results); 1948 STLDeleteElements(&results);
1945 } 1949 }
1946 1950
1947 } // namespace history 1951 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698