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

Unified Diff: chrome/browser/history/in_memory_url_index_base_unittest.cc

Issue 10837244: Replace HistoryQuickProvider protobuf-based caching with an SQLite-based database. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Tweak suppression. Created 8 years, 4 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: chrome/browser/history/in_memory_url_index_base_unittest.cc
===================================================================
--- chrome/browser/history/in_memory_url_index_base_unittest.cc (revision 0)
+++ chrome/browser/history/in_memory_url_index_base_unittest.cc (revision 0)
@@ -0,0 +1,143 @@
+// Copyright (c) 2011 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 "chrome/browser/history/in_memory_url_index_base_unittest.h"
+
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/path_service.h"
+#include "base/string_split.h"
+#include "base/synchronization/waitable_event.h"
+#include "chrome/browser/history/history.h"
+#include "chrome/browser/history/history_backend.h"
+#include "chrome/browser/history/history_service_factory.h"
+#include "chrome/browser/history/in_memory_url_cache_database.h"
+#include "chrome/browser/history/in_memory_url_index.h"
+#include "chrome/browser/history/url_index_private_data.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/browser_thread.h"
+#include "sql/connection.h"
+#include "sql/statement.h"
+#include "sql/transaction.h"
+
+namespace history {
+
+InMemoryURLIndexBaseTest::InMemoryURLIndexBaseTest()
+ : ui_thread_(content::BrowserThread::UI, &message_loop_),
+ db_thread_(content::BrowserThread::DB) {
+}
+
+InMemoryURLIndexBaseTest::~InMemoryURLIndexBaseTest() {
+}
+
+void InMemoryURLIndexBaseTest::SetUp() {
+ if (!profile_.get())
+ profile_.reset(new TestingProfile);
+ db_thread_.Start();
+ // We cannot access the database until the backend has been loaded.
+ profile_->CreateHistoryService(true, false);
+ HistoryService* history_service =
+ HistoryServiceFactory::GetForProfile(profile_.get(),
+ Profile::EXPLICIT_ACCESS);
+ ASSERT_TRUE(history_service);
+ url_index_ = history_service->InMemoryIndex();
+ BlockUntilIndexLoaded();
+ DCHECK(url_index_->index_available());
+ profile_->CreateBookmarkModel(true);
+ HistoryBackend* backend = history_service->get_history_backend_for_testing();
+ history_database_ = backend->db();
+ ui_test_utils::WaitForHistoryToLoad(history_service);
+ DCHECK(history_service->backend_loaded());
+
+ // Create and populate a working copy of the URL history database from the
+ // data contained in the file specified by the TestDBName() function.
+ // TODO(mrossetti): Adopt sqlite3_ functions for performing the database
+ // initialization. See http://crbug.com/137352.
+ FilePath test_file_path;
+ PathService::Get(chrome::DIR_TEST_DATA, &test_file_path);
+ test_file_path = test_file_path.Append(FILE_PATH_LITERAL("History"));
+ test_file_path = test_file_path.Append(TestDBName());
+ EXPECT_TRUE(file_util::PathExists(test_file_path));
+
+ std::string sql_command_buffer;
+ file_util::ReadFileToString(test_file_path, &sql_command_buffer);
+ std::vector<std::string> sql_commands;
+ base::SplitStringDontTrim(sql_command_buffer, '\n', &sql_commands);
+ sql::Connection* db(history_database_->get_db_for_testing());
+ for (std::vector<std::string>::const_iterator i = sql_commands.begin();
+ i != sql_commands.end(); ++i) {
+ // We only process lines which begin with a upper-case letter.
+ // TODO(mrossetti): Can iswupper() be used here?
+ const std::string& sql_command(*i);
+ if (sql_command[0] >= 'A' && sql_command[0] <= 'Z')
+ EXPECT_TRUE(db->Execute(sql_command.c_str()));
+ }
+
+ // Update the last_visit_time table column such that it represents a time
+ // relative to 'now'.
+ // TODO(mrossetti): Do an UPDATE to alter the days-ago.
+ // See http://crbug.com/137352.
+ sql::Statement statement(db->GetUniqueStatement(
+ "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls"));
+ EXPECT_TRUE(statement.is_valid());
+ base::Time time_right_now = base::Time::NowFromSystemTime();
+ base::TimeDelta day_delta = base::TimeDelta::FromDays(1);
+ while (statement.Step()) {
+ URLRow row;
+ history_database_->FillURLRow(statement, &row);
+ row.set_last_visit(time_right_now -
+ day_delta * row.last_visit().ToInternalValue());
+ history_database_->UpdateURLRow(row.id(), row);
+ }
+}
+
+void InMemoryURLIndexBaseTest::TearDown() {
+ profile_->BlockUntilHistoryProcessesPendingRequests();
+ message_loop_.RunAllPending();
+ MessageLoop::current()->RunAllPending();
+ content::BrowserThread::GetBlockingPool()->FlushForTesting();
+ base::WaitableEvent done(false, false);
+ content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE,
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
+ done.Wait();
+ db_thread_.Stop();
+ message_loop_.RunAllPending();
+ MessageLoop::current()->RunAllPending();
+}
+
+void InMemoryURLIndexBaseTest::LoadIndex() {
+ url_index_->ScheduleRebuildFromHistory();
+ BlockUntilIndexLoaded();
+}
+
+void InMemoryURLIndexBaseTest::BlockUntilIndexLoaded() {
+ if (url_index_->index_available())
+ return;
+ content::BrowserThread::GetBlockingPool()->FlushForTesting();
+ InMemoryURLIndex::Observer observer(url_index_);
+ MessageLoop::current()->Run();
+}
+
+URLIndexPrivateData* InMemoryURLIndexBaseTest::GetPrivateData() {
+ return url_index_->private_data();
+}
+
+bool InMemoryURLIndexBaseTest::UpdateURL(const URLRow& row) {
+ bool success = GetPrivateData()->UpdateURL(row);
+ content::BrowserThread::GetBlockingPool()->FlushForTesting();
+ return success;
+}
+
+bool InMemoryURLIndexBaseTest::DeleteURL(const GURL& url) {
+ bool success = GetPrivateData()->DeleteURL(url);
+ content::BrowserThread::GetBlockingPool()->FlushForTesting();
+ return success;
+}
+
+bool InMemoryURLIndexBaseTest::GetCacheDBPath(FilePath* file_path) {
+ return GetPrivateData()->GetCacheDBPath(file_path);
+}
+
+} // namespace history
Property changes on: chrome/browser/history/in_memory_url_index_base_unittest.cc
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698