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

Side by Side Diff: components/webdata/common/web_database_migration_unittest.cc

Issue 2711543002: Experiment to add bank name in autofill ui. (Closed)
Patch Set: address comments Created 3 years, 6 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 unified diff | Download patch
OLDNEW
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
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
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 values in masked_credit_cards are as expected. The
Peter Kasting 2017/06/13 00:04:03 Does this block really test anything of value? It
Shanfeng 2017/06/13 20:39:58 Done.
1323 // values are added to the table in version_72.sql.
1324 sql::Statement s_masked_cards(
1325 connection.GetUniqueStatement("SELECT id, " // 0
1326 "status, " // 1
1327 "name_on_card, " // 2
1328 "network, " // 3
1329 "last_four, " // 4
1330 "exp_month, " // 5
1331 "exp_year, " // 6
1332 "bank_name " // 7
1333 "FROM masked_credit_cards"));
1334 ASSERT_TRUE(s_masked_cards.Step());
1335 EXPECT_EQ("card_1", s_masked_cards.ColumnString(0));
1336 EXPECT_EQ("status", s_masked_cards.ColumnString(1));
1337 EXPECT_EQ("bob", s_masked_cards.ColumnString(2));
1338 EXPECT_EQ("VISA", s_masked_cards.ColumnString(3));
1339 EXPECT_EQ("1234", s_masked_cards.ColumnString(4));
1340 EXPECT_EQ(12, s_masked_cards.ColumnInt(5));
1341 EXPECT_EQ(2050, s_masked_cards.ColumnInt(6));
1342 EXPECT_EQ("", s_masked_cards.ColumnString(7));
1343 }
1344 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698