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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // > .output version_nn.sql | 123 // > .output version_nn.sql |
124 // > .dump | 124 // > .dump |
125 void LoadDatabase(const base::FilePath::StringType& file); | 125 void LoadDatabase(const base::FilePath::StringType& file); |
126 | 126 |
127 private: | 127 private: |
128 base::ScopedTempDir temp_dir_; | 128 base::ScopedTempDir temp_dir_; |
129 | 129 |
130 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); | 130 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); |
131 }; | 131 }; |
132 | 132 |
133 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 72; | 133 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 73; |
134 | 134 |
135 void WebDatabaseMigrationTest::LoadDatabase( | 135 void WebDatabaseMigrationTest::LoadDatabase( |
136 const base::FilePath::StringType& file) { | 136 const base::FilePath::StringType& file) { |
137 std::string contents; | 137 std::string contents; |
138 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); | 138 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); |
139 | 139 |
140 sql::Connection connection; | 140 sql::Connection connection; |
141 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 141 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
142 ASSERT_TRUE(connection.Execute(contents.data())); | 142 ASSERT_TRUE(connection.Execute(contents.data())); |
143 } | 143 } |
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 EXPECT_FALSE(connection.DoesColumnExist("masked_credit_cards", "type")); | 1280 EXPECT_FALSE(connection.DoesColumnExist("masked_credit_cards", "type")); |
1281 EXPECT_TRUE(connection.DoesColumnExist("masked_credit_cards", "network")); | 1281 EXPECT_TRUE(connection.DoesColumnExist("masked_credit_cards", "network")); |
1282 | 1282 |
1283 sql::Statement s_cards_metadata(connection.GetUniqueStatement( | 1283 sql::Statement s_cards_metadata(connection.GetUniqueStatement( |
1284 "SELECT id, network FROM masked_credit_cards")); | 1284 "SELECT id, network FROM masked_credit_cards")); |
1285 ASSERT_TRUE(s_cards_metadata.Step()); | 1285 ASSERT_TRUE(s_cards_metadata.Step()); |
1286 EXPECT_EQ("id", s_cards_metadata.ColumnString(0)); | 1286 EXPECT_EQ("id", s_cards_metadata.ColumnString(0)); |
1287 EXPECT_EQ("VISA", s_cards_metadata.ColumnString(1)); | 1287 EXPECT_EQ("VISA", s_cards_metadata.ColumnString(1)); |
1288 } | 1288 } |
1289 } | 1289 } |
| 1290 |
| 1291 // Tests addition of bank_name to masked_credit_cards |
| 1292 TEST_F(WebDatabaseMigrationTest, MigrateVersion72ToCurrent) { |
| 1293 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_72.sql"))); |
| 1294 |
| 1295 // Verify pre-conditions. |
| 1296 { |
| 1297 sql::Connection connection; |
| 1298 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1299 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 1300 |
| 1301 sql::MetaTable meta_table; |
| 1302 ASSERT_TRUE(meta_table.Init(&connection, 72, 72)); |
| 1303 |
| 1304 EXPECT_FALSE( |
| 1305 connection.DoesColumnExist("masked_credit_cards", "bank_name")); |
| 1306 } |
| 1307 |
| 1308 DoMigration(); |
| 1309 |
| 1310 // Verify post-conditions. |
| 1311 { |
| 1312 sql::Connection connection; |
| 1313 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1314 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 1315 |
| 1316 // Check version. |
| 1317 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
| 1318 |
| 1319 // The bank_name column should exist. |
| 1320 EXPECT_TRUE(connection.DoesColumnExist("masked_credit_cards", "bank_name")); |
| 1321 |
| 1322 // Make sure that the default bank name value is empty. |
| 1323 sql::Statement s_masked_cards(connection.GetUniqueStatement( |
| 1324 "SELECT bank_name FROM masked_credit_cards")); |
| 1325 ASSERT_TRUE(s_masked_cards.Step()); |
| 1326 EXPECT_EQ("", s_masked_cards.ColumnString(0)); |
| 1327 } |
| 1328 } |
OLD | NEW |