1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/guid.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/autofill/core/browser/autofill_country.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/webdata/autofill_change.h"
#include "components/autofill/core/browser/webdata/autofill_entry.h"
#include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/password_manager/core/browser/webdata/logins_table.h"
#include "components/search_engines/keyword_table.h"
#include "components/signin/core/browser/webdata/token_service_table.h"
#include "components/webdata/common/web_database.h"
#include "sql/statement.h"
#include "testing/gtest/include/gtest/gtest.h"
using autofill::AutofillProfile;
using autofill::AutofillTable;
using autofill::CreditCard;
using base::ASCIIToUTF16;
using base::Time;
namespace {
std::string RemoveQuotes(const std::string& has_quotes) {
std::string no_quotes;
// SQLite quotes: http://www.sqlite.org/lang_keywords.html
base::RemoveChars(has_quotes, "\"[]`", &no_quotes);
return no_quotes;
}
} // anonymous namespace
// The WebDatabaseMigrationTest encapsulates testing of database migrations.
// Specifically, these tests are intended to exercise any schema changes in
// the WebDatabase and data migrations that occur in
// |WebDatabase::MigrateOldVersionsAsNeeded()|.
class WebDatabaseMigrationTest : public testing::Test {
public:
WebDatabaseMigrationTest() {}
~WebDatabaseMigrationTest() override {}
void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); }
// Load the database via the WebDatabase class and migrate the database to
// the current version.
void DoMigration() {
AutofillTable autofill_table;
KeywordTable keyword_table;
LoginsTable logins_table;
TokenServiceTable token_service_table;
WebDatabase db;
db.AddTable(&autofill_table);
db.AddTable(&keyword_table);
db.AddTable(&logins_table);
db.AddTable(&token_service_table);
// This causes the migration to occur.
ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath()));
}
protected:
// Current tested version number. When adding a migration in
// |WebDatabase::MigrateOldVersionsAsNeeded()| and changing the version number
// |kCurrentVersionNumber| this value should change to reflect the new version
// number and a new migration test added below.
static const int kCurrentTestedVersionNumber;
base::FilePath GetDatabasePath() {
const base::FilePath::CharType kWebDatabaseFilename[] =
FILE_PATH_LITERAL("TestWebDatabase.sqlite3");
return temp_dir_.GetPath().Append(base::FilePath(kWebDatabaseFilename));
}
// The textual contents of |file| are read from
// "components/test/data/web_database" and returned in the string |contents|.
// Returns true if the file exists and is read successfully, false otherwise.
bool GetWebDatabaseData(const base::FilePath& file, std::string* contents) {
base::FilePath source_path;
PathService::Get(base::DIR_SOURCE_ROOT, &source_path);
source_path = source_path.AppendASCII("components");
source_path = source_path.AppendASCII("test");
source_path = source_path.AppendASCII("data");
source_path = source_path.AppendASCII("web_database");
source_path = source_path.Append(file);
return base::PathExists(source_path) &&
base::ReadFileToString(source_path, contents);
}
static int VersionFromConnection(sql::Connection* connection) {
// Get version.
sql::Statement s(connection->GetUniqueStatement(
"SELECT value FROM meta WHERE key='version'"));
if (!s.Step())
return 0;
return s.ColumnInt(0);
}
// The sql files located in "components/test/data/web_database" were generated
// by launching the Chromium application prior to schema change, then using
// the sqlite3 command-line application to dump the contents of the "Web Data"
// database.
// Like this:
// > .output version_nn.sql
// > .dump
void LoadDatabase(const base::FilePath::StringType& file);
private:
base::ScopedTempDir temp_dir_;
DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest);
};
const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 71;
void WebDatabaseMigrationTest::LoadDatabase(
const base::FilePath::StringType& file) {
std::string contents;
ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents));
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(connection.Execute(contents.data()));
}
// Tests that migrating from the golden files version_XX.sql results in the same
// schema as migrating from an empty database.
TEST_F(WebDatabaseMigrationTest, VersionXxSqlFilesAreGolden) {
DoMigration();
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
const std::string& expected_schema = RemoveQuotes(connection.GetSchema());
for (int i = WebDatabase::kDeprecatedVersionNumber + 1;
i < kCurrentTestedVersionNumber; ++i) {
// We don't test version 52 because there's a slight discrepancy in the
// initialization code and the migration code (relating to schema
// formatting). Fixing the bug is possible, but would require updating every
// version_nn.sql file.
if (i == 52)
continue;
connection.Raze();
const base::FilePath& file_name = base::FilePath::FromUTF8Unsafe(
"version_" + base::IntToString(i) + ".sql");
ASSERT_NO_FATAL_FAILURE(LoadDatabase(file_name.value()))
<< "Failed to load " << file_name.MaybeAsASCII();
DoMigration();
EXPECT_EQ(expected_schema, RemoveQuotes(connection.GetSchema()))
<< "For version " << i;
}
}
// Tests that the all migrations from an empty database succeed.
TEST_F(WebDatabaseMigrationTest, MigrateEmptyToCurrent) {
DoMigration();
// Verify post-conditions. These are expectations for current version of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
// Check that expected tables are present.
EXPECT_TRUE(connection.DoesTableExist("autofill"));
// The autofill_dates table is obsolete. (It's been merged into the autofill
// table.)
EXPECT_FALSE(connection.DoesTableExist("autofill_dates"));
EXPECT_TRUE(connection.DoesTableExist("autofill_profiles"));
EXPECT_TRUE(connection.DoesTableExist("credit_cards"));
EXPECT_TRUE(connection.DoesTableExist("keywords"));
// The logins table is obsolete. (We used to store saved passwords here.)
EXPECT_FALSE(connection.DoesTableExist("logins"));
EXPECT_TRUE(connection.DoesTableExist("meta"));
EXPECT_TRUE(connection.DoesTableExist("token_service"));
// The web_apps and web_apps_icons tables are obsolete as of version 58.
EXPECT_FALSE(connection.DoesTableExist("web_apps"));
EXPECT_FALSE(connection.DoesTableExist("web_app_icons"));
// The web_intents and web_intents_defaults tables are obsolete as of
// version 58.
EXPECT_FALSE(connection.DoesTableExist("web_intents"));
EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults"));
}
}
// Versions below 52 are deprecated. This verifies that old databases are razed.
TEST_F(WebDatabaseMigrationTest, RazeDeprecatedVersionAndReinit) {
ASSERT_NO_FATAL_FAILURE(
LoadDatabase(FILE_PATH_LITERAL("version_50.sql")));
// Verify pre-conditions. These are expectations for version 50 of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 50, 50));
ASSERT_FALSE(connection.DoesColumnExist("keywords", "image_url"));
ASSERT_FALSE(connection.DoesColumnExist("keywords",
"search_url_post_params"));
ASSERT_FALSE(connection.DoesColumnExist("keywords",
"suggest_url_post_params"));
ASSERT_FALSE(connection.DoesColumnExist("keywords",
"instant_url_post_params"));
ASSERT_FALSE(connection.DoesColumnExist("keywords",
"image_url_post_params"));
}
DoMigration();
// Verify post-conditions. These are expectations for current version of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
// New columns should have been created.
EXPECT_TRUE(connection.DoesColumnExist("keywords", "image_url"));
EXPECT_TRUE(connection.DoesColumnExist("keywords",
"search_url_post_params"));
EXPECT_TRUE(connection.DoesColumnExist("keywords",
"suggest_url_post_params"));
EXPECT_TRUE(connection.DoesColumnExist("keywords",
"instant_url_post_params"));
EXPECT_TRUE(connection.DoesColumnExist("keywords",
"image_url_post_params"));
}
}
// Tests that the column |new_tab_url| is added to the keyword table schema for
// a version 52 database.
TEST_F(WebDatabaseMigrationTest, MigrateVersion52ToCurrent) {
ASSERT_NO_FATAL_FAILURE(
LoadDatabase(FILE_PATH_LITERAL("version_52.sql")));
// Verify pre-conditions. These are expectations for version 52 of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 52, 52));
ASSERT_FALSE(connection.DoesColumnExist("keywords", "new_tab_url"));
}
DoMigration();
// Verify post-conditions. These are expectations for current version of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
// New columns should have been created.
EXPECT_TRUE(connection.DoesColumnExist("keywords", "new_tab_url"));
}
}
// Tests that for a version 54 database,
// (a) The street_address, dependent_locality, and sorting_code columns are
// added to the autofill_profiles table schema.
// (b) The address_line1, address_line2, and country columns are dropped from
// the autofill_profiles table schema.
// (c) The type column is dropped from the autofill_profile_phones schema.
TEST_F(WebDatabaseMigrationTest, MigrateVersion53ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_53.sql")));
// Verify pre-conditions. These are expectations for version 53 of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
EXPECT_TRUE(
connection.DoesColumnExist("autofill_profiles", "address_line_1"));
EXPECT_TRUE(
connection.DoesColumnExist("autofill_profiles", "address_line_2"));
EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "country"));
EXPECT_FALSE(
connection.DoesColumnExist("autofill_profiles", "street_address"));
EXPECT_FALSE(
connection.DoesColumnExist("autofill_profiles", "dependent_locality"));
EXPECT_FALSE(
connection.DoesColumnExist("autofill_profiles", "sorting_code"));
EXPECT_TRUE(connection.DoesColumnExist("autofill_profile_phones", "type"));
}
DoMigration();
// Verify post-conditions. These are expectations for current version of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
// Columns should have been added and removed appropriately.
EXPECT_FALSE(
connection.DoesColumnExist("autofill_profiles", "address_line1"));
EXPECT_FALSE(
connection.DoesColumnExist("autofill_profiles", "address_line2"));
EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "country"));
EXPECT_TRUE(
connection.DoesColumnExist("autofill_profiles", "street_address"));
EXPECT_TRUE(
connection.DoesColumnExist("autofill_profiles", "dependent_locality"));
EXPECT_TRUE(
connection.DoesColumnExist("autofill_profiles", "sorting_code"));
EXPECT_FALSE(connection.DoesColumnExist("autofill_profile_phones", "type"));
// Data should have been preserved.
sql::Statement s_profiles(
connection.GetUniqueStatement(
"SELECT guid, company_name, street_address, dependent_locality,"
" city, state, zipcode, sorting_code, country_code, date_modified,"
" origin "
"FROM autofill_profiles"));
// Address lines 1 and 2.
ASSERT_TRUE(s_profiles.Step());
EXPECT_EQ("00000000-0000-0000-0000-000000000001",
s_profiles.ColumnString(0));
EXPECT_EQ(ASCIIToUTF16("Google, Inc."), s_profiles.ColumnString16(1));
EXPECT_EQ(ASCIIToUTF16("1950 Charleston Rd.\n"
"(2nd floor)"),
s_profiles.ColumnString16(2));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(3));
EXPECT_EQ(ASCIIToUTF16("Mountain View"), s_profiles.ColumnString16(4));
EXPECT_EQ(ASCIIToUTF16("CA"), s_profiles.ColumnString16(5));
EXPECT_EQ(ASCIIToUTF16("94043"), s_profiles.ColumnString16(6));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(7));
EXPECT_EQ(ASCIIToUTF16("US"), s_profiles.ColumnString16(8));
EXPECT_EQ(1386046731, s_profiles.ColumnInt(9));
EXPECT_EQ(ASCIIToUTF16(autofill::kSettingsOrigin),
s_profiles.ColumnString16(10));
// Only address line 1.
ASSERT_TRUE(s_profiles.Step());
EXPECT_EQ("00000000-0000-0000-0000-000000000002",
s_profiles.ColumnString(0));
EXPECT_EQ(ASCIIToUTF16("Google!"), s_profiles.ColumnString16(1));
EXPECT_EQ(ASCIIToUTF16("1600 Amphitheatre Pkwy."),
s_profiles.ColumnString16(2));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(3));
EXPECT_EQ(ASCIIToUTF16("Mtn. View"), s_profiles.ColumnString16(4));
EXPECT_EQ(ASCIIToUTF16("California"), s_profiles.ColumnString16(5));
EXPECT_EQ(ASCIIToUTF16("94043-1234"), s_profiles.ColumnString16(6));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(7));
EXPECT_EQ(ASCIIToUTF16("US"), s_profiles.ColumnString16(8));
EXPECT_EQ(1386046800, s_profiles.ColumnInt(9));
EXPECT_EQ(ASCIIToUTF16(autofill::kSettingsOrigin),
s_profiles.ColumnString16(10));
// Only address line 2.
ASSERT_TRUE(s_profiles.Step());
EXPECT_EQ("00000000-0000-0000-0000-000000000003",
s_profiles.ColumnString(0));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(1));
EXPECT_EQ(ASCIIToUTF16("\nOnly line 2???"), s_profiles.ColumnString16(2));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(3));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(4));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(5));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(6));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(7));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(8));
EXPECT_EQ(1386046834, s_profiles.ColumnInt(9));
EXPECT_EQ(ASCIIToUTF16(autofill::kSettingsOrigin),
s_profiles.ColumnString16(10));
// No address lines.
ASSERT_TRUE(s_profiles.Step());
EXPECT_EQ("00000000-0000-0000-0000-000000000004",
s_profiles.ColumnString(0));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(1));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(2));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(3));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(4));
EXPECT_EQ(ASCIIToUTF16("Texas"), s_profiles.ColumnString16(5));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(6));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(7));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(8));
EXPECT_EQ(1386046847, s_profiles.ColumnInt(9));
EXPECT_EQ(ASCIIToUTF16(autofill::kSettingsOrigin),
s_profiles.ColumnString16(10));
// That should be it.
EXPECT_FALSE(s_profiles.Step());
// Verify the phone number data as well.
sql::Statement s_phones(
connection.GetUniqueStatement(
"SELECT guid, number FROM autofill_profile_phones"));
ASSERT_TRUE(s_phones.Step());
EXPECT_EQ("00000000-0000-0000-0000-000000000001", s_phones.ColumnString(0));
EXPECT_EQ(ASCIIToUTF16("1.800.555.1234"), s_phones.ColumnString16(1));
ASSERT_TRUE(s_phones.Step());
EXPECT_EQ("00000000-0000-0000-0000-000000000001", s_phones.ColumnString(0));
EXPECT_EQ(ASCIIToUTF16("+1 (800) 555-4321"), s_phones.ColumnString16(1));
ASSERT_TRUE(s_phones.Step());
EXPECT_EQ("00000000-0000-0000-0000-000000000002", s_phones.ColumnString(0));
EXPECT_EQ(base::string16(), s_phones.ColumnString16(1));
ASSERT_TRUE(s_phones.Step());
EXPECT_EQ("00000000-0000-0000-0000-000000000003", s_phones.ColumnString(0));
EXPECT_EQ(ASCIIToUTF16("6505557890"), s_phones.ColumnString16(1));
ASSERT_TRUE(s_phones.Step());
EXPECT_EQ("00000000-0000-0000-0000-000000000004", s_phones.ColumnString(0));
EXPECT_EQ(base::string16(), s_phones.ColumnString16(1));
EXPECT_FALSE(s_phones.Step());
}
}
// Tests that migrating from version 54 to version 55 drops the autofill_dates
// table, and merges the appropriate dates into the autofill table.
TEST_F(WebDatabaseMigrationTest, MigrateVersion54ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_54.sql")));
// Verify pre-conditions. These are expectations for version 54 of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
EXPECT_TRUE(connection.DoesTableExist("autofill_dates"));
EXPECT_FALSE(connection.DoesColumnExist("autofill", "date_created"));
EXPECT_FALSE(connection.DoesColumnExist("autofill", "date_last_used"));
// Verify the incoming data.
sql::Statement s_autofill(connection.GetUniqueStatement(
"SELECT name, value, value_lower, pair_id, count FROM autofill"));
sql::Statement s_dates(connection.GetUniqueStatement(
"SELECT pair_id, date_created FROM autofill_dates"));
// An entry with one timestamp.
ASSERT_TRUE(s_autofill.Step());
EXPECT_EQ(ASCIIToUTF16("Name"), s_autofill.ColumnString16(0));
EXPECT_EQ(ASCIIToUTF16("John Doe"), s_autofill.ColumnString16(1));
EXPECT_EQ(ASCIIToUTF16("john doe"), s_autofill.ColumnString16(2));
EXPECT_EQ(10, s_autofill.ColumnInt(3));
EXPECT_EQ(1, s_autofill.ColumnInt(4));
ASSERT_TRUE(s_dates.Step());
EXPECT_EQ(10, s_dates.ColumnInt(0));
EXPECT_EQ(1384299100, s_dates.ColumnInt64(1));
// Another entry with one timestamp, differing from the previous one in case
// only.
ASSERT_TRUE(s_autofill.Step());
EXPECT_EQ(ASCIIToUTF16("Name"), s_autofill.ColumnString16(0));
EXPECT_EQ(ASCIIToUTF16("john doe"), s_autofill.ColumnString16(1));
EXPECT_EQ(ASCIIToUTF16("john doe"), s_autofill.ColumnString16(2));
EXPECT_EQ(11, s_autofill.ColumnInt(3));
EXPECT_EQ(1, s_autofill.ColumnInt(4));
ASSERT_TRUE(s_dates.Step());
EXPECT_EQ(11, s_dates.ColumnInt(0));
EXPECT_EQ(1384299200, s_dates.ColumnInt64(1));
// An entry with two timestamps (with count > 2; this is realistic).
ASSERT_TRUE(s_autofill.Step());
EXPECT_EQ(ASCIIToUTF16("Email"), s_autofill.ColumnString16(0));
EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s_autofill.ColumnString16(1));
EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s_autofill.ColumnString16(2));
EXPECT_EQ(20, s_autofill.ColumnInt(3));
EXPECT_EQ(3, s_autofill.ColumnInt(4));
ASSERT_TRUE(s_dates.Step());
EXPECT_EQ(20, s_dates.ColumnInt(0));
EXPECT_EQ(1384299300, s_dates.ColumnInt64(1));
ASSERT_TRUE(s_dates.Step());
EXPECT_EQ(20, s_dates.ColumnInt(0));
EXPECT_EQ(1384299301, s_dates.ColumnInt64(1));
// An entry with more than two timestamps, which are stored out of order.
ASSERT_TRUE(s_autofill.Step());
EXPECT_EQ(ASCIIToUTF16("Email"), s_autofill.ColumnString16(0));
EXPECT_EQ(ASCIIToUTF16("jane.doe@example.org"),
s_autofill.ColumnString16(1));
EXPECT_EQ(ASCIIToUTF16("jane.doe@example.org"),
s_autofill.ColumnString16(2));
EXPECT_EQ(21, s_autofill.ColumnInt(3));
EXPECT_EQ(4, s_autofill.ColumnInt(4));
ASSERT_TRUE(s_dates.Step());
EXPECT_EQ(21, s_dates.ColumnInt(0));
EXPECT_EQ(1384299401, s_dates.ColumnInt64(1));
ASSERT_TRUE(s_dates.Step());
EXPECT_EQ(21, s_dates.ColumnInt(0));
EXPECT_EQ(1384299400, s_dates.ColumnInt64(1));
ASSERT_TRUE(s_dates.Step());
EXPECT_EQ(21, s_dates.ColumnInt(0));
EXPECT_EQ(1384299403, s_dates.ColumnInt64(1));
ASSERT_TRUE(s_dates.Step());
EXPECT_EQ(21, s_dates.ColumnInt(0));
EXPECT_EQ(1384299402, s_dates.ColumnInt64(1));
// No more entries expected.
ASSERT_FALSE(s_autofill.Step());
ASSERT_FALSE(s_dates.Step());
}
DoMigration();
// Verify post-conditions. These are expectations for current version of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
// The autofill_dates table should have been dropped, and its columns should
// have been migrated to the autofill table.
EXPECT_FALSE(connection.DoesTableExist("autofill_dates"));
EXPECT_TRUE(connection.DoesColumnExist("autofill", "date_created"));
EXPECT_TRUE(connection.DoesColumnExist("autofill", "date_last_used"));
// Data should have been preserved. Note that it appears out of order
// relative to the previous table, as it's been alphabetized. That's ok.
sql::Statement s(
connection.GetUniqueStatement(
"SELECT name, value, value_lower, date_created, date_last_used,"
" count "
"FROM autofill "
"ORDER BY name, value ASC"));
// "jane.doe@example.org": Timestamps should be parsed correctly, and only
// the first and last should be kept.
ASSERT_TRUE(s.Step());
EXPECT_EQ(ASCIIToUTF16("Email"), s.ColumnString16(0));
EXPECT_EQ(ASCIIToUTF16("jane.doe@example.org"), s.ColumnString16(1));
EXPECT_EQ(ASCIIToUTF16("jane.doe@example.org"), s.ColumnString16(2));
EXPECT_EQ(1384299400, s.ColumnInt64(3));
EXPECT_EQ(1384299403, s.ColumnInt64(4));
EXPECT_EQ(4, s.ColumnInt(5));
// "jane@example.com": Timestamps should be parsed correctly.
ASSERT_TRUE(s.Step());
EXPECT_EQ(ASCIIToUTF16("Email"), s.ColumnString16(0));
EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s.ColumnString16(1));
EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s.ColumnString16(2));
EXPECT_EQ(1384299300, s.ColumnInt64(3));
EXPECT_EQ(1384299301, s.ColumnInt64(4));
EXPECT_EQ(3, s.ColumnInt(5));
// "John Doe": The single timestamp should be assigned as both the creation
// and the last use timestamp.
ASSERT_TRUE(s.Step());
EXPECT_EQ(ASCIIToUTF16("Name"), s.ColumnString16(0));
EXPECT_EQ(ASCIIToUTF16("John Doe"), s.ColumnString16(1));
EXPECT_EQ(ASCIIToUTF16("john doe"), s.ColumnString16(2));
EXPECT_EQ(1384299100, s.ColumnInt64(3));
EXPECT_EQ(1384299100, s.ColumnInt64(4));
EXPECT_EQ(1, s.ColumnInt(5));
// "john doe": Should not be merged with "John Doe" (case-sensitivity).
ASSERT_TRUE(s.Step());
EXPECT_EQ(ASCIIToUTF16("Name"), s.ColumnString16(0));
EXPECT_EQ(ASCIIToUTF16("john doe"), s.ColumnString16(1));
EXPECT_EQ(ASCIIToUTF16("john doe"), s.ColumnString16(2));
EXPECT_EQ(1384299200, s.ColumnInt64(3));
EXPECT_EQ(1384299200, s.ColumnInt64(4));
EXPECT_EQ(1, s.ColumnInt(5));
// No more entries expected.
ASSERT_FALSE(s.Step());
}
}
// Tests that migrating from version 55 to version 56 adds the language_code
// column to autofill_profiles table.
TEST_F(WebDatabaseMigrationTest, MigrateVersion55ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_55.sql")));
// Verify pre-conditions. These are expectations for version 55 of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
EXPECT_FALSE(
connection.DoesColumnExist("autofill_profiles", "language_code"));
}
DoMigration();
// Verify post-conditions. These are expectations for current version of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
// The language_code column should have been added to autofill_profiles
// table.
EXPECT_TRUE(
connection.DoesColumnExist("autofill_profiles", "language_code"));
// Data should have been preserved. Language code should have been set to
// empty string.
sql::Statement s_profiles(
connection.GetUniqueStatement(
"SELECT guid, company_name, street_address, dependent_locality,"
" city, state, zipcode, sorting_code, country_code, date_modified,"
" origin, language_code "
"FROM autofill_profiles"));
ASSERT_TRUE(s_profiles.Step());
EXPECT_EQ("00000000-0000-0000-0000-000000000001",
s_profiles.ColumnString(0));
EXPECT_EQ(ASCIIToUTF16("Google Inc"), s_profiles.ColumnString16(1));
EXPECT_EQ(ASCIIToUTF16("340 Main St"),
s_profiles.ColumnString16(2));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(3));
EXPECT_EQ(ASCIIToUTF16("Los Angeles"), s_profiles.ColumnString16(4));
EXPECT_EQ(ASCIIToUTF16("CA"), s_profiles.ColumnString16(5));
EXPECT_EQ(ASCIIToUTF16("90291"), s_profiles.ColumnString16(6));
EXPECT_EQ(base::string16(), s_profiles.ColumnString16(7));
EXPECT_EQ(ASCIIToUTF16("US"), s_profiles.ColumnString16(8));
EXPECT_EQ(1395948829, s_profiles.ColumnInt(9));
EXPECT_EQ(ASCIIToUTF16(autofill::kSettingsOrigin),
s_profiles.ColumnString16(10));
EXPECT_EQ(std::string(), s_profiles.ColumnString(11));
// No more entries expected.
ASSERT_FALSE(s_profiles.Step());
}
}
// Tests that migrating from version 56 to version 57 adds the full_name
// column to autofill_profile_names table.
TEST_F(WebDatabaseMigrationTest, MigrateVersion56ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_56.sql")));
// Verify pre-conditions. These are expectations for version 56 of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
EXPECT_FALSE(
connection.DoesColumnExist("autofill_profile_names", "full_name"));
// Verify the starting data.
sql::Statement s_names(
connection.GetUniqueStatement(
"SELECT guid, first_name, middle_name, last_name "
"FROM autofill_profile_names"));
ASSERT_TRUE(s_names.Step());
EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names.ColumnString(0));
EXPECT_EQ(ASCIIToUTF16("Jon"), s_names.ColumnString16(1));
EXPECT_EQ(base::string16(), s_names.ColumnString16(2));
EXPECT_EQ(ASCIIToUTF16("Smith"), s_names.ColumnString16(3));
}
DoMigration();
// Verify post-conditions. These are expectations for current version of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
// The full_name column should have been added to autofill_profile_names
// table.
EXPECT_TRUE(
connection.DoesColumnExist("autofill_profile_names", "full_name"));
// Data should have been preserved. Full name should have been set to the
// empty string.
sql::Statement s_names(
connection.GetUniqueStatement(
"SELECT guid, first_name, middle_name, last_name, full_name "
"FROM autofill_profile_names"));
ASSERT_TRUE(s_names.Step());
EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names.ColumnString(0));
EXPECT_EQ(ASCIIToUTF16("Jon"), s_names.ColumnString16(1));
EXPECT_EQ(base::string16(), s_names.ColumnString16(2));
EXPECT_EQ(ASCIIToUTF16("Smith"), s_names.ColumnString16(3));
EXPECT_EQ(base::string16(), s_names.ColumnString16(4));
// No more entries expected.
ASSERT_FALSE(s_names.Step());
}
}
// Tests that migrating from version 57 to version 58 drops the web_intents and
// web_apps tables.
TEST_F(WebDatabaseMigrationTest, MigrateVersion57ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_57.sql")));
// Verify pre-conditions. These are expectations for version 57 of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
EXPECT_TRUE(connection.DoesTableExist("web_apps"));
EXPECT_TRUE(connection.DoesTableExist("web_app_icons"));
EXPECT_TRUE(connection.DoesTableExist("web_intents"));
EXPECT_TRUE(connection.DoesTableExist("web_intents_defaults"));
}
DoMigration();
// Verify post-conditions. These are expectations for current version of the
// database.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
EXPECT_FALSE(connection.DoesTableExist("web_apps"));
EXPECT_FALSE(connection.DoesTableExist("web_app_icons"));
EXPECT_FALSE(connection.DoesTableExist("web_intents"));
EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults"));
}
}
// Tests that migrating from version 58 to version 59 drops the omnibox
// extension keywords.
TEST_F(WebDatabaseMigrationTest, MigrateVersion58ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_58.sql")));
const char query_extensions[] = "SELECT * FROM keywords "
"WHERE url='chrome-extension://iphchnegaodmijmkdlbhbanjhfphhikp/"
"?q={searchTerms}'";
// Verify pre-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 58, 58));
sql::Statement s(connection.GetUniqueStatement(query_extensions));
ASSERT_TRUE(s.is_valid());
int count = 0;
while (s.Step()) {
++count;
}
EXPECT_EQ(1, count);
}
DoMigration();
// Verify post-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
sql::Statement s(connection.GetUniqueStatement(query_extensions));
ASSERT_TRUE(s.is_valid());
int count = 0;
while (s.Step()) {
++count;
}
EXPECT_EQ(0, count);
s.Assign(connection.GetUniqueStatement("SELECT * FROM keywords "
"WHERE short_name='Google'"));
ASSERT_TRUE(s.is_valid());
count = 0;
while (s.Step()) {
++count;
}
EXPECT_EQ(1, count);
}
}
// Tests creation of the server_credit_cards table.
TEST_F(WebDatabaseMigrationTest, MigrateVersion59ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_59.sql")));
// Verify pre-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 59, 59));
ASSERT_FALSE(connection.DoesTableExist("masked_credit_cards"));
ASSERT_FALSE(connection.DoesTableExist("unmasked_credit_cards"));
ASSERT_FALSE(connection.DoesTableExist("server_addresses"));
}
DoMigration();
// Verify post-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
ASSERT_TRUE(connection.DoesTableExist("masked_credit_cards"));
ASSERT_TRUE(connection.DoesTableExist("unmasked_credit_cards"));
ASSERT_TRUE(connection.DoesTableExist("server_addresses"));
}
}
// Tests addition of use_count and use_date fields to autofill profiles and
// credit cards.
TEST_F(WebDatabaseMigrationTest, MigrateVersion60ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_60.sql")));
// Verify pre-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 60, 60));
EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "use_count"));
EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "use_date"));
EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "use_count"));
EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "use_date"));
}
DoMigration();
// Verify post-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "use_count"));
EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "use_date"));
EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "use_count"));
EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "use_date"));
}
}
// Tests addition of use_count and use_date fields to unmasked server cards.
TEST_F(WebDatabaseMigrationTest, MigrateVersion61ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_61.sql")));
// Verify pre-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 61, 61));
EXPECT_FALSE(connection.DoesColumnExist("unmasked_credit_cards",
"use_count"));
EXPECT_FALSE(connection.DoesColumnExist("unmasked_credit_cards",
"use_date"));
}
DoMigration();
// Verify post-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
EXPECT_TRUE(connection.DoesColumnExist("unmasked_credit_cards",
"use_count"));
EXPECT_TRUE(connection.DoesColumnExist("unmasked_credit_cards",
"use_date"));
}
}
// Tests addition of server metadata tables.
TEST_F(WebDatabaseMigrationTest, MigrateVersion64ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_64.sql")));
// Verify pre-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 64, 64));
EXPECT_FALSE(connection.DoesTableExist("server_card_metadata"));
EXPECT_FALSE(connection.DoesTableExist("server_address_metadata"));
// Add a server address --- make sure it gets an ID.
sql::Statement insert_profiles(
connection.GetUniqueStatement(
"INSERT INTO server_addresses(id, postal_code) "
"VALUES ('', 90210)"));
insert_profiles.Run();
}
DoMigration();
// Verify post-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
EXPECT_TRUE(connection.DoesTableExist("server_card_metadata"));
EXPECT_TRUE(connection.DoesTableExist("server_address_metadata"));
sql::Statement read_profiles(
connection.GetUniqueStatement(
"SELECT id, postal_code FROM server_addresses"));
ASSERT_TRUE(read_profiles.Step());
EXPECT_FALSE(read_profiles.ColumnString(0).empty());
EXPECT_EQ("90210", read_profiles.ColumnString(1));
}
}
// Tests addition of credit card billing address.
TEST_F(WebDatabaseMigrationTest, MigrateVersion65ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_65.sql")));
// Verify pre-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 65, 65));
EXPECT_FALSE(connection.DoesColumnExist("credit_cards",
"billing_address_id"));
EXPECT_TRUE(connection.Execute(
"INSERT INTO credit_cards(guid, name_on_card) VALUES ('', 'Alice')"));
}
DoMigration();
// Verify post-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
EXPECT_TRUE(connection.DoesColumnExist("credit_cards",
"billing_address_id"));
sql::Statement read_credit_cards(connection.GetUniqueStatement(
"SELECT name_on_card, billing_address_id FROM credit_cards"));
ASSERT_TRUE(read_credit_cards.Step());
EXPECT_EQ("Alice", read_credit_cards.ColumnString(0));
EXPECT_TRUE(read_credit_cards.ColumnString(1).empty());
}
}
// Tests addition of masked server credit card billing address.
// That column was moved to server_card_metadata in version 71.
TEST_F(WebDatabaseMigrationTest, MigrateVersion66ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_66.sql")));
// Verify pre-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 66, 66));
EXPECT_FALSE(connection.DoesColumnExist("masked_credit_cards",
"billing_address_id"));
EXPECT_TRUE(connection.Execute(
"INSERT INTO masked_credit_cards(id, name_on_card) "
"VALUES ('id', 'Alice')"));
}
DoMigration();
// Verify post-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
// The column was moved to server_card_metadata in version 71.
EXPECT_FALSE(connection.DoesColumnExist("masked_credit_cards",
"billing_address_id"));
EXPECT_TRUE(connection.DoesColumnExist("server_card_metadata",
"billing_address_id"));
}
}
// Tests deletion of show_in_default_list column in keywords table.
TEST_F(WebDatabaseMigrationTest, MigrateVersion67ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_67.sql")));
// Verify pre-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 67, 67));
EXPECT_TRUE(connection.DoesColumnExist("keywords", "show_in_default_list"));
}
DoMigration();
// Verify post-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
EXPECT_FALSE(
connection.DoesColumnExist("keywords", "show_in_default_list"));
}
}
// Tests addition of last_visited column in keywords table.
TEST_F(WebDatabaseMigrationTest, MigrateVersion68ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_68.sql")));
// Verify pre-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 68, 68));
EXPECT_FALSE(connection.DoesColumnExist("keywords", "last_visited"));
}
DoMigration();
// Verify post-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
EXPECT_TRUE(
connection.DoesColumnExist("keywords", "last_visited"));
}
}
// Tests addition of sync metadata and model type state tables.
TEST_F(WebDatabaseMigrationTest, MigrateVersion69ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_69.sql")));
// Verify pre-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 69, 69));
EXPECT_FALSE(connection.DoesTableExist("autofill_sync_metadata"));
EXPECT_FALSE(connection.DoesTableExist("autofill_model_type_state"));
}
DoMigration();
// Verify post-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
EXPECT_TRUE(connection.DoesTableExist("autofill_sync_metadata"));
EXPECT_TRUE(connection.DoesTableExist("autofill_model_type_state"));
}
}
// Tests addition of billing_address_id to server_card_metadata and
// has_converted to server_profile_metadata and tests that the
// billing_address_id values were moved from the masked_credit_cards table to
// the server_card_metadata table.
TEST_F(WebDatabaseMigrationTest, MigrateVersion70ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_70.sql")));
// Verify pre-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 70, 70));
EXPECT_FALSE(connection.DoesColumnExist("server_card_metadata",
"billing_address_id"));
EXPECT_FALSE(
connection.DoesColumnExist("server_address_metadata", "has_converted"));
}
DoMigration();
// Verify post-conditions.
{
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
// The billing_address_id column should have moved from masked_credit_cards
// to server_card_metadata.
EXPECT_FALSE(connection.DoesColumnExist("masked_credit_cards",
"billing_address_id"));
EXPECT_TRUE(connection.DoesColumnExist("server_card_metadata",
"billing_address_id"));
// The has_converted column should have been added in
// server_address_metadata.
EXPECT_TRUE(
connection.DoesColumnExist("server_address_metadata", "has_converted"));
// Make sure that the billing_address_id was moved from the
// masked_credit_cards table to the server_card_metadata table. The values
// are added to the table in version_70.sql.
sql::Statement s_cards_metadata(connection.GetUniqueStatement(
"SELECT id, billing_address_id FROM server_card_metadata"));
ASSERT_TRUE(s_cards_metadata.Step());
EXPECT_EQ("card_1", s_cards_metadata.ColumnString(0));
EXPECT_EQ("address_1", s_cards_metadata.ColumnString(1));
// Make sure that the has_converted column was set to false.
sql::Statement s_addresses_metadata(connection.GetUniqueStatement(
"SELECT id, has_converted FROM server_address_metadata"));
ASSERT_TRUE(s_addresses_metadata.Step());
EXPECT_EQ("address_1", s_addresses_metadata.ColumnString(0));
EXPECT_FALSE(s_addresses_metadata.ColumnBool(1));
// Make sure that the values in masked_credit_cards are still present except
// for the billing_address_id. The values are added to the table in
// version_70.sql.
sql::Statement s_masked_cards(connection.GetUniqueStatement(
"SELECT id, status, name_on_card, type, last_four, exp_month, exp_year "
"FROM masked_credit_cards"));
ASSERT_TRUE(s_masked_cards.Step());
EXPECT_EQ("card_1", s_masked_cards.ColumnString(0));
EXPECT_EQ("status", s_masked_cards.ColumnString(1));
EXPECT_EQ("bob", s_masked_cards.ColumnString(2));
EXPECT_EQ("MASKED", s_masked_cards.ColumnString(3));
EXPECT_EQ("1234", s_masked_cards.ColumnString(4));
EXPECT_EQ(12, s_masked_cards.ColumnInt(5));
EXPECT_EQ(2050, s_masked_cards.ColumnInt(6));
}
}
|