OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_BASE_UNITTEST_H_ |
| 6 #define CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_BASE_UNITTEST_H_ |
| 7 |
| 8 #include "base/file_util.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" |
| 11 #include "base/scoped_temp_dir.h" |
| 12 #include "chrome/browser/history/history_database.h" |
| 13 #include "chrome/browser/history/in_memory_database.h" |
| 14 #include "chrome/browser/history/in_memory_url_index.h" |
| 15 #include "chrome/test/base/testing_profile.h" |
| 16 #include "content/public/test/test_browser_thread.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 namespace history { |
| 20 |
| 21 class HistoryDatabase; |
| 22 |
| 23 // A base class for unit tests that exercise the InMemoryURLIndex and the |
| 24 // HistoryQuickProvider. Provides initialization of the index using data |
| 25 // contained in a test file. |
| 26 // |
| 27 // The test version of the history url database table ('url') is contained in |
| 28 // a database file created from a text file as specified by the |
| 29 // TestDBName() method overridden by subclasses. The only difference between |
| 30 // the table specified in this test file and a live 'urls' table from a |
| 31 // profile is that the last_visit_time column in the test table contains a |
| 32 // number specifying the number of days relative to 'today' to which the |
| 33 // visit time of the URL will be set during the test setup stage. |
| 34 // |
| 35 // The format of the test database text file is of a SQLite .dump file. |
| 36 // Note that only lines whose first character is an upper-case letter are |
| 37 // processed when creating the test database. |
| 38 // |
| 39 class InMemoryURLIndexBaseTest : public testing::Test { |
| 40 protected: |
| 41 InMemoryURLIndexBaseTest(); |
| 42 virtual ~InMemoryURLIndexBaseTest(); |
| 43 |
| 44 // Specifies the test data file name used by the subclass. The specified file |
| 45 // must reside in the path given by chrome::DIR_TEST_DATA. |
| 46 virtual FilePath::StringType TestDBName() const = 0; |
| 47 |
| 48 // Fills the HistoryBackend with test data from the test data file and creates |
| 49 // the InMemoryURLIndex instance, but does not fill it with data. Call |
| 50 // LoadIndex() after calling SetUp() To fill the InMemoryURLIndex instance |
| 51 // with the test data. |
| 52 // NOTE: By default, TestingProfile does not enable the cache database |
| 53 // (InMemoryURLCacheDatabase). If a test relies on the cache database |
| 54 // having been enabled then that test should subclass TestingProfile |
| 55 // and provide an override of InitHistoryService(...) that causes |
| 56 // the cache database to be created and initialized. For an example, |
| 57 // see CacheTestingProfile in in_memory_url_index_unittest.cc. |
| 58 virtual void SetUp() OVERRIDE; |
| 59 virtual void TearDown() OVERRIDE; |
| 60 |
| 61 // Blocks the caller until the load sequence for the index has completed. |
| 62 // Note that load completion does not imply success. |
| 63 void BlockUntilIndexLoaded(); |
| 64 |
| 65 // Loads the InMemoryURLIndex instance with data from the HistoryBackend. |
| 66 // Blocks until the load completes. Completion does not imply success. |
| 67 void LoadIndex(); |
| 68 |
| 69 // Sets |blockingPoolShutdown_| to true as part of TearDown(). |
| 70 void BlockingPoolShutdown(); |
| 71 |
| 72 // Pass-through function to simplify our friendship with InMemoryURLIndex. |
| 73 URLIndexPrivateData* GetPrivateData(); |
| 74 |
| 75 // Pass-through functions to simplify our friendship with URLIndexPrivateData. |
| 76 bool UpdateURL(const URLRow& row); |
| 77 bool DeleteURL(const GURL& url); |
| 78 bool GetCacheDBPath(FilePath* file_path); |
| 79 |
| 80 InMemoryURLIndex* url_index_; |
| 81 HistoryDatabase* history_database_; |
| 82 |
| 83 MessageLoopForUI message_loop_; |
| 84 content::TestBrowserThread ui_thread_; |
| 85 content::TestBrowserThread db_thread_; |
| 86 scoped_ptr<TestingProfile> profile_; |
| 87 }; |
| 88 |
| 89 } // namespace history |
| 90 |
| 91 #endif // CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_BASE_UNITTEST_H_ |
OLD | NEW |