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

Unified Diff: components/visitedlink/test/visitedlink_unittest.cc

Issue 1417943002: Load the table of visited links from database file asynchronously. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: components/visitedlink/test/visitedlink_unittest.cc
diff --git a/components/visitedlink/test/visitedlink_unittest.cc b/components/visitedlink/test/visitedlink_unittest.cc
index f663f83b0cf816e2d9f6e69505cb5933105d256d..cee8be67975dcc5d021ff2b4071a708453fe7233 100644
--- a/components/visitedlink/test/visitedlink_unittest.cc
+++ b/components/visitedlink/test/visitedlink_unittest.cc
@@ -142,14 +142,23 @@ class VisitedLinkTest : public testing::Test {
//
// |suppress_rebuild| is set when we're not testing rebuilding, see
// the VisitedLinkMaster constructor.
- bool InitVisited(int initial_size, bool suppress_rebuild) {
+ //
+ // |wait_for_io_complete| wait for result of async loading.
+ bool InitVisited(int initial_size,
+ bool suppress_rebuild,
+ bool wait_for_io_complete) {
// Initialize the visited link system.
master_.reset(new VisitedLinkMaster(new TrackingVisitedLinkEventListener(),
&delegate_,
true,
suppress_rebuild, visited_file_,
initial_size));
- return master_->Init();
+ bool result = master_->Init();
+ if (result && wait_for_io_complete) {
+ // Wait for all pending file I/O to be completed.
+ content::RunAllBlockingPoolTasksUntilIdle();
+ }
+ return result;
}
// May be called multiple times (some tests will do this to clear things,
@@ -169,7 +178,8 @@ class VisitedLinkTest : public testing::Test {
// Clean up after our caller, who may have left the database open.
ClearDB();
- ASSERT_TRUE(InitVisited(0, true));
+ ASSERT_TRUE(InitVisited(0, true, true));
+
master_->DebugValidate();
// check that the table has the proper number of entries
@@ -231,7 +241,7 @@ class VisitedLinkTest : public testing::Test {
// This test creates and reads some databases to make sure the data is
// preserved throughout those operations.
TEST_F(VisitedLinkTest, DatabaseIO) {
- ASSERT_TRUE(InitVisited(0, true));
+ ASSERT_TRUE(InitVisited(0, true, true));
for (int i = 0; i < g_test_count; i++)
master_->AddURL(TestURL(i));
@@ -243,7 +253,7 @@ TEST_F(VisitedLinkTest, DatabaseIO) {
// Checks that we can delete things properly when there are collisions.
TEST_F(VisitedLinkTest, Delete) {
static const int32 kInitialSize = 17;
- ASSERT_TRUE(InitVisited(kInitialSize, true));
+ ASSERT_TRUE(InitVisited(kInitialSize, true, true));
// Add a cluster from 14-17 wrapping around to 0. These will all hash to the
// same value.
@@ -281,7 +291,7 @@ TEST_F(VisitedLinkTest, Delete) {
// When we delete more than kBigDeleteThreshold we trigger different behavior
// where the entire file is rewritten.
TEST_F(VisitedLinkTest, BigDelete) {
- ASSERT_TRUE(InitVisited(16381, true));
+ ASSERT_TRUE(InitVisited(16381, true, true));
// Add the base set of URLs that won't be deleted.
// Reload() will test for these.
@@ -305,7 +315,7 @@ TEST_F(VisitedLinkTest, BigDelete) {
}
TEST_F(VisitedLinkTest, DeleteAll) {
- ASSERT_TRUE(InitVisited(0, true));
+ ASSERT_TRUE(InitVisited(0, true, true));
{
VisitedLinkSlave slave;
@@ -340,7 +350,7 @@ TEST_F(VisitedLinkTest, DeleteAll) {
}
// Reopen and validate.
- ASSERT_TRUE(InitVisited(0, true));
+ ASSERT_TRUE(InitVisited(0, true, true));
master_->DebugValidate();
EXPECT_EQ(0, master_->GetUsedCount());
for (int i = 0; i < g_test_count; i++)
@@ -352,7 +362,7 @@ TEST_F(VisitedLinkTest, DeleteAll) {
TEST_F(VisitedLinkTest, Resizing) {
// Create a very small database.
const int32 initial_size = 17;
- ASSERT_TRUE(InitVisited(initial_size, true));
+ ASSERT_TRUE(InitVisited(initial_size, true, true));
// ...and a slave
VisitedLinkSlave slave;
@@ -408,7 +418,7 @@ TEST_F(VisitedLinkTest, Rebuild) {
// Initialize the visited link DB. Since the visited links file doesn't exist
// and we don't suppress history rebuilding, this will load from history.
- ASSERT_TRUE(InitVisited(0, false));
+ ASSERT_TRUE(InitVisited(0, false, false));
// While the table is rebuilding, add the rest of the URLs to the visited
// link system. This isn't guaranteed to happen during the rebuild, so we
@@ -445,7 +455,7 @@ TEST_F(VisitedLinkTest, Rebuild) {
// Test that importing a large number of URLs will work
TEST_F(VisitedLinkTest, BigImport) {
- ASSERT_TRUE(InitVisited(0, false));
+ ASSERT_TRUE(InitVisited(0, false, false));
// Before the table rebuilds, add a large number of URLs
int total_count = VisitedLinkMaster::kDefaultTableSize + 10;
@@ -463,7 +473,7 @@ TEST_F(VisitedLinkTest, BigImport) {
}
TEST_F(VisitedLinkTest, Listener) {
- ASSERT_TRUE(InitVisited(0, true));
+ ASSERT_TRUE(InitVisited(0, true, true));
// Add test URLs.
for (int i = 0; i < g_test_count; i++) {

Powered by Google App Engine
This is Rietveld 408576698