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 = 71; | 133 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 72; |
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 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 // Make sure that the has_converted column was set to false. | 1222 // Make sure that the has_converted column was set to false. |
1223 sql::Statement s_addresses_metadata(connection.GetUniqueStatement( | 1223 sql::Statement s_addresses_metadata(connection.GetUniqueStatement( |
1224 "SELECT id, has_converted FROM server_address_metadata")); | 1224 "SELECT id, has_converted FROM server_address_metadata")); |
1225 ASSERT_TRUE(s_addresses_metadata.Step()); | 1225 ASSERT_TRUE(s_addresses_metadata.Step()); |
1226 EXPECT_EQ("address_1", s_addresses_metadata.ColumnString(0)); | 1226 EXPECT_EQ("address_1", s_addresses_metadata.ColumnString(0)); |
1227 EXPECT_FALSE(s_addresses_metadata.ColumnBool(1)); | 1227 EXPECT_FALSE(s_addresses_metadata.ColumnBool(1)); |
1228 | 1228 |
1229 // Make sure that the values in masked_credit_cards are still present except | 1229 // Make sure that the values in masked_credit_cards are still present except |
1230 // for the billing_address_id. The values are added to the table in | 1230 // for the billing_address_id. The values are added to the table in |
1231 // version_70.sql. | 1231 // version_70.sql. |
1232 sql::Statement s_masked_cards(connection.GetUniqueStatement( | 1232 sql::Statement s_masked_cards( |
1233 "SELECT id, status, name_on_card, type, last_four, exp_month, exp_year " | 1233 connection.GetUniqueStatement("SELECT id, status, name_on_card, " |
1234 "FROM masked_credit_cards")); | 1234 "network, last_four, exp_month, exp_year " |
| 1235 "FROM masked_credit_cards")); |
1235 ASSERT_TRUE(s_masked_cards.Step()); | 1236 ASSERT_TRUE(s_masked_cards.Step()); |
1236 EXPECT_EQ("card_1", s_masked_cards.ColumnString(0)); | 1237 EXPECT_EQ("card_1", s_masked_cards.ColumnString(0)); |
1237 EXPECT_EQ("status", s_masked_cards.ColumnString(1)); | 1238 EXPECT_EQ("status", s_masked_cards.ColumnString(1)); |
1238 EXPECT_EQ("bob", s_masked_cards.ColumnString(2)); | 1239 EXPECT_EQ("bob", s_masked_cards.ColumnString(2)); |
1239 EXPECT_EQ("MASKED", s_masked_cards.ColumnString(3)); | 1240 EXPECT_EQ("VISA", s_masked_cards.ColumnString(3)); |
1240 EXPECT_EQ("1234", s_masked_cards.ColumnString(4)); | 1241 EXPECT_EQ("1234", s_masked_cards.ColumnString(4)); |
1241 EXPECT_EQ(12, s_masked_cards.ColumnInt(5)); | 1242 EXPECT_EQ(12, s_masked_cards.ColumnInt(5)); |
1242 EXPECT_EQ(2050, s_masked_cards.ColumnInt(6)); | 1243 EXPECT_EQ(2050, s_masked_cards.ColumnInt(6)); |
1243 } | 1244 } |
1244 } | 1245 } |
| 1246 |
| 1247 // Tests renaming "type" column into "network" for the "masked_credit_cards" |
| 1248 // table. |
| 1249 TEST_F(WebDatabaseMigrationTest, MigrateVersion71ToCurrent) { |
| 1250 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_71.sql"))); |
| 1251 |
| 1252 // Verify pre-conditions. |
| 1253 { |
| 1254 sql::Connection connection; |
| 1255 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1256 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 1257 |
| 1258 sql::MetaTable meta_table; |
| 1259 ASSERT_TRUE(meta_table.Init(&connection, 71, 71)); |
| 1260 |
| 1261 EXPECT_TRUE(connection.DoesColumnExist("masked_credit_cards", "type")); |
| 1262 EXPECT_FALSE(connection.DoesColumnExist("masked_credit_cards", "network")); |
| 1263 |
| 1264 EXPECT_TRUE( |
| 1265 connection.Execute("INSERT INTO masked_credit_cards(id, type) " |
| 1266 "VALUES ('id', 'VISA')")); |
| 1267 } |
| 1268 |
| 1269 DoMigration(); |
| 1270 |
| 1271 // Verify post-conditions. |
| 1272 { |
| 1273 sql::Connection connection; |
| 1274 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 1275 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 1276 |
| 1277 // Check version. |
| 1278 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
| 1279 |
| 1280 EXPECT_FALSE(connection.DoesColumnExist("masked_credit_cards", "type")); |
| 1281 EXPECT_TRUE(connection.DoesColumnExist("masked_credit_cards", "network")); |
| 1282 |
| 1283 sql::Statement s_cards_metadata(connection.GetUniqueStatement( |
| 1284 "SELECT id, network FROM masked_credit_cards")); |
| 1285 ASSERT_TRUE(s_cards_metadata.Step()); |
| 1286 EXPECT_EQ("id", s_cards_metadata.ColumnString(0)); |
| 1287 EXPECT_EQ("VISA", s_cards_metadata.ColumnString(1)); |
| 1288 } |
| 1289 } |
OLD | NEW |