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 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1235 ASSERT_TRUE(s_masked_cards.Step()); | 1235 ASSERT_TRUE(s_masked_cards.Step()); |
1236 EXPECT_EQ("card_1", s_masked_cards.ColumnString(0)); | 1236 EXPECT_EQ("card_1", s_masked_cards.ColumnString(0)); |
1237 EXPECT_EQ("status", s_masked_cards.ColumnString(1)); | 1237 EXPECT_EQ("status", s_masked_cards.ColumnString(1)); |
1238 EXPECT_EQ("bob", s_masked_cards.ColumnString(2)); | 1238 EXPECT_EQ("bob", s_masked_cards.ColumnString(2)); |
1239 EXPECT_EQ("MASKED", s_masked_cards.ColumnString(3)); | 1239 EXPECT_EQ("MASKED", s_masked_cards.ColumnString(3)); |
1240 EXPECT_EQ("1234", s_masked_cards.ColumnString(4)); | 1240 EXPECT_EQ("1234", s_masked_cards.ColumnString(4)); |
1241 EXPECT_EQ(12, s_masked_cards.ColumnInt(5)); | 1241 EXPECT_EQ(12, s_masked_cards.ColumnInt(5)); |
1242 EXPECT_EQ(2050, s_masked_cards.ColumnInt(6)); | 1242 EXPECT_EQ(2050, s_masked_cards.ColumnInt(6)); |
1243 } | 1243 } |
1244 } | 1244 } |
1245 | |
1246 // Tests addition of bank_name to masked_credit_cards | |
1247 TEST_F(WebDatabaseMigrationTest, MigrateVersion71ToCurrent) { | |
1248 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_71.sql"))); | |
1249 | |
1250 // Verify pre-conditions. | |
1251 { | |
1252 sql::Connection connection; | |
1253 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
1254 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
1255 | |
1256 sql::MetaTable meta_table; | |
1257 ASSERT_TRUE(meta_table.Init(&connection, 71, 71)); | |
1258 | |
1259 EXPECT_FALSE(connection.DoesColumnExist("masked_credit_cards", | |
1260 "bank_name")); | |
1261 | |
1262 | |
1263 EXPECT_FALSE(connection.DoesColumnExist("masked_credit_cards", | |
1264 "billing_address_id")); | |
1265 EXPECT_TRUE(connection.DoesColumnExist("server_card_metadata", | |
1266 "billing_address_id")); | |
1267 EXPECT_TRUE( | |
1268 connection.DoesColumnExist("server_address_metadata", "has_converted")); | |
1269 } | |
1270 | |
1271 DoMigration(); | |
1272 | |
1273 // Verify post-conditions. | |
1274 { | |
1275 sql::Connection connection; | |
1276 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
1277 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
1278 | |
1279 // Check version. | |
1280 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | |
1281 | |
1282 // The bank_name column should exist. | |
1283 EXPECT_TRUE(connection.DoesColumnExist("masked_credit_cards", "bank_name")); | |
1284 | |
1285 // Make sure that the values in masked_credit_cards are as expected. The | |
1286 // values are added to the table in version_71.sql. | |
1287 sql::Statement s_masked_cards(connection.GetUniqueStatement( | |
1288 "SELECT id, " // 0 | |
1289 "status, " // 1 | |
1290 "name_on_card, " // 2 | |
1291 "type, " // 3 | |
1292 "last_four, " // 4 | |
1293 "exp_month, " // 5 | |
1294 "exp_year, " // 6 | |
1295 "bank_name " // 7 | |
1296 "FROM masked_credit_cards")); | |
1297 ASSERT_TRUE(s_masked_cards.Step()); | |
1298 EXPECT_EQ("card_1", s_masked_cards.ColumnString(0)); | |
1299 EXPECT_EQ("status", s_masked_cards.ColumnString(1)); | |
1300 EXPECT_EQ("bob", s_masked_cards.ColumnString(2)); | |
1301 EXPECT_EQ("MASKED", s_masked_cards.ColumnString(3)); | |
1302 EXPECT_EQ("1234", s_masked_cards.ColumnString(4)); | |
1303 EXPECT_EQ(12, s_masked_cards.ColumnInt(5)); | |
1304 EXPECT_EQ(2050, s_masked_cards.ColumnInt(6)); | |
1305 EXPECT_EQ("", s_masked_cards.ColumnString(7)); | |
Jared Saul
2017/03/10 19:51:54
Can bank name be tested here instead of being ""?
Shanfeng
2017/03/10 21:49:57
This is intended.
This test case is to verify the
| |
1306 } | |
1307 } | |
OLD | NEW |