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
3 // found in the LICENSE file.
7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/path_service.h"
12 #include "base/stl_util.h"
13 #include "base/strings/string16.h"
14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "base/time/time.h"
18 #include "base/values.h"
19 #include "components/autofill/core/browser/autofill_country.h"
20 #include "components/autofill/core/browser/autofill_profile.h"
21 #include "components/autofill/core/browser/autofill_type.h"
22 #include "components/autofill/core/browser/credit_card.h"
23 #include "components/autofill/core/browser/webdata/autofill_change.h"
24 #include "components/autofill/core/browser/webdata/autofill_entry.h"
25 #include "components/autofill/core/browser/webdata/autofill_table.h"
26 #include "components/password_manager/core/browser/webdata/logins_table.h"
27 #include "components/search_engines/keyword_table.h"
28 #include "components/signin/core/browser/webdata/token_service_table.h"
29 #include "components/webdata/common/web_database.h"
30 #include "sql/statement.h"
31 #include "testing/gtest/include/gtest/gtest.h"
33 using autofill::AutofillProfile
;
34 using autofill::AutofillTable
;
35 using autofill::CreditCard
;
36 using base::ASCIIToUTF16
;
41 void AutofillProfile31FromStatement(const sql::Statement
& s
,
42 AutofillProfile
* profile
,
43 base::string16
* label
,
45 int64
* date_modified
) {
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));
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()));
71 void AutofillProfile33FromStatement(const sql::Statement
& s
,
72 AutofillProfile
* profile
,
73 int64
* date_modified
) {
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
,
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));
85 autofill::AutofillType(autofill::ADDRESS_HOME_COUNTRY
),
86 s
.ColumnString16(6), "en-US");
87 *date_modified
= s
.ColumnInt64(7);
90 void CreditCard31FromStatement(const sql::Statement
& s
,
91 CreditCard
* credit_card
,
92 base::string16
* label
,
94 std::string
* encrypted_number
,
95 int64
* date_modified
) {
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
);
113 *date_modified
= s
.ColumnInt64(12);
114 credit_card
->set_guid(s
.ColumnString(13));
115 EXPECT_TRUE(base::IsValidGUID(credit_card
->guid()));
118 void CreditCard32FromStatement(const sql::Statement
& s
,
119 CreditCard
* credit_card
,
120 std::string
* encrypted_number
,
121 int64
* date_modified
) {
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
);
136 *date_modified
= s
.ColumnInt64(5);
139 void CheckHasBackupData(sql::MetaTable
* meta_table
) {
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
));
147 void CheckNoBackupData(const sql::Connection
& connection
,
148 sql::MetaTable
* meta_table
) {
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"));
157 std::string
RemoveQuotes(const std::string
& has_quotes
) {
158 std::string no_quotes
;
159 // SQLite quotes: http://www.sqlite.org/lang_keywords.html
160 base::RemoveChars(has_quotes
, "\"[]`", &no_quotes
);
164 } // anonymous namespace
166 // The WebDatabaseMigrationTest encapsulates testing of database migrations.
167 // Specifically, these tests are intended to exercise any schema changes in
168 // the WebDatabase and data migrations that occur in
169 // |WebDatabase::MigrateOldVersionsAsNeeded()|.
170 class WebDatabaseMigrationTest
: public testing::Test
{
172 WebDatabaseMigrationTest() {}
173 ~WebDatabaseMigrationTest() override
{}
175 void SetUp() override
{ ASSERT_TRUE(temp_dir_
.CreateUniqueTempDir()); }
177 // Load the database via the WebDatabase class and migrate the database to
178 // the current version.
180 // TODO(joi): This whole unit test file needs to stay in //chrome
181 // for now, as it needs to know about all the different table
182 // types. Once all webdata datatypes have been componentized, this
183 // could move to components_unittests.
184 AutofillTable
autofill_table("en-US");
185 KeywordTable keyword_table
;
186 LoginsTable logins_table
;
187 TokenServiceTable token_service_table
;
190 db
.AddTable(&autofill_table
);
191 db
.AddTable(&keyword_table
);
192 db
.AddTable(&logins_table
);
193 db
.AddTable(&token_service_table
);
195 // This causes the migration to occur.
196 ASSERT_EQ(sql::INIT_OK
, db
.Init(GetDatabasePath()));
200 // Current tested version number. When adding a migration in
201 // |WebDatabase::MigrateOldVersionsAsNeeded()| and changing the version number
202 // |kCurrentVersionNumber| this value should change to reflect the new version
203 // number and a new migration test added below.
204 static const int kCurrentTestedVersionNumber
;
206 base::FilePath
GetDatabasePath() {
207 const base::FilePath::CharType kWebDatabaseFilename
[] =
208 FILE_PATH_LITERAL("TestWebDatabase.sqlite3");
209 return temp_dir_
.path().Append(base::FilePath(kWebDatabaseFilename
));
212 // The textual contents of |file| are read from
213 // "components/test/data/web_database" and returned in the string |contents|.
214 // Returns true if the file exists and is read successfully, false otherwise.
215 bool GetWebDatabaseData(const base::FilePath
& file
, std::string
* contents
) {
216 base::FilePath source_path
;
217 PathService::Get(base::DIR_SOURCE_ROOT
, &source_path
);
218 source_path
= source_path
.AppendASCII("components");
219 source_path
= source_path
.AppendASCII("test");
220 source_path
= source_path
.AppendASCII("data");
221 source_path
= source_path
.AppendASCII("web_database");
222 source_path
= source_path
.Append(file
);
223 return base::PathExists(source_path
) &&
224 base::ReadFileToString(source_path
, contents
);
227 static int VersionFromConnection(sql::Connection
* connection
) {
229 sql::Statement
s(connection
->GetUniqueStatement(
230 "SELECT value FROM meta WHERE key='version'"));
233 return s
.ColumnInt(0);
236 // The sql files located in "chrome/test/data/web_database" were generated by
237 // launching the Chromium application prior to schema change, then using the
238 // sqlite3 command-line application to dump the contents of the "Web Data"
241 // > .output version_nn.sql
243 void LoadDatabase(const base::FilePath::StringType
& file
);
246 base::ScopedTempDir temp_dir_
;
248 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest
);
251 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber
= 60;
253 void WebDatabaseMigrationTest::LoadDatabase(
254 const base::FilePath::StringType
& file
) {
255 std::string contents
;
256 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file
), &contents
));
258 sql::Connection connection
;
259 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
260 ASSERT_TRUE(connection
.Execute(contents
.data()));
263 // Tests that migrating from the golden files version_XX.sql results in the same
264 // schema as migrating from an empty database.
265 TEST_F(WebDatabaseMigrationTest
, VersionXxSqlFilesAreGolden
) {
267 sql::Connection connection
;
268 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
269 const std::string
& expected_schema
= RemoveQuotes(connection
.GetSchema());
270 static const int kFirstVersion
= 53;
271 for (int i
= kFirstVersion
; i
< kCurrentTestedVersionNumber
; ++i
) {
273 const base::FilePath
& file_name
= base::FilePath::FromUTF8Unsafe(
274 "version_" + base::IntToString(i
) + ".sql");
275 ASSERT_NO_FATAL_FAILURE(LoadDatabase(file_name
.value()))
276 << "Failed to load " << file_name
.MaybeAsASCII();
278 EXPECT_EQ(expected_schema
, RemoveQuotes(connection
.GetSchema()));
282 // Tests that the all migrations from an empty database succeed.
283 TEST_F(WebDatabaseMigrationTest
, MigrateEmptyToCurrent
) {
286 // Verify post-conditions. These are expectations for current version of the
289 sql::Connection connection
;
290 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
293 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
295 // Check that expected tables are present.
296 EXPECT_TRUE(connection
.DoesTableExist("autofill"));
297 // The autofill_dates table is obsolete. (It's been merged into the autofill
299 EXPECT_FALSE(connection
.DoesTableExist("autofill_dates"));
300 EXPECT_TRUE(connection
.DoesTableExist("autofill_profiles"));
301 EXPECT_TRUE(connection
.DoesTableExist("credit_cards"));
302 EXPECT_TRUE(connection
.DoesTableExist("keywords"));
303 // The logins table is obsolete. (We used to store saved passwords here.)
304 EXPECT_FALSE(connection
.DoesTableExist("logins"));
305 EXPECT_TRUE(connection
.DoesTableExist("meta"));
306 EXPECT_TRUE(connection
.DoesTableExist("token_service"));
307 // The web_apps and web_apps_icons tables are obsolete as of version 58.
308 EXPECT_FALSE(connection
.DoesTableExist("web_apps"));
309 EXPECT_FALSE(connection
.DoesTableExist("web_app_icons"));
310 // The web_intents and web_intents_defaults tables are obsolete as of
312 EXPECT_FALSE(connection
.DoesTableExist("web_intents"));
313 EXPECT_FALSE(connection
.DoesTableExist("web_intents_defaults"));
317 // Tests that absent Autofill tables do not create any problems when migrating
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")));
322 // Verify pre-conditions.
324 sql::Connection connection
;
325 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
327 EXPECT_FALSE(connection
.DoesTableExist("autofill"));
328 EXPECT_FALSE(connection
.DoesTableExist("autofill_profiles"));
329 EXPECT_FALSE(connection
.DoesTableExist("credit_cards"));
334 // Verify post-conditions. These are expectations for current version of the
337 sql::Connection connection
;
338 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
341 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
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"));
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")));
355 // Verify pre-conditions.
357 sql::Connection connection
;
358 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
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"));
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));
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));
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));
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));
422 // No more entries expected.
423 ASSERT_FALSE(s_autofill
.Step());
424 ASSERT_FALSE(s_dates
.Step());
429 // Verify post-conditions. These are expectations for current version of the
432 sql::Connection connection
;
433 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
436 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
438 // Entries with empty values should have been dropped. The remaining
439 // entries should have been preserved.
441 connection
.GetUniqueStatement(
442 "SELECT name, value, value_lower, date_created, date_last_used,"
445 "ORDER BY name, value ASC"));
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));
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));
465 // No more entries expected.
466 ASSERT_FALSE(s
.Step());
470 // Tests that the |credit_card| table gets added to the schema for a version 22
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")));
478 // Verify pre-conditions.
480 sql::Connection connection
;
481 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
483 // No |credit_card| table prior to version 23.
484 ASSERT_FALSE(connection
.DoesColumnExist("credit_cards", "guid"));
486 connection
.DoesColumnExist("credit_cards", "card_number_encrypted"));
491 // Verify post-conditions. These are expectations for current version of the
494 sql::Connection connection
;
495 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
498 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
500 // |credit_card| table now exists.
501 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "guid"));
503 connection
.DoesColumnExist("credit_cards", "card_number_encrypted"));
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")));
519 // Verify pre-conditions. These are expectations for corrupt version 22 of
522 sql::Connection connection
;
523 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
525 // Columns existing and not existing before current version.
526 ASSERT_TRUE(connection
.DoesColumnExist("credit_cards", "unique_id"));
528 connection
.DoesColumnExist("credit_cards", "card_number_encrypted"));
529 ASSERT_TRUE(connection
.DoesColumnExist("keywords", "id"));
534 // Verify post-conditions. These are expectations for current version of the
537 sql::Connection connection
;
538 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
541 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
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"));
548 connection
.DoesColumnExist("credit_cards", "card_number_encrypted"));
549 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "id"));
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")));
560 // Verify pre-conditions. These are expectations for version 25 of the
563 sql::Connection connection
;
564 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
569 // Verify post-conditions. These are expectations for current version of the
572 sql::Connection connection
;
573 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
576 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
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"));
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")));
592 // Verify pre-conditions. These are expectations for version 26 of the
595 sql::Connection connection
;
596 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
598 // Columns existing and not existing before current version.
599 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "billing_address"));
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());
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());
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
);
627 // Verify post-conditions. These are expectations for current version of the
630 sql::Connection connection
;
631 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
634 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
635 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards", "billing_address"));
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.
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")));
659 // Verify pre-conditions. These are expectations for version 26 of the
662 sql::Connection connection
;
663 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
664 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "billing_address"));
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());
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());
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
);
692 // Verify post-conditions. These are expectations for current version of the
695 sql::Connection connection
;
696 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
699 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
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"));
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.
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")));
725 // Verify pre-conditions. These are expectations for version 27 of the
728 sql::Connection connection
;
729 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
731 ASSERT_FALSE(connection
.DoesColumnExist("keywords", "instant_url"));
736 // Verify post-conditions. These are expectations for current version of the
739 sql::Connection connection
;
740 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
743 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
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"));
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));
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}"\
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));
784 // Makes sure date_modified is added correctly to autofill_profiles and
786 TEST_F(WebDatabaseMigrationTest
, MigrateVersion29ToCurrent
) {
787 // Initialize the database.
788 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_29.sql")));
790 // Verify pre-conditions. These are expectations for version 29 of the
793 sql::Connection connection
;
794 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
796 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles",
798 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards",
802 Time pre_creation_time
= Time::Now();
804 Time post_creation_time
= Time::Now();
806 // Verify post-conditions. These are expectations for current version of the
809 sql::Connection connection
;
810 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
813 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
815 // Check that the columns were created.
816 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
818 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards",
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());
830 EXPECT_TRUE(s_profiles
.Succeeded());
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());
841 EXPECT_TRUE(s_credit_cards
.Succeeded());
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")));
850 // Verify pre-conditions. These are expectations for version 29 of the
853 sql::Connection connection
;
854 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
856 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "guid"));
857 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards", "guid"));
862 // Verify post-conditions. These are expectations for current version of the
865 sql::Connection connection
;
866 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
869 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
871 ASSERT_TRUE(connection
.DoesColumnExist("autofill_profiles", "guid"));
872 ASSERT_TRUE(connection
.DoesColumnExist("credit_cards", "guid"));
874 // Check that guids are non-null, non-empty, conforms to guid format, and
877 connection
.GetUniqueStatement("SELECT guid FROM autofill_profiles"));
879 ASSERT_TRUE(s
.Step());
880 std::string guid1
= s
.ColumnString(0);
881 EXPECT_TRUE(base::IsValidGUID(guid1
));
883 ASSERT_TRUE(s
.Step());
884 std::string guid2
= s
.ColumnString(0);
885 EXPECT_TRUE(base::IsValidGUID(guid2
));
887 EXPECT_NE(guid1
, guid2
);
891 // Removes unique IDs and make GUIDs the primary key. Also removes unused
893 TEST_F(WebDatabaseMigrationTest
, MigrateVersion31ToCurrent
) {
894 // Initialize the database.
895 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_31.sql")));
897 // Verify pre-conditions. These are expectations for version 30 of the
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;
909 sql::Connection connection
;
910 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
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"));
926 // Fetch data in the database prior to migration.
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
));
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
,
950 &cc_number_encrypted
,
953 EXPECT_NE(profile_unique_id
, cc_unique_id
);
954 EXPECT_NE(profile
.guid(), credit_card
.guid());
959 // Verify post-conditions. These are expectations for current version of the
962 sql::Connection connection
;
963 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
966 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
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"));
983 // Verify data in the database after the migration.
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());
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
);
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());
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
,
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
);
1034 // Factor |autofill_profiles| address information separately from name, email,
1036 TEST_F(WebDatabaseMigrationTest
, MigrateVersion32ToCurrent
) {
1037 // Initialize the database.
1038 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_32.sql")));
1040 // Verify pre-conditions. These are expectations for version 32 of the
1043 sql::Connection connection
;
1044 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
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",
1055 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1057 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
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",
1068 EXPECT_FALSE(connection
.DoesTableExist("autofill_profile_names"));
1069 EXPECT_FALSE(connection
.DoesTableExist("autofill_profile_emails"));
1070 EXPECT_FALSE(connection
.DoesTableExist("autofill_profile_phones"));
1072 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "label"));
1077 // Verify post-conditions. These are expectations for current version of the
1080 sql::Connection connection
;
1081 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1084 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
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",
1092 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "last_name"));
1093 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "email"));
1094 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1096 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
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",
1103 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "phone"));
1104 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "fax"));
1105 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1108 // New "names" table.
1109 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_names", "guid"));
1110 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_names",
1112 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_names",
1114 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_names",
1117 // New "emails" table.
1118 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_emails", "guid"));
1119 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_emails", "email"));
1121 // New "phones" table.
1122 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_phones", "guid"));
1123 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_phones",
1126 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards", "label"));
1128 // Verify data in the database after the migration.
1130 connection
.GetUniqueStatement(
1131 "SELECT guid, company_name, street_address, city, state, zipcode, "
1132 " country_code, date_modified "
1133 "FROM autofill_profiles"));
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"
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));
1149 // Gets merged during migration from 35 to 37 due to multi-valued fields.
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));
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));
1174 // Gets culled during migration from 35 to 36 due to incomplete address.
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));
1187 // That should be all.
1188 EXPECT_FALSE(s1
.Step());
1191 connection
.GetUniqueStatement(
1192 "SELECT guid, first_name, middle_name, last_name "
1193 "FROM autofill_profile_names"));
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));
1202 // John P. Doe. Note same guid as above due to merging of multi-valued
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));
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));
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));
1225 // Gets culled during migration from 35 to 36 due to incomplete address.
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));
1235 EXPECT_FALSE(s2
.Step());
1238 connection
.GetUniqueStatement(
1239 "SELECT guid, email "
1240 "FROM autofill_profile_emails"));
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));
1248 // Gets culled during migration from 35 to 37 due to merging of John Doe and
1249 // John P. Doe addresses.
1252 ASSERT_TRUE(s3
.Step());
1253 EXPECT_EQ("4C74A9D8-7EEE-423E-F9C2-E7FA70ED1396", s3
.ColumnString(0));
1254 EXPECT_EQ(base::string16(), s3
.ColumnString16(1));
1257 ASSERT_TRUE(s3
.Step());
1258 EXPECT_EQ("722DF5C4-F74A-294A-46F0-31FFDED0D635", s3
.ColumnString(0));
1259 EXPECT_EQ(base::string16(), s3
.ColumnString16(1));
1262 // Gets culled during migration from 35 to 36 due to incomplete address.
1265 ASSERT_TRUE(s3
.Step());
1266 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s3
.ColumnString(0));
1267 EXPECT_EQ(base::string16(), s3
.ColumnString16(1));
1270 EXPECT_FALSE(s3
.Step());
1273 connection
.GetUniqueStatement(
1274 "SELECT guid, number "
1275 "FROM autofill_profile_phones"));
1278 ASSERT_TRUE(s4
.Step());
1279 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s4
.ColumnString(0));
1280 EXPECT_EQ(ASCIIToUTF16("4151112222"), s4
.ColumnString16(1));
1283 // Gets culled after fax type removed.
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.
1290 // Gets culled during migration from 35 to 37 due to merging of John Doe and
1291 // John P. Doe addresses.
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));
1298 // 2 Main Street fax.
1299 // Gets culled after fax type removed.
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));
1308 // Gets culled after fax type removed.
1310 // Note no phone or fax for Alfred E Newman.
1313 ASSERT_TRUE(s4
.Step());
1314 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s4
.ColumnString(0));
1315 EXPECT_EQ(base::string16(), s4
.ColumnString16(1));
1318 // Gets culled after fax type removed.
1321 EXPECT_FALSE(s4
.Step());
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")));
1330 // Verify pre-conditions. These are expectations for version 33 of the
1333 sql::Connection connection
;
1334 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1336 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles",
1339 // Check that the country value is the one we expect.
1341 connection
.GetUniqueStatement("SELECT country FROM autofill_profiles"));
1343 ASSERT_TRUE(s
.Step());
1344 std::string country
= s
.ColumnString(0);
1345 EXPECT_EQ("United States", country
);
1350 // Verify post-conditions. These are expectations for current version of the
1353 sql::Connection connection
;
1354 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1357 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1359 ASSERT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1362 // Check that the country code is properly converted.
1363 sql::Statement
s(connection
.GetUniqueStatement(
1364 "SELECT country_code FROM autofill_profiles"));
1366 ASSERT_TRUE(s
.Step());
1367 std::string country_code
= s
.ColumnString(0);
1368 EXPECT_EQ("US", country_code
);
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")));
1377 // Verify pre-conditions. These are expectations for version 34 of the
1380 sql::Connection connection
;
1381 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1383 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1386 // Check that the country_code value is the one we expect.
1388 connection
.GetUniqueStatement("SELECT country_code "
1389 "FROM autofill_profiles"));
1391 ASSERT_TRUE(s
.Step());
1392 std::string country_code
= s
.ColumnString(0);
1393 EXPECT_EQ("UK", country_code
);
1395 // Should have only one.
1396 ASSERT_FALSE(s
.Step());
1401 // Verify post-conditions. These are expectations for current version of the
1404 sql::Connection connection
;
1405 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1408 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1410 ASSERT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1413 // Check that the country_code code is properly converted.
1414 sql::Statement
s(connection
.GetUniqueStatement(
1415 "SELECT country_code FROM autofill_profiles"));
1417 ASSERT_TRUE(s
.Step());
1418 std::string country_code
= s
.ColumnString(0);
1419 EXPECT_EQ("GB", country_code
);
1421 // Should have only one.
1422 ASSERT_FALSE(s
.Step());
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")));
1433 // Verify pre-conditions. These are expectations for version 34 of the
1436 sql::Connection connection
;
1437 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1439 EXPECT_FALSE(connection
.DoesTableExist("autofill_profiles_trash"));
1440 ASSERT_TRUE(connection
.DoesColumnExist("autofill_profiles", "guid"));
1442 // Check that there are 6 profiles prior to merge.
1444 connection
.GetUniqueStatement("SELECT guid FROM autofill_profiles"));
1453 // Verify post-conditions. These are expectations for current version of the
1456 sql::Connection connection
;
1457 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1460 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
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"));
1466 // Verify data in the database after the migration.
1468 connection
.GetUniqueStatement(
1469 "SELECT guid, company_name, street_address, city, state, zipcode,"
1470 " country_code, date_modified "
1471 "FROM autofill_profiles"));
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"
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));
1486 // That should be it.
1487 ASSERT_FALSE(s1
.Step());
1489 // Check that there 5 trashed profile after the merge.
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));
1496 ASSERT_TRUE(s2
.Step());
1497 EXPECT_EQ("00000000-0000-0000-0000-000000000003", s2
.ColumnString(0));
1499 ASSERT_TRUE(s2
.Step());
1500 EXPECT_EQ("00000000-0000-0000-0000-000000000004", s2
.ColumnString(0));
1502 ASSERT_TRUE(s2
.Step());
1503 EXPECT_EQ("00000000-0000-0000-0000-000000000005", s2
.ColumnString(0));
1505 ASSERT_TRUE(s2
.Step());
1506 EXPECT_EQ("00000000-0000-0000-0000-000000000006", s2
.ColumnString(0));
1508 // That should be it.
1509 ASSERT_FALSE(s2
.Step());
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")));
1520 // Verify pre-conditions. These are expectations for version 37 of the
1523 sql::Connection connection
;
1524 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1526 // Columns existing and not existing before current version.
1527 ASSERT_TRUE(connection
.DoesColumnExist("keywords", "id"));
1528 ASSERT_FALSE(connection
.DoesColumnExist("keywords", "last_modified"));
1533 // Verify post-conditions. These are expectations for current version of the
1536 sql::Connection connection
;
1537 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1540 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1542 // |keywords| |last_modified| column should have been added.
1543 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "id"));
1544 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "last_modified"));
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")));
1555 // Verify pre-conditions. These are expectations for version 38 of the
1558 sql::Connection connection
;
1559 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1561 // Columns existing and not existing before current version.
1562 ASSERT_TRUE(connection
.DoesColumnExist("keywords", "id"));
1563 ASSERT_FALSE(connection
.DoesColumnExist("keywords", "sync_guid"));
1568 // Verify post-conditions. These are expectations for current version of the
1571 sql::Connection connection
;
1572 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1575 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1577 // |keywords| |sync_guid| column should have been added.
1578 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "id"));
1579 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "sync_guid"));
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")));
1589 // Verify pre-conditions. These are expectations for version 39 of the
1592 sql::Connection connection
;
1593 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1594 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1596 sql::MetaTable meta_table
;
1597 ASSERT_TRUE(meta_table
.Init(&connection
, 39, 39));
1599 int64 default_search_provider_id
= 0;
1600 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1601 &default_search_provider_id
));
1603 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
1608 // Verify post-conditions. These are expectations for current version of the
1611 sql::Connection connection
;
1612 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1613 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1616 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1618 sql::MetaTable meta_table
;
1619 ASSERT_TRUE(meta_table
.Init(&connection
, kCurrentTestedVersionNumber
,
1620 kCurrentTestedVersionNumber
));
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
);
1627 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
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")));
1635 // Verify pre-conditions. These are expectations for version 40 of the
1638 sql::Connection connection
;
1639 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1640 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1642 sql::MetaTable meta_table
;
1643 ASSERT_TRUE(meta_table
.Init(&connection
, 40, 40));
1645 int64 default_search_provider_id
= 0;
1646 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1647 &default_search_provider_id
));
1649 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table
));
1654 // Verify post-conditions. These are expectations for current version of the
1657 sql::Connection connection
;
1658 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1659 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1662 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1664 sql::MetaTable meta_table
;
1665 ASSERT_TRUE(meta_table
.Init(&connection
, kCurrentTestedVersionNumber
,
1666 kCurrentTestedVersionNumber
));
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
);
1673 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
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")));
1681 // Verify pre-conditions. These are expectations for version 41 of the
1684 sql::Connection connection
;
1685 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1686 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1688 sql::MetaTable meta_table
;
1689 ASSERT_TRUE(meta_table
.Init(&connection
, 41, 41));
1691 int64 default_search_provider_id
= 0;
1692 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1693 &default_search_provider_id
));
1695 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table
));
1700 // Verify post-conditions. These are expectations for current version of the
1703 sql::Connection connection
;
1704 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1705 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1708 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1710 sql::MetaTable meta_table
;
1711 ASSERT_TRUE(meta_table
.Init(&connection
, kCurrentTestedVersionNumber
,
1712 kCurrentTestedVersionNumber
));
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
);
1719 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
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")));
1727 // Verify pre-conditions. These are expectations for version 42 of the
1730 sql::Connection connection
;
1731 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1732 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1734 sql::MetaTable meta_table
;
1735 ASSERT_TRUE(meta_table
.Init(&connection
, 42, 42));
1737 int64 default_search_provider_id
= 0;
1738 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1739 &default_search_provider_id
));
1741 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table
));
1743 EXPECT_FALSE(connection
.DoesTableExist("keywords_backup"));
1748 // Verify post-conditions. These are expectations for current version of the
1751 sql::Connection connection
;
1752 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1753 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1756 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1758 sql::MetaTable meta_table
;
1759 ASSERT_TRUE(meta_table
.Init(&connection
, kCurrentTestedVersionNumber
,
1760 kCurrentTestedVersionNumber
));
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
);
1767 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
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")));
1775 int64 previous_default_search_provider_id
;
1777 // Verify pre-conditions. These are expectations for version 43 of the
1780 sql::Connection connection
;
1781 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1782 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1784 sql::MetaTable meta_table
;
1785 ASSERT_TRUE(meta_table
.Init(&connection
, 43, 43));
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
;
1793 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table
));
1794 EXPECT_TRUE(connection
.DoesTableExist("keywords_backup"));
1799 // Verify post-conditions. These are expectations for current version of the
1802 sql::Connection connection
;
1803 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1804 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1807 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1809 sql::MetaTable meta_table
;
1810 ASSERT_TRUE(meta_table
.Init(
1812 kCurrentTestedVersionNumber
,
1813 kCurrentTestedVersionNumber
));
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
);
1821 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
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")));
1830 // Verify pre-conditions. These are expectations for version 44 of the
1833 sql::Connection connection
;
1834 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1835 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1837 sql::MetaTable meta_table
;
1838 ASSERT_TRUE(meta_table
.Init(&connection
, 44, 44));
1840 ASSERT_TRUE(connection
.DoesColumnExist("keywords", "autogenerate_keyword"));
1841 ASSERT_TRUE(connection
.DoesColumnExist("keywords", "logo_id"));
1846 // Verify post-conditions. These are expectations for current version of the
1849 sql::Connection connection
;
1850 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1851 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1854 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1856 sql::MetaTable meta_table
;
1857 ASSERT_TRUE(meta_table
.Init(&connection
, kCurrentTestedVersionNumber
,
1858 kCurrentTestedVersionNumber
));
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
));
1865 // Two columns should have been removed.
1866 EXPECT_FALSE(connection
.DoesColumnExist("keywords",
1867 "autogenerate_keyword"));
1868 EXPECT_FALSE(connection
.DoesColumnExist("keywords", "logo_id"));
1870 // Backup data should have been removed.
1871 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
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")));
1882 // Verify pre-conditions. These are expectations for version 45 of the
1885 sql::Connection connection
;
1886 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1887 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1889 sql::MetaTable meta_table
;
1890 ASSERT_TRUE(meta_table
.Init(&connection
, 45, 45));
1892 ASSERT_FALSE(connection
.DoesColumnExist("scheme", "web_intents"));
1893 ASSERT_FALSE(connection
.DoesColumnExist(
1894 "scheme", "web_intents_defaults"));
1899 // Verify post-conditions. These are expectations for current version of the
1902 sql::Connection connection
;
1903 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1904 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1907 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1909 sql::MetaTable meta_table
;
1910 ASSERT_TRUE(meta_table
.Init(
1912 kCurrentTestedVersionNumber
,
1913 kCurrentTestedVersionNumber
));
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"));
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")));
1929 // Verify pre-conditions. These are expectations for version 45 of the
1932 sql::Connection connection
;
1933 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1934 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1936 sql::MetaTable meta_table
;
1937 ASSERT_TRUE(meta_table
.Init(&connection
, 45, 45));
1939 ASSERT_FALSE(connection
.DoesColumnExist("scheme", "web_intents"));
1940 ASSERT_FALSE(connection
.DoesColumnExist(
1941 "scheme", "web_intents_defaults"));
1946 // Verify post-conditions. These are expectations for current version of the
1949 sql::Connection connection
;
1950 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1951 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1954 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1956 sql::MetaTable meta_table
;
1957 ASSERT_TRUE(meta_table
.Init(
1959 kCurrentTestedVersionNumber
,
1960 kCurrentTestedVersionNumber
));
1962 EXPECT_FALSE(connection
.DoesTableExist("web_intents"));
1963 EXPECT_FALSE(connection
.DoesTableExist("web_intents_defaults"));
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")));
1973 // Verify pre-conditions. These are expectations for version 45 of the
1976 sql::Connection connection
;
1977 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1978 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
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));
1987 // Verify post-conditions. These are expectations for current version of the
1990 sql::Connection connection
;
1991 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1992 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1995 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1996 EXPECT_LE(45, VersionFromConnection(&connection
));
2000 // Tests that the |alternate_urls| column is added to the keyword table schema
2001 // for a version 47 database.
2002 TEST_F(WebDatabaseMigrationTest
, MigrateVersion46ToCurrent
) {
2003 ASSERT_NO_FATAL_FAILURE(
2004 LoadDatabase(FILE_PATH_LITERAL("version_46.sql")));
2006 // Verify pre-conditions. These are expectations for version 46 of the
2009 sql::Connection connection
;
2010 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2011 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2013 sql::MetaTable meta_table
;
2014 ASSERT_TRUE(meta_table
.Init(&connection
, 46, 46));
2016 ASSERT_FALSE(connection
.DoesColumnExist("keywords", "alternate_urls"));
2017 ASSERT_FALSE(connection
.DoesColumnExist("keywords_backup",
2023 // Verify post-conditions. These are expectations for current version of the
2026 sql::Connection connection
;
2027 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2028 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2031 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2033 // A new column should have been created.
2034 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "alternate_urls"));
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")));
2042 // Verify pre-conditions. These are expectations for version 47 of the
2045 sql::Connection connection
;
2046 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2047 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2049 sql::MetaTable meta_table
;
2050 ASSERT_TRUE(meta_table
.Init(&connection
, 47, 47));
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
);
2057 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table
));
2058 EXPECT_TRUE(connection
.DoesTableExist("keywords_backup"));
2063 // Verify post-conditions. These are expectations for current version of the
2066 sql::Connection connection
;
2067 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2068 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2071 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2073 sql::MetaTable meta_table
;
2074 ASSERT_TRUE(meta_table
.Init(&connection
, kCurrentTestedVersionNumber
,
2075 kCurrentTestedVersionNumber
));
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
);
2082 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
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")));
2092 // Verify pre-conditions. These are expectations for version 48 of the
2095 sql::Connection connection
;
2096 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2097 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2099 sql::MetaTable meta_table
;
2100 ASSERT_TRUE(meta_table
.Init(&connection
, 48, 48));
2102 ASSERT_FALSE(connection
.DoesColumnExist("keywords",
2103 "search_terms_replacement_key"));
2108 // Verify post-conditions. These are expectations for current version of the
2111 sql::Connection connection
;
2112 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2113 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2116 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2118 // A new column should have been created.
2119 EXPECT_TRUE(connection
.DoesColumnExist("keywords",
2120 "search_terms_replacement_key"));
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")));
2129 // Verify pre-conditions. These are expectations for version 49 of the
2132 sql::Connection connection
;
2133 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2135 ASSERT_FALSE(connection
.DoesColumnExist("autofill_profiles", "origin"));
2136 ASSERT_FALSE(connection
.DoesColumnExist("credit_cards", "origin"));
2141 // Verify post-conditions. These are expectations for current version of the
2144 sql::Connection connection
;
2145 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2146 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2149 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
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"));
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
2161 TEST_F(WebDatabaseMigrationTest
, MigrateVersion50ToCurrent
) {
2162 ASSERT_NO_FATAL_FAILURE(
2163 LoadDatabase(FILE_PATH_LITERAL("version_50.sql")));
2165 // Verify pre-conditions. These are expectations for version 50 of the
2168 sql::Connection connection
;
2169 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2170 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2172 sql::MetaTable meta_table
;
2173 ASSERT_TRUE(meta_table
.Init(&connection
, 50, 50));
2175 ASSERT_FALSE(connection
.DoesColumnExist("keywords", "image_url"));
2176 ASSERT_FALSE(connection
.DoesColumnExist("keywords",
2177 "search_url_post_params"));
2178 ASSERT_FALSE(connection
.DoesColumnExist("keywords",
2179 "suggest_url_post_params"));
2180 ASSERT_FALSE(connection
.DoesColumnExist("keywords",
2181 "instant_url_post_params"));
2182 ASSERT_FALSE(connection
.DoesColumnExist("keywords",
2183 "image_url_post_params"));
2188 // Verify post-conditions. These are expectations for current version of the
2191 sql::Connection connection
;
2192 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2193 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2196 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2198 // New columns should have been created.
2199 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "image_url"));
2200 EXPECT_TRUE(connection
.DoesColumnExist("keywords",
2201 "search_url_post_params"));
2202 EXPECT_TRUE(connection
.DoesColumnExist("keywords",
2203 "suggest_url_post_params"));
2204 EXPECT_TRUE(connection
.DoesColumnExist("keywords",
2205 "instant_url_post_params"));
2206 EXPECT_TRUE(connection
.DoesColumnExist("keywords",
2207 "image_url_post_params"));
2211 // Tests that the column |new_tab_url| is added to the keyword table schema for
2212 // a version 52 database.
2213 TEST_F(WebDatabaseMigrationTest
, MigrateVersion52ToCurrent
) {
2214 ASSERT_NO_FATAL_FAILURE(
2215 LoadDatabase(FILE_PATH_LITERAL("version_52.sql")));
2217 // Verify pre-conditions. These are expectations for version 52 of the
2220 sql::Connection connection
;
2221 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2222 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2224 sql::MetaTable meta_table
;
2225 ASSERT_TRUE(meta_table
.Init(&connection
, 52, 52));
2227 ASSERT_FALSE(connection
.DoesColumnExist("keywords", "new_tab_url"));
2232 // Verify post-conditions. These are expectations for current version of the
2235 sql::Connection connection
;
2236 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2237 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2240 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2242 // New columns should have been created.
2243 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "new_tab_url"));
2247 // Tests that for a version 54 database,
2248 // (a) The street_address, dependent_locality, and sorting_code columns are
2249 // added to the autofill_profiles table schema.
2250 // (b) The address_line1, address_line2, and country columns are dropped from
2251 // the autofill_profiles table schema.
2252 // (c) The type column is dropped from the autofill_profile_phones schema.
2253 TEST_F(WebDatabaseMigrationTest
, MigrateVersion53ToCurrent
) {
2254 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_53.sql")));
2256 // Verify pre-conditions. These are expectations for version 53 of the
2259 sql::Connection connection
;
2260 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2263 connection
.DoesColumnExist("autofill_profiles", "address_line_1"));
2265 connection
.DoesColumnExist("autofill_profiles", "address_line_2"));
2266 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "country"));
2268 connection
.DoesColumnExist("autofill_profiles", "street_address"));
2270 connection
.DoesColumnExist("autofill_profiles", "dependent_locality"));
2272 connection
.DoesColumnExist("autofill_profiles", "sorting_code"));
2273 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_phones", "type"));
2278 // Verify post-conditions. These are expectations for current version of the
2281 sql::Connection connection
;
2282 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2283 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2286 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2288 // Columns should have been added and removed appropriately.
2290 connection
.DoesColumnExist("autofill_profiles", "address_line1"));
2292 connection
.DoesColumnExist("autofill_profiles", "address_line2"));
2293 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "country"));
2295 connection
.DoesColumnExist("autofill_profiles", "street_address"));
2297 connection
.DoesColumnExist("autofill_profiles", "dependent_locality"));
2299 connection
.DoesColumnExist("autofill_profiles", "sorting_code"));
2300 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profile_phones", "type"));
2302 // Data should have been preserved.
2303 sql::Statement
s_profiles(
2304 connection
.GetUniqueStatement(
2305 "SELECT guid, company_name, street_address, dependent_locality,"
2306 " city, state, zipcode, sorting_code, country_code, date_modified,"
2308 "FROM autofill_profiles"));
2310 // Address lines 1 and 2.
2311 ASSERT_TRUE(s_profiles
.Step());
2312 EXPECT_EQ("00000000-0000-0000-0000-000000000001",
2313 s_profiles
.ColumnString(0));
2314 EXPECT_EQ(ASCIIToUTF16("Google, Inc."), s_profiles
.ColumnString16(1));
2315 EXPECT_EQ(ASCIIToUTF16("1950 Charleston Rd.\n"
2317 s_profiles
.ColumnString16(2));
2318 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(3));
2319 EXPECT_EQ(ASCIIToUTF16("Mountain View"), s_profiles
.ColumnString16(4));
2320 EXPECT_EQ(ASCIIToUTF16("CA"), s_profiles
.ColumnString16(5));
2321 EXPECT_EQ(ASCIIToUTF16("94043"), s_profiles
.ColumnString16(6));
2322 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(7));
2323 EXPECT_EQ(ASCIIToUTF16("US"), s_profiles
.ColumnString16(8));
2324 EXPECT_EQ(1386046731, s_profiles
.ColumnInt(9));
2325 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles
.ColumnString16(10));
2327 // Only address line 1.
2328 ASSERT_TRUE(s_profiles
.Step());
2329 EXPECT_EQ("00000000-0000-0000-0000-000000000002",
2330 s_profiles
.ColumnString(0));
2331 EXPECT_EQ(ASCIIToUTF16("Google!"), s_profiles
.ColumnString16(1));
2332 EXPECT_EQ(ASCIIToUTF16("1600 Amphitheatre Pkwy."),
2333 s_profiles
.ColumnString16(2));
2334 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(3));
2335 EXPECT_EQ(ASCIIToUTF16("Mtn. View"), s_profiles
.ColumnString16(4));
2336 EXPECT_EQ(ASCIIToUTF16("California"), s_profiles
.ColumnString16(5));
2337 EXPECT_EQ(ASCIIToUTF16("94043-1234"), s_profiles
.ColumnString16(6));
2338 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(7));
2339 EXPECT_EQ(ASCIIToUTF16("US"), s_profiles
.ColumnString16(8));
2340 EXPECT_EQ(1386046800, s_profiles
.ColumnInt(9));
2341 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles
.ColumnString16(10));
2343 // Only address line 2.
2344 ASSERT_TRUE(s_profiles
.Step());
2345 EXPECT_EQ("00000000-0000-0000-0000-000000000003",
2346 s_profiles
.ColumnString(0));
2347 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(1));
2348 EXPECT_EQ(ASCIIToUTF16("\nOnly line 2???"), s_profiles
.ColumnString16(2));
2349 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(3));
2350 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(4));
2351 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(5));
2352 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(6));
2353 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(7));
2354 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(8));
2355 EXPECT_EQ(1386046834, s_profiles
.ColumnInt(9));
2356 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles
.ColumnString16(10));
2358 // No address lines.
2359 ASSERT_TRUE(s_profiles
.Step());
2360 EXPECT_EQ("00000000-0000-0000-0000-000000000004",
2361 s_profiles
.ColumnString(0));
2362 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(1));
2363 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(2));
2364 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(3));
2365 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(4));
2366 EXPECT_EQ(ASCIIToUTF16("Texas"), s_profiles
.ColumnString16(5));
2367 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(6));
2368 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(7));
2369 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(8));
2370 EXPECT_EQ(1386046847, s_profiles
.ColumnInt(9));
2371 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles
.ColumnString16(10));
2373 // That should be it.
2374 EXPECT_FALSE(s_profiles
.Step());
2376 // Verify the phone number data as well.
2377 sql::Statement
s_phones(
2378 connection
.GetUniqueStatement(
2379 "SELECT guid, number FROM autofill_profile_phones"));
2381 ASSERT_TRUE(s_phones
.Step());
2382 EXPECT_EQ("00000000-0000-0000-0000-000000000001", s_phones
.ColumnString(0));
2383 EXPECT_EQ(ASCIIToUTF16("1.800.555.1234"), s_phones
.ColumnString16(1));
2385 ASSERT_TRUE(s_phones
.Step());
2386 EXPECT_EQ("00000000-0000-0000-0000-000000000001", s_phones
.ColumnString(0));
2387 EXPECT_EQ(ASCIIToUTF16("+1 (800) 555-4321"), s_phones
.ColumnString16(1));
2389 ASSERT_TRUE(s_phones
.Step());
2390 EXPECT_EQ("00000000-0000-0000-0000-000000000002", s_phones
.ColumnString(0));
2391 EXPECT_EQ(base::string16(), s_phones
.ColumnString16(1));
2393 ASSERT_TRUE(s_phones
.Step());
2394 EXPECT_EQ("00000000-0000-0000-0000-000000000003", s_phones
.ColumnString(0));
2395 EXPECT_EQ(ASCIIToUTF16("6505557890"), s_phones
.ColumnString16(1));
2397 ASSERT_TRUE(s_phones
.Step());
2398 EXPECT_EQ("00000000-0000-0000-0000-000000000004", s_phones
.ColumnString(0));
2399 EXPECT_EQ(base::string16(), s_phones
.ColumnString16(1));
2401 EXPECT_FALSE(s_phones
.Step());
2405 // Tests that migrating from version 54 to version 55 drops the autofill_dates
2406 // table, and merges the appropriate dates into the autofill table.
2407 TEST_F(WebDatabaseMigrationTest
, MigrateVersion54ToCurrent
) {
2408 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_54.sql")));
2410 // Verify pre-conditions. These are expectations for version 54 of the
2413 sql::Connection connection
;
2414 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2416 EXPECT_TRUE(connection
.DoesTableExist("autofill_dates"));
2417 EXPECT_FALSE(connection
.DoesColumnExist("autofill", "date_created"));
2418 EXPECT_FALSE(connection
.DoesColumnExist("autofill", "date_last_used"));
2420 // Verify the incoming data.
2421 sql::Statement
s_autofill(connection
.GetUniqueStatement(
2422 "SELECT name, value, value_lower, pair_id, count FROM autofill"));
2423 sql::Statement
s_dates(connection
.GetUniqueStatement(
2424 "SELECT pair_id, date_created FROM autofill_dates"));
2426 // An entry with one timestamp.
2427 ASSERT_TRUE(s_autofill
.Step());
2428 EXPECT_EQ(ASCIIToUTF16("Name"), s_autofill
.ColumnString16(0));
2429 EXPECT_EQ(ASCIIToUTF16("John Doe"), s_autofill
.ColumnString16(1));
2430 EXPECT_EQ(ASCIIToUTF16("john doe"), s_autofill
.ColumnString16(2));
2431 EXPECT_EQ(10, s_autofill
.ColumnInt(3));
2432 EXPECT_EQ(1, s_autofill
.ColumnInt(4));
2433 ASSERT_TRUE(s_dates
.Step());
2434 EXPECT_EQ(10, s_dates
.ColumnInt(0));
2435 EXPECT_EQ(1384299100, s_dates
.ColumnInt64(1));
2437 // Another entry with one timestamp, differing from the previous one in case
2439 ASSERT_TRUE(s_autofill
.Step());
2440 EXPECT_EQ(ASCIIToUTF16("Name"), s_autofill
.ColumnString16(0));
2441 EXPECT_EQ(ASCIIToUTF16("john doe"), s_autofill
.ColumnString16(1));
2442 EXPECT_EQ(ASCIIToUTF16("john doe"), s_autofill
.ColumnString16(2));
2443 EXPECT_EQ(11, s_autofill
.ColumnInt(3));
2444 EXPECT_EQ(1, s_autofill
.ColumnInt(4));
2445 ASSERT_TRUE(s_dates
.Step());
2446 EXPECT_EQ(11, s_dates
.ColumnInt(0));
2447 EXPECT_EQ(1384299200, s_dates
.ColumnInt64(1));
2449 // An entry with two timestamps (with count > 2; this is realistic).
2450 ASSERT_TRUE(s_autofill
.Step());
2451 EXPECT_EQ(ASCIIToUTF16("Email"), s_autofill
.ColumnString16(0));
2452 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s_autofill
.ColumnString16(1));
2453 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s_autofill
.ColumnString16(2));
2454 EXPECT_EQ(20, s_autofill
.ColumnInt(3));
2455 EXPECT_EQ(3, s_autofill
.ColumnInt(4));
2456 ASSERT_TRUE(s_dates
.Step());
2457 EXPECT_EQ(20, s_dates
.ColumnInt(0));
2458 EXPECT_EQ(1384299300, s_dates
.ColumnInt64(1));
2459 ASSERT_TRUE(s_dates
.Step());
2460 EXPECT_EQ(20, s_dates
.ColumnInt(0));
2461 EXPECT_EQ(1384299301, s_dates
.ColumnInt64(1));
2463 // An entry with more than two timestamps, which are stored out of order.
2464 ASSERT_TRUE(s_autofill
.Step());
2465 EXPECT_EQ(ASCIIToUTF16("Email"), s_autofill
.ColumnString16(0));
2466 EXPECT_EQ(ASCIIToUTF16("jane.doe@example.org"),
2467 s_autofill
.ColumnString16(1));
2468 EXPECT_EQ(ASCIIToUTF16("jane.doe@example.org"),
2469 s_autofill
.ColumnString16(2));
2470 EXPECT_EQ(21, s_autofill
.ColumnInt(3));
2471 EXPECT_EQ(4, s_autofill
.ColumnInt(4));
2472 ASSERT_TRUE(s_dates
.Step());
2473 EXPECT_EQ(21, s_dates
.ColumnInt(0));
2474 EXPECT_EQ(1384299401, s_dates
.ColumnInt64(1));
2475 ASSERT_TRUE(s_dates
.Step());
2476 EXPECT_EQ(21, s_dates
.ColumnInt(0));
2477 EXPECT_EQ(1384299400, s_dates
.ColumnInt64(1));
2478 ASSERT_TRUE(s_dates
.Step());
2479 EXPECT_EQ(21, s_dates
.ColumnInt(0));
2480 EXPECT_EQ(1384299403, s_dates
.ColumnInt64(1));
2481 ASSERT_TRUE(s_dates
.Step());
2482 EXPECT_EQ(21, s_dates
.ColumnInt(0));
2483 EXPECT_EQ(1384299402, s_dates
.ColumnInt64(1));
2485 // No more entries expected.
2486 ASSERT_FALSE(s_autofill
.Step());
2487 ASSERT_FALSE(s_dates
.Step());
2492 // Verify post-conditions. These are expectations for current version of the
2495 sql::Connection connection
;
2496 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2497 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2500 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2502 // The autofill_dates table should have been dropped, and its columns should
2503 // have been migrated to the autofill table.
2504 EXPECT_FALSE(connection
.DoesTableExist("autofill_dates"));
2505 EXPECT_TRUE(connection
.DoesColumnExist("autofill", "date_created"));
2506 EXPECT_TRUE(connection
.DoesColumnExist("autofill", "date_last_used"));
2508 // Data should have been preserved. Note that it appears out of order
2509 // relative to the previous table, as it's been alphabetized. That's ok.
2511 connection
.GetUniqueStatement(
2512 "SELECT name, value, value_lower, date_created, date_last_used,"
2515 "ORDER BY name, value ASC"));
2517 // "jane.doe@example.org": Timestamps should be parsed correctly, and only
2518 // the first and last should be kept.
2519 ASSERT_TRUE(s
.Step());
2520 EXPECT_EQ(ASCIIToUTF16("Email"), s
.ColumnString16(0));
2521 EXPECT_EQ(ASCIIToUTF16("jane.doe@example.org"), s
.ColumnString16(1));
2522 EXPECT_EQ(ASCIIToUTF16("jane.doe@example.org"), s
.ColumnString16(2));
2523 EXPECT_EQ(1384299400, s
.ColumnInt64(3));
2524 EXPECT_EQ(1384299403, s
.ColumnInt64(4));
2525 EXPECT_EQ(4, s
.ColumnInt(5));
2527 // "jane@example.com": Timestamps should be parsed correctly.
2528 ASSERT_TRUE(s
.Step());
2529 EXPECT_EQ(ASCIIToUTF16("Email"), s
.ColumnString16(0));
2530 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s
.ColumnString16(1));
2531 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s
.ColumnString16(2));
2532 EXPECT_EQ(1384299300, s
.ColumnInt64(3));
2533 EXPECT_EQ(1384299301, s
.ColumnInt64(4));
2534 EXPECT_EQ(3, s
.ColumnInt(5));
2536 // "John Doe": The single timestamp should be assigned as both the creation
2537 // and the last use timestamp.
2538 ASSERT_TRUE(s
.Step());
2539 EXPECT_EQ(ASCIIToUTF16("Name"), s
.ColumnString16(0));
2540 EXPECT_EQ(ASCIIToUTF16("John Doe"), s
.ColumnString16(1));
2541 EXPECT_EQ(ASCIIToUTF16("john doe"), s
.ColumnString16(2));
2542 EXPECT_EQ(1384299100, s
.ColumnInt64(3));
2543 EXPECT_EQ(1384299100, s
.ColumnInt64(4));
2544 EXPECT_EQ(1, s
.ColumnInt(5));
2546 // "john doe": Should not be merged with "John Doe" (case-sensitivity).
2547 ASSERT_TRUE(s
.Step());
2548 EXPECT_EQ(ASCIIToUTF16("Name"), s
.ColumnString16(0));
2549 EXPECT_EQ(ASCIIToUTF16("john doe"), s
.ColumnString16(1));
2550 EXPECT_EQ(ASCIIToUTF16("john doe"), s
.ColumnString16(2));
2551 EXPECT_EQ(1384299200, s
.ColumnInt64(3));
2552 EXPECT_EQ(1384299200, s
.ColumnInt64(4));
2553 EXPECT_EQ(1, s
.ColumnInt(5));
2555 // No more entries expected.
2556 ASSERT_FALSE(s
.Step());
2560 // Tests that migrating from version 55 to version 56 adds the language_code
2561 // column to autofill_profiles table.
2562 TEST_F(WebDatabaseMigrationTest
, MigrateVersion55ToCurrent
) {
2563 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_55.sql")));
2565 // Verify pre-conditions. These are expectations for version 55 of the
2568 sql::Connection connection
;
2569 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2570 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2573 connection
.DoesColumnExist("autofill_profiles", "language_code"));
2578 // Verify post-conditions. These are expectations for current version of the
2581 sql::Connection connection
;
2582 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2583 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2586 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2588 // The language_code column should have been added to autofill_profiles
2591 connection
.DoesColumnExist("autofill_profiles", "language_code"));
2593 // Data should have been preserved. Language code should have been set to
2595 sql::Statement
s_profiles(
2596 connection
.GetUniqueStatement(
2597 "SELECT guid, company_name, street_address, dependent_locality,"
2598 " city, state, zipcode, sorting_code, country_code, date_modified,"
2599 " origin, language_code "
2600 "FROM autofill_profiles"));
2602 ASSERT_TRUE(s_profiles
.Step());
2603 EXPECT_EQ("00000000-0000-0000-0000-000000000001",
2604 s_profiles
.ColumnString(0));
2605 EXPECT_EQ(ASCIIToUTF16("Google Inc"), s_profiles
.ColumnString16(1));
2606 EXPECT_EQ(ASCIIToUTF16("340 Main St"),
2607 s_profiles
.ColumnString16(2));
2608 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(3));
2609 EXPECT_EQ(ASCIIToUTF16("Los Angeles"), s_profiles
.ColumnString16(4));
2610 EXPECT_EQ(ASCIIToUTF16("CA"), s_profiles
.ColumnString16(5));
2611 EXPECT_EQ(ASCIIToUTF16("90291"), s_profiles
.ColumnString16(6));
2612 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(7));
2613 EXPECT_EQ(ASCIIToUTF16("US"), s_profiles
.ColumnString16(8));
2614 EXPECT_EQ(1395948829, s_profiles
.ColumnInt(9));
2615 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles
.ColumnString16(10));
2616 EXPECT_EQ(std::string(), s_profiles
.ColumnString(11));
2618 // No more entries expected.
2619 ASSERT_FALSE(s_profiles
.Step());
2623 // Tests that migrating from version 56 to version 57 adds the full_name
2624 // column to autofill_profile_names table.
2625 TEST_F(WebDatabaseMigrationTest
, MigrateVersion56ToCurrent
) {
2626 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_56.sql")));
2628 // Verify pre-conditions. These are expectations for version 56 of the
2631 sql::Connection connection
;
2632 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2633 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2636 connection
.DoesColumnExist("autofill_profile_names", "full_name"));
2638 // Verify the starting data.
2639 sql::Statement
s_names(
2640 connection
.GetUniqueStatement(
2641 "SELECT guid, first_name, middle_name, last_name "
2642 "FROM autofill_profile_names"));
2643 ASSERT_TRUE(s_names
.Step());
2644 EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names
.ColumnString(0));
2645 EXPECT_EQ(ASCIIToUTF16("Jon"), s_names
.ColumnString16(1));
2646 EXPECT_EQ(base::string16(), s_names
.ColumnString16(2));
2647 EXPECT_EQ(ASCIIToUTF16("Smith"), s_names
.ColumnString16(3));
2652 // Verify post-conditions. These are expectations for current version of the
2655 sql::Connection connection
;
2656 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2657 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2660 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2662 // The full_name column should have been added to autofill_profile_names
2665 connection
.DoesColumnExist("autofill_profile_names", "full_name"));
2667 // Data should have been preserved. Full name should have been set to the
2669 sql::Statement
s_names(
2670 connection
.GetUniqueStatement(
2671 "SELECT guid, first_name, middle_name, last_name, full_name "
2672 "FROM autofill_profile_names"));
2674 ASSERT_TRUE(s_names
.Step());
2675 EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names
.ColumnString(0));
2676 EXPECT_EQ(ASCIIToUTF16("Jon"), s_names
.ColumnString16(1));
2677 EXPECT_EQ(base::string16(), s_names
.ColumnString16(2));
2678 EXPECT_EQ(ASCIIToUTF16("Smith"), s_names
.ColumnString16(3));
2679 EXPECT_EQ(base::string16(), s_names
.ColumnString16(4));
2681 // No more entries expected.
2682 ASSERT_FALSE(s_names
.Step());
2686 // Tests that migrating from version 57 to version 58 drops the web_intents and
2688 TEST_F(WebDatabaseMigrationTest
, MigrateVersion57ToCurrent
) {
2689 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_57.sql")));
2691 // Verify pre-conditions. These are expectations for version 57 of the
2694 sql::Connection connection
;
2695 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2696 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2698 EXPECT_TRUE(connection
.DoesTableExist("web_apps"));
2699 EXPECT_TRUE(connection
.DoesTableExist("web_app_icons"));
2700 EXPECT_TRUE(connection
.DoesTableExist("web_intents"));
2701 EXPECT_TRUE(connection
.DoesTableExist("web_intents_defaults"));
2706 // Verify post-conditions. These are expectations for current version of the
2709 sql::Connection connection
;
2710 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2711 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2714 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2716 EXPECT_FALSE(connection
.DoesTableExist("web_apps"));
2717 EXPECT_FALSE(connection
.DoesTableExist("web_app_icons"));
2718 EXPECT_FALSE(connection
.DoesTableExist("web_intents"));
2719 EXPECT_FALSE(connection
.DoesTableExist("web_intents_defaults"));
2723 // Tests that migrating from version 58 to version 59 drops the omnibox
2724 // extension keywords.
2725 TEST_F(WebDatabaseMigrationTest
, MigrateVersion58ToCurrent
) {
2726 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_58.sql")));
2728 const char query_extensions
[] = "SELECT * FROM keywords "
2729 "WHERE url='chrome-extension://iphchnegaodmijmkdlbhbanjhfphhikp/"
2730 "?q={searchTerms}'";
2731 // Verify pre-conditions.
2733 sql::Connection connection
;
2734 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2735 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2737 sql::MetaTable meta_table
;
2738 ASSERT_TRUE(meta_table
.Init(&connection
, 58, 58));
2740 sql::Statement
s(connection
.GetUniqueStatement(query_extensions
));
2741 ASSERT_TRUE(s
.is_valid());
2746 EXPECT_EQ(1, count
);
2751 // Verify post-conditions.
2753 sql::Connection connection
;
2754 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2755 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2758 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2760 sql::Statement
s(connection
.GetUniqueStatement(query_extensions
));
2761 ASSERT_TRUE(s
.is_valid());
2766 EXPECT_EQ(0, count
);
2768 s
.Assign(connection
.GetUniqueStatement("SELECT * FROM keywords "
2769 "WHERE short_name='Google'"));
2770 ASSERT_TRUE(s
.is_valid());
2775 EXPECT_EQ(1, count
);
2779 // Tests creation of the server_credit_cards table.
2780 TEST_F(WebDatabaseMigrationTest
, MigrateVersion59ToCurrent
) {
2781 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_59.sql")));
2783 // Verify pre-conditions.
2785 sql::Connection connection
;
2786 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2787 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2789 sql::MetaTable meta_table
;
2790 ASSERT_TRUE(meta_table
.Init(&connection
, 59, 59));
2792 ASSERT_FALSE(connection
.DoesTableExist("masked_credit_cards"));
2793 ASSERT_FALSE(connection
.DoesTableExist("unmasked_credit_cards"));
2794 ASSERT_FALSE(connection
.DoesTableExist("server_addresses"));
2799 // Verify post-conditions.
2801 sql::Connection connection
;
2802 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2803 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2806 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2808 ASSERT_TRUE(connection
.DoesTableExist("masked_credit_cards"));
2809 ASSERT_TRUE(connection
.DoesTableExist("unmasked_credit_cards"));
2810 ASSERT_TRUE(connection
.DoesTableExist("server_addresses"));