Chromium Code Reviews| Index: components/omnibox/browser/shortcuts_database_unittest.cc |
| diff --git a/components/omnibox/browser/shortcuts_database_unittest.cc b/components/omnibox/browser/shortcuts_database_unittest.cc |
| index 15116b803d60a1be6fd6fab1deda1030fb2448fa..4d3f9edf8549144a87da080a0b145cda5639a901 100644 |
| --- a/components/omnibox/browser/shortcuts_database_unittest.cc |
| +++ b/components/omnibox/browser/shortcuts_database_unittest.cc |
| @@ -17,6 +17,7 @@ |
| #include "components/omnibox/browser/autocomplete_match_type.h" |
| #include "components/omnibox/browser/shortcuts_constants.h" |
| #include "sql/statement.h" |
| +#include "sql/test/scoped_error_ignorer.h" |
| #include "sql/test/test_helpers.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/base/page_transition_types.h" |
| @@ -299,3 +300,59 @@ TEST(ShortcutsDatabaseMigrationTest, MigrateV0ToV1) { |
| EXPECT_TRUE(temp_dir.Delete()); |
| #endif |
| } |
| + |
| +TEST(ShortcutsDatabaseMigrationTest, Recovery1) { |
| +#if defined(OS_ANDROID) |
| + char kBasename[] = "Shortcuts.v1.sql"; |
| +#else |
| + char kBasename[] = "Shortcuts.no_fill_into_edit.sql"; |
| +#endif |
| + // Use the pre-v0 test file to create a test database in a temp dir. |
| + base::FilePath sql_path = GetTestDataDir().AppendASCII(kBasename); |
| + base::ScopedTempDir temp_dir; |
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| + base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts.db")); |
|
Mark P
2016/04/19 23:34:28
If it doesn't matter that they're different, pleas
Scott Hess - ex-Googler
2016/05/13 21:24:35
Done.
|
| + ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); |
| + |
| + // Break the database. |
| + ASSERT_TRUE(sql::test::CorruptSizeInHeader(db_path)); |
| + |
| + // Verify that the database is broken. |
| + { |
| + sql::ScopedErrorIgnorer ignore_errors; |
| + ignore_errors.IgnoreError(SQLITE_CORRUPT); |
| + |
| + sql::Connection connection; |
| + ASSERT_TRUE(connection.Open(db_path)); |
| + sql::Statement statement(connection.GetUniqueStatement( |
|
Mark P
2016/04/19 23:34:28
Thank you for the explanation. That said, my orig
Scott Hess - ex-Googler
2016/05/13 21:24:36
Done. Pulled up the statement sql, noted that the
|
| + "SELECT COUNT(*) FROM omni_box_shortcuts")); |
| + ASSERT_FALSE(statement.is_valid()); |
| + |
| + ASSERT_TRUE(ignore_errors.CheckIgnoredErrors()); |
|
Mark P
2016/04/19 23:34:28
I don't agree. I see at least two ways to underst
Scott Hess - ex-Googler
2016/05/13 21:24:36
Obviously there's a terminology problem, here, but
|
| + } |
| + |
| + // The sql::Connection::Open() in ShortcutsDatabase::Init() will hit the |
|
Mark P
2016/04/19 23:34:28
nit: in -> call in
Scott Hess - ex-Googler
2016/05/13 21:24:36
Done.
|
| + // corruption, the error callback will recover and poison the database, then |
| + // Open() will retry, allowing Init() to succeed. |
| + { |
| + sql::ScopedErrorIgnorer ignore_errors; |
| + ignore_errors.IgnoreError(SQLITE_CORRUPT); |
| + |
| + scoped_refptr<ShortcutsDatabase> db(new ShortcutsDatabase(db_path)); |
| + ASSERT_TRUE(db->Init()); |
| + |
| + ASSERT_TRUE(ignore_errors.CheckIgnoredErrors()); |
|
Mark P
2016/04/19 23:34:28
Given this, I don't like this test's structure. I
Scott Hess - ex-Googler
2016/05/13 21:24:36
I'm not sure what you're referring to with "clears
|
| + } |
| + |
| + CheckV2ColumnExistence(db_path, true); |
| + |
| + // All of the data should have been recovered. |
| + { |
| + sql::Connection connection; |
| + ASSERT_TRUE(connection.Open(db_path)); |
| + sql::Statement statement(connection.GetUniqueStatement( |
| + "SELECT COUNT(*) FROM omni_box_shortcuts")); |
|
Mark P
2016/04/19 23:34:28
Almost done. I'd like exactly the same tests, i.e
Scott Hess - ex-Googler
2016/05/13 21:24:36
Done.
|
| + ASSERT_TRUE(statement.Step()); |
| + EXPECT_EQ(5, statement.ColumnInt(0)); |
|
Mark P
2016/04/19 23:34:27
I don't have a strong preference for how you fix i
Scott Hess - ex-Googler
2016/05/13 21:24:36
It's dependent on the contents of the golden file.
|
| + } |
| +} |