// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/file_util.h" #include "base/message_loop.h" #include "chrome/browser/history/text_database_manager.h" #include "testing/gtest/include/gtest/gtest.h" using base::Time; using base::TimeDelta; using base::TimeTicks; namespace history { namespace { const char* kURL1 = "http://www.google.com/asdf"; const wchar_t* kTitle1 = L"Google A"; const wchar_t* kBody1 = L"FOO page one."; const char* kURL2 = "http://www.google.com/qwer"; const wchar_t* kTitle2 = L"Google B"; const wchar_t* kBody2 = L"FOO two."; const char* kURL3 = "http://www.google.com/zxcv"; const wchar_t* kTitle3 = L"Google C"; const wchar_t* kBody3 = L"FOO drei"; const char* kURL4 = "http://www.google.com/hjkl"; const wchar_t* kTitle4 = L"Google D"; const wchar_t* kBody4 = L"FOO lalala four."; const char* kURL5 = "http://www.google.com/uiop"; const wchar_t* kTitle5 = L"Google cinq"; const wchar_t* kBody5 = L"FOO page one."; class TextDatabaseManagerTest : public testing::Test { public: // Called manually by the test so it can report failure to initialize. bool Init() { return file_util::CreateNewTempDirectory(L"TestSearchTest", &dir_); } protected: void SetUp() { } void TearDown() { file_util::Delete(dir_, true); } MessageLoop message_loop_; // Directory containing the databases. std::wstring dir_; }; // This provides a simple implementation of a URL+VisitDatabase using an // in-memory sqlite connection. The text database manager expects to be able to // update the visit database to keep in sync. class InMemDB : public URLDatabase, public VisitDatabase { public: InMemDB() { sqlite3_open(":memory:", &db_); statement_cache_ = new SqliteStatementCache(db_); CreateURLTable(false); InitVisitTable(); } ~InMemDB() { delete statement_cache_; sqlite3_close(db_); } private: virtual sqlite3* GetDB() { return db_; } virtual SqliteStatementCache& GetStatementCache() { return *statement_cache_; } sqlite3* db_; SqliteStatementCache* statement_cache_; DISALLOW_EVIL_CONSTRUCTORS(InMemDB); }; // Adds all the pages once, and the first page once more in the next month. // The times of all the pages will be filled into |*times|. void AddAllPages(TextDatabaseManager& manager, VisitDatabase* visit_db, std::vector