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..d6fda97e79f0dc7562db679185fce64e19723855 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,53 @@ 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("TestShortcuts1.db")); |
Mark P
2016/04/08 20:12:06
This probably should be "3", not "1". (Otherwise
Scott Hess - ex-Googler
2016/04/15 00:38:14
Copy/pasta. Since it's in a unique temp dir, I'll
|
+ ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); |
+ ASSERT_TRUE(sql::test::CorruptSizeInHeader(db_path)); |
+ |
+ // The database is broken. |
Mark P
2016/04/08 20:12:06
How about putting a blank line after 315, then add
Scott Hess - ex-Googler
2016/04/15 00:38:14
Done.
|
+ { |
+ sql::ScopedErrorIgnorer ignore_errors; |
+ ignore_errors.IgnoreError(SQLITE_CORRUPT); |
+ |
+ sql::Connection connection; |
+ ASSERT_TRUE(connection.Open(db_path)); |
+ ASSERT_FALSE(connection.Execute("SELECT count(*) FROM omni_box_shortcuts")); |
Mark P
2016/04/08 20:12:06
Why does this return failure if we're ignoring the
Scott Hess - ex-Googler
2016/04/15 00:38:14
Production code in debug mode fails with a FATAL,
|
+ |
+ ASSERT_TRUE(ignore_errors.CheckIgnoredErrors()); |
Mark P
2016/04/08 20:12:06
Side comment: the comment by the declaration of Ch
Scott Hess - ex-Googler
2016/04/15 00:38:14
I don't really follow. It says it's used to check
|
+ } |
+ |
+ // sql::Connection::Open() will hit the corruption, the error callback will |
Mark P
2016/04/08 20:12:06
sql::Connection::Open() will hit
->
The sql::Conne
Scott Hess - ex-Googler
2016/04/15 00:38:14
Done.
|
+ // 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/08 20:12:06
I think it's odd that we still see this error. Sh
Scott Hess - ex-Googler
2016/04/15 00:38:14
The error will be thrown in the first Open(), the
|
+ } |
+ |
+ 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( |
Mark P
2016/04/08 20:12:06
Please use an identical call to the one you used t
Scott Hess - ex-Googler
2016/04/15 00:38:14
Done.
|
+ "SELECT COUNT(*) FROM omni_box_shortcuts")); |
+ ASSERT_TRUE(statement.Step()); |
+ EXPECT_EQ(5, statement.ColumnInt(0)); |
Mark P
2016/04/08 20:12:06
Consider using something like
EXPECT_EQ(arraysize(
Scott Hess - ex-Googler
2016/04/15 00:38:14
CountRecords() runs against the sql::Connection co
|
+} |