Chromium Code Reviews| Index: components/omnibox/browser/shortcuts_database_unittest.cc |
| diff --git a/chrome/browser/autocomplete/shortcuts_database_unittest.cc b/components/omnibox/browser/shortcuts_database_unittest.cc |
| similarity index 89% |
| rename from chrome/browser/autocomplete/shortcuts_database_unittest.cc |
| rename to components/omnibox/browser/shortcuts_database_unittest.cc |
| index 812c31f45e22699df09f3219517042d0aef2cb7b..4ac920d0d49e54391605ae03b6da26baa0620ec6 100644 |
| --- a/chrome/browser/autocomplete/shortcuts_database_unittest.cc |
| +++ b/components/omnibox/browser/shortcuts_database_unittest.cc |
| @@ -6,15 +6,13 @@ |
| #include "base/files/scoped_temp_dir.h" |
| #include "base/format_macros.h" |
| +#include "base/message_loop/message_loop.h" |
| #include "base/path_service.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/time/time.h" |
| -#include "chrome/common/chrome_paths.h" |
| -#include "chrome/test/base/testing_profile.h" |
| #include "components/omnibox/browser/autocomplete_match_type.h" |
| #include "components/omnibox/browser/shortcuts_constants.h" |
| -#include "content/public/test/test_browser_thread_bundle.h" |
| #include "sql/statement.h" |
| #include "sql/test/test_helpers.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -63,14 +61,26 @@ typedef testing::Test ShortcutsDatabaseMigrationTest; |
| void CheckV2ColumnExistence(const base::FilePath& db_path, bool is_v2) { |
| sql::Connection connection; |
| ASSERT_TRUE(connection.Open(db_path)); |
| - EXPECT_EQ(is_v2, connection.DoesColumnExist("omni_box_shortcuts", |
| - "fill_into_edit")); |
| - EXPECT_EQ(is_v2, connection.DoesColumnExist("omni_box_shortcuts", |
| - "transition")); |
| + EXPECT_EQ(is_v2, |
| + connection.DoesColumnExist("omni_box_shortcuts", "fill_into_edit")); |
| + EXPECT_EQ(is_v2, |
| + connection.DoesColumnExist("omni_box_shortcuts", "transition")); |
| EXPECT_EQ(is_v2, connection.DoesColumnExist("omni_box_shortcuts", "type")); |
| EXPECT_EQ(is_v2, connection.DoesColumnExist("omni_box_shortcuts", "keyword")); |
| } |
| +const base::FilePath& GetTestDataDir() { |
| + CR_DEFINE_STATIC_LOCAL(base::FilePath, dir, ()); |
| + if (dir.empty()) { |
| + PathService::Get(base::DIR_SOURCE_ROOT, &dir); |
| + dir = dir.AppendASCII("components"); |
| + dir = dir.AppendASCII("test"); |
| + dir = dir.AppendASCII("data"); |
| + dir = dir.AppendASCII("omnibox"); |
| + } |
| + return dir; |
|
droger
2015/12/11 12:08:23
I don't think the static local is useful here.
I
Abhishek
2015/12/11 15:54:11
Done.
|
| +} |
| + |
| } // namespace |
| // ShortcutsDatabaseTest ------------------------------------------------------ |
| @@ -88,15 +98,15 @@ class ShortcutsDatabaseTest : public testing::Test { |
| void AddAll(); |
| - content::TestBrowserThreadBundle thread_bundle_; |
| - scoped_ptr<TestingProfile> profile_; |
| + base::MessageLoop message_loop_; |
|
droger
2015/12/11 12:08:23
Is this even needed?
Abhishek
2015/12/11 15:54:11
Yeah! We don't require it now.
I've removed it.
|
| scoped_refptr<ShortcutsDatabase> db_; |
| }; |
| void ShortcutsDatabaseTest::SetUp() { |
| - profile_.reset(new TestingProfile()); |
| - db_ = new ShortcutsDatabase( |
| - profile_->GetPath().Append(kShortcutsDatabaseName)); |
| + base::ScopedTempDir temp_dir; |
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| + base::FilePath db_path(temp_dir.path().AppendASCII(kShortcutsDatabaseName)); |
|
droger
2015/12/11 12:08:23
This does not compile on windows, can you try usin
Abhishek
2015/12/11 15:54:11
Done.
|
| + db_ = new ShortcutsDatabase(db_path); |
| ASSERT_TRUE(db_->Init()); |
| ClearDB(); |
| } |
| @@ -106,14 +116,14 @@ void ShortcutsDatabaseTest::TearDown() { |
| } |
| void ShortcutsDatabaseTest::ClearDB() { |
| - sql::Statement |
| - s(db_->db_.GetUniqueStatement("DELETE FROM omni_box_shortcuts")); |
| + sql::Statement s( |
| + db_->db_.GetUniqueStatement("DELETE FROM omni_box_shortcuts")); |
| EXPECT_TRUE(s.Run()); |
| } |
| size_t ShortcutsDatabaseTest::CountRecords() const { |
| - sql::Statement s(db_->db_.GetUniqueStatement( |
| - "SELECT count(*) FROM omni_box_shortcuts")); |
| + sql::Statement s( |
| + db_->db_.GetUniqueStatement("SELECT count(*) FROM omni_box_shortcuts")); |
| EXPECT_TRUE(s.Step()); |
| return static_cast<size_t>(s.ColumnInt(0)); |
| } |
| @@ -138,7 +148,6 @@ void ShortcutsDatabaseTest::AddAll() { |
| EXPECT_EQ(arraysize(shortcut_test_db), CountRecords()); |
| } |
| - |
| // Actual tests --------------------------------------------------------------- |
| TEST_F(ShortcutsDatabaseTest, AddShortcut) { |
| @@ -208,7 +217,6 @@ TEST_F(ShortcutsDatabaseTest, DeleteShortcutsWithURL) { |
| EXPECT_TRUE(it == shortcuts.end()); |
| } |
| - |
| TEST_F(ShortcutsDatabaseTest, DeleteAllShortcuts) { |
| AddAll(); |
| ShortcutsDatabase::GuidToShortcutMap shortcuts; |
| @@ -221,9 +229,7 @@ TEST_F(ShortcutsDatabaseTest, DeleteAllShortcuts) { |
| TEST(ShortcutsDatabaseMigrationTest, MigrateTableAddFillIntoEdit) { |
| // Use the pre-v0 test file to create a test database in a temp dir. |
| - base::FilePath sql_path; |
| - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &sql_path)); |
| - sql_path = sql_path.AppendASCII("History").AppendASCII( |
| + base::FilePath sql_path = GetTestDataDir().AppendASCII( |
| #if defined(OS_ANDROID) |
| "Shortcuts.v1.sql"); |
| #else |
| @@ -271,9 +277,7 @@ TEST(ShortcutsDatabaseMigrationTest, MigrateTableAddFillIntoEdit) { |
| TEST(ShortcutsDatabaseMigrationTest, MigrateV0ToV1) { |
| // Use the v0 test file to create a test database in a temp dir. |
| - base::FilePath sql_path; |
| - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &sql_path)); |
| - sql_path = sql_path.AppendASCII("History").AppendASCII("Shortcuts.v0.sql"); |
| + base::FilePath sql_path = GetTestDataDir().AppendASCII("Shortcuts.v0.sql"); |
| base::ScopedTempDir temp_dir; |
| ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts2.db")); |