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

Unified Diff: components/omnibox/browser/shortcuts_database_unittest.cc

Issue 1515853002: Componentize shortcuts_database_unittest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated Created 5 years 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
« no previous file with comments | « components/omnibox/browser/BUILD.gn ('k') | components/test/data/omnibox/Shortcuts.no_fill_into_edit.sql » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..902868c91a7d87ea34ca41379906b1514a8cfd92 100644
--- a/chrome/browser/autocomplete/shortcuts_database_unittest.cc
+++ b/components/omnibox/browser/shortcuts_database_unittest.cc
@@ -10,11 +10,8 @@
#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 +60,20 @@ 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() {
+ base::FilePath path;
+ PathService::Get(base::DIR_SOURCE_ROOT, &path);
+ return path.AppendASCII("components/test/data/omnibox");
+}
+
} // namespace
// ShortcutsDatabaseTest ------------------------------------------------------
@@ -88,15 +91,14 @@ class ShortcutsDatabaseTest : public testing::Test {
void AddAll();
- content::TestBrowserThreadBundle thread_bundle_;
- scoped_ptr<TestingProfile> profile_;
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().Append(kShortcutsDatabaseName));
+ db_ = new ShortcutsDatabase(db_path);
ASSERT_TRUE(db_->Init());
ClearDB();
}
@@ -106,14 +108,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 +140,6 @@ void ShortcutsDatabaseTest::AddAll() {
EXPECT_EQ(arraysize(shortcut_test_db), CountRecords());
}
-
// Actual tests ---------------------------------------------------------------
TEST_F(ShortcutsDatabaseTest, AddShortcut) {
@@ -208,7 +209,6 @@ TEST_F(ShortcutsDatabaseTest, DeleteShortcutsWithURL) {
EXPECT_TRUE(it == shortcuts.end());
}
-
TEST_F(ShortcutsDatabaseTest, DeleteAllShortcuts) {
AddAll();
ShortcutsDatabase::GuidToShortcutMap shortcuts;
@@ -221,9 +221,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 +269,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"));
« no previous file with comments | « components/omnibox/browser/BUILD.gn ('k') | components/test/data/omnibox/Shortcuts.no_fill_into_edit.sql » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698