| OLD | NEW |
| 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 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle, | 986 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle, |
| 987 std::vector<PageUsageData*>* data) { | 987 std::vector<PageUsageData*>* data) { |
| 988 page_usage_data_.swap(*data); | 988 page_usage_data_.swap(*data); |
| 989 base::MessageLoop::current()->Quit(); | 989 base::MessageLoop::current()->Quit(); |
| 990 } | 990 } |
| 991 | 991 |
| 992 void OnDeleteURLsDone(CancelableRequestProvider::Handle handle) { | 992 void OnDeleteURLsDone(CancelableRequestProvider::Handle handle) { |
| 993 base::MessageLoop::current()->Quit(); | 993 base::MessageLoop::current()->Quit(); |
| 994 } | 994 } |
| 995 | 995 |
| 996 void OnMostVisitedURLsAvailable(CancelableRequestProvider::Handle handle, | 996 void OnMostVisitedURLsAvailable(const MostVisitedURLList* url_list) { |
| 997 MostVisitedURLList url_list) { | 997 most_visited_urls_ = *url_list; |
| 998 most_visited_urls_.swap(url_list); | |
| 999 base::MessageLoop::current()->Quit(); | 998 base::MessageLoop::current()->Quit(); |
| 1000 } | 999 } |
| 1001 | 1000 |
| 1002 protected: | 1001 protected: |
| 1003 friend class BackendDelegate; | 1002 friend class BackendDelegate; |
| 1004 | 1003 |
| 1005 // testing::Test | 1004 // testing::Test |
| 1006 virtual void SetUp() { | 1005 virtual void SetUp() { |
| 1007 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 1006 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 1008 history_dir_ = temp_dir_.path().AppendASCII("HistoryTest"); | 1007 history_dir_ = temp_dir_.path().AppendASCII("HistoryTest"); |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 // Add two pages. | 1470 // Add two pages. |
| 1472 history_service_->AddPage( | 1471 history_service_->AddPage( |
| 1473 url0, base::Time::Now(), context_id, 0, GURL(), | 1472 url0, base::Time::Now(), context_id, 0, GURL(), |
| 1474 history::RedirectList(), content::PAGE_TRANSITION_TYPED, | 1473 history::RedirectList(), content::PAGE_TRANSITION_TYPED, |
| 1475 history::SOURCE_BROWSED, false); | 1474 history::SOURCE_BROWSED, false); |
| 1476 history_service_->AddPage( | 1475 history_service_->AddPage( |
| 1477 url1, base::Time::Now(), context_id, 0, GURL(), | 1476 url1, base::Time::Now(), context_id, 0, GURL(), |
| 1478 history::RedirectList(), content::PAGE_TRANSITION_TYPED, | 1477 history::RedirectList(), content::PAGE_TRANSITION_TYPED, |
| 1479 history::SOURCE_BROWSED, false); | 1478 history::SOURCE_BROWSED, false); |
| 1480 history_service_->QueryMostVisitedURLs( | 1479 history_service_->QueryMostVisitedURLs( |
| 1481 20, 90, &consumer_, | 1480 20, |
| 1482 base::Bind( | 1481 90, |
| 1483 &HistoryTest::OnMostVisitedURLsAvailable, | 1482 base::Bind(&HistoryTest::OnMostVisitedURLsAvailable, |
| 1484 base::Unretained(this))); | 1483 base::Unretained(this)), |
| 1484 &tracker_); |
| 1485 base::MessageLoop::current()->Run(); | 1485 base::MessageLoop::current()->Run(); |
| 1486 | 1486 |
| 1487 EXPECT_EQ(2U, most_visited_urls_.size()); | 1487 EXPECT_EQ(2U, most_visited_urls_.size()); |
| 1488 EXPECT_EQ(url0, most_visited_urls_[0].url); | 1488 EXPECT_EQ(url0, most_visited_urls_[0].url); |
| 1489 EXPECT_EQ(url1, most_visited_urls_[1].url); | 1489 EXPECT_EQ(url1, most_visited_urls_[1].url); |
| 1490 | 1490 |
| 1491 // Add another page. | 1491 // Add another page. |
| 1492 history_service_->AddPage( | 1492 history_service_->AddPage( |
| 1493 url2, base::Time::Now(), context_id, 0, GURL(), | 1493 url2, base::Time::Now(), context_id, 0, GURL(), |
| 1494 history::RedirectList(), content::PAGE_TRANSITION_TYPED, | 1494 history::RedirectList(), content::PAGE_TRANSITION_TYPED, |
| 1495 history::SOURCE_BROWSED, false); | 1495 history::SOURCE_BROWSED, false); |
| 1496 history_service_->QueryMostVisitedURLs( | 1496 history_service_->QueryMostVisitedURLs( |
| 1497 20, 90, &consumer_, | 1497 20, |
| 1498 base::Bind( | 1498 90, |
| 1499 &HistoryTest::OnMostVisitedURLsAvailable, | 1499 base::Bind(&HistoryTest::OnMostVisitedURLsAvailable, |
| 1500 base::Unretained(this))); | 1500 base::Unretained(this)), |
| 1501 &tracker_); |
| 1501 base::MessageLoop::current()->Run(); | 1502 base::MessageLoop::current()->Run(); |
| 1502 | 1503 |
| 1503 EXPECT_EQ(3U, most_visited_urls_.size()); | 1504 EXPECT_EQ(3U, most_visited_urls_.size()); |
| 1504 EXPECT_EQ(url0, most_visited_urls_[0].url); | 1505 EXPECT_EQ(url0, most_visited_urls_[0].url); |
| 1505 EXPECT_EQ(url1, most_visited_urls_[1].url); | 1506 EXPECT_EQ(url1, most_visited_urls_[1].url); |
| 1506 EXPECT_EQ(url2, most_visited_urls_[2].url); | 1507 EXPECT_EQ(url2, most_visited_urls_[2].url); |
| 1507 | 1508 |
| 1508 // Revisit url2, making it the top URL. | 1509 // Revisit url2, making it the top URL. |
| 1509 history_service_->AddPage( | 1510 history_service_->AddPage( |
| 1510 url2, base::Time::Now(), context_id, 0, GURL(), | 1511 url2, base::Time::Now(), context_id, 0, GURL(), |
| 1511 history::RedirectList(), content::PAGE_TRANSITION_TYPED, | 1512 history::RedirectList(), content::PAGE_TRANSITION_TYPED, |
| 1512 history::SOURCE_BROWSED, false); | 1513 history::SOURCE_BROWSED, false); |
| 1513 history_service_->QueryMostVisitedURLs( | 1514 history_service_->QueryMostVisitedURLs( |
| 1514 20, 90, &consumer_, | 1515 20, |
| 1515 base::Bind( | 1516 90, |
| 1516 &HistoryTest::OnMostVisitedURLsAvailable, | 1517 base::Bind(&HistoryTest::OnMostVisitedURLsAvailable, |
| 1517 base::Unretained(this))); | 1518 base::Unretained(this)), |
| 1519 &tracker_); |
| 1518 base::MessageLoop::current()->Run(); | 1520 base::MessageLoop::current()->Run(); |
| 1519 | 1521 |
| 1520 EXPECT_EQ(3U, most_visited_urls_.size()); | 1522 EXPECT_EQ(3U, most_visited_urls_.size()); |
| 1521 EXPECT_EQ(url2, most_visited_urls_[0].url); | 1523 EXPECT_EQ(url2, most_visited_urls_[0].url); |
| 1522 EXPECT_EQ(url0, most_visited_urls_[1].url); | 1524 EXPECT_EQ(url0, most_visited_urls_[1].url); |
| 1523 EXPECT_EQ(url1, most_visited_urls_[2].url); | 1525 EXPECT_EQ(url1, most_visited_urls_[2].url); |
| 1524 | 1526 |
| 1525 // Revisit url1, making it the top URL. | 1527 // Revisit url1, making it the top URL. |
| 1526 history_service_->AddPage( | 1528 history_service_->AddPage( |
| 1527 url1, base::Time::Now(), context_id, 0, GURL(), | 1529 url1, base::Time::Now(), context_id, 0, GURL(), |
| 1528 history::RedirectList(), content::PAGE_TRANSITION_TYPED, | 1530 history::RedirectList(), content::PAGE_TRANSITION_TYPED, |
| 1529 history::SOURCE_BROWSED, false); | 1531 history::SOURCE_BROWSED, false); |
| 1530 history_service_->QueryMostVisitedURLs( | 1532 history_service_->QueryMostVisitedURLs( |
| 1531 20, 90, &consumer_, | 1533 20, |
| 1532 base::Bind( | 1534 90, |
| 1533 &HistoryTest::OnMostVisitedURLsAvailable, | 1535 base::Bind(&HistoryTest::OnMostVisitedURLsAvailable, |
| 1534 base::Unretained(this))); | 1536 base::Unretained(this)), |
| 1537 &tracker_); |
| 1535 base::MessageLoop::current()->Run(); | 1538 base::MessageLoop::current()->Run(); |
| 1536 | 1539 |
| 1537 EXPECT_EQ(3U, most_visited_urls_.size()); | 1540 EXPECT_EQ(3U, most_visited_urls_.size()); |
| 1538 EXPECT_EQ(url1, most_visited_urls_[0].url); | 1541 EXPECT_EQ(url1, most_visited_urls_[0].url); |
| 1539 EXPECT_EQ(url2, most_visited_urls_[1].url); | 1542 EXPECT_EQ(url2, most_visited_urls_[1].url); |
| 1540 EXPECT_EQ(url0, most_visited_urls_[2].url); | 1543 EXPECT_EQ(url0, most_visited_urls_[2].url); |
| 1541 | 1544 |
| 1542 // Redirects | 1545 // Redirects |
| 1543 history::RedirectList redirects; | 1546 history::RedirectList redirects; |
| 1544 redirects.push_back(url3); | 1547 redirects.push_back(url3); |
| 1545 redirects.push_back(url4); | 1548 redirects.push_back(url4); |
| 1546 | 1549 |
| 1547 // Visit url4 using redirects. | 1550 // Visit url4 using redirects. |
| 1548 history_service_->AddPage( | 1551 history_service_->AddPage( |
| 1549 url4, base::Time::Now(), context_id, 0, GURL(), | 1552 url4, base::Time::Now(), context_id, 0, GURL(), |
| 1550 redirects, content::PAGE_TRANSITION_TYPED, | 1553 redirects, content::PAGE_TRANSITION_TYPED, |
| 1551 history::SOURCE_BROWSED, false); | 1554 history::SOURCE_BROWSED, false); |
| 1552 history_service_->QueryMostVisitedURLs( | 1555 history_service_->QueryMostVisitedURLs( |
| 1553 20, 90, &consumer_, | 1556 20, |
| 1554 base::Bind( | 1557 90, |
| 1555 &HistoryTest::OnMostVisitedURLsAvailable, | 1558 base::Bind(&HistoryTest::OnMostVisitedURLsAvailable, |
| 1556 base::Unretained(this))); | 1559 base::Unretained(this)), |
| 1560 &tracker_); |
| 1557 base::MessageLoop::current()->Run(); | 1561 base::MessageLoop::current()->Run(); |
| 1558 | 1562 |
| 1559 EXPECT_EQ(4U, most_visited_urls_.size()); | 1563 EXPECT_EQ(4U, most_visited_urls_.size()); |
| 1560 EXPECT_EQ(url1, most_visited_urls_[0].url); | 1564 EXPECT_EQ(url1, most_visited_urls_[0].url); |
| 1561 EXPECT_EQ(url2, most_visited_urls_[1].url); | 1565 EXPECT_EQ(url2, most_visited_urls_[1].url); |
| 1562 EXPECT_EQ(url0, most_visited_urls_[2].url); | 1566 EXPECT_EQ(url0, most_visited_urls_[2].url); |
| 1563 EXPECT_EQ(url3, most_visited_urls_[3].url); | 1567 EXPECT_EQ(url3, most_visited_urls_[3].url); |
| 1564 EXPECT_EQ(2U, most_visited_urls_[3].redirects.size()); | 1568 EXPECT_EQ(2U, most_visited_urls_[3].redirects.size()); |
| 1565 } | 1569 } |
| 1566 | 1570 |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1932 std::vector<PageUsageData*> results; | 1936 std::vector<PageUsageData*> results; |
| 1933 db_->QuerySegmentUsage(segment_time, 10, &results); | 1937 db_->QuerySegmentUsage(segment_time, 10, &results); |
| 1934 ASSERT_EQ(1u, results.size()); | 1938 ASSERT_EQ(1u, results.size()); |
| 1935 EXPECT_EQ(url, results[0]->GetURL()); | 1939 EXPECT_EQ(url, results[0]->GetURL()); |
| 1936 EXPECT_EQ(segment_id, results[0]->GetID()); | 1940 EXPECT_EQ(segment_id, results[0]->GetID()); |
| 1937 EXPECT_EQ(title, results[0]->GetTitle()); | 1941 EXPECT_EQ(title, results[0]->GetTitle()); |
| 1938 STLDeleteElements(&results); | 1942 STLDeleteElements(&results); |
| 1939 } | 1943 } |
| 1940 | 1944 |
| 1941 } // namespace history | 1945 } // namespace history |
| OLD | NEW |