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

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

Issue 962583003: Raze old WebDatabases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 20 matching lines...) Expand all
31 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 32
33 using autofill::AutofillProfile; 33 using autofill::AutofillProfile;
34 using autofill::AutofillTable; 34 using autofill::AutofillTable;
35 using autofill::CreditCard; 35 using autofill::CreditCard;
36 using base::ASCIIToUTF16; 36 using base::ASCIIToUTF16;
37 using base::Time; 37 using base::Time;
38 38
39 namespace { 39 namespace {
40 40
41 void AutofillProfile31FromStatement(const sql::Statement& s,
42 AutofillProfile* profile,
43 base::string16* label,
44 int* unique_id,
45 int64* date_modified) {
46 DCHECK(profile);
47 DCHECK(label);
48 DCHECK(unique_id);
49 DCHECK(date_modified);
50 *label = s.ColumnString16(0);
51 *unique_id = s.ColumnInt(1);
52 profile->SetRawInfo(autofill::NAME_FIRST, s.ColumnString16(2));
53 profile->SetRawInfo(autofill::NAME_MIDDLE, s.ColumnString16(3));
54 profile->SetRawInfo(autofill::NAME_LAST, s.ColumnString16(4));
55 profile->SetRawInfo(autofill::EMAIL_ADDRESS, s.ColumnString16(5));
56 profile->SetRawInfo(autofill::COMPANY_NAME, s.ColumnString16(6));
57 profile->SetRawInfo(autofill::ADDRESS_HOME_LINE1, s.ColumnString16(7));
58 profile->SetRawInfo(autofill::ADDRESS_HOME_LINE2, s.ColumnString16(8));
59 profile->SetRawInfo(autofill::ADDRESS_HOME_CITY, s.ColumnString16(9));
60 profile->SetRawInfo(autofill::ADDRESS_HOME_STATE, s.ColumnString16(10));
61 profile->SetRawInfo(autofill::ADDRESS_HOME_ZIP, s.ColumnString16(11));
62 profile->SetInfo(
63 autofill::AutofillType(autofill::ADDRESS_HOME_COUNTRY),
64 s.ColumnString16(12), "en-US");
65 profile->SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(13));
66 *date_modified = s.ColumnInt64(15);
67 profile->set_guid(s.ColumnString(16));
68 EXPECT_TRUE(base::IsValidGUID(profile->guid()));
69 }
70
71 void AutofillProfile33FromStatement(const sql::Statement& s,
72 AutofillProfile* profile,
73 int64* date_modified) {
74 DCHECK(profile);
75 DCHECK(date_modified);
76 profile->set_guid(s.ColumnString(0));
77 EXPECT_TRUE(base::IsValidGUID(profile->guid()));
78 profile->SetRawInfo(autofill::COMPANY_NAME, s.ColumnString16(1));
79 profile->SetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS,
80 s.ColumnString16(2));
81 profile->SetRawInfo(autofill::ADDRESS_HOME_CITY, s.ColumnString16(3));
82 profile->SetRawInfo(autofill::ADDRESS_HOME_STATE, s.ColumnString16(4));
83 profile->SetRawInfo(autofill::ADDRESS_HOME_ZIP, s.ColumnString16(5));
84 profile->SetInfo(
85 autofill::AutofillType(autofill::ADDRESS_HOME_COUNTRY),
86 s.ColumnString16(6), "en-US");
87 *date_modified = s.ColumnInt64(7);
88 }
89
90 void CreditCard31FromStatement(const sql::Statement& s,
91 CreditCard* credit_card,
92 base::string16* label,
93 int* unique_id,
94 std::string* encrypted_number,
95 int64* date_modified) {
96 DCHECK(credit_card);
97 DCHECK(label);
98 DCHECK(unique_id);
99 DCHECK(encrypted_number);
100 DCHECK(date_modified);
101 *label = s.ColumnString16(0);
102 *unique_id = s.ColumnInt(1);
103 credit_card->SetRawInfo(autofill::CREDIT_CARD_NAME, s.ColumnString16(2));
104 credit_card->SetRawInfo(autofill::CREDIT_CARD_TYPE, s.ColumnString16(3));
105 credit_card->SetRawInfo(autofill::CREDIT_CARD_EXP_MONTH, s.ColumnString16(5));
106 credit_card->SetRawInfo(
107 autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(6));
108 int encrypted_number_len = s.ColumnByteLength(10);
109 if (encrypted_number_len) {
110 encrypted_number->resize(encrypted_number_len);
111 memcpy(&(*encrypted_number)[0], s.ColumnBlob(10), encrypted_number_len);
112 }
113 *date_modified = s.ColumnInt64(12);
114 credit_card->set_guid(s.ColumnString(13));
115 EXPECT_TRUE(base::IsValidGUID(credit_card->guid()));
116 }
117
118 void CreditCard32FromStatement(const sql::Statement& s,
119 CreditCard* credit_card,
120 std::string* encrypted_number,
121 int64* date_modified) {
122 DCHECK(credit_card);
123 DCHECK(encrypted_number);
124 DCHECK(date_modified);
125 credit_card->set_guid(s.ColumnString(0));
126 EXPECT_TRUE(base::IsValidGUID(credit_card->guid()));
127 credit_card->SetRawInfo(autofill::CREDIT_CARD_NAME, s.ColumnString16(1));
128 credit_card->SetRawInfo(autofill::CREDIT_CARD_EXP_MONTH, s.ColumnString16(2));
129 credit_card->SetRawInfo(
130 autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR, s.ColumnString16(3));
131 int encrypted_number_len = s.ColumnByteLength(4);
132 if (encrypted_number_len) {
133 encrypted_number->resize(encrypted_number_len);
134 memcpy(&(*encrypted_number)[0], s.ColumnBlob(4), encrypted_number_len);
135 }
136 *date_modified = s.ColumnInt64(5);
137 }
138
139 void CheckHasBackupData(sql::MetaTable* meta_table) {
140 std::string value;
141 EXPECT_TRUE(meta_table->GetValue(
142 "Default Search Provider ID Backup", &value));
143 EXPECT_TRUE(meta_table->GetValue(
144 "Default Search Provider ID Backup Signature", &value));
145 }
146
147 void CheckNoBackupData(const sql::Connection& connection,
148 sql::MetaTable* meta_table) {
149 std::string value;
150 EXPECT_FALSE(meta_table->GetValue(
151 "Default Search Provider ID Backup", &value));
152 EXPECT_FALSE(meta_table->GetValue(
153 "Default Search Provider ID Backup Signature", &value));
154 EXPECT_FALSE(connection.DoesTableExist("keywords_backup"));
155 }
156
157 std::string RemoveQuotes(const std::string& has_quotes) { 41 std::string RemoveQuotes(const std::string& has_quotes) {
158 std::string no_quotes; 42 std::string no_quotes;
159 // SQLite quotes: http://www.sqlite.org/lang_keywords.html 43 // SQLite quotes: http://www.sqlite.org/lang_keywords.html
160 base::RemoveChars(has_quotes, "\"[]`", &no_quotes); 44 base::RemoveChars(has_quotes, "\"[]`", &no_quotes);
161 return no_quotes; 45 return no_quotes;
162 } 46 }
163 47
164 } // anonymous namespace 48 } // anonymous namespace
165 49
166 // The WebDatabaseMigrationTest encapsulates testing of database migrations. 50 // The WebDatabaseMigrationTest encapsulates testing of database migrations.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 ASSERT_TRUE(connection.Execute(contents.data())); 144 ASSERT_TRUE(connection.Execute(contents.data()));
261 } 145 }
262 146
263 // Tests that migrating from the golden files version_XX.sql results in the same 147 // Tests that migrating from the golden files version_XX.sql results in the same
264 // schema as migrating from an empty database. 148 // schema as migrating from an empty database.
265 TEST_F(WebDatabaseMigrationTest, VersionXxSqlFilesAreGolden) { 149 TEST_F(WebDatabaseMigrationTest, VersionXxSqlFilesAreGolden) {
266 DoMigration(); 150 DoMigration();
267 sql::Connection connection; 151 sql::Connection connection;
268 ASSERT_TRUE(connection.Open(GetDatabasePath())); 152 ASSERT_TRUE(connection.Open(GetDatabasePath()));
269 const std::string& expected_schema = RemoveQuotes(connection.GetSchema()); 153 const std::string& expected_schema = RemoveQuotes(connection.GetSchema());
270 static const int kFirstVersion = 53; 154 for (int i = WebDatabase::kDeprecatedVersionNumber + 1;
271 for (int i = kFirstVersion; i < kCurrentTestedVersionNumber; ++i) { 155 i < kCurrentTestedVersionNumber; ++i) {
156 // We don't test version 52 because there's a slight discrepancy in the
157 // initialization code and the migration code (relating to schema
158 // formatting). Fixing the bug is possible, but would require updating every
159 // version_nn.sql file.
Peter Kasting 2015/02/26 22:33:19 So why not do that? There aren't so many of these
Evan Stade 2015/02/26 22:37:19 That's somewhat orthogonal. This wasn't being test
Peter Kasting 2015/02/26 22:40:08 OK... seems like something that would be nice to f
160 if (i == 52)
161 continue;
162
272 connection.Raze(); 163 connection.Raze();
273 const base::FilePath& file_name = base::FilePath::FromUTF8Unsafe( 164 const base::FilePath& file_name = base::FilePath::FromUTF8Unsafe(
274 "version_" + base::IntToString(i) + ".sql"); 165 "version_" + base::IntToString(i) + ".sql");
275 ASSERT_NO_FATAL_FAILURE(LoadDatabase(file_name.value())) 166 ASSERT_NO_FATAL_FAILURE(LoadDatabase(file_name.value()))
276 << "Failed to load " << file_name.MaybeAsASCII(); 167 << "Failed to load " << file_name.MaybeAsASCII();
277 DoMigration(); 168 DoMigration();
278 EXPECT_EQ(expected_schema, RemoveQuotes(connection.GetSchema())); 169 EXPECT_EQ(expected_schema, RemoveQuotes(connection.GetSchema()))
170 << "For version " << i;
279 } 171 }
280 } 172 }
281 173
282 // Tests that the all migrations from an empty database succeed. 174 // Tests that the all migrations from an empty database succeed.
283 TEST_F(WebDatabaseMigrationTest, MigrateEmptyToCurrent) { 175 TEST_F(WebDatabaseMigrationTest, MigrateEmptyToCurrent) {
284 DoMigration(); 176 DoMigration();
285 177
286 // Verify post-conditions. These are expectations for current version of the 178 // Verify post-conditions. These are expectations for current version of the
287 // database. 179 // database.
288 { 180 {
(...skipping 17 matching lines...) Expand all
306 EXPECT_TRUE(connection.DoesTableExist("token_service")); 198 EXPECT_TRUE(connection.DoesTableExist("token_service"));
307 // The web_apps and web_apps_icons tables are obsolete as of version 58. 199 // The web_apps and web_apps_icons tables are obsolete as of version 58.
308 EXPECT_FALSE(connection.DoesTableExist("web_apps")); 200 EXPECT_FALSE(connection.DoesTableExist("web_apps"));
309 EXPECT_FALSE(connection.DoesTableExist("web_app_icons")); 201 EXPECT_FALSE(connection.DoesTableExist("web_app_icons"));
310 // The web_intents and web_intents_defaults tables are obsolete as of 202 // The web_intents and web_intents_defaults tables are obsolete as of
311 // version 58. 203 // version 58.
312 EXPECT_FALSE(connection.DoesTableExist("web_intents")); 204 EXPECT_FALSE(connection.DoesTableExist("web_intents"));
313 EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults")); 205 EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults"));
314 } 206 }
315 } 207 }
208 // Check that current version is forced to compatible version before migration,
209 // if the former is smaller.
210 TEST_F(WebDatabaseMigrationTest, MigrateVersion45CompatibleToCurrent) {
211 ASSERT_NO_FATAL_FAILURE(
212 LoadDatabase(FILE_PATH_LITERAL("version_45_compatible.sql")));
316 213
317 // Tests that absent Autofill tables do not create any problems when migrating 214 // Verify pre-conditions. These are expectations for version 45 of the
318 // from a DB written by the earliest publicly released version of Chrome.
319 TEST_F(WebDatabaseMigrationTest, MigrateVersion20ToCurrent) {
320 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_20.sql")));
321
322 // Verify pre-conditions.
323 {
324 sql::Connection connection;
325 ASSERT_TRUE(connection.Open(GetDatabasePath()));
326
327 EXPECT_FALSE(connection.DoesTableExist("autofill"));
328 EXPECT_FALSE(connection.DoesTableExist("autofill_profiles"));
329 EXPECT_FALSE(connection.DoesTableExist("credit_cards"));
330 }
331
332 DoMigration();
333
334 // Verify post-conditions. These are expectations for current version of the
335 // database. 215 // database.
336 { 216 {
337 sql::Connection connection; 217 sql::Connection connection;
338 ASSERT_TRUE(connection.Open(GetDatabasePath())); 218 ASSERT_TRUE(connection.Open(GetDatabasePath()));
219 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
339 220
340 // Check version. 221 sql::MetaTable meta_table;
341 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); 222 // Database is actually version 45 but the version field states 40.
342 223 ASSERT_TRUE(meta_table.Init(&connection, 40, 45));
343 // Mostly this test just verifies that no SQL errors occur during migration;
344 // but might as well verify that the tables were created as well.
345 EXPECT_TRUE(connection.DoesTableExist("autofill"));
346 EXPECT_TRUE(connection.DoesTableExist("autofill_profiles"));
347 EXPECT_TRUE(connection.DoesTableExist("credit_cards"));
348 }
349 }
350
351 // Tests that rows with empty values get removed from the autofill tables.
352 TEST_F(WebDatabaseMigrationTest, MigrateVersion21ToCurrent) {
353 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_21.sql")));
354
355 // Verify pre-conditions.
356 {
357 sql::Connection connection;
358 ASSERT_TRUE(connection.Open(GetDatabasePath()));
359
360 // Both empty and non-empty values are allowed in a version 21 database.
361 sql::Statement s_autofill(connection.GetUniqueStatement(
362 "SELECT name, value, value_lower, pair_id, count FROM autofill"));
363 sql::Statement s_dates(connection.GetUniqueStatement(
364 "SELECT pair_id, date_created FROM autofill_dates"));
365
366 // An entry with a non-empty value.
367 ASSERT_TRUE(s_autofill.Step());
368 EXPECT_EQ(ASCIIToUTF16("Name"), s_autofill.ColumnString16(0));
369 EXPECT_EQ(ASCIIToUTF16("John Doe"), s_autofill.ColumnString16(1));
370 EXPECT_EQ(ASCIIToUTF16("john doe"), s_autofill.ColumnString16(2));
371 EXPECT_EQ(10, s_autofill.ColumnInt(3));
372 EXPECT_EQ(1, s_autofill.ColumnInt(4));
373 ASSERT_TRUE(s_dates.Step());
374 EXPECT_EQ(10, s_dates.ColumnInt(0));
375 EXPECT_EQ(1384299100, s_dates.ColumnInt64(1));
376
377 // An entry with an empty value.
378 ASSERT_TRUE(s_autofill.Step());
379 EXPECT_EQ(ASCIIToUTF16("Name"), s_autofill.ColumnString16(0));
380 EXPECT_EQ(base::string16(), s_autofill.ColumnString16(1));
381 EXPECT_EQ(base::string16(), s_autofill.ColumnString16(2));
382 EXPECT_EQ(11, s_autofill.ColumnInt(3));
383 EXPECT_EQ(1, s_autofill.ColumnInt(4));
384 ASSERT_TRUE(s_dates.Step());
385 EXPECT_EQ(11, s_dates.ColumnInt(0));
386 EXPECT_EQ(1384299200, s_dates.ColumnInt64(1));
387
388 // Another entry with a non-empty value.
389 ASSERT_TRUE(s_autofill.Step());
390 EXPECT_EQ(ASCIIToUTF16("Email"), s_autofill.ColumnString16(0));
391 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s_autofill.ColumnString16(1));
392 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s_autofill.ColumnString16(2));
393 EXPECT_EQ(20, s_autofill.ColumnInt(3));
394 EXPECT_EQ(3, s_autofill.ColumnInt(4));
395 ASSERT_TRUE(s_dates.Step());
396 EXPECT_EQ(20, s_dates.ColumnInt(0));
397 EXPECT_EQ(1384299300, s_dates.ColumnInt64(1));
398 ASSERT_TRUE(s_dates.Step());
399 EXPECT_EQ(20, s_dates.ColumnInt(0));
400 EXPECT_EQ(1384299301, s_dates.ColumnInt64(1));
401
402 // Another entry with an empty value.
403 ASSERT_TRUE(s_autofill.Step());
404 EXPECT_EQ(ASCIIToUTF16("Email"), s_autofill.ColumnString16(0));
405 EXPECT_EQ(base::string16(), s_autofill.ColumnString16(1));
406 EXPECT_EQ(base::string16(), s_autofill.ColumnString16(2));
407 EXPECT_EQ(21, s_autofill.ColumnInt(3));
408 EXPECT_EQ(4, s_autofill.ColumnInt(4));
409 ASSERT_TRUE(s_dates.Step());
410 EXPECT_EQ(21, s_dates.ColumnInt(0));
411 EXPECT_EQ(1384299401, s_dates.ColumnInt64(1));
412 ASSERT_TRUE(s_dates.Step());
413 EXPECT_EQ(21, s_dates.ColumnInt(0));
414 EXPECT_EQ(1384299400, s_dates.ColumnInt64(1));
415 ASSERT_TRUE(s_dates.Step());
416 EXPECT_EQ(21, s_dates.ColumnInt(0));
417 EXPECT_EQ(1384299403, s_dates.ColumnInt64(1));
418 ASSERT_TRUE(s_dates.Step());
419 EXPECT_EQ(21, s_dates.ColumnInt(0));
420 EXPECT_EQ(1384299402, s_dates.ColumnInt64(1));
421
422 // No more entries expected.
423 ASSERT_FALSE(s_autofill.Step());
424 ASSERT_FALSE(s_dates.Step());
425 } 224 }
426 225
427 DoMigration(); 226 DoMigration();
428
429 // Verify post-conditions. These are expectations for current version of the
430 // database.
431 {
432 sql::Connection connection;
433 ASSERT_TRUE(connection.Open(GetDatabasePath()));
434
435 // Check version.
436 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
437
438 // Entries with empty values should have been dropped. The remaining
439 // entries should have been preserved.
440 sql::Statement s(
441 connection.GetUniqueStatement(
442 "SELECT name, value, value_lower, date_created, date_last_used,"
443 " count "
444 "FROM autofill "
445 "ORDER BY name, value ASC"));
446
447 // "jane@example.com"
448 ASSERT_TRUE(s.Step());
449 EXPECT_EQ(ASCIIToUTF16("Email"), s.ColumnString16(0));
450 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s.ColumnString16(1));
451 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s.ColumnString16(2));
452 EXPECT_EQ(1384299300, s.ColumnInt64(3));
453 EXPECT_EQ(1384299301, s.ColumnInt64(4));
454 EXPECT_EQ(3, s.ColumnInt(5));
455
456 // "John Doe"
457 ASSERT_TRUE(s.Step());
458 EXPECT_EQ(ASCIIToUTF16("Name"), s.ColumnString16(0));
459 EXPECT_EQ(ASCIIToUTF16("John Doe"), s.ColumnString16(1));
460 EXPECT_EQ(ASCIIToUTF16("john doe"), s.ColumnString16(2));
461 EXPECT_EQ(1384299100, s.ColumnInt64(3));
462 EXPECT_EQ(1384299100, s.ColumnInt64(4));
463 EXPECT_EQ(1, s.ColumnInt(5));
464
465 // No more entries expected.
466 ASSERT_FALSE(s.Step());
467 }
468 }
469
470 // Tests that the |credit_card| table gets added to the schema for a version 22
471 // database.
472 TEST_F(WebDatabaseMigrationTest, MigrateVersion22ToCurrent) {
473 // This schema is taken from a build prior to the addition of the
474 // |credit_card| table. Version 22 of the schema. Contrast this with the
475 // corrupt version below.
476 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_22.sql")));
477
478 // Verify pre-conditions.
479 {
480 sql::Connection connection;
481 ASSERT_TRUE(connection.Open(GetDatabasePath()));
482
483 // No |credit_card| table prior to version 23.
484 ASSERT_FALSE(connection.DoesColumnExist("credit_cards", "guid"));
485 ASSERT_FALSE(
486 connection.DoesColumnExist("credit_cards", "card_number_encrypted"));
487 }
488
489 DoMigration();
490
491 // Verify post-conditions. These are expectations for current version of the
492 // database.
493 {
494 sql::Connection connection;
495 ASSERT_TRUE(connection.Open(GetDatabasePath()));
496
497 // Check version.
498 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
499
500 // |credit_card| table now exists.
501 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "guid"));
502 EXPECT_TRUE(
503 connection.DoesColumnExist("credit_cards", "card_number_encrypted"));
504 }
505 }
506
507 // Tests that the |credit_card| table gets added to the schema for a corrupt
508 // version 22 database. The corruption is that the |credit_cards| table exists
509 // but the schema version number was not set correctly to 23 or later. This
510 // test exercises code introduced to fix bug http://crbug.com/50699 that
511 // resulted from the corruption.
512 TEST_F(WebDatabaseMigrationTest, MigrateVersion22CorruptedToCurrent) {
513 // This schema is taken from a build after the addition of the |credit_card|
514 // table. Due to a bug in the migration logic the version is set incorrectly
515 // to 22 (it should have been updated to 23 at least).
516 ASSERT_NO_FATAL_FAILURE(
517 LoadDatabase(FILE_PATH_LITERAL("version_22_corrupt.sql")));
518
519 // Verify pre-conditions. These are expectations for corrupt version 22 of
520 // the database.
521 {
522 sql::Connection connection;
523 ASSERT_TRUE(connection.Open(GetDatabasePath()));
524
525 // Columns existing and not existing before current version.
526 ASSERT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id"));
527 ASSERT_TRUE(
528 connection.DoesColumnExist("credit_cards", "card_number_encrypted"));
529 ASSERT_TRUE(connection.DoesColumnExist("keywords", "id"));
530 }
531
532 DoMigration();
533
534 // Verify post-conditions. These are expectations for current version of the
535 // database.
536 {
537 sql::Connection connection;
538 ASSERT_TRUE(connection.Open(GetDatabasePath()));
539
540 // Check version.
541 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
542
543
544 // Columns existing and not existing before version 25.
545 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "unique_id"));
546 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "guid"));
547 EXPECT_TRUE(
548 connection.DoesColumnExist("credit_cards", "card_number_encrypted"));
549 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
550 }
551 }
552
553 // Tests that the |keywords| |created_by_policy| column gets added to the schema
554 // for a version 25 database.
555 TEST_F(WebDatabaseMigrationTest, MigrateVersion25ToCurrent) {
556 // This schema is taken from a build prior to the addition of the |keywords|
557 // |created_by_policy| column.
558 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_25.sql")));
559
560 // Verify pre-conditions. These are expectations for version 25 of the
561 // database.
562 {
563 sql::Connection connection;
564 ASSERT_TRUE(connection.Open(GetDatabasePath()));
565 }
566
567 DoMigration();
568
569 // Verify post-conditions. These are expectations for current version of the
570 // database.
571 {
572 sql::Connection connection;
573 ASSERT_TRUE(connection.Open(GetDatabasePath()));
574
575 // Check version.
576 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
577
578 // |keywords| |created_by_policy| column should have been added.
579 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
580 EXPECT_TRUE(connection.DoesColumnExist("keywords", "created_by_policy"));
581 }
582 }
583
584 // Tests that the credit_cards.billing_address column is changed from a string
585 // to an int whilst preserving the associated billing address. This version of
586 // the test makes sure a stored label is converted to an ID.
587 TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringLabels) {
588 // This schema is taken from a build prior to the change of column type for
589 // credit_cards.billing_address from string to int.
590 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_26.sql")));
591
592 // Verify pre-conditions. These are expectations for version 26 of the
593 // database.
594 {
595 sql::Connection connection;
596 ASSERT_TRUE(connection.Open(GetDatabasePath()));
597
598 // Columns existing and not existing before current version.
599 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "billing_address"));
600
601 std::string stmt = "INSERT INTO autofill_profiles"
602 "(label, unique_id, first_name, middle_name, last_name, email,"
603 " company_name, address_line_1, address_line_2, city, state, zipcode,"
604 " country, phone, fax)"
605 "VALUES ('Home',1,'','','','','','','','','','','','','')";
606 sql::Statement s(connection.GetUniqueStatement(stmt.c_str()));
607 ASSERT_TRUE(s.Run());
608
609 // Insert a CC linked to an existing address.
610 std::string stmt2 = "INSERT INTO credit_cards"
611 "(label, unique_id, name_on_card, type, card_number,"
612 " expiration_month, expiration_year, verification_code, billing_address,"
613 " shipping_address, card_number_encrypted, verification_code_encrypted)"
614 "VALUES ('label',2,'Jack','Visa','1234',2,2012,'','Home','','','')";
615 sql::Statement s2(connection.GetUniqueStatement(stmt2.c_str()));
616 ASSERT_TRUE(s2.Run());
617
618 // |billing_address| is a string.
619 std::string stmt3 = "SELECT billing_address FROM credit_cards";
620 sql::Statement s3(connection.GetUniqueStatement(stmt3.c_str()));
621 ASSERT_TRUE(s3.Step());
622 EXPECT_EQ(s3.ColumnType(0), sql::COLUMN_TYPE_TEXT);
623 }
624
625 DoMigration();
626
627 // Verify post-conditions. These are expectations for current version of the
628 // database.
629 {
630 sql::Connection connection;
631 ASSERT_TRUE(connection.Open(GetDatabasePath()));
632
633 // Check version.
634 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
635 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "billing_address"));
636
637 // Verify the credit card data is converted.
638 sql::Statement s(connection.GetUniqueStatement(
639 "SELECT guid, name_on_card, expiration_month, expiration_year, "
640 "card_number_encrypted, date_modified "
641 "FROM credit_cards"));
642 ASSERT_TRUE(s.Step());
643 EXPECT_EQ("Jack", s.ColumnString(1));
644 EXPECT_EQ(2, s.ColumnInt(2));
645 EXPECT_EQ(2012, s.ColumnInt(3));
646 // Column 5 is encrypted number blob.
647 // Column 6 is date_modified.
648 }
649 }
650
651 // Tests that the credit_cards.billing_address column is changed from a string
652 // to an int whilst preserving the associated billing address. This version of
653 // the test makes sure a stored string ID is converted to an integer ID.
654 TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringIDs) {
655 // This schema is taken from a build prior to the change of column type for
656 // credit_cards.billing_address from string to int.
657 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_26.sql")));
658
659 // Verify pre-conditions. These are expectations for version 26 of the
660 // database.
661 {
662 sql::Connection connection;
663 ASSERT_TRUE(connection.Open(GetDatabasePath()));
664 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "billing_address"));
665
666 std::string stmt = "INSERT INTO autofill_profiles"
667 "(label, unique_id, first_name, middle_name, last_name, email,"
668 " company_name, address_line_1, address_line_2, city, state, zipcode,"
669 " country, phone, fax)"
670 "VALUES ('Home',1,'','','','','','','','','','','','','')";
671 sql::Statement s(connection.GetUniqueStatement(stmt.c_str()));
672 ASSERT_TRUE(s.Run());
673
674 // Insert a CC linked to an existing address.
675 std::string stmt2 = "INSERT INTO credit_cards"
676 "(label, unique_id, name_on_card, type, card_number,"
677 " expiration_month, expiration_year, verification_code, billing_address,"
678 " shipping_address, card_number_encrypted, verification_code_encrypted)"
679 "VALUES ('label',2,'Jack','Visa','1234',2,2012,'','1','','','')";
680 sql::Statement s2(connection.GetUniqueStatement(stmt2.c_str()));
681 ASSERT_TRUE(s2.Run());
682
683 // |billing_address| is a string.
684 std::string stmt3 = "SELECT billing_address FROM credit_cards";
685 sql::Statement s3(connection.GetUniqueStatement(stmt3.c_str()));
686 ASSERT_TRUE(s3.Step());
687 EXPECT_EQ(s3.ColumnType(0), sql::COLUMN_TYPE_TEXT);
688 }
689
690 DoMigration();
691 227
692 // Verify post-conditions. These are expectations for current version of the 228 // Verify post-conditions. These are expectations for current version of the
693 // database. 229 // database.
694 { 230 {
695 sql::Connection connection; 231 sql::Connection connection;
696 ASSERT_TRUE(connection.Open(GetDatabasePath())); 232 ASSERT_TRUE(connection.Open(GetDatabasePath()));
697
698 // Check version.
699 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
700
701 // |keywords| |created_by_policy| column should have been added.
702 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
703 EXPECT_TRUE(connection.DoesColumnExist("keywords", "created_by_policy"));
704 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "billing_address"));
705
706 // Verify the credit card data is converted.
707 sql::Statement s(connection.GetUniqueStatement(
708 "SELECT guid, name_on_card, expiration_month, expiration_year, "
709 "card_number_encrypted, date_modified "
710 "FROM credit_cards"));
711 ASSERT_TRUE(s.Step());
712 EXPECT_EQ("Jack", s.ColumnString(1));
713 EXPECT_EQ(2, s.ColumnInt(2));
714 EXPECT_EQ(2012, s.ColumnInt(3));
715 // Column 5 is encrypted credit card number blo b.
716 // Column 6 is date_modified.
717 }
718 }
719
720 // Makes sure instant_url is added correctly to keywords.
721 TEST_F(WebDatabaseMigrationTest, MigrateVersion27ToCurrent) {
722 // Initialize the database.
723 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_27.sql")));
724
725 // Verify pre-conditions. These are expectations for version 27 of the
726 // database.
727 {
728 sql::Connection connection;
729 ASSERT_TRUE(connection.Open(GetDatabasePath()));
730
731 ASSERT_FALSE(connection.DoesColumnExist("keywords", "instant_url"));
732 }
733
734 DoMigration();
735
736 // Verify post-conditions. These are expectations for current version of the
737 // database.
738 {
739 sql::Connection connection;
740 ASSERT_TRUE(connection.Open(GetDatabasePath()));
741
742 // Check version.
743 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
744
745 // Make sure supports_instant (added in Version 28) was ultimately dropped
746 // again and instant_url was added.
747 EXPECT_FALSE(connection.DoesColumnExist("keywords", "supports_instant"));
748 EXPECT_TRUE(connection.DoesColumnExist("keywords", "instant_url"));
749
750 // Check that instant_url is empty.
751 std::string stmt = "SELECT instant_url FROM keywords";
752 sql::Statement s(connection.GetUniqueStatement(stmt.c_str()));
753 ASSERT_TRUE(s.Step());
754 EXPECT_EQ(std::string(), s.ColumnString(0));
755
756 // Verify the data made it over.
757 stmt = "SELECT " + KeywordTable::GetKeywordColumns() + " FROM keywords";
758 sql::Statement s2(connection.GetUniqueStatement(stmt.c_str()));
759 ASSERT_TRUE(s2.Step());
760 EXPECT_EQ(2, s2.ColumnInt(0));
761 EXPECT_EQ("Google", s2.ColumnString(1));
762 EXPECT_EQ("google.com", s2.ColumnString(2));
763 EXPECT_EQ("http://www.google.com/favicon.ico", s2.ColumnString(3));
764 EXPECT_EQ("{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}"\
765 "{google:originalQueryForSuggestion}sourceid=chrome&ie={inputEncoding}"\
766 "&q={searchTerms}",
767 s2.ColumnString(4));
768 EXPECT_TRUE(s2.ColumnBool(5));
769 EXPECT_EQ(std::string(), s2.ColumnString(6));
770 EXPECT_EQ(0, s2.ColumnInt(7));
771 EXPECT_EQ(0, s2.ColumnInt(8));
772 EXPECT_EQ(std::string("UTF-8"), s2.ColumnString(9));
773 EXPECT_TRUE(s2.ColumnBool(10));
774 EXPECT_EQ(std::string("{google:baseSuggestURL}search?client=chrome&hl="
775 "{language}&q={searchTerms}"), s2.ColumnString(11));
776 EXPECT_EQ(1, s2.ColumnInt(12));
777 EXPECT_FALSE(s2.ColumnBool(13));
778 EXPECT_EQ(std::string(), s2.ColumnString(14));
779 EXPECT_EQ(0, s2.ColumnInt(15));
780 EXPECT_EQ(std::string(), s2.ColumnString(16));
781 }
782 }
783
784 // Makes sure date_modified is added correctly to autofill_profiles and
785 // credit_cards.
786 TEST_F(WebDatabaseMigrationTest, MigrateVersion29ToCurrent) {
787 // Initialize the database.
788 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_29.sql")));
789
790 // Verify pre-conditions. These are expectations for version 29 of the
791 // database.
792 {
793 sql::Connection connection;
794 ASSERT_TRUE(connection.Open(GetDatabasePath()));
795
796 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles",
797 "date_modified"));
798 EXPECT_FALSE(connection.DoesColumnExist("credit_cards",
799 "date_modified"));
800 }
801
802 Time pre_creation_time = Time::Now();
803 DoMigration();
804 Time post_creation_time = Time::Now();
805
806 // Verify post-conditions. These are expectations for current version of the
807 // database.
808 {
809 sql::Connection connection;
810 ASSERT_TRUE(connection.Open(GetDatabasePath()));
811
812 // Check version.
813 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
814
815 // Check that the columns were created.
816 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles",
817 "date_modified"));
818 EXPECT_TRUE(connection.DoesColumnExist("credit_cards",
819 "date_modified"));
820
821 sql::Statement s_profiles(connection.GetUniqueStatement(
822 "SELECT date_modified FROM autofill_profiles "));
823 ASSERT_TRUE(s_profiles.is_valid());
824 while (s_profiles.Step()) {
825 EXPECT_GE(s_profiles.ColumnInt64(0),
826 pre_creation_time.ToTimeT());
827 EXPECT_LE(s_profiles.ColumnInt64(0),
828 post_creation_time.ToTimeT());
829 }
830 EXPECT_TRUE(s_profiles.Succeeded());
831
832 sql::Statement s_credit_cards(connection.GetUniqueStatement(
833 "SELECT date_modified FROM credit_cards "));
834 ASSERT_TRUE(s_credit_cards.is_valid());
835 while (s_credit_cards.Step()) {
836 EXPECT_GE(s_credit_cards.ColumnInt64(0),
837 pre_creation_time.ToTimeT());
838 EXPECT_LE(s_credit_cards.ColumnInt64(0),
839 post_creation_time.ToTimeT());
840 }
841 EXPECT_TRUE(s_credit_cards.Succeeded());
842 }
843 }
844
845 // Makes sure guids are added to autofill_profiles and credit_cards tables.
846 TEST_F(WebDatabaseMigrationTest, MigrateVersion30ToCurrent) {
847 // Initialize the database.
848 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_30.sql")));
849
850 // Verify pre-conditions. These are expectations for version 29 of the
851 // database.
852 {
853 sql::Connection connection;
854 ASSERT_TRUE(connection.Open(GetDatabasePath()));
855
856 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "guid"));
857 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "guid"));
858 }
859
860 DoMigration();
861
862 // Verify post-conditions. These are expectations for current version of the
863 // database.
864 {
865 sql::Connection connection;
866 ASSERT_TRUE(connection.Open(GetDatabasePath()));
867
868 // Check version.
869 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
870
871 ASSERT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid"));
872 ASSERT_TRUE(connection.DoesColumnExist("credit_cards", "guid"));
873
874 // Check that guids are non-null, non-empty, conforms to guid format, and
875 // are different.
876 sql::Statement s(
877 connection.GetUniqueStatement("SELECT guid FROM autofill_profiles"));
878
879 ASSERT_TRUE(s.Step());
880 std::string guid1 = s.ColumnString(0);
881 EXPECT_TRUE(base::IsValidGUID(guid1));
882
883 ASSERT_TRUE(s.Step());
884 std::string guid2 = s.ColumnString(0);
885 EXPECT_TRUE(base::IsValidGUID(guid2));
886
887 EXPECT_NE(guid1, guid2);
888 }
889 }
890
891 // Removes unique IDs and make GUIDs the primary key. Also removes unused
892 // columns.
893 TEST_F(WebDatabaseMigrationTest, MigrateVersion31ToCurrent) {
894 // Initialize the database.
895 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_31.sql")));
896
897 // Verify pre-conditions. These are expectations for version 30 of the
898 // database.
899 AutofillProfile profile;
900 base::string16 profile_label;
901 int profile_unique_id = 0;
902 int64 profile_date_modified = 0;
903 CreditCard credit_card;
904 base::string16 cc_label;
905 int cc_unique_id = 0;
906 std::string cc_number_encrypted;
907 int64 cc_date_modified = 0;
908 {
909 sql::Connection connection;
910 ASSERT_TRUE(connection.Open(GetDatabasePath()));
911
912 // Verify existence of columns we'll be changing.
913 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid"));
914 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "unique_id"));
915 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "guid"));
916 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id"));
917 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "type"));
918 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "card_number"));
919 EXPECT_TRUE(connection.DoesColumnExist("credit_cards",
920 "verification_code"));
921 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "billing_address"));
922 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "shipping_address"));
923 EXPECT_TRUE(connection.DoesColumnExist("credit_cards",
924 "verification_code_encrypted"));
925
926 // Fetch data in the database prior to migration.
927 sql::Statement s1(
928 connection.GetUniqueStatement(
929 "SELECT label, unique_id, first_name, middle_name, last_name, "
930 "email, company_name, address_line_1, address_line_2, city, state, "
931 "zipcode, country, phone, fax, date_modified, guid "
932 "FROM autofill_profiles"));
933 ASSERT_TRUE(s1.Step());
934 EXPECT_NO_FATAL_FAILURE(AutofillProfile31FromStatement(
935 s1, &profile, &profile_label, &profile_unique_id,
936 &profile_date_modified));
937
938 sql::Statement s2(
939 connection.GetUniqueStatement(
940 "SELECT label, unique_id, name_on_card, type, card_number, "
941 "expiration_month, expiration_year, verification_code, "
942 "billing_address, shipping_address, card_number_encrypted, "
943 "verification_code_encrypted, date_modified, guid "
944 "FROM credit_cards"));
945 ASSERT_TRUE(s2.Step());
946 EXPECT_NO_FATAL_FAILURE(CreditCard31FromStatement(s2,
947 &credit_card,
948 &cc_label,
949 &cc_unique_id,
950 &cc_number_encrypted,
951 &cc_date_modified));
952
953 EXPECT_NE(profile_unique_id, cc_unique_id);
954 EXPECT_NE(profile.guid(), credit_card.guid());
955 }
956
957 DoMigration();
958
959 // Verify post-conditions. These are expectations for current version of the
960 // database.
961 {
962 sql::Connection connection;
963 ASSERT_TRUE(connection.Open(GetDatabasePath()));
964
965 // Check version.
966 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
967
968 // Verify existence of columns we'll be changing.
969 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid"));
970 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "unique_id"));
971 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "guid"));
972 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "unique_id"));
973 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "type"));
974 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "card_number"));
975 EXPECT_FALSE(connection.DoesColumnExist("credit_cards",
976 "verification_code"));
977 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "billing_address"));
978 EXPECT_FALSE(connection.DoesColumnExist("credit_cards",
979 "shipping_address"));
980 EXPECT_FALSE(connection.DoesColumnExist("credit_cards",
981 "verification_code_encrypted"));
982
983 // Verify data in the database after the migration.
984 sql::Statement s1(
985 connection.GetUniqueStatement(
986 "SELECT guid, company_name, street_address, city, state, zipcode,"
987 " country_code, date_modified "
988 "FROM autofill_profiles"));
989 ASSERT_TRUE(s1.Step());
990
991 AutofillProfile profile_a;
992 int64 profile_date_modified_a = 0;
993 EXPECT_NO_FATAL_FAILURE(AutofillProfile33FromStatement(
994 s1, &profile_a, &profile_date_modified_a));
995 EXPECT_EQ(profile.guid(), profile_a.guid());
996 EXPECT_EQ(profile.GetRawInfo(autofill::COMPANY_NAME),
997 profile_a.GetRawInfo(autofill::COMPANY_NAME));
998 EXPECT_EQ(profile.GetRawInfo(autofill::ADDRESS_HOME_LINE1),
999 profile_a.GetRawInfo(autofill::ADDRESS_HOME_LINE1));
1000 EXPECT_EQ(profile.GetRawInfo(autofill::ADDRESS_HOME_LINE2),
1001 profile_a.GetRawInfo(autofill::ADDRESS_HOME_LINE2));
1002 EXPECT_EQ(profile.GetRawInfo(autofill::ADDRESS_HOME_CITY),
1003 profile_a.GetRawInfo(autofill::ADDRESS_HOME_CITY));
1004 EXPECT_EQ(profile.GetRawInfo(autofill::ADDRESS_HOME_STATE),
1005 profile_a.GetRawInfo(autofill::ADDRESS_HOME_STATE));
1006 EXPECT_EQ(profile.GetRawInfo(autofill::ADDRESS_HOME_ZIP),
1007 profile_a.GetRawInfo(autofill::ADDRESS_HOME_ZIP));
1008 EXPECT_EQ(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY),
1009 profile_a.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY));
1010 EXPECT_EQ(profile_date_modified, profile_date_modified_a);
1011
1012 sql::Statement s2(
1013 connection.GetUniqueStatement(
1014 "SELECT guid, name_on_card, expiration_month, "
1015 "expiration_year, card_number_encrypted, date_modified "
1016 "FROM credit_cards"));
1017 ASSERT_TRUE(s2.Step());
1018
1019 CreditCard credit_card_a;
1020 base::string16 cc_label_a;
1021 std::string cc_number_encrypted_a;
1022 int64 cc_date_modified_a = 0;
1023 EXPECT_NO_FATAL_FAILURE(CreditCard32FromStatement(s2,
1024 &credit_card_a,
1025 &cc_number_encrypted_a,
1026 &cc_date_modified_a));
1027 EXPECT_EQ(credit_card, credit_card_a);
1028 EXPECT_EQ(cc_label, cc_label_a);
1029 EXPECT_EQ(cc_number_encrypted, cc_number_encrypted_a);
1030 EXPECT_EQ(cc_date_modified, cc_date_modified_a);
1031 }
1032 }
1033
1034 // Factor |autofill_profiles| address information separately from name, email,
1035 // and phone.
1036 TEST_F(WebDatabaseMigrationTest, MigrateVersion32ToCurrent) {
1037 // Initialize the database.
1038 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_32.sql")));
1039
1040 // Verify pre-conditions. These are expectations for version 32 of the
1041 // database.
1042 {
1043 sql::Connection connection;
1044 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1045
1046 // Verify existence of columns we'll be changing.
1047 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid"));
1048 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "label"));
1049 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "first_name"));
1050 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "middle_name"));
1051 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "last_name"));
1052 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "email"));
1053 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles",
1054 "company_name"));
1055 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles",
1056 "address_line_1"));
1057 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles",
1058 "address_line_2"));
1059 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "city"));
1060 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "state"));
1061 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "zipcode"));
1062 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "country"));
1063 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "phone"));
1064 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "fax"));
1065 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles",
1066 "date_modified"));
1067
1068 EXPECT_FALSE(connection.DoesTableExist("autofill_profile_names"));
1069 EXPECT_FALSE(connection.DoesTableExist("autofill_profile_emails"));
1070 EXPECT_FALSE(connection.DoesTableExist("autofill_profile_phones"));
1071
1072 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "label"));
1073 }
1074
1075 DoMigration();
1076
1077 // Verify post-conditions. These are expectations for current version of the
1078 // database.
1079 {
1080 sql::Connection connection;
1081 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1082
1083 // Check version.
1084 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1085
1086 // Verify changes to columns.
1087 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid"));
1088 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "label"));
1089 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "first_name"));
1090 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles",
1091 "middle_name"));
1092 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "last_name"));
1093 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "email"));
1094 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles",
1095 "company_name"));
1096 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles",
1097 "street_address"));
1098 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "city"));
1099 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "state"));
1100 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "zipcode"));
1101 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles",
1102 "country_code"));
1103 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "phone"));
1104 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "fax"));
1105 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles",
1106 "date_modified"));
1107
1108 // New "names" table.
1109 EXPECT_TRUE(connection.DoesColumnExist("autofill_profile_names", "guid"));
1110 EXPECT_TRUE(connection.DoesColumnExist("autofill_profile_names",
1111 "first_name"));
1112 EXPECT_TRUE(connection.DoesColumnExist("autofill_profile_names",
1113 "middle_name"));
1114 EXPECT_TRUE(connection.DoesColumnExist("autofill_profile_names",
1115 "last_name"));
1116
1117 // New "emails" table.
1118 EXPECT_TRUE(connection.DoesColumnExist("autofill_profile_emails", "guid"));
1119 EXPECT_TRUE(connection.DoesColumnExist("autofill_profile_emails", "email"));
1120
1121 // New "phones" table.
1122 EXPECT_TRUE(connection.DoesColumnExist("autofill_profile_phones", "guid"));
1123 EXPECT_TRUE(connection.DoesColumnExist("autofill_profile_phones",
1124 "number"));
1125
1126 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "label"));
1127
1128 // Verify data in the database after the migration.
1129 sql::Statement s1(
1130 connection.GetUniqueStatement(
1131 "SELECT guid, company_name, street_address, city, state, zipcode, "
1132 " country_code, date_modified "
1133 "FROM autofill_profiles"));
1134
1135 // John Doe.
1136 ASSERT_TRUE(s1.Step());
1137 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s1.ColumnString(0));
1138 EXPECT_EQ(ASCIIToUTF16("Doe Enterprises"), s1.ColumnString16(1));
1139 EXPECT_EQ(ASCIIToUTF16("1 Main St\n"
1140 "Apt 1"),
1141 s1.ColumnString16(2));
1142 EXPECT_EQ(ASCIIToUTF16("Los Altos"), s1.ColumnString16(3));
1143 EXPECT_EQ(ASCIIToUTF16("CA"), s1.ColumnString16(4));
1144 EXPECT_EQ(ASCIIToUTF16("94022"), s1.ColumnString16(5));
1145 EXPECT_EQ(ASCIIToUTF16("US"), s1.ColumnString16(6));
1146 EXPECT_EQ(1297882100L, s1.ColumnInt64(7));
1147
1148 // John P. Doe.
1149 // Gets merged during migration from 35 to 37 due to multi-valued fields.
1150
1151 // Dave Smith.
1152 ASSERT_TRUE(s1.Step());
1153 EXPECT_EQ("4C74A9D8-7EEE-423E-F9C2-E7FA70ED1396", s1.ColumnString(0));
1154 EXPECT_EQ(base::string16(), s1.ColumnString16(1));
1155 EXPECT_EQ(ASCIIToUTF16("2 Main Street"), s1.ColumnString16(2));
1156 EXPECT_EQ(ASCIIToUTF16("Los Altos"), s1.ColumnString16(3));
1157 EXPECT_EQ(ASCIIToUTF16("CA"), s1.ColumnString16(4));
1158 EXPECT_EQ(ASCIIToUTF16("94022"), s1.ColumnString16(5));
1159 EXPECT_EQ(ASCIIToUTF16("US"), s1.ColumnString16(6));
1160 EXPECT_EQ(1297882100L, s1.ColumnInt64(7));
1161
1162 // Dave Smith (Part 2).
1163 ASSERT_TRUE(s1.Step());
1164 EXPECT_EQ("722DF5C4-F74A-294A-46F0-31FFDED0D635", s1.ColumnString(0));
1165 EXPECT_EQ(base::string16(), s1.ColumnString16(1));
1166 EXPECT_EQ(ASCIIToUTF16("2 Main St"), s1.ColumnString16(2));
1167 EXPECT_EQ(ASCIIToUTF16("Los Altos"), s1.ColumnString16(3));
1168 EXPECT_EQ(ASCIIToUTF16("CA"), s1.ColumnString16(4));
1169 EXPECT_EQ(ASCIIToUTF16("94022"), s1.ColumnString16(5));
1170 EXPECT_EQ(ASCIIToUTF16("US"), s1.ColumnString16(6));
1171 EXPECT_EQ(1297882100L, s1.ColumnInt64(7));
1172
1173 // Alfred E Newman.
1174 // Gets culled during migration from 35 to 36 due to incomplete address.
1175
1176 // 3 Main St.
1177 ASSERT_TRUE(s1.Step());
1178 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s1.ColumnString(0));
1179 EXPECT_EQ(base::string16(), s1.ColumnString16(1));
1180 EXPECT_EQ(ASCIIToUTF16("3 Main St"), s1.ColumnString16(2));
1181 EXPECT_EQ(ASCIIToUTF16("Los Altos"), s1.ColumnString16(3));
1182 EXPECT_EQ(ASCIIToUTF16("CA"), s1.ColumnString16(4));
1183 EXPECT_EQ(ASCIIToUTF16("94022"), s1.ColumnString16(5));
1184 EXPECT_EQ(ASCIIToUTF16("US"), s1.ColumnString16(6));
1185 EXPECT_EQ(1297882100L, s1.ColumnInt64(7));
1186
1187 // That should be all.
1188 EXPECT_FALSE(s1.Step());
1189
1190 sql::Statement s2(
1191 connection.GetUniqueStatement(
1192 "SELECT guid, first_name, middle_name, last_name "
1193 "FROM autofill_profile_names"));
1194
1195 // John Doe.
1196 ASSERT_TRUE(s2.Step());
1197 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s2.ColumnString(0));
1198 EXPECT_EQ(ASCIIToUTF16("John"), s2.ColumnString16(1));
1199 EXPECT_EQ(base::string16(), s2.ColumnString16(2));
1200 EXPECT_EQ(ASCIIToUTF16("Doe"), s2.ColumnString16(3));
1201
1202 // John P. Doe. Note same guid as above due to merging of multi-valued
1203 // fields.
1204 ASSERT_TRUE(s2.Step());
1205 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s2.ColumnString(0));
1206 EXPECT_EQ(ASCIIToUTF16("John"), s2.ColumnString16(1));
1207 EXPECT_EQ(ASCIIToUTF16("P."), s2.ColumnString16(2));
1208 EXPECT_EQ(ASCIIToUTF16("Doe"), s2.ColumnString16(3));
1209
1210 // Dave Smith.
1211 ASSERT_TRUE(s2.Step());
1212 EXPECT_EQ("4C74A9D8-7EEE-423E-F9C2-E7FA70ED1396", s2.ColumnString(0));
1213 EXPECT_EQ(ASCIIToUTF16("Dave"), s2.ColumnString16(1));
1214 EXPECT_EQ(base::string16(), s2.ColumnString16(2));
1215 EXPECT_EQ(ASCIIToUTF16("Smith"), s2.ColumnString16(3));
1216
1217 // Dave Smith (Part 2).
1218 ASSERT_TRUE(s2.Step());
1219 EXPECT_EQ("722DF5C4-F74A-294A-46F0-31FFDED0D635", s2.ColumnString(0));
1220 EXPECT_EQ(ASCIIToUTF16("Dave"), s2.ColumnString16(1));
1221 EXPECT_EQ(base::string16(), s2.ColumnString16(2));
1222 EXPECT_EQ(ASCIIToUTF16("Smith"), s2.ColumnString16(3));
1223
1224 // Alfred E Newman.
1225 // Gets culled during migration from 35 to 36 due to incomplete address.
1226
1227 // 3 Main St.
1228 ASSERT_TRUE(s2.Step());
1229 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s2.ColumnString(0));
1230 EXPECT_EQ(base::string16(), s2.ColumnString16(1));
1231 EXPECT_EQ(base::string16(), s2.ColumnString16(2));
1232 EXPECT_EQ(base::string16(), s2.ColumnString16(3));
1233
1234 // Should be all.
1235 EXPECT_FALSE(s2.Step());
1236
1237 sql::Statement s3(
1238 connection.GetUniqueStatement(
1239 "SELECT guid, email "
1240 "FROM autofill_profile_emails"));
1241
1242 // John Doe.
1243 ASSERT_TRUE(s3.Step());
1244 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s3.ColumnString(0));
1245 EXPECT_EQ(ASCIIToUTF16("john@doe.com"), s3.ColumnString16(1));
1246
1247 // John P. Doe.
1248 // Gets culled during migration from 35 to 37 due to merging of John Doe and
1249 // John P. Doe addresses.
1250
1251 // 2 Main Street.
1252 ASSERT_TRUE(s3.Step());
1253 EXPECT_EQ("4C74A9D8-7EEE-423E-F9C2-E7FA70ED1396", s3.ColumnString(0));
1254 EXPECT_EQ(base::string16(), s3.ColumnString16(1));
1255
1256 // 2 Main St.
1257 ASSERT_TRUE(s3.Step());
1258 EXPECT_EQ("722DF5C4-F74A-294A-46F0-31FFDED0D635", s3.ColumnString(0));
1259 EXPECT_EQ(base::string16(), s3.ColumnString16(1));
1260
1261 // Alfred E Newman.
1262 // Gets culled during migration from 35 to 36 due to incomplete address.
1263
1264 // 3 Main St.
1265 ASSERT_TRUE(s3.Step());
1266 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s3.ColumnString(0));
1267 EXPECT_EQ(base::string16(), s3.ColumnString16(1));
1268
1269 // Should be all.
1270 EXPECT_FALSE(s3.Step());
1271
1272 sql::Statement s4(
1273 connection.GetUniqueStatement(
1274 "SELECT guid, number "
1275 "FROM autofill_profile_phones"));
1276
1277 // John Doe phone.
1278 ASSERT_TRUE(s4.Step());
1279 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s4.ColumnString(0));
1280 EXPECT_EQ(ASCIIToUTF16("4151112222"), s4.ColumnString16(1));
1281
1282 // John Doe fax.
1283 // Gets culled after fax type removed.
1284
1285 // John P. Doe phone.
1286 // Gets culled during migration from 35 to 37 due to merging of John Doe and
1287 // John P. Doe addresses.
1288
1289 // John P. Doe fax.
1290 // Gets culled during migration from 35 to 37 due to merging of John Doe and
1291 // John P. Doe addresses.
1292
1293 // 2 Main Street phone.
1294 ASSERT_TRUE(s4.Step());
1295 EXPECT_EQ("4C74A9D8-7EEE-423E-F9C2-E7FA70ED1396", s4.ColumnString(0));
1296 EXPECT_EQ(base::string16(), s4.ColumnString16(1));
1297
1298 // 2 Main Street fax.
1299 // Gets culled after fax type removed.
1300
1301 // 2 Main St phone.
1302 ASSERT_TRUE(s4.Step());
1303 EXPECT_EQ("722DF5C4-F74A-294A-46F0-31FFDED0D635", s4.ColumnString(0));
1304 EXPECT_EQ(0, s4.ColumnInt(1)); // 0 means phone.
1305 EXPECT_EQ(base::string16(), s4.ColumnString16(2));
1306
1307 // 2 Main St fax.
1308 // Gets culled after fax type removed.
1309
1310 // Note no phone or fax for Alfred E Newman.
1311
1312 // 3 Main St phone.
1313 ASSERT_TRUE(s4.Step());
1314 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s4.ColumnString(0));
1315 EXPECT_EQ(base::string16(), s4.ColumnString16(1));
1316
1317 // 2 Main St fax.
1318 // Gets culled after fax type removed.
1319
1320 // Should be all.
1321 EXPECT_FALSE(s4.Step());
1322 }
1323 }
1324
1325 // Adds a column for the autofill profile's country code.
1326 TEST_F(WebDatabaseMigrationTest, MigrateVersion33ToCurrent) {
1327 // Initialize the database.
1328 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_33.sql")));
1329
1330 // Verify pre-conditions. These are expectations for version 33 of the
1331 // database.
1332 {
1333 sql::Connection connection;
1334 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1335
1336 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles",
1337 "country_code"));
1338
1339 // Check that the country value is the one we expect.
1340 sql::Statement s(
1341 connection.GetUniqueStatement("SELECT country FROM autofill_profiles"));
1342
1343 ASSERT_TRUE(s.Step());
1344 std::string country = s.ColumnString(0);
1345 EXPECT_EQ("United States", country);
1346 }
1347
1348 DoMigration();
1349
1350 // Verify post-conditions. These are expectations for current version of the
1351 // database.
1352 {
1353 sql::Connection connection;
1354 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1355
1356 // Check version.
1357 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1358
1359 ASSERT_TRUE(connection.DoesColumnExist("autofill_profiles",
1360 "country_code"));
1361
1362 // Check that the country code is properly converted.
1363 sql::Statement s(connection.GetUniqueStatement(
1364 "SELECT country_code FROM autofill_profiles"));
1365
1366 ASSERT_TRUE(s.Step());
1367 std::string country_code = s.ColumnString(0);
1368 EXPECT_EQ("US", country_code);
1369 }
1370 }
1371
1372 // Cleans up bad country code "UK" in favor of good country code "GB".
1373 TEST_F(WebDatabaseMigrationTest, MigrateVersion34ToCurrent) {
1374 // Initialize the database.
1375 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_34.sql")));
1376
1377 // Verify pre-conditions. These are expectations for version 34 of the
1378 // database.
1379 {
1380 sql::Connection connection;
1381 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1382
1383 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles",
1384 "country_code"));
1385
1386 // Check that the country_code value is the one we expect.
1387 sql::Statement s(
1388 connection.GetUniqueStatement("SELECT country_code "
1389 "FROM autofill_profiles"));
1390
1391 ASSERT_TRUE(s.Step());
1392 std::string country_code = s.ColumnString(0);
1393 EXPECT_EQ("UK", country_code);
1394
1395 // Should have only one.
1396 ASSERT_FALSE(s.Step());
1397 }
1398
1399 DoMigration();
1400
1401 // Verify post-conditions. These are expectations for current version of the
1402 // database.
1403 {
1404 sql::Connection connection;
1405 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1406
1407 // Check version.
1408 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1409
1410 ASSERT_TRUE(connection.DoesColumnExist("autofill_profiles",
1411 "country_code"));
1412
1413 // Check that the country_code code is properly converted.
1414 sql::Statement s(connection.GetUniqueStatement(
1415 "SELECT country_code FROM autofill_profiles"));
1416
1417 ASSERT_TRUE(s.Step());
1418 std::string country_code = s.ColumnString(0);
1419 EXPECT_EQ("GB", country_code);
1420
1421 // Should have only one.
1422 ASSERT_FALSE(s.Step());
1423 }
1424 }
1425
1426 // Cleans up invalid profiles based on more agressive merging. Filters out
1427 // profiles that are subsets of other profiles, and profiles with invalid email,
1428 // state, and incomplete address.
1429 TEST_F(WebDatabaseMigrationTest, MigrateVersion35ToCurrent) {
1430 // Initialize the database.
1431 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_35.sql")));
1432
1433 // Verify pre-conditions. These are expectations for version 34 of the
1434 // database.
1435 {
1436 sql::Connection connection;
1437 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1438
1439 EXPECT_FALSE(connection.DoesTableExist("autofill_profiles_trash"));
1440 ASSERT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid"));
1441
1442 // Check that there are 6 profiles prior to merge.
1443 sql::Statement s(
1444 connection.GetUniqueStatement("SELECT guid FROM autofill_profiles"));
1445 int i = 0;
1446 while (s.Step())
1447 ++i;
1448 EXPECT_EQ(6, i);
1449 }
1450
1451 DoMigration();
1452
1453 // Verify post-conditions. These are expectations for current version of the
1454 // database.
1455 {
1456 sql::Connection connection;
1457 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1458
1459 // Check version.
1460 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1461
1462 ASSERT_TRUE(connection.DoesTableExist("autofill_profiles_trash"));
1463 ASSERT_TRUE(connection.DoesColumnExist("autofill_profiles_trash", "guid"));
1464 ASSERT_TRUE(connection.DoesColumnExist("autofill_profiles", "guid"));
1465
1466 // Verify data in the database after the migration.
1467 sql::Statement s1(
1468 connection.GetUniqueStatement(
1469 "SELECT guid, company_name, street_address, city, state, zipcode,"
1470 " country_code, date_modified "
1471 "FROM autofill_profiles"));
1472
1473 // John Doe.
1474 ASSERT_TRUE(s1.Step());
1475 EXPECT_EQ("00000000-0000-0000-0000-000000000001", s1.ColumnString(0));
1476 EXPECT_EQ(ASCIIToUTF16("Acme Inc."), s1.ColumnString16(1));
1477 EXPECT_EQ(ASCIIToUTF16("1 Main Street\n"
1478 "Apt 2"),
1479 s1.ColumnString16(2));
1480 EXPECT_EQ(ASCIIToUTF16("San Francisco"), s1.ColumnString16(3));
1481 EXPECT_EQ(ASCIIToUTF16("CA"), s1.ColumnString16(4));
1482 EXPECT_EQ(ASCIIToUTF16("94102"), s1.ColumnString16(5));
1483 EXPECT_EQ(ASCIIToUTF16("US"), s1.ColumnString16(6));
1484 EXPECT_EQ(1300131704, s1.ColumnInt64(7));
1485
1486 // That should be it.
1487 ASSERT_FALSE(s1.Step());
1488
1489 // Check that there 5 trashed profile after the merge.
1490 sql::Statement s2(
1491 connection.GetUniqueStatement("SELECT guid "
1492 "FROM autofill_profiles_trash"));
1493 ASSERT_TRUE(s2.Step());
1494 EXPECT_EQ("00000000-0000-0000-0000-000000000002", s2.ColumnString(0));
1495
1496 ASSERT_TRUE(s2.Step());
1497 EXPECT_EQ("00000000-0000-0000-0000-000000000003", s2.ColumnString(0));
1498
1499 ASSERT_TRUE(s2.Step());
1500 EXPECT_EQ("00000000-0000-0000-0000-000000000004", s2.ColumnString(0));
1501
1502 ASSERT_TRUE(s2.Step());
1503 EXPECT_EQ("00000000-0000-0000-0000-000000000005", s2.ColumnString(0));
1504
1505 ASSERT_TRUE(s2.Step());
1506 EXPECT_EQ("00000000-0000-0000-0000-000000000006", s2.ColumnString(0));
1507
1508 // That should be it.
1509 ASSERT_FALSE(s2.Step());
1510 }
1511 }
1512
1513 // Tests that the |keywords| |last_modified| column gets added to the schema for
1514 // a version 37 database.
1515 TEST_F(WebDatabaseMigrationTest, MigrateVersion37ToCurrent) {
1516 // This schema is taken from a build prior to the addition of the |keywords|
1517 // |last_modified| column.
1518 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_37.sql")));
1519
1520 // Verify pre-conditions. These are expectations for version 37 of the
1521 // database.
1522 {
1523 sql::Connection connection;
1524 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1525
1526 // Columns existing and not existing before current version.
1527 ASSERT_TRUE(connection.DoesColumnExist("keywords", "id"));
1528 ASSERT_FALSE(connection.DoesColumnExist("keywords", "last_modified"));
1529 }
1530
1531 DoMigration();
1532
1533 // Verify post-conditions. These are expectations for current version of the
1534 // database.
1535 {
1536 sql::Connection connection;
1537 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1538
1539 // Check version.
1540 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1541
1542 // |keywords| |last_modified| column should have been added.
1543 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
1544 EXPECT_TRUE(connection.DoesColumnExist("keywords", "last_modified"));
1545 }
1546 }
1547
1548 // Tests that the |keywords| |sync_guid| column gets added to the schema for
1549 // a version 38 database.
1550 TEST_F(WebDatabaseMigrationTest, MigrateVersion38ToCurrent) {
1551 // This schema is taken from a build prior to the addition of the |keywords|
1552 // |sync_guid| column.
1553 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_38.sql")));
1554
1555 // Verify pre-conditions. These are expectations for version 38 of the
1556 // database.
1557 {
1558 sql::Connection connection;
1559 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1560
1561 // Columns existing and not existing before current version.
1562 ASSERT_TRUE(connection.DoesColumnExist("keywords", "id"));
1563 ASSERT_FALSE(connection.DoesColumnExist("keywords", "sync_guid"));
1564 }
1565
1566 DoMigration();
1567
1568 // Verify post-conditions. These are expectations for current version of the
1569 // database.
1570 {
1571 sql::Connection connection;
1572 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1573
1574 // Check version.
1575 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1576
1577 // |keywords| |sync_guid| column should have been added.
1578 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
1579 EXPECT_TRUE(connection.DoesColumnExist("keywords", "sync_guid"));
1580 }
1581 }
1582
1583 // Tests that no backup data is added to a version 39 database.
1584 TEST_F(WebDatabaseMigrationTest, MigrateVersion39ToCurrent) {
1585 // This schema is taken from a build prior to the addition of the default
1586 // search provider backup field to the meta table.
1587 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_39.sql")));
1588
1589 // Verify pre-conditions. These are expectations for version 39 of the
1590 // database.
1591 {
1592 sql::Connection connection;
1593 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1594 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1595
1596 sql::MetaTable meta_table;
1597 ASSERT_TRUE(meta_table.Init(&connection, 39, 39));
1598
1599 int64 default_search_provider_id = 0;
1600 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey,
1601 &default_search_provider_id));
1602
1603 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table));
1604 }
1605
1606 DoMigration();
1607
1608 // Verify post-conditions. These are expectations for current version of the
1609 // database.
1610 {
1611 sql::Connection connection;
1612 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1613 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); 233 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1614 234
1615 // Check version. 235 // Check version.
1616 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); 236 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1617
1618 sql::MetaTable meta_table;
1619 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber,
1620 kCurrentTestedVersionNumber));
1621
1622 int64 default_search_provider_id = 0;
1623 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey,
1624 &default_search_provider_id));
1625 EXPECT_NE(0, default_search_provider_id);
1626
1627 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table));
1628 }
1629 }
1630
1631 // Tests that the backup data is removed from the database.
1632 TEST_F(WebDatabaseMigrationTest, MigrateVersion40ToCurrent) {
1633 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_40.sql")));
1634
1635 // Verify pre-conditions. These are expectations for version 40 of the
1636 // database.
1637 {
1638 sql::Connection connection;
1639 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1640 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1641
1642 sql::MetaTable meta_table;
1643 ASSERT_TRUE(meta_table.Init(&connection, 40, 40));
1644
1645 int64 default_search_provider_id = 0;
1646 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey,
1647 &default_search_provider_id));
1648
1649 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table));
1650 }
1651
1652 DoMigration();
1653
1654 // Verify post-conditions. These are expectations for current version of the
1655 // database.
1656 {
1657 sql::Connection connection;
1658 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1659 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1660
1661 // Check version.
1662 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1663
1664 sql::MetaTable meta_table;
1665 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber,
1666 kCurrentTestedVersionNumber));
1667
1668 int64 default_search_provider_id = 0;
1669 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey,
1670 &default_search_provider_id));
1671 EXPECT_NE(0, default_search_provider_id);
1672
1673 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table));
1674 }
1675 }
1676
1677 // Tests that the backup data is removed from the database.
1678 TEST_F(WebDatabaseMigrationTest, MigrateVersion41ToCurrent) {
1679 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_41.sql")));
1680
1681 // Verify pre-conditions. These are expectations for version 41 of the
1682 // database.
1683 {
1684 sql::Connection connection;
1685 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1686 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1687
1688 sql::MetaTable meta_table;
1689 ASSERT_TRUE(meta_table.Init(&connection, 41, 41));
1690
1691 int64 default_search_provider_id = 0;
1692 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey,
1693 &default_search_provider_id));
1694
1695 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table));
1696 }
1697
1698 DoMigration();
1699
1700 // Verify post-conditions. These are expectations for current version of the
1701 // database.
1702 {
1703 sql::Connection connection;
1704 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1705 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1706
1707 // Check version.
1708 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1709
1710 sql::MetaTable meta_table;
1711 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber,
1712 kCurrentTestedVersionNumber));
1713
1714 int64 default_search_provider_id = 0;
1715 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey,
1716 &default_search_provider_id));
1717 EXPECT_NE(0, default_search_provider_id);
1718
1719 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table));
1720 }
1721 }
1722
1723 // Tests that the backup data is removed from the database.
1724 TEST_F(WebDatabaseMigrationTest, MigrateVersion42ToCurrent) {
1725 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_42.sql")));
1726
1727 // Verify pre-conditions. These are expectations for version 42 of the
1728 // database.
1729 {
1730 sql::Connection connection;
1731 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1732 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1733
1734 sql::MetaTable meta_table;
1735 ASSERT_TRUE(meta_table.Init(&connection, 42, 42));
1736
1737 int64 default_search_provider_id = 0;
1738 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey,
1739 &default_search_provider_id));
1740
1741 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table));
1742
1743 EXPECT_FALSE(connection.DoesTableExist("keywords_backup"));
1744 }
1745
1746 DoMigration();
1747
1748 // Verify post-conditions. These are expectations for current version of the
1749 // database.
1750 {
1751 sql::Connection connection;
1752 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1753 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1754
1755 // Check version.
1756 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1757
1758 sql::MetaTable meta_table;
1759 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber,
1760 kCurrentTestedVersionNumber));
1761
1762 int64 default_search_provider_id = 0;
1763 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey,
1764 &default_search_provider_id));
1765 EXPECT_NE(0, default_search_provider_id);
1766
1767 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table));
1768 }
1769 }
1770
1771 // Tests that the backup data is removed from the database.
1772 TEST_F(WebDatabaseMigrationTest, MigrateVersion43ToCurrent) {
1773 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_43.sql")));
1774
1775 int64 previous_default_search_provider_id;
1776
1777 // Verify pre-conditions. These are expectations for version 43 of the
1778 // database.
1779 {
1780 sql::Connection connection;
1781 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1782 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1783
1784 sql::MetaTable meta_table;
1785 ASSERT_TRUE(meta_table.Init(&connection, 43, 43));
1786
1787 int64 default_search_provider_id = 0;
1788 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey,
1789 &default_search_provider_id));
1790 EXPECT_NE(default_search_provider_id, 0);
1791 previous_default_search_provider_id = default_search_provider_id;
1792
1793 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table));
1794 EXPECT_TRUE(connection.DoesTableExist("keywords_backup"));
1795 }
1796
1797 DoMigration();
1798
1799 // Verify post-conditions. These are expectations for current version of the
1800 // database.
1801 {
1802 sql::Connection connection;
1803 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1804 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1805
1806 // Check version.
1807 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1808
1809 sql::MetaTable meta_table;
1810 ASSERT_TRUE(meta_table.Init(
1811 &connection,
1812 kCurrentTestedVersionNumber,
1813 kCurrentTestedVersionNumber));
1814
1815 int64 default_search_provider_id = 0;
1816 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey,
1817 &default_search_provider_id));
1818 // Default search provider ID should not change.
1819 EXPECT_EQ(previous_default_search_provider_id, default_search_provider_id);
1820
1821 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table));
1822 }
1823 }
1824
1825 // Tests that the |autogenerate_keyword| and |logo_id| columns get removed from
1826 // the keyword table schema for a version 45 database.
1827 TEST_F(WebDatabaseMigrationTest, MigrateVersion44ToCurrent) {
1828 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_44.sql")));
1829
1830 // Verify pre-conditions. These are expectations for version 44 of the
1831 // database.
1832 {
1833 sql::Connection connection;
1834 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1835 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1836
1837 sql::MetaTable meta_table;
1838 ASSERT_TRUE(meta_table.Init(&connection, 44, 44));
1839
1840 ASSERT_TRUE(connection.DoesColumnExist("keywords", "autogenerate_keyword"));
1841 ASSERT_TRUE(connection.DoesColumnExist("keywords", "logo_id"));
1842 }
1843
1844 DoMigration();
1845
1846 // Verify post-conditions. These are expectations for current version of the
1847 // database.
1848 {
1849 sql::Connection connection;
1850 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1851 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1852
1853 // Check version.
1854 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1855
1856 sql::MetaTable meta_table;
1857 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber,
1858 kCurrentTestedVersionNumber));
1859
1860 // We should have removed this obsolete key.
1861 std::string default_search_provider_backup;
1862 EXPECT_FALSE(meta_table.GetValue("Default Search Provider Backup",
1863 &default_search_provider_backup));
1864
1865 // Two columns should have been removed.
1866 EXPECT_FALSE(connection.DoesColumnExist("keywords",
1867 "autogenerate_keyword"));
1868 EXPECT_FALSE(connection.DoesColumnExist("keywords", "logo_id"));
1869
1870 // Backup data should have been removed.
1871 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table));
1872 }
1873 }
1874
1875 // Previously, this tested that the web_intents and web_intents_defaults tables
1876 // were modified to include "scheme" columns. Since the web_intents and
1877 // web_intents_defaults tables are now obsolete, this test checks to ensure that
1878 // they are properly removed.
1879 TEST_F(WebDatabaseMigrationTest, MigrateVersion45ToCurrent) {
1880 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_45.sql")));
1881
1882 // Verify pre-conditions. These are expectations for version 45 of the
1883 // database.
1884 {
1885 sql::Connection connection;
1886 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1887 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1888
1889 sql::MetaTable meta_table;
1890 ASSERT_TRUE(meta_table.Init(&connection, 45, 45));
1891
1892 ASSERT_FALSE(connection.DoesColumnExist("scheme", "web_intents"));
1893 ASSERT_FALSE(connection.DoesColumnExist(
1894 "scheme", "web_intents_defaults"));
1895 }
1896
1897 DoMigration();
1898
1899 // Verify post-conditions. These are expectations for current version of the
1900 // database.
1901 {
1902 sql::Connection connection;
1903 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1904 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1905
1906 // Check version.
1907 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1908
1909 sql::MetaTable meta_table;
1910 ASSERT_TRUE(meta_table.Init(
1911 &connection,
1912 kCurrentTestedVersionNumber,
1913 kCurrentTestedVersionNumber));
1914
1915 // finally ensure the migration code cleaned up after itself
1916 EXPECT_FALSE(connection.DoesTableExist("web_intents"));
1917 EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults"));
1918 }
1919 }
1920
1921 // Previously, this tested that the web_intents and web_intents_defaults tables
1922 // were modified to include "scheme" columns. Since the web_intents and
1923 // web_intents_defaults tables are now obsolete, this test checks to ensure that
1924 // they are properly removed.
1925 TEST_F(WebDatabaseMigrationTest, MigrateVersion45InvalidToCurrent) {
1926 ASSERT_NO_FATAL_FAILURE(
1927 LoadDatabase(FILE_PATH_LITERAL("version_45_invalid.sql")));
1928
1929 // Verify pre-conditions. These are expectations for version 45 of the
1930 // database.
1931 {
1932 sql::Connection connection;
1933 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1934 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1935
1936 sql::MetaTable meta_table;
1937 ASSERT_TRUE(meta_table.Init(&connection, 45, 45));
1938
1939 ASSERT_FALSE(connection.DoesColumnExist("scheme", "web_intents"));
1940 ASSERT_FALSE(connection.DoesColumnExist(
1941 "scheme", "web_intents_defaults"));
1942 }
1943
1944 DoMigration();
1945
1946 // Verify post-conditions. These are expectations for current version of the
1947 // database.
1948 {
1949 sql::Connection connection;
1950 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1951 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1952
1953 // Check version.
1954 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1955
1956 sql::MetaTable meta_table;
1957 ASSERT_TRUE(meta_table.Init(
1958 &connection,
1959 kCurrentTestedVersionNumber,
1960 kCurrentTestedVersionNumber));
1961
1962 EXPECT_FALSE(connection.DoesTableExist("web_intents"));
1963 EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults"));
1964 }
1965 }
1966
1967 // Check that current version is forced to compatible version before migration,
1968 // if the former is smaller.
1969 TEST_F(WebDatabaseMigrationTest, MigrateVersion45CompatibleToCurrent) {
1970 ASSERT_NO_FATAL_FAILURE(
1971 LoadDatabase(FILE_PATH_LITERAL("version_45_compatible.sql")));
1972
1973 // Verify pre-conditions. These are expectations for version 45 of the
1974 // database.
1975 {
1976 sql::Connection connection;
1977 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1978 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1979
1980 sql::MetaTable meta_table;
1981 // Database is actually version 45 but the version field states 40.
1982 ASSERT_TRUE(meta_table.Init(&connection, 40, 45));
1983 }
1984
1985 DoMigration();
1986
1987 // Verify post-conditions. These are expectations for current version of the
1988 // database.
1989 {
1990 sql::Connection connection;
1991 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1992 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1993
1994 // Check version.
1995 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1996 EXPECT_LE(45, VersionFromConnection(&connection)); 237 EXPECT_LE(45, VersionFromConnection(&connection));
1997 } 238 }
1998 } 239 }
1999 240
2000 // Tests that the |alternate_urls| column is added to the keyword table schema 241 // Versions below 52 are deprecated. This verifies that old databases are razed.
2001 // for a version 47 database. 242 TEST_F(WebDatabaseMigrationTest, RazeDeprecatedVersionAndReinit) {
2002 TEST_F(WebDatabaseMigrationTest, MigrateVersion46ToCurrent) {
2003 ASSERT_NO_FATAL_FAILURE(
2004 LoadDatabase(FILE_PATH_LITERAL("version_46.sql")));
2005
2006 // Verify pre-conditions. These are expectations for version 46 of the
2007 // database.
2008 {
2009 sql::Connection connection;
2010 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2011 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
2012
2013 sql::MetaTable meta_table;
2014 ASSERT_TRUE(meta_table.Init(&connection, 46, 46));
2015
2016 ASSERT_FALSE(connection.DoesColumnExist("keywords", "alternate_urls"));
2017 ASSERT_FALSE(connection.DoesColumnExist("keywords_backup",
2018 "alternate_urls"));
2019 }
2020
2021 DoMigration();
2022
2023 // Verify post-conditions. These are expectations for current version of the
2024 // database.
2025 {
2026 sql::Connection connection;
2027 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2028 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
2029
2030 // Check version.
2031 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
2032
2033 // A new column should have been created.
2034 EXPECT_TRUE(connection.DoesColumnExist("keywords", "alternate_urls"));
2035 }
2036 }
2037
2038 // Tests that the backup data is removed from the database.
2039 TEST_F(WebDatabaseMigrationTest, MigrateVersion47ToCurrent) {
2040 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_47.sql")));
2041
2042 // Verify pre-conditions. These are expectations for version 47 of the
2043 // database.
2044 {
2045 sql::Connection connection;
2046 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2047 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
2048
2049 sql::MetaTable meta_table;
2050 ASSERT_TRUE(meta_table.Init(&connection, 47, 47));
2051
2052 int64 default_search_provider_id = 0;
2053 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey,
2054 &default_search_provider_id));
2055 EXPECT_NE(0, default_search_provider_id);
2056
2057 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table));
2058 EXPECT_TRUE(connection.DoesTableExist("keywords_backup"));
2059 }
2060
2061 DoMigration();
2062
2063 // Verify post-conditions. These are expectations for current version of the
2064 // database.
2065 {
2066 sql::Connection connection;
2067 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2068 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
2069
2070 // Check version.
2071 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
2072
2073 sql::MetaTable meta_table;
2074 ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber,
2075 kCurrentTestedVersionNumber));
2076
2077 int64 default_search_provider_id = 0;
2078 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey,
2079 &default_search_provider_id));
2080 EXPECT_NE(0, default_search_provider_id);
2081
2082 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table));
2083 }
2084 }
2085
2086 // Tests that the |search_terms_replacement_key| column is added to the keyword
2087 // table schema for a version 49 database.
2088 TEST_F(WebDatabaseMigrationTest, MigrateVersion48ToCurrent) {
2089 ASSERT_NO_FATAL_FAILURE(
2090 LoadDatabase(FILE_PATH_LITERAL("version_48.sql")));
2091
2092 // Verify pre-conditions. These are expectations for version 48 of the
2093 // database.
2094 {
2095 sql::Connection connection;
2096 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2097 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
2098
2099 sql::MetaTable meta_table;
2100 ASSERT_TRUE(meta_table.Init(&connection, 48, 48));
2101
2102 ASSERT_FALSE(connection.DoesColumnExist("keywords",
2103 "search_terms_replacement_key"));
2104 }
2105
2106 DoMigration();
2107
2108 // Verify post-conditions. These are expectations for current version of the
2109 // database.
2110 {
2111 sql::Connection connection;
2112 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2113 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
2114
2115 // Check version.
2116 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
2117
2118 // A new column should have been created.
2119 EXPECT_TRUE(connection.DoesColumnExist("keywords",
2120 "search_terms_replacement_key"));
2121 }
2122 }
2123
2124 // Tests that the |origin| column is added to the autofill_profiles and
2125 // credit_cards table schemas for a version 50 database.
2126 TEST_F(WebDatabaseMigrationTest, MigrateVersion49ToCurrent) {
2127 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_49.sql")));
2128
2129 // Verify pre-conditions. These are expectations for version 49 of the
2130 // database.
2131 {
2132 sql::Connection connection;
2133 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2134
2135 ASSERT_FALSE(connection.DoesColumnExist("autofill_profiles", "origin"));
2136 ASSERT_FALSE(connection.DoesColumnExist("credit_cards", "origin"));
2137 }
2138
2139 DoMigration();
2140
2141 // Verify post-conditions. These are expectations for current version of the
2142 // database.
2143 {
2144 sql::Connection connection;
2145 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2146 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
2147
2148 // Check version.
2149 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
2150
2151 // A new column should have been created in both tables.
2152 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "origin"));
2153 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "origin"));
2154 }
2155 }
2156
2157 // Tests that the columns |image_url|, |search_url_post_params|,
2158 // |suggest_url_post_params|, |instant_url_post_params|, and
2159 // |image_url_post_params| are added to the keyword table schema for a version
2160 // 50 database.
2161 TEST_F(WebDatabaseMigrationTest, MigrateVersion50ToCurrent) {
2162 ASSERT_NO_FATAL_FAILURE( 243 ASSERT_NO_FATAL_FAILURE(
2163 LoadDatabase(FILE_PATH_LITERAL("version_50.sql"))); 244 LoadDatabase(FILE_PATH_LITERAL("version_50.sql")));
2164 245
2165 // Verify pre-conditions. These are expectations for version 50 of the 246 // Verify pre-conditions. These are expectations for version 50 of the
2166 // database. 247 // database.
2167 { 248 {
2168 sql::Connection connection; 249 sql::Connection connection;
2169 ASSERT_TRUE(connection.Open(GetDatabasePath())); 250 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2170 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); 251 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
2171 252
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
2878 959
2879 // Check version. 960 // Check version.
2880 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); 961 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
2881 962
2882 EXPECT_TRUE(connection.DoesColumnExist("unmasked_credit_cards", 963 EXPECT_TRUE(connection.DoesColumnExist("unmasked_credit_cards",
2883 "use_count")); 964 "use_count"));
2884 EXPECT_TRUE(connection.DoesColumnExist("unmasked_credit_cards", 965 EXPECT_TRUE(connection.DoesColumnExist("unmasked_credit_cards",
2885 "use_date")); 966 "use_date"));
2886 } 967 }
2887 } 968 }
OLDNEW
« components/webdata/common/web_database.cc ('K') | « components/webdata/common/web_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698