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

Unified Diff: components/password_manager/core/browser/login_database_unittest.cc

Issue 2265103002: LoginDatabase::Init: rollback before closing a DB (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CreateUniqueTempDir Created 4 years, 4 months 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/password_manager/core/browser/login_database.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/password_manager/core/browser/login_database_unittest.cc
diff --git a/components/password_manager/core/browser/login_database_unittest.cc b/components/password_manager/core/browser/login_database_unittest.cc
index d3464f5c632b49bf51e0a8f528a3c2a3369f7de5..2e30015a8d38358c1817c62dce44fb6a12c02031 100644
--- a/components/password_manager/core/browser/login_database_unittest.cc
+++ b/components/password_manager/core/browser/login_database_unittest.cc
@@ -1476,6 +1476,30 @@ TEST_F(LoginDatabaseTest, FilePermissions) {
}
#endif // defined(OS_POSIX)
+// If the database initialisation fails, the initialisation transaction should
+// roll back without crashing.
+TEST(LoginDatabaseFailureTest, Init_NoCrashOnFailedRollback) {
+ base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
vabr (Chromium) 2016/08/22 15:38:05 I forgot to initialise the temp dir. It passed on
+ base::FilePath database_path = temp_dir.path().AppendASCII("test.db");
+
+ // To cause an init failure, set the compatible version to be higher than the
+ // current version (in reality, this could happen if, e.g., someone opened a
+ // Canary-created profile with Chrome Stable.
+ {
+ sql::Connection connection;
+ sql::MetaTable meta_table;
+ ASSERT_TRUE(connection.Open(database_path));
+ ASSERT_TRUE(meta_table.Init(&connection, kCurrentVersionNumber + 1,
+ kCompatibleVersionNumber + 1));
+ }
+
+ // Now try to init the database with the file. The test succeeds if it does
+ // not crash.
+ LoginDatabase db(database_path);
+ EXPECT_FALSE(db.Init());
+}
+
// Test the migration from GetParam() version to kCurrentVersionNumber.
class LoginDatabaseMigrationTest : public testing::TestWithParam<int> {
protected:
« no previous file with comments | « components/password_manager/core/browser/login_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698