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

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

Issue 2703673002: [Merge-57] Add billing_address_id and has_converted to autofill_table (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « components/webdata/common/web_database.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 = 70; 133 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 71;
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 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 1022
1023 sql::Statement read_credit_cards(connection.GetUniqueStatement( 1023 sql::Statement read_credit_cards(connection.GetUniqueStatement(
1024 "SELECT name_on_card, billing_address_id FROM credit_cards")); 1024 "SELECT name_on_card, billing_address_id FROM credit_cards"));
1025 ASSERT_TRUE(read_credit_cards.Step()); 1025 ASSERT_TRUE(read_credit_cards.Step());
1026 EXPECT_EQ("Alice", read_credit_cards.ColumnString(0)); 1026 EXPECT_EQ("Alice", read_credit_cards.ColumnString(0));
1027 EXPECT_TRUE(read_credit_cards.ColumnString(1).empty()); 1027 EXPECT_TRUE(read_credit_cards.ColumnString(1).empty());
1028 } 1028 }
1029 } 1029 }
1030 1030
1031 // Tests addition of masked server credit card billing address. 1031 // Tests addition of masked server credit card billing address.
1032 // That column was moved to server_card_metadata in version 71.
1032 TEST_F(WebDatabaseMigrationTest, MigrateVersion66ToCurrent) { 1033 TEST_F(WebDatabaseMigrationTest, MigrateVersion66ToCurrent) {
1033 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_66.sql"))); 1034 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_66.sql")));
1034 1035
1035 // Verify pre-conditions. 1036 // Verify pre-conditions.
1036 { 1037 {
1037 sql::Connection connection; 1038 sql::Connection connection;
1038 ASSERT_TRUE(connection.Open(GetDatabasePath())); 1039 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1039 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); 1040 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1040 1041
1041 sql::MetaTable meta_table; 1042 sql::MetaTable meta_table;
(...skipping 11 matching lines...) Expand all
1053 1054
1054 // Verify post-conditions. 1055 // Verify post-conditions.
1055 { 1056 {
1056 sql::Connection connection; 1057 sql::Connection connection;
1057 ASSERT_TRUE(connection.Open(GetDatabasePath())); 1058 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1058 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); 1059 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1059 1060
1060 // Check version. 1061 // Check version.
1061 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); 1062 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1062 1063
1063 EXPECT_TRUE(connection.DoesColumnExist("masked_credit_cards", 1064 // The column was moved to server_card_metadata in version 71.
1065 EXPECT_FALSE(connection.DoesColumnExist("masked_credit_cards",
1066 "billing_address_id"));
1067 EXPECT_TRUE(connection.DoesColumnExist("server_card_metadata",
1064 "billing_address_id")); 1068 "billing_address_id"));
1065
1066 sql::Statement read_masked(connection.GetUniqueStatement(
1067 "SELECT name_on_card, billing_address_id FROM masked_credit_cards"));
1068 ASSERT_TRUE(read_masked.Step());
1069 EXPECT_EQ("Alice", read_masked.ColumnString(0));
1070 EXPECT_TRUE(read_masked.ColumnString(1).empty());
1071 } 1069 }
1072 } 1070 }
1073 1071
1074 // Tests deletion of show_in_default_list column in keywords table. 1072 // Tests deletion of show_in_default_list column in keywords table.
1075 TEST_F(WebDatabaseMigrationTest, MigrateVersion67ToCurrent) { 1073 TEST_F(WebDatabaseMigrationTest, MigrateVersion67ToCurrent) {
1076 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_67.sql"))); 1074 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_67.sql")));
1077 1075
1078 // Verify pre-conditions. 1076 // Verify pre-conditions.
1079 { 1077 {
1080 sql::Connection connection; 1078 sql::Connection connection;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 sql::Connection connection; 1157 sql::Connection connection;
1160 ASSERT_TRUE(connection.Open(GetDatabasePath())); 1158 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1161 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); 1159 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1162 1160
1163 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); 1161 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1164 1162
1165 EXPECT_TRUE(connection.DoesTableExist("autofill_sync_metadata")); 1163 EXPECT_TRUE(connection.DoesTableExist("autofill_sync_metadata"));
1166 EXPECT_TRUE(connection.DoesTableExist("autofill_model_type_state")); 1164 EXPECT_TRUE(connection.DoesTableExist("autofill_model_type_state"));
1167 } 1165 }
1168 } 1166 }
1167
1168 // Tests addition of billing_address_id to server_card_metadata and
1169 // has_converted to server_profile_metadata and tests that the
1170 // billing_address_id values were moved from the masked_credit_cards table to
1171 // the server_card_metadata table.
1172 TEST_F(WebDatabaseMigrationTest, MigrateVersion70ToCurrent) {
1173 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_70.sql")));
1174
1175 // Verify pre-conditions.
1176 {
1177 sql::Connection connection;
1178 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1179 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1180
1181 sql::MetaTable meta_table;
1182 ASSERT_TRUE(meta_table.Init(&connection, 70, 70));
1183
1184 EXPECT_FALSE(connection.DoesColumnExist("server_card_metadata",
1185 "billing_address_id"));
1186 EXPECT_FALSE(
1187 connection.DoesColumnExist("server_address_metadata", "has_converted"));
1188 }
1189
1190 DoMigration();
1191
1192 // Verify post-conditions.
1193 {
1194 sql::Connection connection;
1195 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1196 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1197
1198 // Check version.
1199 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1200
1201 // The billing_address_id column should have moved from masked_credit_cards
1202 // to server_card_metadata.
1203 EXPECT_FALSE(connection.DoesColumnExist("masked_credit_cards",
1204 "billing_address_id"));
1205 EXPECT_TRUE(connection.DoesColumnExist("server_card_metadata",
1206 "billing_address_id"));
1207
1208 // The has_converted column should have been added in
1209 // server_address_metadata.
1210 EXPECT_TRUE(
1211 connection.DoesColumnExist("server_address_metadata", "has_converted"));
1212
1213 // Make sure that the billing_address_id was moved from the
1214 // masked_credit_cards table to the server_card_metadata table. The values
1215 // are added to the table in version_70.sql.
1216 sql::Statement s_cards_metadata(connection.GetUniqueStatement(
1217 "SELECT id, billing_address_id FROM server_card_metadata"));
1218 ASSERT_TRUE(s_cards_metadata.Step());
1219 EXPECT_EQ("card_1", s_cards_metadata.ColumnString(0));
1220 EXPECT_EQ("address_1", s_cards_metadata.ColumnString(1));
1221
1222 // Make sure that the has_converted column was set to false.
1223 sql::Statement s_addresses_metadata(connection.GetUniqueStatement(
1224 "SELECT id, has_converted FROM server_address_metadata"));
1225 ASSERT_TRUE(s_addresses_metadata.Step());
1226 EXPECT_EQ("address_1", s_addresses_metadata.ColumnString(0));
1227 EXPECT_FALSE(s_addresses_metadata.ColumnBool(1));
1228
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
1231 // version_70.sql.
1232 sql::Statement s_masked_cards(connection.GetUniqueStatement(
1233 "SELECT id, status, name_on_card, type, last_four, exp_month, exp_year "
1234 "FROM masked_credit_cards"));
1235 ASSERT_TRUE(s_masked_cards.Step());
1236 EXPECT_EQ("card_1", s_masked_cards.ColumnString(0));
1237 EXPECT_EQ("status", s_masked_cards.ColumnString(1));
1238 EXPECT_EQ("bob", s_masked_cards.ColumnString(2));
1239 EXPECT_EQ("MASKED", s_masked_cards.ColumnString(3));
1240 EXPECT_EQ("1234", s_masked_cards.ColumnString(4));
1241 EXPECT_EQ(12, s_masked_cards.ColumnInt(5));
1242 EXPECT_EQ(2050, s_masked_cards.ColumnInt(6));
1243 }
1244 }
OLDNEW
« no previous file with comments | « components/webdata/common/web_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698