diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-02 21:40:00 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-02 21:40:00 +0000 |
commit | d486a085bd85065f8952d43f20e3f2c622ef7b7a (patch) | |
tree | 6b56ee8893dd1660a3c2ed7a2ecb8a5c8d948441 /chrome | |
parent | 740847d37d057d41ea5956ec0cb123a7dbd5b904 (diff) | |
download | chromium_src-d486a085bd85065f8952d43f20e3f2c622ef7b7a.zip chromium_src-d486a085bd85065f8952d43f20e3f2c622ef7b7a.tar.gz chromium_src-d486a085bd85065f8952d43f20e3f2c622ef7b7a.tar.bz2 |
Unittest for fix to allow navigation when there is no history DB.
BUG=25822
TEST=none
Review URL: http://codereview.chromium.org/343067
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30744 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/autocomplete/history_contents_provider_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/autocomplete/history_url_provider_unittest.cc | 36 | ||||
-rw-r--r-- | chrome/browser/autocomplete/search_provider_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_index_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model_unittest.cc | 10 | ||||
-rw-r--r-- | chrome/browser/history/history.cc | 42 | ||||
-rw-r--r-- | chrome/browser/history/history.h | 11 | ||||
-rw-r--r-- | chrome/browser/history/history_backend.cc | 5 | ||||
-rw-r--r-- | chrome/browser/history/history_backend.h | 6 | ||||
-rw-r--r-- | chrome/browser/history/history_backend_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/history/history_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_model_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/test/testing_profile.cc | 4 | ||||
-rw-r--r-- | chrome/test/testing_profile.h | 8 |
14 files changed, 90 insertions, 44 deletions
diff --git a/chrome/browser/autocomplete/history_contents_provider_unittest.cc b/chrome/browser/autocomplete/history_contents_provider_unittest.cc index 1afbd88..f956228 100644 --- a/chrome/browser/autocomplete/history_contents_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_contents_provider_unittest.cc @@ -54,7 +54,7 @@ class HistoryContentsProviderTest : public testing::Test, // testing::Test virtual void SetUp() { profile_.reset(new TestingProfile()); - profile_->CreateHistoryService(false); + profile_->CreateHistoryService(false, false); HistoryService* history_service = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc index 6254e7f..e11b7e5 100644 --- a/chrome/browser/autocomplete/history_url_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -105,10 +105,15 @@ class HistoryURLProviderTest : public testing::Test, protected: // testing::Test - virtual void SetUp(); + virtual void SetUp() { + SetUpImpl(false); + } virtual void TearDown(); - // Fills test data into the history system + // Does the real setup. + void SetUpImpl(bool no_db); + + // Fills test data into the history system. void FillData(); // Runs an autocomplete query on |text| and checks to see that the returned @@ -130,16 +135,23 @@ class HistoryURLProviderTest : public testing::Test, scoped_refptr<HistoryURLProvider> autocomplete_; }; +class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { + protected: + virtual void SetUp() { + SetUpImpl(true); + } +}; + void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { if (autocomplete_->done()) MessageLoop::current()->Quit(); } -void HistoryURLProviderTest::SetUp() { +void HistoryURLProviderTest::SetUpImpl(bool no_db) { profile_.reset(new TestingProfile()); profile_->CreateBookmarkModel(true); profile_->BlockUntilBookmarkModelLoaded(); - profile_->CreateHistoryService(true); + profile_->CreateHistoryService(true, no_db); history_service_ = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); autocomplete_ = new HistoryURLProvider(this, profile_.get()); @@ -384,3 +396,17 @@ TEST_F(HistoryURLProviderTest, Fixup) { std::string fixup_5[] = {"http://www.17173.com/"}; RunTest(L"17173", std::wstring(), false, fixup_5, arraysize(fixup_5)); } + +TEST_F(HistoryURLProviderTestNoDB, NavigateWithoutDB) { + // Ensure that we will still produce matches for navigation when there is no + // database. + std::string navigation_1[] = {"http://test.com/"}; + RunTest(L"test.com", std::wstring(), false, navigation_1, + arraysize(navigation_1)); + + std::string navigation_2[] = {"http://slash/"}; + RunTest(L"slash", std::wstring(), false, navigation_2, + arraysize(navigation_2)); + + RunTest(L"this is a query", std::wstring(), false, NULL, 0); +} diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc index b5f9bcd..9b53178 100644 --- a/chrome/browser/autocomplete/search_provider_unittest.cc +++ b/chrome/browser/autocomplete/search_provider_unittest.cc @@ -88,7 +88,7 @@ void SearchProviderTest::SetUp() { SearchProvider::set_query_suggest_immediately(true); // We need both the history service and template url model loaded. - profile_.CreateHistoryService(true); + profile_.CreateHistoryService(true, false); profile_.CreateTemplateURLModel(); TemplateURLModel* turl_model = profile_.GetTemplateURLModel(); diff --git a/chrome/browser/bookmarks/bookmark_index_unittest.cc b/chrome/browser/bookmarks/bookmark_index_unittest.cc index 9ef6907..cbc941e 100644 --- a/chrome/browser/bookmarks/bookmark_index_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_index_unittest.cc @@ -217,7 +217,7 @@ TEST_F(BookmarkIndexTest, GetResultsSortedByTypedCount) { ChromeThread file_thread(ChromeThread::FILE, &loop); TestingProfile profile; - profile.CreateHistoryService(true); + profile.CreateHistoryService(true, false); profile.BlockUntilHistoryProcessesPendingRequests(); profile.CreateBookmarkModel(true); profile.BlockUntilBookmarkModelLoaded(); diff --git a/chrome/browser/bookmarks/bookmark_model_unittest.cc b/chrome/browser/bookmarks/bookmark_model_unittest.cc index d511530..1e5b90e 100644 --- a/chrome/browser/bookmarks/bookmark_model_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_model_unittest.cc @@ -619,7 +619,7 @@ class BookmarkModelTestWithProfile : public testing::Test, // Need to shutdown the old one before creating a new one. profile_.reset(NULL); profile_.reset(new TestingProfile()); - profile_->CreateHistoryService(true); + profile_->CreateHistoryService(true, false); } BookmarkModel* bb_model_; @@ -685,7 +685,7 @@ TEST_F(BookmarkModelTestWithProfile, CreateAndRestore) { profile_.reset(NULL); profile_.reset(new TestingProfile()); profile_->CreateBookmarkModel(true); - profile_->CreateHistoryService(true); + profile_->CreateHistoryService(true, false); BlockTillBookmarkModelLoaded(); TestNode bbn; @@ -818,7 +818,7 @@ TEST_F(BookmarkModelTestWithProfile2, MigrateFromDBToFileTest) { // Create the history service making sure it doesn't blow away the file we // just copied. - profile_->CreateHistoryService(false); + profile_->CreateHistoryService(false, false); profile_->CreateBookmarkModel(true); BlockTillBookmarkModelLoaded(); @@ -847,7 +847,7 @@ TEST_F(BookmarkModelTestWithProfile2, MigrateFromDBToFileTest) { // Recreate the history service (with a clean db). Do this just to make sure // we're loading correctly from the bookmarks file. - profile_->CreateHistoryService(true); + profile_->CreateHistoryService(true, false); profile_->CreateBookmarkModel(false); BlockTillBookmarkModelLoaded(); VerifyExpectedState(); @@ -857,7 +857,7 @@ TEST_F(BookmarkModelTestWithProfile2, MigrateFromDBToFileTest) { // Simple test that removes a bookmark. This test exercises the code paths in // History that block till bookmark bar model is loaded. TEST_F(BookmarkModelTestWithProfile2, RemoveNotification) { - profile_->CreateHistoryService(false); + profile_->CreateHistoryService(false, false); profile_->CreateBookmarkModel(true); BlockTillBookmarkModelLoaded(); diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc index ee13114..ad64727 100644 --- a/chrome/browser/history/history.cc +++ b/chrome/browser/history/history.cc @@ -130,7 +130,9 @@ const history::StarID HistoryService::kBookmarkBarID = 1; HistoryService::HistoryService() : thread_(new ChromeHistoryThread()), profile_(NULL), - backend_loaded_(false) { + backend_loaded_(false), + bookmark_service_(NULL), + no_db_(false) { // Is NULL when running generate_profile. if (NotificationService::current()) { registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, @@ -141,7 +143,9 @@ HistoryService::HistoryService() HistoryService::HistoryService(Profile* profile) : thread_(new ChromeHistoryThread()), profile_(profile), - backend_loaded_(false) { + backend_loaded_(false), + bookmark_service_(NULL), + no_db_(false) { registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, Source<Profile>(profile_)); } @@ -151,21 +155,6 @@ HistoryService::~HistoryService() { Cleanup(); } -bool HistoryService::Init(const FilePath& history_dir, - BookmarkService* bookmark_service) { - if (!thread_->Start()) { - Cleanup(); - return false; - } - - history_dir_ = history_dir; - bookmark_service_ = bookmark_service; - - // Create the history backend. - LoadBackendIfNecessary(); - return true; -} - bool HistoryService::BackendLoaded() { // NOTE: We start the backend loading even though it completes asynchronously // and thus won't affect the return value of this function. This is because @@ -620,6 +609,23 @@ void HistoryService::Observe(NotificationType type, visited_links->DeleteURLs(deleted_details->urls); } +bool HistoryService::Init(const FilePath& history_dir, + BookmarkService* bookmark_service, + bool no_db) { + if (!thread_->Start()) { + Cleanup(); + return false; + } + + history_dir_ = history_dir; + bookmark_service_ = bookmark_service; + no_db_ = no_db; + + // Create the history backend. + LoadBackendIfNecessary(); + return true; +} + void HistoryService::ScheduleAutocomplete(HistoryURLProvider* provider, HistoryURLProviderParams* params) { ScheduleAndForget(PRIORITY_UI, &HistoryBackend::ScheduleAutocomplete, @@ -722,7 +728,7 @@ void HistoryService::LoadBackendIfNecessary() { bookmark_service_)); history_backend_.swap(backend); - ScheduleAndForget(PRIORITY_UI, &HistoryBackend::Init); + ScheduleAndForget(PRIORITY_UI, &HistoryBackend::Init, no_db_); } void HistoryService::OnDBLoaded() { diff --git a/chrome/browser/history/history.h b/chrome/browser/history/history.h index d6dab37..6a886b9 100644 --- a/chrome/browser/history/history.h +++ b/chrome/browser/history/history.h @@ -101,7 +101,9 @@ class HistoryService : public CancelableRequestProvider, // not call any other functions. The given directory will be used for storing // the history files. The BookmarkService is used when deleting URLs to // test if a URL is bookmarked; it may be NULL during testing. - bool Init(const FilePath& history_dir, BookmarkService* bookmark_service); + bool Init(const FilePath& history_dir, BookmarkService* bookmark_service) { + return Init(history_dir, bookmark_service, false); + } // Triggers the backend to load if it hasn't already, and then returns whether // it's finished loading. @@ -545,6 +547,12 @@ class HistoryService : public CancelableRequestProvider, const NotificationSource& source, const NotificationDetails& details); + // Low-level Init(). Same as the public version, but adds a |no_db| parameter + // that is only set by unittests which causes the backend to not init its DB. + bool Init(const FilePath& history_dir, + BookmarkService* bookmark_service, + bool no_db); + // Called by the HistoryURLProvider class to schedule an autocomplete, it // will be called back on the internal history thread with the history // database so it can query. See history_autocomplete.cc for a diagram. @@ -797,6 +805,7 @@ class HistoryService : public CancelableRequestProvider, // Cached values from Init(), used whenever we need to reload the backend. FilePath history_dir_; BookmarkService* bookmark_service_; + bool no_db_; DISALLOW_COPY_AND_ASSIGN(HistoryService); }; diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index b7d1a47..d614a92 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -212,8 +212,9 @@ HistoryBackend::~HistoryBackend() { } } -void HistoryBackend::Init() { - InitImpl(); +void HistoryBackend::Init(bool force_fail) { + if (!force_fail) + InitImpl(); delegate_->DBLoaded(); } diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h index 34481ce..0d854e2 100644 --- a/chrome/browser/history/history_backend.h +++ b/chrome/browser/history/history_backend.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -99,7 +99,9 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, // Must be called after creation but before any objects are created. If this // fails, all other functions will fail as well. (Since this runs on another // thread, we don't bother returning failure.) - void Init(); + // + // |force_fail| can be set during unittests to unconditionally fail to init. + void Init(bool force_fail); // Notification that the history system is shutting down. This will break // the refs owned by the delegate and any pending transaction so it will diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc index 833059e..dd2e2fc 100644 --- a/chrome/browser/history/history_backend_unittest.cc +++ b/chrome/browser/history/history_backend_unittest.cc @@ -121,7 +121,7 @@ class HistoryBackendTest : public testing::Test { backend_ = new HistoryBackend(test_dir_, new HistoryBackendTestDelegate(this), &bookmark_model_); - backend_->Init(); + backend_->Init(false); } virtual void TearDown() { backend_->Closing(); diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc index 4316c27..aa9d00f 100644 --- a/chrome/browser/history/history_unittest.cc +++ b/chrome/browser/history/history_unittest.cc @@ -138,7 +138,7 @@ class HistoryTest : public testing::Test { void CreateBackendAndDatabase() { backend_ = new HistoryBackend(history_dir_, new BackendDelegate(this), NULL); - backend_->Init(); + backend_->Init(false); db_ = backend_->db_.get(); DCHECK(in_mem_backend_.get()) << "Mem backend should have been set by " "HistoryBackend::Init"; diff --git a/chrome/browser/search_engines/template_url_model_unittest.cc b/chrome/browser/search_engines/template_url_model_unittest.cc index 7030c31..f0c5e80 100644 --- a/chrome/browser/search_engines/template_url_model_unittest.cc +++ b/chrome/browser/search_engines/template_url_model_unittest.cc @@ -655,7 +655,7 @@ struct QueryHistoryCallbackImpl { // KEYWORD visits. TEST_F(TemplateURLModelTest, GenerateVisitOnKeyword) { VerifyLoad(); - profile_->CreateHistoryService(true); + profile_->CreateHistoryService(true, false); // Create a keyword. TemplateURL* t_url = AddKeywordWithDate( diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc index e787a6b..775f20b 100644 --- a/chrome/test/testing_profile.cc +++ b/chrome/test/testing_profile.cc @@ -104,7 +104,7 @@ TestingProfile::~TestingProfile() { file_util::Delete(path_, true); } -void TestingProfile::CreateHistoryService(bool delete_file) { +void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { if (history_service_.get()) history_service_->Cleanup(); @@ -116,7 +116,7 @@ void TestingProfile::CreateHistoryService(bool delete_file) { file_util::Delete(path, false); } history_service_ = new HistoryService(this); - history_service_->Init(GetPath(), bookmark_bar_model_.get()); + history_service_->Init(GetPath(), bookmark_bar_model_.get(), no_db); } void TestingProfile::DestroyHistoryService() { diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 61083af..1a415d5 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -32,9 +32,11 @@ class TestingProfile : public Profile { // Creates the history service. If |delete_file| is true, the history file is // deleted first, then the HistoryService is created. As TestingProfile - // deletes the directory containing the files used by HistoryService, the - // boolean only matters if you're recreating the HistoryService. - void CreateHistoryService(bool delete_file); + // deletes the directory containing the files used by HistoryService, this + // only matters if you're recreating the HistoryService. If |no_db| is true, + // the history backend will fail to initialize its database; this is useful + // for testing error conditions. + void CreateHistoryService(bool delete_file, bool no_db); // Creates the BookmkarBarModel. If not invoked the bookmark bar model is // NULL. If |delete_file| is true, the bookmarks file is deleted first, then |