| Index: chrome/browser/history/history_backend_unittest.cc
|
| diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc
|
| index b4c071674365348e3d4515e1a8954de6ec41d60e..c8622e2ff785ce4c46fb3f191e1571ddb73d1a03 100644
|
| --- a/chrome/browser/history/history_backend_unittest.cc
|
| +++ b/chrome/browser/history/history_backend_unittest.cc
|
| @@ -1385,4 +1385,119 @@ TEST_F(HistoryBackendTest, QueryFilteredURLs) {
|
| get_most_visited_list()[0].url.spec());
|
| }
|
|
|
| +TEST_F(HistoryBackendTest, UpdateVisitDuration) {
|
| + // This unit test will test adding and deleting visit details information.
|
| + ASSERT_TRUE(backend_.get());
|
| +
|
| + GURL url1("http://www.cnn.com");
|
| + std::vector<VisitInfo> visit_info1, visit_info2;
|
| + Time start_ts = Time::Now() - base::TimeDelta::FromDays(5);
|
| + Time end_ts = start_ts + base::TimeDelta::FromDays(2);
|
| + visit_info1.push_back(VisitInfo(start_ts, content::PAGE_TRANSITION_LINK));
|
| +
|
| + GURL url2("http://www.example.com");
|
| + visit_info2.push_back(VisitInfo(Time::Now() - base::TimeDelta::FromDays(10),
|
| + content::PAGE_TRANSITION_LINK));
|
| +
|
| + // Clear all history.
|
| + backend_->DeleteAllHistory();
|
| +
|
| + // Add the visits.
|
| + backend_->AddVisits(url1, visit_info1, history::SOURCE_BROWSED);
|
| + backend_->AddVisits(url2, visit_info2, history::SOURCE_BROWSED);
|
| +
|
| + // Verify the entries for both visits were added in visit_details.
|
| + VisitVector visits1, visits2;
|
| + URLRow row;
|
| + URLID url_id1 = backend_->db()->GetRowForURL(url1, &row);
|
| + ASSERT_TRUE(backend_->db()->GetVisitsForURL(url_id1, &visits1));
|
| + ASSERT_EQ(1U, visits1.size());
|
| + EXPECT_EQ(0, visits1[0].visit_duration.ToInternalValue());
|
| +
|
| + URLID url_id2 = backend_->db()->GetRowForURL(url2, &row);
|
| + ASSERT_TRUE(backend_->db()->GetVisitsForURL(url_id2, &visits2));
|
| + ASSERT_EQ(1U, visits2.size());
|
| + EXPECT_EQ(0, visits2[0].visit_duration.ToInternalValue());
|
| +
|
| + // Update the visit to cnn.com.
|
| + backend_->UpdateVisitDuration(visits1[0].visit_id, end_ts);
|
| +
|
| + // Check the duration for visiting cnn.com was correctly updated.
|
| + ASSERT_TRUE(backend_->db()->GetVisitsForURL(url_id1, &visits1));
|
| + ASSERT_EQ(1U, visits1.size());
|
| + base::TimeDelta expected_duration = end_ts - start_ts;
|
| + EXPECT_EQ(expected_duration.ToInternalValue(),
|
| + visits1[0].visit_duration.ToInternalValue());
|
| +
|
| + // Remove the visit to cnn.com.
|
| + ASSERT_TRUE(backend_->RemoveVisits(visits1));
|
| +}
|
| +
|
| +// Test for migration of adding visit_duration column.
|
| +TEST_F(HistoryBackendTest, MigrationVisitDuration) {
|
| + ASSERT_TRUE(backend_.get());
|
| + backend_->Closing();
|
| + backend_ = NULL;
|
| +
|
| + FilePath old_history_path, old_history, old_archived;
|
| + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &old_history_path));
|
| + old_history_path = old_history_path.AppendASCII("History");
|
| + old_history = old_history_path.AppendASCII("HistoryNoDuration");
|
| + old_archived = old_history_path.AppendASCII("ArchivedNoDuration");
|
| +
|
| + // Copy history database file to current directory so that it will be deleted
|
| + // in Teardown.
|
| + FilePath new_history_path(getTestDir());
|
| + file_util::Delete(new_history_path, true);
|
| + file_util::CreateDirectory(new_history_path);
|
| + FilePath new_history_file = new_history_path.Append(chrome::kHistoryFilename);
|
| + FilePath new_archived_file =
|
| + new_history_path.Append(chrome::kArchivedHistoryFilename);
|
| + ASSERT_TRUE(file_util::CopyFile(old_history, new_history_file));
|
| + ASSERT_TRUE(file_util::CopyFile(old_archived, new_archived_file));
|
| +
|
| + backend_ = new HistoryBackend(new_history_path,
|
| + 0,
|
| + new HistoryBackendTestDelegate(this),
|
| + &bookmark_model_);
|
| + backend_->Init(std::string(), false);
|
| + backend_->Closing();
|
| + backend_ = NULL;
|
| +
|
| + // Now both history and archived_history databases should already be migrated.
|
| +
|
| + // Check version in history database first.
|
| + int cur_version = HistoryDatabase::GetCurrentVersion();
|
| + sql::Connection db;
|
| + ASSERT_TRUE(db.Open(new_history_file));
|
| + sql::Statement s(db.GetUniqueStatement(
|
| + "SELECT value FROM meta WHERE key = 'version'"));
|
| + ASSERT_TRUE(s.Step());
|
| + int file_version = s.ColumnInt(0);
|
| + EXPECT_EQ(cur_version, file_version);
|
| +
|
| + // Check visit_duration column in visits table is created and set to 0.
|
| + s.Assign(db.GetUniqueStatement(
|
| + "SELECT visit_duration FROM visits LIMIT 1"));
|
| + ASSERT_TRUE(s.Step());
|
| + EXPECT_EQ(0, s.ColumnInt(0));
|
| +
|
| + // Repeat version and visit_duration checks in archived history database
|
| + // also.
|
| + cur_version = ArchivedDatabase::GetCurrentVersion();
|
| + sql::Connection archived_db;
|
| + ASSERT_TRUE(archived_db.Open(new_archived_file));
|
| + sql::Statement s1(archived_db.GetUniqueStatement(
|
| + "SELECT value FROM meta WHERE key = 'version'"));
|
| + ASSERT_TRUE(s1.Step());
|
| + file_version = s1.ColumnInt(0);
|
| + EXPECT_EQ(cur_version, file_version);
|
| +
|
| + // Check visit_duration column in visits table is created and set to 0.
|
| + s1.Assign(archived_db.GetUniqueStatement(
|
| + "SELECT visit_duration FROM visits LIMIT 1"));
|
| + ASSERT_TRUE(s1.Step());
|
| + EXPECT_EQ(0, s1.ColumnInt(0));
|
| +}
|
| +
|
| } // namespace history
|
|
|