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

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

Issue 2626843004: [Payments] Add billing_address_id and has_converted to autofill_table (Closed)
Patch Set: Rebase Created 3 years, 11 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 = 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 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 sql::Connection connection; 1159 sql::Connection connection;
1160 ASSERT_TRUE(connection.Open(GetDatabasePath())); 1160 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1161 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); 1161 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1162 1162
1163 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); 1163 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1164 1164
1165 EXPECT_TRUE(connection.DoesTableExist("autofill_sync_metadata")); 1165 EXPECT_TRUE(connection.DoesTableExist("autofill_sync_metadata"));
1166 EXPECT_TRUE(connection.DoesTableExist("autofill_model_type_state")); 1166 EXPECT_TRUE(connection.DoesTableExist("autofill_model_type_state"));
1167 } 1167 }
1168 } 1168 }
1169
1170 // Tests addition of billing_address_id to server_card_metadata and
1171 // has_converted to server_profile_metadata and tests that the
1172 // billing_address_id values were moved from the masked_credit_cards table to
1173 // the server_card_metadata table.
1174 TEST_F(WebDatabaseMigrationTest, MigrateVersion70ToCurrent) {
1175 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_70.sql")));
1176
1177 // Verify pre-conditions.
1178 {
1179 sql::Connection connection;
1180 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1181 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1182
1183 sql::MetaTable meta_table;
1184 ASSERT_TRUE(meta_table.Init(&connection, 70, 70));
1185
1186 EXPECT_FALSE(connection.DoesColumnExist("server_card_metadata",
1187 "billing_address_id"));
1188 EXPECT_FALSE(
1189 connection.DoesColumnExist("server_address_metadata", "has_converted"));
1190 }
1191
1192 DoMigration();
1193
1194 // Verify post-conditions.
1195 {
1196 sql::Connection connection;
1197 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1198 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1199
1200 // Check version.
1201 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1202
1203 EXPECT_TRUE(connection.DoesColumnExist("server_card_metadata",
1204 "billing_address_id"));
1205 EXPECT_TRUE(
1206 connection.DoesColumnExist("server_address_metadata", "has_converted"));
1207
1208 // Make sure that the billing_address_id was moved from the
1209 // masked_credit_cards table to the server_card_metadata table.
1210 sql::Statement s_cards_metadata(
1211 connection.GetUniqueStatement(
1212 "SELECT id, billing_address_id FROM server_card_metadata"));
1213 ASSERT_TRUE(s_cards_metadata.Step());
1214 EXPECT_EQ("card_1", s_cards_metadata.ColumnString(0));
please use gerrit instead 2017/01/12 19:10:59 Add a comment that this is defined in version_70.s
sebsg 2017/01/12 19:21:13 Done.
1215 EXPECT_EQ("address_1", s_cards_metadata.ColumnString(1));
1216
1217 // Make sure that the has_converted column was set to false.
1218 sql::Statement s_addresses_metadata(
1219 connection.GetUniqueStatement(
1220 "SELECT id, has_converted FROM server_address_metadata"));
1221 ASSERT_TRUE(s_addresses_metadata.Step());
1222 EXPECT_EQ("address_1", s_addresses_metadata.ColumnString(0));
1223 EXPECT_EQ(false, s_addresses_metadata.ColumnBool(1));
1224 }
1225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698