OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/omnibox/browser/shortcuts_database.h" | 5 #include "components/omnibox/browser/shortcuts_database.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 const ShortcutsDatabaseTestInfo& info); | 95 const ShortcutsDatabaseTestInfo& info); |
96 | 96 |
97 void AddAll(); | 97 void AddAll(); |
98 | 98 |
99 base::ScopedTempDir temp_dir_; | 99 base::ScopedTempDir temp_dir_; |
100 scoped_refptr<ShortcutsDatabase> db_; | 100 scoped_refptr<ShortcutsDatabase> db_; |
101 }; | 101 }; |
102 | 102 |
103 void ShortcutsDatabaseTest::SetUp() { | 103 void ShortcutsDatabaseTest::SetUp() { |
104 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 104 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
105 base::FilePath db_path(temp_dir_.path().Append(kShortcutsDatabaseName)); | 105 base::FilePath db_path(temp_dir_.GetPath().Append(kShortcutsDatabaseName)); |
106 db_ = new ShortcutsDatabase(db_path); | 106 db_ = new ShortcutsDatabase(db_path); |
107 ASSERT_TRUE(db_->Init()); | 107 ASSERT_TRUE(db_->Init()); |
108 ClearDB(); | 108 ClearDB(); |
109 } | 109 } |
110 | 110 |
111 void ShortcutsDatabaseTest::TearDown() { | 111 void ShortcutsDatabaseTest::TearDown() { |
112 db_ = NULL; | 112 db_ = NULL; |
113 } | 113 } |
114 | 114 |
115 void ShortcutsDatabaseTest::ClearDB() { | 115 void ShortcutsDatabaseTest::ClearDB() { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 TEST(ShortcutsDatabaseMigrationTest, MigrateTableAddFillIntoEdit) { | 227 TEST(ShortcutsDatabaseMigrationTest, MigrateTableAddFillIntoEdit) { |
228 // Use the pre-v0 test file to create a test database in a temp dir. | 228 // Use the pre-v0 test file to create a test database in a temp dir. |
229 base::FilePath sql_path = GetTestDataDir().AppendASCII( | 229 base::FilePath sql_path = GetTestDataDir().AppendASCII( |
230 #if defined(OS_ANDROID) | 230 #if defined(OS_ANDROID) |
231 "Shortcuts.v1.sql"); | 231 "Shortcuts.v1.sql"); |
232 #else | 232 #else |
233 "Shortcuts.no_fill_into_edit.sql"); | 233 "Shortcuts.no_fill_into_edit.sql"); |
234 #endif | 234 #endif |
235 base::ScopedTempDir temp_dir; | 235 base::ScopedTempDir temp_dir; |
236 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 236 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
237 base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts.db")); | 237 base::FilePath db_path(temp_dir.GetPath().AppendASCII("TestShortcuts.db")); |
238 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); | 238 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); |
239 | 239 |
240 CheckV2ColumnExistence(db_path, false); | 240 CheckV2ColumnExistence(db_path, false); |
241 | 241 |
242 // Create a ShortcutsDatabase from the test database, which will migrate the | 242 // Create a ShortcutsDatabase from the test database, which will migrate the |
243 // test database to the current version. | 243 // test database to the current version. |
244 { | 244 { |
245 scoped_refptr<ShortcutsDatabase> db(new ShortcutsDatabase(db_path)); | 245 scoped_refptr<ShortcutsDatabase> db(new ShortcutsDatabase(db_path)); |
246 db->Init(); | 246 db->Init(); |
247 } | 247 } |
(...skipping 23 matching lines...) Expand all Loading... |
271 #if !defined(OS_WIN) | 271 #if !defined(OS_WIN) |
272 EXPECT_TRUE(temp_dir.Delete()); | 272 EXPECT_TRUE(temp_dir.Delete()); |
273 #endif | 273 #endif |
274 } | 274 } |
275 | 275 |
276 TEST(ShortcutsDatabaseMigrationTest, MigrateV0ToV1) { | 276 TEST(ShortcutsDatabaseMigrationTest, MigrateV0ToV1) { |
277 // Use the v0 test file to create a test database in a temp dir. | 277 // Use the v0 test file to create a test database in a temp dir. |
278 base::FilePath sql_path = GetTestDataDir().AppendASCII("Shortcuts.v0.sql"); | 278 base::FilePath sql_path = GetTestDataDir().AppendASCII("Shortcuts.v0.sql"); |
279 base::ScopedTempDir temp_dir; | 279 base::ScopedTempDir temp_dir; |
280 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 280 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
281 base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts.db")); | 281 base::FilePath db_path(temp_dir.GetPath().AppendASCII("TestShortcuts.db")); |
282 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); | 282 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); |
283 | 283 |
284 // Create a ShortcutsDatabase from the test database, which will migrate the | 284 // Create a ShortcutsDatabase from the test database, which will migrate the |
285 // test database to the current version. | 285 // test database to the current version. |
286 { | 286 { |
287 scoped_refptr<ShortcutsDatabase> db(new ShortcutsDatabase(db_path)); | 287 scoped_refptr<ShortcutsDatabase> db(new ShortcutsDatabase(db_path)); |
288 db->Init(); | 288 db->Init(); |
289 } | 289 } |
290 | 290 |
291 // Check that all the old type values got converted to new values. | 291 // Check that all the old type values got converted to new values. |
(...skipping 13 matching lines...) Expand all Loading... |
305 TEST(ShortcutsDatabaseMigrationTest, Recovery1) { | 305 TEST(ShortcutsDatabaseMigrationTest, Recovery1) { |
306 #if defined(OS_ANDROID) | 306 #if defined(OS_ANDROID) |
307 char kBasename[] = "Shortcuts.v1.sql"; | 307 char kBasename[] = "Shortcuts.v1.sql"; |
308 #else | 308 #else |
309 char kBasename[] = "Shortcuts.no_fill_into_edit.sql"; | 309 char kBasename[] = "Shortcuts.no_fill_into_edit.sql"; |
310 #endif | 310 #endif |
311 // Use the pre-v0 test file to create a test database in a temp dir. | 311 // Use the pre-v0 test file to create a test database in a temp dir. |
312 base::FilePath sql_path = GetTestDataDir().AppendASCII(kBasename); | 312 base::FilePath sql_path = GetTestDataDir().AppendASCII(kBasename); |
313 base::ScopedTempDir temp_dir; | 313 base::ScopedTempDir temp_dir; |
314 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 314 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
315 base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts.db")); | 315 base::FilePath db_path(temp_dir.GetPath().AppendASCII("TestShortcuts.db")); |
316 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); | 316 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); |
317 | 317 |
318 // Capture the row count from the golden file before corrupting the database. | 318 // Capture the row count from the golden file before corrupting the database. |
319 const char kCountSql[] = "SELECT COUNT(*) FROM omni_box_shortcuts"; | 319 const char kCountSql[] = "SELECT COUNT(*) FROM omni_box_shortcuts"; |
320 int row_count; | 320 int row_count; |
321 { | 321 { |
322 sql::Connection connection; | 322 sql::Connection connection; |
323 ASSERT_TRUE(connection.Open(db_path)); | 323 ASSERT_TRUE(connection.Open(db_path)); |
324 sql::Statement statement(connection.GetUniqueStatement(kCountSql)); | 324 sql::Statement statement(connection.GetUniqueStatement(kCountSql)); |
325 ASSERT_TRUE(statement.is_valid()); | 325 ASSERT_TRUE(statement.is_valid()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 // recovered. | 363 // recovered. |
364 { | 364 { |
365 sql::Connection connection; | 365 sql::Connection connection; |
366 ASSERT_TRUE(connection.Open(db_path)); | 366 ASSERT_TRUE(connection.Open(db_path)); |
367 sql::Statement statement(connection.GetUniqueStatement(kCountSql)); | 367 sql::Statement statement(connection.GetUniqueStatement(kCountSql)); |
368 ASSERT_TRUE(statement.is_valid()); | 368 ASSERT_TRUE(statement.is_valid()); |
369 ASSERT_TRUE(statement.Step()); | 369 ASSERT_TRUE(statement.Step()); |
370 EXPECT_EQ(row_count, statement.ColumnInt(0)); | 370 EXPECT_EQ(row_count, statement.ColumnInt(0)); |
371 } | 371 } |
372 } | 372 } |
OLD | NEW |