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/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 virtual ~WebDatabaseMigrationTest() {}
175 virtual void SetUp() {
176 ASSERT_TRUE(temp_dir_
.CreateUniqueTempDir());
179 // Load the database via the WebDatabase class and migrate the database to
180 // the current version.
182 // TODO(joi): This whole unit test file needs to stay in //chrome
183 // for now, as it needs to know about all the different table
184 // types. Once all webdata datatypes have been componentized, this
185 // could move to components_unittests.
186 AutofillTable
autofill_table("en-US");
187 KeywordTable keyword_table
;
188 LoginsTable logins_table
;
189 TokenServiceTable token_service_table
;
192 db
.AddTable(&autofill_table
);
193 db
.AddTable(&keyword_table
);
194 db
.AddTable(&logins_table
);
195 db
.AddTable(&token_service_table
);
197 // This causes the migration to occur.
198 ASSERT_EQ(sql::INIT_OK
, db
.Init(GetDatabasePath()));
202 // Current tested version number. When adding a migration in
203 // |WebDatabase::MigrateOldVersionsAsNeeded()| and changing the version number
204 // |kCurrentVersionNumber| this value should change to reflect the new version
205 // number and a new migration test added below.
206 static const int kCurrentTestedVersionNumber
;
208 base::FilePath
GetDatabasePath() {
209 const base::FilePath::CharType kWebDatabaseFilename
[] =
210 FILE_PATH_LITERAL("TestWebDatabase.sqlite3");
211 return temp_dir_
.path().Append(base::FilePath(kWebDatabaseFilename
));
214 // The textual contents of |file| are read from
215 // "components/test/data/web_database" and returned in the string |contents|.
216 // Returns true if the file exists and is read successfully, false otherwise.
217 bool GetWebDatabaseData(const base::FilePath
& file
, std::string
* contents
) {
218 base::FilePath source_path
;
219 PathService::Get(base::DIR_SOURCE_ROOT
, &source_path
);
220 source_path
= source_path
.AppendASCII("components");
221 source_path
= source_path
.AppendASCII("test");
222 source_path
= source_path
.AppendASCII("data");
223 source_path
= source_path
.AppendASCII("web_database");
224 source_path
= source_path
.Append(file
);
225 return base::PathExists(source_path
) &&
226 base::ReadFileToString(source_path
, contents
);
229 static int VersionFromConnection(sql::Connection
* connection
) {
231 sql::Statement
s(connection
->GetUniqueStatement(
232 "SELECT value FROM meta WHERE key='version'"));
235 return s
.ColumnInt(0);
238 // The sql files located in "chrome/test/data/web_database" were generated by
239 // launching the Chromium application prior to schema change, then using the
240 // sqlite3 command-line application to dump the contents of the "Web Data"
243 // > .output version_nn.sql
245 void LoadDatabase(const base::FilePath::StringType
& file
);
248 base::ScopedTempDir temp_dir_
;
250 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest
);
253 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber
= 58;
255 void WebDatabaseMigrationTest::LoadDatabase(
256 const base::FilePath::StringType
& file
) {
257 std::string contents
;
258 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file
), &contents
));
260 sql::Connection connection
;
261 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
262 ASSERT_TRUE(connection
.Execute(contents
.data()));
265 // Tests that migrating from the golden files version_XX.sql results in the same
266 // schema as migrating from an empty database.
267 TEST_F(WebDatabaseMigrationTest
, VersionXxSqlFilesAreGolden
) {
269 sql::Connection connection
;
270 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
271 const std::string
& expected_schema
= RemoveQuotes(connection
.GetSchema());
272 static const int kFirstVersion
= 53;
273 for (int i
= kFirstVersion
; i
< kCurrentTestedVersionNumber
; ++i
) {
275 const base::FilePath
& file_name
= base::FilePath::FromUTF8Unsafe(
276 "version_" + base::IntToString(i
) + ".sql");
277 ASSERT_NO_FATAL_FAILURE(LoadDatabase(file_name
.value()))
278 << "Failed to load " << file_name
.MaybeAsASCII();
280 EXPECT_EQ(expected_schema
, RemoveQuotes(connection
.GetSchema()));
284 // Tests that the all migrations from an empty database succeed.
285 TEST_F(WebDatabaseMigrationTest
, MigrateEmptyToCurrent
) {
288 // Verify post-conditions. These are expectations for current version of the
291 sql::Connection connection
;
292 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
295 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
297 // Check that expected tables are present.
298 EXPECT_TRUE(connection
.DoesTableExist("autofill"));
299 // The autofill_dates table is obsolete. (It's been merged into the autofill
301 EXPECT_FALSE(connection
.DoesTableExist("autofill_dates"));
302 EXPECT_TRUE(connection
.DoesTableExist("autofill_profiles"));
303 EXPECT_TRUE(connection
.DoesTableExist("credit_cards"));
304 EXPECT_TRUE(connection
.DoesTableExist("keywords"));
305 // The logins table is obsolete. (We used to store saved passwords here.)
306 EXPECT_FALSE(connection
.DoesTableExist("logins"));
307 EXPECT_TRUE(connection
.DoesTableExist("meta"));
308 EXPECT_TRUE(connection
.DoesTableExist("token_service"));
309 // The web_apps and web_apps_icons tables are obsolete as of version 58.
310 EXPECT_FALSE(connection
.DoesTableExist("web_apps"));
311 EXPECT_FALSE(connection
.DoesTableExist("web_app_icons"));
312 // The web_intents and web_intents_defaults tables are obsolete as of
314 EXPECT_FALSE(connection
.DoesTableExist("web_intents"));
315 EXPECT_FALSE(connection
.DoesTableExist("web_intents_defaults"));
319 // Tests that absent Autofill tables do not create any problems when migrating
320 // from a DB written by the earliest publicly released version of Chrome.
321 TEST_F(WebDatabaseMigrationTest
, MigrateVersion20ToCurrent
) {
322 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_20.sql")));
324 // Verify pre-conditions.
326 sql::Connection connection
;
327 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
329 EXPECT_FALSE(connection
.DoesTableExist("autofill"));
330 EXPECT_FALSE(connection
.DoesTableExist("autofill_profiles"));
331 EXPECT_FALSE(connection
.DoesTableExist("credit_cards"));
336 // Verify post-conditions. These are expectations for current version of the
339 sql::Connection connection
;
340 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
343 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
345 // Mostly this test just verifies that no SQL errors occur during migration;
346 // but might as well verify that the tables were created as well.
347 EXPECT_TRUE(connection
.DoesTableExist("autofill"));
348 EXPECT_TRUE(connection
.DoesTableExist("autofill_profiles"));
349 EXPECT_TRUE(connection
.DoesTableExist("credit_cards"));
353 // Tests that rows with empty values get removed from the autofill tables.
354 TEST_F(WebDatabaseMigrationTest
, MigrateVersion21ToCurrent
) {
355 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_21.sql")));
357 // Verify pre-conditions.
359 sql::Connection connection
;
360 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
362 // Both empty and non-empty values are allowed in a version 21 database.
363 sql::Statement
s_autofill(connection
.GetUniqueStatement(
364 "SELECT name, value, value_lower, pair_id, count FROM autofill"));
365 sql::Statement
s_dates(connection
.GetUniqueStatement(
366 "SELECT pair_id, date_created FROM autofill_dates"));
368 // An entry with a non-empty value.
369 ASSERT_TRUE(s_autofill
.Step());
370 EXPECT_EQ(ASCIIToUTF16("Name"), s_autofill
.ColumnString16(0));
371 EXPECT_EQ(ASCIIToUTF16("John Doe"), s_autofill
.ColumnString16(1));
372 EXPECT_EQ(ASCIIToUTF16("john doe"), s_autofill
.ColumnString16(2));
373 EXPECT_EQ(10, s_autofill
.ColumnInt(3));
374 EXPECT_EQ(1, s_autofill
.ColumnInt(4));
375 ASSERT_TRUE(s_dates
.Step());
376 EXPECT_EQ(10, s_dates
.ColumnInt(0));
377 EXPECT_EQ(1384299100, s_dates
.ColumnInt64(1));
379 // An entry with an empty value.
380 ASSERT_TRUE(s_autofill
.Step());
381 EXPECT_EQ(ASCIIToUTF16("Name"), s_autofill
.ColumnString16(0));
382 EXPECT_EQ(base::string16(), s_autofill
.ColumnString16(1));
383 EXPECT_EQ(base::string16(), s_autofill
.ColumnString16(2));
384 EXPECT_EQ(11, s_autofill
.ColumnInt(3));
385 EXPECT_EQ(1, s_autofill
.ColumnInt(4));
386 ASSERT_TRUE(s_dates
.Step());
387 EXPECT_EQ(11, s_dates
.ColumnInt(0));
388 EXPECT_EQ(1384299200, s_dates
.ColumnInt64(1));
390 // Another entry with a non-empty value.
391 ASSERT_TRUE(s_autofill
.Step());
392 EXPECT_EQ(ASCIIToUTF16("Email"), s_autofill
.ColumnString16(0));
393 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s_autofill
.ColumnString16(1));
394 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s_autofill
.ColumnString16(2));
395 EXPECT_EQ(20, s_autofill
.ColumnInt(3));
396 EXPECT_EQ(3, s_autofill
.ColumnInt(4));
397 ASSERT_TRUE(s_dates
.Step());
398 EXPECT_EQ(20, s_dates
.ColumnInt(0));
399 EXPECT_EQ(1384299300, s_dates
.ColumnInt64(1));
400 ASSERT_TRUE(s_dates
.Step());
401 EXPECT_EQ(20, s_dates
.ColumnInt(0));
402 EXPECT_EQ(1384299301, s_dates
.ColumnInt64(1));
404 // Another entry with an empty value.
405 ASSERT_TRUE(s_autofill
.Step());
406 EXPECT_EQ(ASCIIToUTF16("Email"), s_autofill
.ColumnString16(0));
407 EXPECT_EQ(base::string16(), s_autofill
.ColumnString16(1));
408 EXPECT_EQ(base::string16(), s_autofill
.ColumnString16(2));
409 EXPECT_EQ(21, s_autofill
.ColumnInt(3));
410 EXPECT_EQ(4, s_autofill
.ColumnInt(4));
411 ASSERT_TRUE(s_dates
.Step());
412 EXPECT_EQ(21, s_dates
.ColumnInt(0));
413 EXPECT_EQ(1384299401, s_dates
.ColumnInt64(1));
414 ASSERT_TRUE(s_dates
.Step());
415 EXPECT_EQ(21, s_dates
.ColumnInt(0));
416 EXPECT_EQ(1384299400, s_dates
.ColumnInt64(1));
417 ASSERT_TRUE(s_dates
.Step());
418 EXPECT_EQ(21, s_dates
.ColumnInt(0));
419 EXPECT_EQ(1384299403, s_dates
.ColumnInt64(1));
420 ASSERT_TRUE(s_dates
.Step());
421 EXPECT_EQ(21, s_dates
.ColumnInt(0));
422 EXPECT_EQ(1384299402, s_dates
.ColumnInt64(1));
424 // No more entries expected.
425 ASSERT_FALSE(s_autofill
.Step());
426 ASSERT_FALSE(s_dates
.Step());
431 // Verify post-conditions. These are expectations for current version of the
434 sql::Connection connection
;
435 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
438 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
440 // Entries with empty values should have been dropped. The remaining
441 // entries should have been preserved.
443 connection
.GetUniqueStatement(
444 "SELECT name, value, value_lower, date_created, date_last_used,"
447 "ORDER BY name, value ASC"));
449 // "jane@example.com"
450 ASSERT_TRUE(s
.Step());
451 EXPECT_EQ(ASCIIToUTF16("Email"), s
.ColumnString16(0));
452 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s
.ColumnString16(1));
453 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s
.ColumnString16(2));
454 EXPECT_EQ(1384299300, s
.ColumnInt64(3));
455 EXPECT_EQ(1384299301, s
.ColumnInt64(4));
456 EXPECT_EQ(3, s
.ColumnInt(5));
459 ASSERT_TRUE(s
.Step());
460 EXPECT_EQ(ASCIIToUTF16("Name"), s
.ColumnString16(0));
461 EXPECT_EQ(ASCIIToUTF16("John Doe"), s
.ColumnString16(1));
462 EXPECT_EQ(ASCIIToUTF16("john doe"), s
.ColumnString16(2));
463 EXPECT_EQ(1384299100, s
.ColumnInt64(3));
464 EXPECT_EQ(1384299100, s
.ColumnInt64(4));
465 EXPECT_EQ(1, s
.ColumnInt(5));
467 // No more entries expected.
468 ASSERT_FALSE(s
.Step());
472 // Tests that the |credit_card| table gets added to the schema for a version 22
474 TEST_F(WebDatabaseMigrationTest
, MigrateVersion22ToCurrent
) {
475 // This schema is taken from a build prior to the addition of the
476 // |credit_card| table. Version 22 of the schema. Contrast this with the
477 // corrupt version below.
478 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_22.sql")));
480 // Verify pre-conditions.
482 sql::Connection connection
;
483 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
485 // No |credit_card| table prior to version 23.
486 ASSERT_FALSE(connection
.DoesColumnExist("credit_cards", "guid"));
488 connection
.DoesColumnExist("credit_cards", "card_number_encrypted"));
493 // Verify post-conditions. These are expectations for current version of the
496 sql::Connection connection
;
497 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
500 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
502 // |credit_card| table now exists.
503 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "guid"));
505 connection
.DoesColumnExist("credit_cards", "card_number_encrypted"));
509 // Tests that the |credit_card| table gets added to the schema for a corrupt
510 // version 22 database. The corruption is that the |credit_cards| table exists
511 // but the schema version number was not set correctly to 23 or later. This
512 // test exercises code introduced to fix bug http://crbug.com/50699 that
513 // resulted from the corruption.
514 TEST_F(WebDatabaseMigrationTest
, MigrateVersion22CorruptedToCurrent
) {
515 // This schema is taken from a build after the addition of the |credit_card|
516 // table. Due to a bug in the migration logic the version is set incorrectly
517 // to 22 (it should have been updated to 23 at least).
518 ASSERT_NO_FATAL_FAILURE(
519 LoadDatabase(FILE_PATH_LITERAL("version_22_corrupt.sql")));
521 // Verify pre-conditions. These are expectations for corrupt version 22 of
524 sql::Connection connection
;
525 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
527 // Columns existing and not existing before current version.
528 ASSERT_TRUE(connection
.DoesColumnExist("credit_cards", "unique_id"));
530 connection
.DoesColumnExist("credit_cards", "card_number_encrypted"));
531 ASSERT_TRUE(connection
.DoesColumnExist("keywords", "id"));
536 // Verify post-conditions. These are expectations for current version of the
539 sql::Connection connection
;
540 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
543 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
546 // Columns existing and not existing before version 25.
547 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards", "unique_id"));
548 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "guid"));
550 connection
.DoesColumnExist("credit_cards", "card_number_encrypted"));
551 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "id"));
555 // Tests that the |keywords| |created_by_policy| column gets added to the schema
556 // for a version 25 database.
557 TEST_F(WebDatabaseMigrationTest
, MigrateVersion25ToCurrent
) {
558 // This schema is taken from a build prior to the addition of the |keywords|
559 // |created_by_policy| column.
560 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_25.sql")));
562 // Verify pre-conditions. These are expectations for version 25 of the
565 sql::Connection connection
;
566 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
571 // Verify post-conditions. These are expectations for current version of the
574 sql::Connection connection
;
575 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
578 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
580 // |keywords| |created_by_policy| column should have been added.
581 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "id"));
582 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "created_by_policy"));
586 // Tests that the credit_cards.billing_address column is changed from a string
587 // to an int whilst preserving the associated billing address. This version of
588 // the test makes sure a stored label is converted to an ID.
589 TEST_F(WebDatabaseMigrationTest
, MigrateVersion26ToCurrentStringLabels
) {
590 // This schema is taken from a build prior to the change of column type for
591 // credit_cards.billing_address from string to int.
592 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_26.sql")));
594 // Verify pre-conditions. These are expectations for version 26 of the
597 sql::Connection connection
;
598 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
600 // Columns existing and not existing before current version.
601 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "billing_address"));
603 std::string stmt
= "INSERT INTO autofill_profiles"
604 "(label, unique_id, first_name, middle_name, last_name, email,"
605 " company_name, address_line_1, address_line_2, city, state, zipcode,"
606 " country, phone, fax)"
607 "VALUES ('Home',1,'','','','','','','','','','','','','')";
608 sql::Statement
s(connection
.GetUniqueStatement(stmt
.c_str()));
609 ASSERT_TRUE(s
.Run());
611 // Insert a CC linked to an existing address.
612 std::string stmt2
= "INSERT INTO credit_cards"
613 "(label, unique_id, name_on_card, type, card_number,"
614 " expiration_month, expiration_year, verification_code, billing_address,"
615 " shipping_address, card_number_encrypted, verification_code_encrypted)"
616 "VALUES ('label',2,'Jack','Visa','1234',2,2012,'','Home','','','')";
617 sql::Statement
s2(connection
.GetUniqueStatement(stmt2
.c_str()));
618 ASSERT_TRUE(s2
.Run());
620 // |billing_address| is a string.
621 std::string stmt3
= "SELECT billing_address FROM credit_cards";
622 sql::Statement
s3(connection
.GetUniqueStatement(stmt3
.c_str()));
623 ASSERT_TRUE(s3
.Step());
624 EXPECT_EQ(s3
.ColumnType(0), sql::COLUMN_TYPE_TEXT
);
629 // Verify post-conditions. These are expectations for current version of the
632 sql::Connection connection
;
633 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
636 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
637 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards", "billing_address"));
639 // Verify the credit card data is converted.
640 sql::Statement
s(connection
.GetUniqueStatement(
641 "SELECT guid, name_on_card, expiration_month, expiration_year, "
642 "card_number_encrypted, date_modified "
643 "FROM credit_cards"));
644 ASSERT_TRUE(s
.Step());
645 EXPECT_EQ("Jack", s
.ColumnString(1));
646 EXPECT_EQ(2, s
.ColumnInt(2));
647 EXPECT_EQ(2012, s
.ColumnInt(3));
648 // Column 5 is encrypted number blob.
649 // Column 6 is date_modified.
653 // Tests that the credit_cards.billing_address column is changed from a string
654 // to an int whilst preserving the associated billing address. This version of
655 // the test makes sure a stored string ID is converted to an integer ID.
656 TEST_F(WebDatabaseMigrationTest
, MigrateVersion26ToCurrentStringIDs
) {
657 // This schema is taken from a build prior to the change of column type for
658 // credit_cards.billing_address from string to int.
659 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_26.sql")));
661 // Verify pre-conditions. These are expectations for version 26 of the
664 sql::Connection connection
;
665 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
666 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "billing_address"));
668 std::string stmt
= "INSERT INTO autofill_profiles"
669 "(label, unique_id, first_name, middle_name, last_name, email,"
670 " company_name, address_line_1, address_line_2, city, state, zipcode,"
671 " country, phone, fax)"
672 "VALUES ('Home',1,'','','','','','','','','','','','','')";
673 sql::Statement
s(connection
.GetUniqueStatement(stmt
.c_str()));
674 ASSERT_TRUE(s
.Run());
676 // Insert a CC linked to an existing address.
677 std::string stmt2
= "INSERT INTO credit_cards"
678 "(label, unique_id, name_on_card, type, card_number,"
679 " expiration_month, expiration_year, verification_code, billing_address,"
680 " shipping_address, card_number_encrypted, verification_code_encrypted)"
681 "VALUES ('label',2,'Jack','Visa','1234',2,2012,'','1','','','')";
682 sql::Statement
s2(connection
.GetUniqueStatement(stmt2
.c_str()));
683 ASSERT_TRUE(s2
.Run());
685 // |billing_address| is a string.
686 std::string stmt3
= "SELECT billing_address FROM credit_cards";
687 sql::Statement
s3(connection
.GetUniqueStatement(stmt3
.c_str()));
688 ASSERT_TRUE(s3
.Step());
689 EXPECT_EQ(s3
.ColumnType(0), sql::COLUMN_TYPE_TEXT
);
694 // Verify post-conditions. These are expectations for current version of the
697 sql::Connection connection
;
698 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
701 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
703 // |keywords| |created_by_policy| column should have been added.
704 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "id"));
705 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "created_by_policy"));
706 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards", "billing_address"));
708 // Verify the credit card data is converted.
709 sql::Statement
s(connection
.GetUniqueStatement(
710 "SELECT guid, name_on_card, expiration_month, expiration_year, "
711 "card_number_encrypted, date_modified "
712 "FROM credit_cards"));
713 ASSERT_TRUE(s
.Step());
714 EXPECT_EQ("Jack", s
.ColumnString(1));
715 EXPECT_EQ(2, s
.ColumnInt(2));
716 EXPECT_EQ(2012, s
.ColumnInt(3));
717 // Column 5 is encrypted credit card number blo b.
718 // Column 6 is date_modified.
722 // Makes sure instant_url is added correctly to keywords.
723 TEST_F(WebDatabaseMigrationTest
, MigrateVersion27ToCurrent
) {
724 // Initialize the database.
725 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_27.sql")));
727 // Verify pre-conditions. These are expectations for version 27 of the
730 sql::Connection connection
;
731 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
733 ASSERT_FALSE(connection
.DoesColumnExist("keywords", "instant_url"));
738 // Verify post-conditions. These are expectations for current version of the
741 sql::Connection connection
;
742 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
745 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
747 // Make sure supports_instant (added in Version 28) was ultimately dropped
748 // again and instant_url was added.
749 EXPECT_FALSE(connection
.DoesColumnExist("keywords", "supports_instant"));
750 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "instant_url"));
752 // Check that instant_url is empty.
753 std::string stmt
= "SELECT instant_url FROM keywords";
754 sql::Statement
s(connection
.GetUniqueStatement(stmt
.c_str()));
755 ASSERT_TRUE(s
.Step());
756 EXPECT_EQ(std::string(), s
.ColumnString(0));
758 // Verify the data made it over.
759 stmt
= "SELECT " + KeywordTable::GetKeywordColumns() + " FROM keywords";
760 sql::Statement
s2(connection
.GetUniqueStatement(stmt
.c_str()));
761 ASSERT_TRUE(s2
.Step());
762 EXPECT_EQ(2, s2
.ColumnInt(0));
763 EXPECT_EQ("Google", s2
.ColumnString(1));
764 EXPECT_EQ("google.com", s2
.ColumnString(2));
765 EXPECT_EQ("http://www.google.com/favicon.ico", s2
.ColumnString(3));
766 EXPECT_EQ("{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}"\
767 "{google:originalQueryForSuggestion}sourceid=chrome&ie={inputEncoding}"\
770 EXPECT_TRUE(s2
.ColumnBool(5));
771 EXPECT_EQ(std::string(), s2
.ColumnString(6));
772 EXPECT_EQ(0, s2
.ColumnInt(7));
773 EXPECT_EQ(0, s2
.ColumnInt(8));
774 EXPECT_EQ(std::string("UTF-8"), s2
.ColumnString(9));
775 EXPECT_TRUE(s2
.ColumnBool(10));
776 EXPECT_EQ(std::string("{google:baseSuggestURL}search?client=chrome&hl="
777 "{language}&q={searchTerms}"), s2
.ColumnString(11));
778 EXPECT_EQ(1, s2
.ColumnInt(12));
779 EXPECT_FALSE(s2
.ColumnBool(13));
780 EXPECT_EQ(std::string(), s2
.ColumnString(14));
781 EXPECT_EQ(0, s2
.ColumnInt(15));
782 EXPECT_EQ(std::string(), s2
.ColumnString(16));
786 // Makes sure date_modified is added correctly to autofill_profiles and
788 TEST_F(WebDatabaseMigrationTest
, MigrateVersion29ToCurrent
) {
789 // Initialize the database.
790 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_29.sql")));
792 // Verify pre-conditions. These are expectations for version 29 of the
795 sql::Connection connection
;
796 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
798 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles",
800 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards",
804 Time pre_creation_time
= Time::Now();
806 Time post_creation_time
= Time::Now();
808 // Verify post-conditions. These are expectations for current version of the
811 sql::Connection connection
;
812 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
815 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
817 // Check that the columns were created.
818 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
820 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards",
823 sql::Statement
s_profiles(connection
.GetUniqueStatement(
824 "SELECT date_modified FROM autofill_profiles "));
825 ASSERT_TRUE(s_profiles
.is_valid());
826 while (s_profiles
.Step()) {
827 EXPECT_GE(s_profiles
.ColumnInt64(0),
828 pre_creation_time
.ToTimeT());
829 EXPECT_LE(s_profiles
.ColumnInt64(0),
830 post_creation_time
.ToTimeT());
832 EXPECT_TRUE(s_profiles
.Succeeded());
834 sql::Statement
s_credit_cards(connection
.GetUniqueStatement(
835 "SELECT date_modified FROM credit_cards "));
836 ASSERT_TRUE(s_credit_cards
.is_valid());
837 while (s_credit_cards
.Step()) {
838 EXPECT_GE(s_credit_cards
.ColumnInt64(0),
839 pre_creation_time
.ToTimeT());
840 EXPECT_LE(s_credit_cards
.ColumnInt64(0),
841 post_creation_time
.ToTimeT());
843 EXPECT_TRUE(s_credit_cards
.Succeeded());
847 // Makes sure guids are added to autofill_profiles and credit_cards tables.
848 TEST_F(WebDatabaseMigrationTest
, MigrateVersion30ToCurrent
) {
849 // Initialize the database.
850 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_30.sql")));
852 // Verify pre-conditions. These are expectations for version 29 of the
855 sql::Connection connection
;
856 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
858 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "guid"));
859 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards", "guid"));
864 // Verify post-conditions. These are expectations for current version of the
867 sql::Connection connection
;
868 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
871 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
873 ASSERT_TRUE(connection
.DoesColumnExist("autofill_profiles", "guid"));
874 ASSERT_TRUE(connection
.DoesColumnExist("credit_cards", "guid"));
876 // Check that guids are non-null, non-empty, conforms to guid format, and
879 connection
.GetUniqueStatement("SELECT guid FROM autofill_profiles"));
881 ASSERT_TRUE(s
.Step());
882 std::string guid1
= s
.ColumnString(0);
883 EXPECT_TRUE(base::IsValidGUID(guid1
));
885 ASSERT_TRUE(s
.Step());
886 std::string guid2
= s
.ColumnString(0);
887 EXPECT_TRUE(base::IsValidGUID(guid2
));
889 EXPECT_NE(guid1
, guid2
);
893 // Removes unique IDs and make GUIDs the primary key. Also removes unused
895 TEST_F(WebDatabaseMigrationTest
, MigrateVersion31ToCurrent
) {
896 // Initialize the database.
897 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_31.sql")));
899 // Verify pre-conditions. These are expectations for version 30 of the
901 AutofillProfile profile
;
902 base::string16 profile_label
;
903 int profile_unique_id
= 0;
904 int64 profile_date_modified
= 0;
905 CreditCard credit_card
;
906 base::string16 cc_label
;
907 int cc_unique_id
= 0;
908 std::string cc_number_encrypted
;
909 int64 cc_date_modified
= 0;
911 sql::Connection connection
;
912 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
914 // Verify existence of columns we'll be changing.
915 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "guid"));
916 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "unique_id"));
917 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "guid"));
918 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "unique_id"));
919 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "type"));
920 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "card_number"));
921 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards",
922 "verification_code"));
923 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "billing_address"));
924 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "shipping_address"));
925 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards",
926 "verification_code_encrypted"));
928 // Fetch data in the database prior to migration.
930 connection
.GetUniqueStatement(
931 "SELECT label, unique_id, first_name, middle_name, last_name, "
932 "email, company_name, address_line_1, address_line_2, city, state, "
933 "zipcode, country, phone, fax, date_modified, guid "
934 "FROM autofill_profiles"));
935 ASSERT_TRUE(s1
.Step());
936 EXPECT_NO_FATAL_FAILURE(AutofillProfile31FromStatement(
937 s1
, &profile
, &profile_label
, &profile_unique_id
,
938 &profile_date_modified
));
941 connection
.GetUniqueStatement(
942 "SELECT label, unique_id, name_on_card, type, card_number, "
943 "expiration_month, expiration_year, verification_code, "
944 "billing_address, shipping_address, card_number_encrypted, "
945 "verification_code_encrypted, date_modified, guid "
946 "FROM credit_cards"));
947 ASSERT_TRUE(s2
.Step());
948 EXPECT_NO_FATAL_FAILURE(CreditCard31FromStatement(s2
,
952 &cc_number_encrypted
,
955 EXPECT_NE(profile_unique_id
, cc_unique_id
);
956 EXPECT_NE(profile
.guid(), credit_card
.guid());
961 // Verify post-conditions. These are expectations for current version of the
964 sql::Connection connection
;
965 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
968 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
970 // Verify existence of columns we'll be changing.
971 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "guid"));
972 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "unique_id"));
973 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "guid"));
974 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards", "unique_id"));
975 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards", "type"));
976 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards", "card_number"));
977 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards",
978 "verification_code"));
979 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards", "billing_address"));
980 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards",
981 "shipping_address"));
982 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards",
983 "verification_code_encrypted"));
985 // Verify data in the database after the migration.
987 connection
.GetUniqueStatement(
988 "SELECT guid, company_name, street_address, city, state, zipcode,"
989 " country_code, date_modified "
990 "FROM autofill_profiles"));
991 ASSERT_TRUE(s1
.Step());
993 AutofillProfile profile_a
;
994 int64 profile_date_modified_a
= 0;
995 EXPECT_NO_FATAL_FAILURE(AutofillProfile33FromStatement(
996 s1
, &profile_a
, &profile_date_modified_a
));
997 EXPECT_EQ(profile
.guid(), profile_a
.guid());
998 EXPECT_EQ(profile
.GetRawInfo(autofill::COMPANY_NAME
),
999 profile_a
.GetRawInfo(autofill::COMPANY_NAME
));
1000 EXPECT_EQ(profile
.GetRawInfo(autofill::ADDRESS_HOME_LINE1
),
1001 profile_a
.GetRawInfo(autofill::ADDRESS_HOME_LINE1
));
1002 EXPECT_EQ(profile
.GetRawInfo(autofill::ADDRESS_HOME_LINE2
),
1003 profile_a
.GetRawInfo(autofill::ADDRESS_HOME_LINE2
));
1004 EXPECT_EQ(profile
.GetRawInfo(autofill::ADDRESS_HOME_CITY
),
1005 profile_a
.GetRawInfo(autofill::ADDRESS_HOME_CITY
));
1006 EXPECT_EQ(profile
.GetRawInfo(autofill::ADDRESS_HOME_STATE
),
1007 profile_a
.GetRawInfo(autofill::ADDRESS_HOME_STATE
));
1008 EXPECT_EQ(profile
.GetRawInfo(autofill::ADDRESS_HOME_ZIP
),
1009 profile_a
.GetRawInfo(autofill::ADDRESS_HOME_ZIP
));
1010 EXPECT_EQ(profile
.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY
),
1011 profile_a
.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY
));
1012 EXPECT_EQ(profile_date_modified
, profile_date_modified_a
);
1015 connection
.GetUniqueStatement(
1016 "SELECT guid, name_on_card, expiration_month, "
1017 "expiration_year, card_number_encrypted, date_modified "
1018 "FROM credit_cards"));
1019 ASSERT_TRUE(s2
.Step());
1021 CreditCard credit_card_a
;
1022 base::string16 cc_label_a
;
1023 std::string cc_number_encrypted_a
;
1024 int64 cc_date_modified_a
= 0;
1025 EXPECT_NO_FATAL_FAILURE(CreditCard32FromStatement(s2
,
1027 &cc_number_encrypted_a
,
1028 &cc_date_modified_a
));
1029 EXPECT_EQ(credit_card
, credit_card_a
);
1030 EXPECT_EQ(cc_label
, cc_label_a
);
1031 EXPECT_EQ(cc_number_encrypted
, cc_number_encrypted_a
);
1032 EXPECT_EQ(cc_date_modified
, cc_date_modified_a
);
1036 // Factor |autofill_profiles| address information separately from name, email,
1038 TEST_F(WebDatabaseMigrationTest
, MigrateVersion32ToCurrent
) {
1039 // Initialize the database.
1040 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_32.sql")));
1042 // Verify pre-conditions. These are expectations for version 32 of the
1045 sql::Connection connection
;
1046 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1048 // Verify existence of columns we'll be changing.
1049 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "guid"));
1050 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "label"));
1051 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "first_name"));
1052 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "middle_name"));
1053 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "last_name"));
1054 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "email"));
1055 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1057 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1059 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1061 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "city"));
1062 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "state"));
1063 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "zipcode"));
1064 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "country"));
1065 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "phone"));
1066 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "fax"));
1067 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1070 EXPECT_FALSE(connection
.DoesTableExist("autofill_profile_names"));
1071 EXPECT_FALSE(connection
.DoesTableExist("autofill_profile_emails"));
1072 EXPECT_FALSE(connection
.DoesTableExist("autofill_profile_phones"));
1074 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "label"));
1079 // Verify post-conditions. These are expectations for current version of the
1082 sql::Connection connection
;
1083 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1086 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1088 // Verify changes to columns.
1089 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "guid"));
1090 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "label"));
1091 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "first_name"));
1092 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles",
1094 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "last_name"));
1095 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "email"));
1096 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1098 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1100 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "city"));
1101 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "state"));
1102 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "zipcode"));
1103 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1105 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "phone"));
1106 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "fax"));
1107 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1110 // New "names" table.
1111 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_names", "guid"));
1112 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_names",
1114 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_names",
1116 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_names",
1119 // New "emails" table.
1120 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_emails", "guid"));
1121 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_emails", "email"));
1123 // New "phones" table.
1124 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_phones", "guid"));
1125 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_phones",
1128 EXPECT_FALSE(connection
.DoesColumnExist("credit_cards", "label"));
1130 // Verify data in the database after the migration.
1132 connection
.GetUniqueStatement(
1133 "SELECT guid, company_name, street_address, city, state, zipcode, "
1134 " country_code, date_modified "
1135 "FROM autofill_profiles"));
1138 ASSERT_TRUE(s1
.Step());
1139 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s1
.ColumnString(0));
1140 EXPECT_EQ(ASCIIToUTF16("Doe Enterprises"), s1
.ColumnString16(1));
1141 EXPECT_EQ(ASCIIToUTF16("1 Main St\n"
1143 s1
.ColumnString16(2));
1144 EXPECT_EQ(ASCIIToUTF16("Los Altos"), s1
.ColumnString16(3));
1145 EXPECT_EQ(ASCIIToUTF16("CA"), s1
.ColumnString16(4));
1146 EXPECT_EQ(ASCIIToUTF16("94022"), s1
.ColumnString16(5));
1147 EXPECT_EQ(ASCIIToUTF16("US"), s1
.ColumnString16(6));
1148 EXPECT_EQ(1297882100L, s1
.ColumnInt64(7));
1151 // Gets merged during migration from 35 to 37 due to multi-valued fields.
1154 ASSERT_TRUE(s1
.Step());
1155 EXPECT_EQ("4C74A9D8-7EEE-423E-F9C2-E7FA70ED1396", s1
.ColumnString(0));
1156 EXPECT_EQ(base::string16(), s1
.ColumnString16(1));
1157 EXPECT_EQ(ASCIIToUTF16("2 Main Street"), s1
.ColumnString16(2));
1158 EXPECT_EQ(ASCIIToUTF16("Los Altos"), s1
.ColumnString16(3));
1159 EXPECT_EQ(ASCIIToUTF16("CA"), s1
.ColumnString16(4));
1160 EXPECT_EQ(ASCIIToUTF16("94022"), s1
.ColumnString16(5));
1161 EXPECT_EQ(ASCIIToUTF16("US"), s1
.ColumnString16(6));
1162 EXPECT_EQ(1297882100L, s1
.ColumnInt64(7));
1164 // Dave Smith (Part 2).
1165 ASSERT_TRUE(s1
.Step());
1166 EXPECT_EQ("722DF5C4-F74A-294A-46F0-31FFDED0D635", s1
.ColumnString(0));
1167 EXPECT_EQ(base::string16(), s1
.ColumnString16(1));
1168 EXPECT_EQ(ASCIIToUTF16("2 Main St"), s1
.ColumnString16(2));
1169 EXPECT_EQ(ASCIIToUTF16("Los Altos"), s1
.ColumnString16(3));
1170 EXPECT_EQ(ASCIIToUTF16("CA"), s1
.ColumnString16(4));
1171 EXPECT_EQ(ASCIIToUTF16("94022"), s1
.ColumnString16(5));
1172 EXPECT_EQ(ASCIIToUTF16("US"), s1
.ColumnString16(6));
1173 EXPECT_EQ(1297882100L, s1
.ColumnInt64(7));
1176 // Gets culled during migration from 35 to 36 due to incomplete address.
1179 ASSERT_TRUE(s1
.Step());
1180 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s1
.ColumnString(0));
1181 EXPECT_EQ(base::string16(), s1
.ColumnString16(1));
1182 EXPECT_EQ(ASCIIToUTF16("3 Main St"), s1
.ColumnString16(2));
1183 EXPECT_EQ(ASCIIToUTF16("Los Altos"), s1
.ColumnString16(3));
1184 EXPECT_EQ(ASCIIToUTF16("CA"), s1
.ColumnString16(4));
1185 EXPECT_EQ(ASCIIToUTF16("94022"), s1
.ColumnString16(5));
1186 EXPECT_EQ(ASCIIToUTF16("US"), s1
.ColumnString16(6));
1187 EXPECT_EQ(1297882100L, s1
.ColumnInt64(7));
1189 // That should be all.
1190 EXPECT_FALSE(s1
.Step());
1193 connection
.GetUniqueStatement(
1194 "SELECT guid, first_name, middle_name, last_name "
1195 "FROM autofill_profile_names"));
1198 ASSERT_TRUE(s2
.Step());
1199 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s2
.ColumnString(0));
1200 EXPECT_EQ(ASCIIToUTF16("John"), s2
.ColumnString16(1));
1201 EXPECT_EQ(base::string16(), s2
.ColumnString16(2));
1202 EXPECT_EQ(ASCIIToUTF16("Doe"), s2
.ColumnString16(3));
1204 // John P. Doe. Note same guid as above due to merging of multi-valued
1206 ASSERT_TRUE(s2
.Step());
1207 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s2
.ColumnString(0));
1208 EXPECT_EQ(ASCIIToUTF16("John"), s2
.ColumnString16(1));
1209 EXPECT_EQ(ASCIIToUTF16("P."), s2
.ColumnString16(2));
1210 EXPECT_EQ(ASCIIToUTF16("Doe"), s2
.ColumnString16(3));
1213 ASSERT_TRUE(s2
.Step());
1214 EXPECT_EQ("4C74A9D8-7EEE-423E-F9C2-E7FA70ED1396", s2
.ColumnString(0));
1215 EXPECT_EQ(ASCIIToUTF16("Dave"), s2
.ColumnString16(1));
1216 EXPECT_EQ(base::string16(), s2
.ColumnString16(2));
1217 EXPECT_EQ(ASCIIToUTF16("Smith"), s2
.ColumnString16(3));
1219 // Dave Smith (Part 2).
1220 ASSERT_TRUE(s2
.Step());
1221 EXPECT_EQ("722DF5C4-F74A-294A-46F0-31FFDED0D635", s2
.ColumnString(0));
1222 EXPECT_EQ(ASCIIToUTF16("Dave"), s2
.ColumnString16(1));
1223 EXPECT_EQ(base::string16(), s2
.ColumnString16(2));
1224 EXPECT_EQ(ASCIIToUTF16("Smith"), s2
.ColumnString16(3));
1227 // Gets culled during migration from 35 to 36 due to incomplete address.
1230 ASSERT_TRUE(s2
.Step());
1231 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s2
.ColumnString(0));
1232 EXPECT_EQ(base::string16(), s2
.ColumnString16(1));
1233 EXPECT_EQ(base::string16(), s2
.ColumnString16(2));
1234 EXPECT_EQ(base::string16(), s2
.ColumnString16(3));
1237 EXPECT_FALSE(s2
.Step());
1240 connection
.GetUniqueStatement(
1241 "SELECT guid, email "
1242 "FROM autofill_profile_emails"));
1245 ASSERT_TRUE(s3
.Step());
1246 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s3
.ColumnString(0));
1247 EXPECT_EQ(ASCIIToUTF16("john@doe.com"), s3
.ColumnString16(1));
1250 // Gets culled during migration from 35 to 37 due to merging of John Doe and
1251 // John P. Doe addresses.
1254 ASSERT_TRUE(s3
.Step());
1255 EXPECT_EQ("4C74A9D8-7EEE-423E-F9C2-E7FA70ED1396", s3
.ColumnString(0));
1256 EXPECT_EQ(base::string16(), s3
.ColumnString16(1));
1259 ASSERT_TRUE(s3
.Step());
1260 EXPECT_EQ("722DF5C4-F74A-294A-46F0-31FFDED0D635", s3
.ColumnString(0));
1261 EXPECT_EQ(base::string16(), s3
.ColumnString16(1));
1264 // Gets culled during migration from 35 to 36 due to incomplete address.
1267 ASSERT_TRUE(s3
.Step());
1268 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s3
.ColumnString(0));
1269 EXPECT_EQ(base::string16(), s3
.ColumnString16(1));
1272 EXPECT_FALSE(s3
.Step());
1275 connection
.GetUniqueStatement(
1276 "SELECT guid, number "
1277 "FROM autofill_profile_phones"));
1280 ASSERT_TRUE(s4
.Step());
1281 EXPECT_EQ("00580526-FF81-EE2A-0546-1AC593A32E2F", s4
.ColumnString(0));
1282 EXPECT_EQ(ASCIIToUTF16("4151112222"), s4
.ColumnString16(1));
1285 // Gets culled after fax type removed.
1287 // John P. Doe phone.
1288 // Gets culled during migration from 35 to 37 due to merging of John Doe and
1289 // John P. Doe addresses.
1292 // Gets culled during migration from 35 to 37 due to merging of John Doe and
1293 // John P. Doe addresses.
1295 // 2 Main Street phone.
1296 ASSERT_TRUE(s4
.Step());
1297 EXPECT_EQ("4C74A9D8-7EEE-423E-F9C2-E7FA70ED1396", s4
.ColumnString(0));
1298 EXPECT_EQ(base::string16(), s4
.ColumnString16(1));
1300 // 2 Main Street fax.
1301 // Gets culled after fax type removed.
1304 ASSERT_TRUE(s4
.Step());
1305 EXPECT_EQ("722DF5C4-F74A-294A-46F0-31FFDED0D635", s4
.ColumnString(0));
1306 EXPECT_EQ(0, s4
.ColumnInt(1)); // 0 means phone.
1307 EXPECT_EQ(base::string16(), s4
.ColumnString16(2));
1310 // Gets culled after fax type removed.
1312 // Note no phone or fax for Alfred E Newman.
1315 ASSERT_TRUE(s4
.Step());
1316 EXPECT_EQ("9E5FE298-62C7-83DF-6293-381BC589183F", s4
.ColumnString(0));
1317 EXPECT_EQ(base::string16(), s4
.ColumnString16(1));
1320 // Gets culled after fax type removed.
1323 EXPECT_FALSE(s4
.Step());
1327 // Adds a column for the autofill profile's country code.
1328 TEST_F(WebDatabaseMigrationTest
, MigrateVersion33ToCurrent
) {
1329 // Initialize the database.
1330 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_33.sql")));
1332 // Verify pre-conditions. These are expectations for version 33 of the
1335 sql::Connection connection
;
1336 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1338 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles",
1341 // Check that the country value is the one we expect.
1343 connection
.GetUniqueStatement("SELECT country FROM autofill_profiles"));
1345 ASSERT_TRUE(s
.Step());
1346 std::string country
= s
.ColumnString(0);
1347 EXPECT_EQ("United States", country
);
1352 // Verify post-conditions. These are expectations for current version of the
1355 sql::Connection connection
;
1356 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1359 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1361 ASSERT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1364 // Check that the country code is properly converted.
1365 sql::Statement
s(connection
.GetUniqueStatement(
1366 "SELECT country_code FROM autofill_profiles"));
1368 ASSERT_TRUE(s
.Step());
1369 std::string country_code
= s
.ColumnString(0);
1370 EXPECT_EQ("US", country_code
);
1374 // Cleans up bad country code "UK" in favor of good country code "GB".
1375 TEST_F(WebDatabaseMigrationTest
, MigrateVersion34ToCurrent
) {
1376 // Initialize the database.
1377 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_34.sql")));
1379 // Verify pre-conditions. These are expectations for version 34 of the
1382 sql::Connection connection
;
1383 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1385 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1388 // Check that the country_code value is the one we expect.
1390 connection
.GetUniqueStatement("SELECT country_code "
1391 "FROM autofill_profiles"));
1393 ASSERT_TRUE(s
.Step());
1394 std::string country_code
= s
.ColumnString(0);
1395 EXPECT_EQ("UK", country_code
);
1397 // Should have only one.
1398 ASSERT_FALSE(s
.Step());
1403 // Verify post-conditions. These are expectations for current version of the
1406 sql::Connection connection
;
1407 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1410 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1412 ASSERT_TRUE(connection
.DoesColumnExist("autofill_profiles",
1415 // Check that the country_code code is properly converted.
1416 sql::Statement
s(connection
.GetUniqueStatement(
1417 "SELECT country_code FROM autofill_profiles"));
1419 ASSERT_TRUE(s
.Step());
1420 std::string country_code
= s
.ColumnString(0);
1421 EXPECT_EQ("GB", country_code
);
1423 // Should have only one.
1424 ASSERT_FALSE(s
.Step());
1428 // Cleans up invalid profiles based on more agressive merging. Filters out
1429 // profiles that are subsets of other profiles, and profiles with invalid email,
1430 // state, and incomplete address.
1431 TEST_F(WebDatabaseMigrationTest
, MigrateVersion35ToCurrent
) {
1432 // Initialize the database.
1433 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_35.sql")));
1435 // Verify pre-conditions. These are expectations for version 34 of the
1438 sql::Connection connection
;
1439 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1441 EXPECT_FALSE(connection
.DoesTableExist("autofill_profiles_trash"));
1442 ASSERT_TRUE(connection
.DoesColumnExist("autofill_profiles", "guid"));
1444 // Check that there are 6 profiles prior to merge.
1446 connection
.GetUniqueStatement("SELECT guid FROM autofill_profiles"));
1455 // Verify post-conditions. These are expectations for current version of the
1458 sql::Connection connection
;
1459 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1462 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1464 ASSERT_TRUE(connection
.DoesTableExist("autofill_profiles_trash"));
1465 ASSERT_TRUE(connection
.DoesColumnExist("autofill_profiles_trash", "guid"));
1466 ASSERT_TRUE(connection
.DoesColumnExist("autofill_profiles", "guid"));
1468 // Verify data in the database after the migration.
1470 connection
.GetUniqueStatement(
1471 "SELECT guid, company_name, street_address, city, state, zipcode,"
1472 " country_code, date_modified "
1473 "FROM autofill_profiles"));
1476 ASSERT_TRUE(s1
.Step());
1477 EXPECT_EQ("00000000-0000-0000-0000-000000000001", s1
.ColumnString(0));
1478 EXPECT_EQ(ASCIIToUTF16("Acme Inc."), s1
.ColumnString16(1));
1479 EXPECT_EQ(ASCIIToUTF16("1 Main Street\n"
1481 s1
.ColumnString16(2));
1482 EXPECT_EQ(ASCIIToUTF16("San Francisco"), s1
.ColumnString16(3));
1483 EXPECT_EQ(ASCIIToUTF16("CA"), s1
.ColumnString16(4));
1484 EXPECT_EQ(ASCIIToUTF16("94102"), s1
.ColumnString16(5));
1485 EXPECT_EQ(ASCIIToUTF16("US"), s1
.ColumnString16(6));
1486 EXPECT_EQ(1300131704, s1
.ColumnInt64(7));
1488 // That should be it.
1489 ASSERT_FALSE(s1
.Step());
1491 // Check that there 5 trashed profile after the merge.
1493 connection
.GetUniqueStatement("SELECT guid "
1494 "FROM autofill_profiles_trash"));
1495 ASSERT_TRUE(s2
.Step());
1496 EXPECT_EQ("00000000-0000-0000-0000-000000000002", s2
.ColumnString(0));
1498 ASSERT_TRUE(s2
.Step());
1499 EXPECT_EQ("00000000-0000-0000-0000-000000000003", s2
.ColumnString(0));
1501 ASSERT_TRUE(s2
.Step());
1502 EXPECT_EQ("00000000-0000-0000-0000-000000000004", s2
.ColumnString(0));
1504 ASSERT_TRUE(s2
.Step());
1505 EXPECT_EQ("00000000-0000-0000-0000-000000000005", s2
.ColumnString(0));
1507 ASSERT_TRUE(s2
.Step());
1508 EXPECT_EQ("00000000-0000-0000-0000-000000000006", s2
.ColumnString(0));
1510 // That should be it.
1511 ASSERT_FALSE(s2
.Step());
1515 // Tests that the |keywords| |last_modified| column gets added to the schema for
1516 // a version 37 database.
1517 TEST_F(WebDatabaseMigrationTest
, MigrateVersion37ToCurrent
) {
1518 // This schema is taken from a build prior to the addition of the |keywords|
1519 // |last_modified| column.
1520 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_37.sql")));
1522 // Verify pre-conditions. These are expectations for version 37 of the
1525 sql::Connection connection
;
1526 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1528 // Columns existing and not existing before current version.
1529 ASSERT_TRUE(connection
.DoesColumnExist("keywords", "id"));
1530 ASSERT_FALSE(connection
.DoesColumnExist("keywords", "last_modified"));
1535 // Verify post-conditions. These are expectations for current version of the
1538 sql::Connection connection
;
1539 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1542 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1544 // |keywords| |last_modified| column should have been added.
1545 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "id"));
1546 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "last_modified"));
1550 // Tests that the |keywords| |sync_guid| column gets added to the schema for
1551 // a version 38 database.
1552 TEST_F(WebDatabaseMigrationTest
, MigrateVersion38ToCurrent
) {
1553 // This schema is taken from a build prior to the addition of the |keywords|
1554 // |sync_guid| column.
1555 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_38.sql")));
1557 // Verify pre-conditions. These are expectations for version 38 of the
1560 sql::Connection connection
;
1561 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1563 // Columns existing and not existing before current version.
1564 ASSERT_TRUE(connection
.DoesColumnExist("keywords", "id"));
1565 ASSERT_FALSE(connection
.DoesColumnExist("keywords", "sync_guid"));
1570 // Verify post-conditions. These are expectations for current version of the
1573 sql::Connection connection
;
1574 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1577 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1579 // |keywords| |sync_guid| column should have been added.
1580 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "id"));
1581 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "sync_guid"));
1585 // Tests that no backup data is added to a version 39 database.
1586 TEST_F(WebDatabaseMigrationTest
, MigrateVersion39ToCurrent
) {
1587 // This schema is taken from a build prior to the addition of the default
1588 // search provider backup field to the meta table.
1589 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_39.sql")));
1591 // Verify pre-conditions. These are expectations for version 39 of the
1594 sql::Connection connection
;
1595 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1596 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1598 sql::MetaTable meta_table
;
1599 ASSERT_TRUE(meta_table
.Init(&connection
, 39, 39));
1601 int64 default_search_provider_id
= 0;
1602 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1603 &default_search_provider_id
));
1605 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
1610 // Verify post-conditions. These are expectations for current version of the
1613 sql::Connection connection
;
1614 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1615 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1618 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1620 sql::MetaTable meta_table
;
1621 ASSERT_TRUE(meta_table
.Init(&connection
, kCurrentTestedVersionNumber
,
1622 kCurrentTestedVersionNumber
));
1624 int64 default_search_provider_id
= 0;
1625 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1626 &default_search_provider_id
));
1627 EXPECT_NE(0, default_search_provider_id
);
1629 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
1633 // Tests that the backup data is removed from the database.
1634 TEST_F(WebDatabaseMigrationTest
, MigrateVersion40ToCurrent
) {
1635 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_40.sql")));
1637 // Verify pre-conditions. These are expectations for version 40 of the
1640 sql::Connection connection
;
1641 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1642 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1644 sql::MetaTable meta_table
;
1645 ASSERT_TRUE(meta_table
.Init(&connection
, 40, 40));
1647 int64 default_search_provider_id
= 0;
1648 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1649 &default_search_provider_id
));
1651 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table
));
1656 // Verify post-conditions. These are expectations for current version of the
1659 sql::Connection connection
;
1660 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1661 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1664 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1666 sql::MetaTable meta_table
;
1667 ASSERT_TRUE(meta_table
.Init(&connection
, kCurrentTestedVersionNumber
,
1668 kCurrentTestedVersionNumber
));
1670 int64 default_search_provider_id
= 0;
1671 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1672 &default_search_provider_id
));
1673 EXPECT_NE(0, default_search_provider_id
);
1675 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
1679 // Tests that the backup data is removed from the database.
1680 TEST_F(WebDatabaseMigrationTest
, MigrateVersion41ToCurrent
) {
1681 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_41.sql")));
1683 // Verify pre-conditions. These are expectations for version 41 of the
1686 sql::Connection connection
;
1687 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1688 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1690 sql::MetaTable meta_table
;
1691 ASSERT_TRUE(meta_table
.Init(&connection
, 41, 41));
1693 int64 default_search_provider_id
= 0;
1694 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1695 &default_search_provider_id
));
1697 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table
));
1702 // Verify post-conditions. These are expectations for current version of the
1705 sql::Connection connection
;
1706 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1707 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1710 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1712 sql::MetaTable meta_table
;
1713 ASSERT_TRUE(meta_table
.Init(&connection
, kCurrentTestedVersionNumber
,
1714 kCurrentTestedVersionNumber
));
1716 int64 default_search_provider_id
= 0;
1717 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1718 &default_search_provider_id
));
1719 EXPECT_NE(0, default_search_provider_id
);
1721 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
1725 // Tests that the backup data is removed from the database.
1726 TEST_F(WebDatabaseMigrationTest
, MigrateVersion42ToCurrent
) {
1727 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_42.sql")));
1729 // Verify pre-conditions. These are expectations for version 42 of the
1732 sql::Connection connection
;
1733 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1734 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1736 sql::MetaTable meta_table
;
1737 ASSERT_TRUE(meta_table
.Init(&connection
, 42, 42));
1739 int64 default_search_provider_id
= 0;
1740 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1741 &default_search_provider_id
));
1743 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table
));
1745 EXPECT_FALSE(connection
.DoesTableExist("keywords_backup"));
1750 // Verify post-conditions. These are expectations for current version of the
1753 sql::Connection connection
;
1754 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1755 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1758 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1760 sql::MetaTable meta_table
;
1761 ASSERT_TRUE(meta_table
.Init(&connection
, kCurrentTestedVersionNumber
,
1762 kCurrentTestedVersionNumber
));
1764 int64 default_search_provider_id
= 0;
1765 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1766 &default_search_provider_id
));
1767 EXPECT_NE(0, default_search_provider_id
);
1769 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
1773 // Tests that the backup data is removed from the database.
1774 TEST_F(WebDatabaseMigrationTest
, MigrateVersion43ToCurrent
) {
1775 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_43.sql")));
1777 int64 previous_default_search_provider_id
;
1779 // Verify pre-conditions. These are expectations for version 43 of the
1782 sql::Connection connection
;
1783 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1784 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1786 sql::MetaTable meta_table
;
1787 ASSERT_TRUE(meta_table
.Init(&connection
, 43, 43));
1789 int64 default_search_provider_id
= 0;
1790 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1791 &default_search_provider_id
));
1792 EXPECT_NE(default_search_provider_id
, 0);
1793 previous_default_search_provider_id
= default_search_provider_id
;
1795 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table
));
1796 EXPECT_TRUE(connection
.DoesTableExist("keywords_backup"));
1801 // Verify post-conditions. These are expectations for current version of the
1804 sql::Connection connection
;
1805 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1806 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1809 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1811 sql::MetaTable meta_table
;
1812 ASSERT_TRUE(meta_table
.Init(
1814 kCurrentTestedVersionNumber
,
1815 kCurrentTestedVersionNumber
));
1817 int64 default_search_provider_id
= 0;
1818 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
1819 &default_search_provider_id
));
1820 // Default search provider ID should not change.
1821 EXPECT_EQ(previous_default_search_provider_id
, default_search_provider_id
);
1823 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
1827 // Tests that the |autogenerate_keyword| and |logo_id| columns get removed from
1828 // the keyword table schema for a version 45 database.
1829 TEST_F(WebDatabaseMigrationTest
, MigrateVersion44ToCurrent
) {
1830 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_44.sql")));
1832 // Verify pre-conditions. These are expectations for version 44 of the
1835 sql::Connection connection
;
1836 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1837 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1839 sql::MetaTable meta_table
;
1840 ASSERT_TRUE(meta_table
.Init(&connection
, 44, 44));
1842 ASSERT_TRUE(connection
.DoesColumnExist("keywords", "autogenerate_keyword"));
1843 ASSERT_TRUE(connection
.DoesColumnExist("keywords", "logo_id"));
1848 // Verify post-conditions. These are expectations for current version of the
1851 sql::Connection connection
;
1852 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1853 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1856 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1858 sql::MetaTable meta_table
;
1859 ASSERT_TRUE(meta_table
.Init(&connection
, kCurrentTestedVersionNumber
,
1860 kCurrentTestedVersionNumber
));
1862 // We should have removed this obsolete key.
1863 std::string default_search_provider_backup
;
1864 EXPECT_FALSE(meta_table
.GetValue("Default Search Provider Backup",
1865 &default_search_provider_backup
));
1867 // Two columns should have been removed.
1868 EXPECT_FALSE(connection
.DoesColumnExist("keywords",
1869 "autogenerate_keyword"));
1870 EXPECT_FALSE(connection
.DoesColumnExist("keywords", "logo_id"));
1872 // Backup data should have been removed.
1873 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
1877 // Previously, this tested that the web_intents and web_intents_defaults tables
1878 // were modified to include "scheme" columns. Since the web_intents and
1879 // web_intents_defaults tables are now obsolete, this test checks to ensure that
1880 // they are properly removed.
1881 TEST_F(WebDatabaseMigrationTest
, MigrateVersion45ToCurrent
) {
1882 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_45.sql")));
1884 // Verify pre-conditions. These are expectations for version 45 of the
1887 sql::Connection connection
;
1888 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1889 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1891 sql::MetaTable meta_table
;
1892 ASSERT_TRUE(meta_table
.Init(&connection
, 45, 45));
1894 ASSERT_FALSE(connection
.DoesColumnExist("scheme", "web_intents"));
1895 ASSERT_FALSE(connection
.DoesColumnExist(
1896 "scheme", "web_intents_defaults"));
1901 // Verify post-conditions. These are expectations for current version of the
1904 sql::Connection connection
;
1905 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1906 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1909 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1911 sql::MetaTable meta_table
;
1912 ASSERT_TRUE(meta_table
.Init(
1914 kCurrentTestedVersionNumber
,
1915 kCurrentTestedVersionNumber
));
1917 // finally ensure the migration code cleaned up after itself
1918 EXPECT_FALSE(connection
.DoesTableExist("web_intents"));
1919 EXPECT_FALSE(connection
.DoesTableExist("web_intents_defaults"));
1923 // Previously, this tested that the web_intents and web_intents_defaults tables
1924 // were modified to include "scheme" columns. Since the web_intents and
1925 // web_intents_defaults tables are now obsolete, this test checks to ensure that
1926 // they are properly removed.
1927 TEST_F(WebDatabaseMigrationTest
, MigrateVersion45InvalidToCurrent
) {
1928 ASSERT_NO_FATAL_FAILURE(
1929 LoadDatabase(FILE_PATH_LITERAL("version_45_invalid.sql")));
1931 // Verify pre-conditions. These are expectations for version 45 of the
1934 sql::Connection connection
;
1935 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1936 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1938 sql::MetaTable meta_table
;
1939 ASSERT_TRUE(meta_table
.Init(&connection
, 45, 45));
1941 ASSERT_FALSE(connection
.DoesColumnExist("scheme", "web_intents"));
1942 ASSERT_FALSE(connection
.DoesColumnExist(
1943 "scheme", "web_intents_defaults"));
1948 // Verify post-conditions. These are expectations for current version of the
1951 sql::Connection connection
;
1952 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1953 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1956 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1958 sql::MetaTable meta_table
;
1959 ASSERT_TRUE(meta_table
.Init(
1961 kCurrentTestedVersionNumber
,
1962 kCurrentTestedVersionNumber
));
1964 EXPECT_FALSE(connection
.DoesTableExist("web_intents"));
1965 EXPECT_FALSE(connection
.DoesTableExist("web_intents_defaults"));
1969 // Check that current version is forced to compatible version before migration,
1970 // if the former is smaller.
1971 TEST_F(WebDatabaseMigrationTest
, MigrateVersion45CompatibleToCurrent
) {
1972 ASSERT_NO_FATAL_FAILURE(
1973 LoadDatabase(FILE_PATH_LITERAL("version_45_compatible.sql")));
1975 // Verify pre-conditions. These are expectations for version 45 of the
1978 sql::Connection connection
;
1979 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1980 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1982 sql::MetaTable meta_table
;
1983 // Database is actually version 45 but the version field states 40.
1984 ASSERT_TRUE(meta_table
.Init(&connection
, 40, 45));
1989 // Verify post-conditions. These are expectations for current version of the
1992 sql::Connection connection
;
1993 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
1994 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
1997 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
1998 EXPECT_LE(45, VersionFromConnection(&connection
));
2002 // Tests that the |alternate_urls| column is added to the keyword table schema
2003 // for a version 47 database.
2004 TEST_F(WebDatabaseMigrationTest
, MigrateVersion46ToCurrent
) {
2005 ASSERT_NO_FATAL_FAILURE(
2006 LoadDatabase(FILE_PATH_LITERAL("version_46.sql")));
2008 // Verify pre-conditions. These are expectations for version 46 of the
2011 sql::Connection connection
;
2012 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2013 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2015 sql::MetaTable meta_table
;
2016 ASSERT_TRUE(meta_table
.Init(&connection
, 46, 46));
2018 ASSERT_FALSE(connection
.DoesColumnExist("keywords", "alternate_urls"));
2019 ASSERT_FALSE(connection
.DoesColumnExist("keywords_backup",
2025 // Verify post-conditions. These are expectations for current version of the
2028 sql::Connection connection
;
2029 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2030 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2033 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2035 // A new column should have been created.
2036 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "alternate_urls"));
2040 // Tests that the backup data is removed from the database.
2041 TEST_F(WebDatabaseMigrationTest
, MigrateVersion47ToCurrent
) {
2042 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_47.sql")));
2044 // Verify pre-conditions. These are expectations for version 47 of the
2047 sql::Connection connection
;
2048 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2049 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2051 sql::MetaTable meta_table
;
2052 ASSERT_TRUE(meta_table
.Init(&connection
, 47, 47));
2054 int64 default_search_provider_id
= 0;
2055 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
2056 &default_search_provider_id
));
2057 EXPECT_NE(0, default_search_provider_id
);
2059 EXPECT_NO_FATAL_FAILURE(CheckHasBackupData(&meta_table
));
2060 EXPECT_TRUE(connection
.DoesTableExist("keywords_backup"));
2065 // Verify post-conditions. These are expectations for current version of the
2068 sql::Connection connection
;
2069 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2070 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2073 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2075 sql::MetaTable meta_table
;
2076 ASSERT_TRUE(meta_table
.Init(&connection
, kCurrentTestedVersionNumber
,
2077 kCurrentTestedVersionNumber
));
2079 int64 default_search_provider_id
= 0;
2080 EXPECT_TRUE(meta_table
.GetValue(KeywordTable::kDefaultSearchProviderKey
,
2081 &default_search_provider_id
));
2082 EXPECT_NE(0, default_search_provider_id
);
2084 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection
, &meta_table
));
2088 // Tests that the |search_terms_replacement_key| column is added to the keyword
2089 // table schema for a version 49 database.
2090 TEST_F(WebDatabaseMigrationTest
, MigrateVersion48ToCurrent
) {
2091 ASSERT_NO_FATAL_FAILURE(
2092 LoadDatabase(FILE_PATH_LITERAL("version_48.sql")));
2094 // Verify pre-conditions. These are expectations for version 48 of the
2097 sql::Connection connection
;
2098 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2099 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2101 sql::MetaTable meta_table
;
2102 ASSERT_TRUE(meta_table
.Init(&connection
, 48, 48));
2104 ASSERT_FALSE(connection
.DoesColumnExist("keywords",
2105 "search_terms_replacement_key"));
2110 // Verify post-conditions. These are expectations for current version of the
2113 sql::Connection connection
;
2114 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2115 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2118 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2120 // A new column should have been created.
2121 EXPECT_TRUE(connection
.DoesColumnExist("keywords",
2122 "search_terms_replacement_key"));
2126 // Tests that the |origin| column is added to the autofill_profiles and
2127 // credit_cards table schemas for a version 50 database.
2128 TEST_F(WebDatabaseMigrationTest
, MigrateVersion49ToCurrent
) {
2129 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_49.sql")));
2131 // Verify pre-conditions. These are expectations for version 49 of the
2134 sql::Connection connection
;
2135 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2137 ASSERT_FALSE(connection
.DoesColumnExist("autofill_profiles", "origin"));
2138 ASSERT_FALSE(connection
.DoesColumnExist("credit_cards", "origin"));
2143 // Verify post-conditions. These are expectations for current version of the
2146 sql::Connection connection
;
2147 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2148 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2151 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2153 // A new column should have been created in both tables.
2154 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "origin"));
2155 EXPECT_TRUE(connection
.DoesColumnExist("credit_cards", "origin"));
2159 // Tests that the columns |image_url|, |search_url_post_params|,
2160 // |suggest_url_post_params|, |instant_url_post_params|, and
2161 // |image_url_post_params| are added to the keyword table schema for a version
2163 TEST_F(WebDatabaseMigrationTest
, MigrateVersion50ToCurrent
) {
2164 ASSERT_NO_FATAL_FAILURE(
2165 LoadDatabase(FILE_PATH_LITERAL("version_50.sql")));
2167 // Verify pre-conditions. These are expectations for version 50 of the
2170 sql::Connection connection
;
2171 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2172 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2174 sql::MetaTable meta_table
;
2175 ASSERT_TRUE(meta_table
.Init(&connection
, 50, 50));
2177 ASSERT_FALSE(connection
.DoesColumnExist("keywords", "image_url"));
2178 ASSERT_FALSE(connection
.DoesColumnExist("keywords",
2179 "search_url_post_params"));
2180 ASSERT_FALSE(connection
.DoesColumnExist("keywords",
2181 "suggest_url_post_params"));
2182 ASSERT_FALSE(connection
.DoesColumnExist("keywords",
2183 "instant_url_post_params"));
2184 ASSERT_FALSE(connection
.DoesColumnExist("keywords",
2185 "image_url_post_params"));
2190 // Verify post-conditions. These are expectations for current version of the
2193 sql::Connection connection
;
2194 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2195 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2198 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2200 // New columns should have been created.
2201 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "image_url"));
2202 EXPECT_TRUE(connection
.DoesColumnExist("keywords",
2203 "search_url_post_params"));
2204 EXPECT_TRUE(connection
.DoesColumnExist("keywords",
2205 "suggest_url_post_params"));
2206 EXPECT_TRUE(connection
.DoesColumnExist("keywords",
2207 "instant_url_post_params"));
2208 EXPECT_TRUE(connection
.DoesColumnExist("keywords",
2209 "image_url_post_params"));
2213 // Tests that the column |new_tab_url| is added to the keyword table schema for
2214 // a version 52 database.
2215 TEST_F(WebDatabaseMigrationTest
, MigrateVersion52ToCurrent
) {
2216 ASSERT_NO_FATAL_FAILURE(
2217 LoadDatabase(FILE_PATH_LITERAL("version_52.sql")));
2219 // Verify pre-conditions. These are expectations for version 52 of the
2222 sql::Connection connection
;
2223 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2224 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2226 sql::MetaTable meta_table
;
2227 ASSERT_TRUE(meta_table
.Init(&connection
, 52, 52));
2229 ASSERT_FALSE(connection
.DoesColumnExist("keywords", "new_tab_url"));
2234 // Verify post-conditions. These are expectations for current version of the
2237 sql::Connection connection
;
2238 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2239 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2242 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2244 // New columns should have been created.
2245 EXPECT_TRUE(connection
.DoesColumnExist("keywords", "new_tab_url"));
2249 // Tests that for a version 54 database,
2250 // (a) The street_address, dependent_locality, and sorting_code columns are
2251 // added to the autofill_profiles table schema.
2252 // (b) The address_line1, address_line2, and country columns are dropped from
2253 // the autofill_profiles table schema.
2254 // (c) The type column is dropped from the autofill_profile_phones schema.
2255 TEST_F(WebDatabaseMigrationTest
, MigrateVersion53ToCurrent
) {
2256 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_53.sql")));
2258 // Verify pre-conditions. These are expectations for version 53 of the
2261 sql::Connection connection
;
2262 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2265 connection
.DoesColumnExist("autofill_profiles", "address_line_1"));
2267 connection
.DoesColumnExist("autofill_profiles", "address_line_2"));
2268 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profiles", "country"));
2270 connection
.DoesColumnExist("autofill_profiles", "street_address"));
2272 connection
.DoesColumnExist("autofill_profiles", "dependent_locality"));
2274 connection
.DoesColumnExist("autofill_profiles", "sorting_code"));
2275 EXPECT_TRUE(connection
.DoesColumnExist("autofill_profile_phones", "type"));
2280 // Verify post-conditions. These are expectations for current version of the
2283 sql::Connection connection
;
2284 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2285 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2288 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2290 // Columns should have been added and removed appropriately.
2292 connection
.DoesColumnExist("autofill_profiles", "address_line1"));
2294 connection
.DoesColumnExist("autofill_profiles", "address_line2"));
2295 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profiles", "country"));
2297 connection
.DoesColumnExist("autofill_profiles", "street_address"));
2299 connection
.DoesColumnExist("autofill_profiles", "dependent_locality"));
2301 connection
.DoesColumnExist("autofill_profiles", "sorting_code"));
2302 EXPECT_FALSE(connection
.DoesColumnExist("autofill_profile_phones", "type"));
2304 // Data should have been preserved.
2305 sql::Statement
s_profiles(
2306 connection
.GetUniqueStatement(
2307 "SELECT guid, company_name, street_address, dependent_locality,"
2308 " city, state, zipcode, sorting_code, country_code, date_modified,"
2310 "FROM autofill_profiles"));
2312 // Address lines 1 and 2.
2313 ASSERT_TRUE(s_profiles
.Step());
2314 EXPECT_EQ("00000000-0000-0000-0000-000000000001",
2315 s_profiles
.ColumnString(0));
2316 EXPECT_EQ(ASCIIToUTF16("Google, Inc."), s_profiles
.ColumnString16(1));
2317 EXPECT_EQ(ASCIIToUTF16("1950 Charleston Rd.\n"
2319 s_profiles
.ColumnString16(2));
2320 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(3));
2321 EXPECT_EQ(ASCIIToUTF16("Mountain View"), s_profiles
.ColumnString16(4));
2322 EXPECT_EQ(ASCIIToUTF16("CA"), s_profiles
.ColumnString16(5));
2323 EXPECT_EQ(ASCIIToUTF16("94043"), s_profiles
.ColumnString16(6));
2324 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(7));
2325 EXPECT_EQ(ASCIIToUTF16("US"), s_profiles
.ColumnString16(8));
2326 EXPECT_EQ(1386046731, s_profiles
.ColumnInt(9));
2327 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles
.ColumnString16(10));
2329 // Only address line 1.
2330 ASSERT_TRUE(s_profiles
.Step());
2331 EXPECT_EQ("00000000-0000-0000-0000-000000000002",
2332 s_profiles
.ColumnString(0));
2333 EXPECT_EQ(ASCIIToUTF16("Google!"), s_profiles
.ColumnString16(1));
2334 EXPECT_EQ(ASCIIToUTF16("1600 Amphitheatre Pkwy."),
2335 s_profiles
.ColumnString16(2));
2336 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(3));
2337 EXPECT_EQ(ASCIIToUTF16("Mtn. View"), s_profiles
.ColumnString16(4));
2338 EXPECT_EQ(ASCIIToUTF16("California"), s_profiles
.ColumnString16(5));
2339 EXPECT_EQ(ASCIIToUTF16("94043-1234"), s_profiles
.ColumnString16(6));
2340 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(7));
2341 EXPECT_EQ(ASCIIToUTF16("US"), s_profiles
.ColumnString16(8));
2342 EXPECT_EQ(1386046800, s_profiles
.ColumnInt(9));
2343 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles
.ColumnString16(10));
2345 // Only address line 2.
2346 ASSERT_TRUE(s_profiles
.Step());
2347 EXPECT_EQ("00000000-0000-0000-0000-000000000003",
2348 s_profiles
.ColumnString(0));
2349 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(1));
2350 EXPECT_EQ(ASCIIToUTF16("\nOnly line 2???"), s_profiles
.ColumnString16(2));
2351 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(3));
2352 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(4));
2353 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(5));
2354 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(6));
2355 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(7));
2356 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(8));
2357 EXPECT_EQ(1386046834, s_profiles
.ColumnInt(9));
2358 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles
.ColumnString16(10));
2360 // No address lines.
2361 ASSERT_TRUE(s_profiles
.Step());
2362 EXPECT_EQ("00000000-0000-0000-0000-000000000004",
2363 s_profiles
.ColumnString(0));
2364 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(1));
2365 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(2));
2366 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(3));
2367 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(4));
2368 EXPECT_EQ(ASCIIToUTF16("Texas"), s_profiles
.ColumnString16(5));
2369 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(6));
2370 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(7));
2371 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(8));
2372 EXPECT_EQ(1386046847, s_profiles
.ColumnInt(9));
2373 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles
.ColumnString16(10));
2375 // That should be it.
2376 EXPECT_FALSE(s_profiles
.Step());
2378 // Verify the phone number data as well.
2379 sql::Statement
s_phones(
2380 connection
.GetUniqueStatement(
2381 "SELECT guid, number FROM autofill_profile_phones"));
2383 ASSERT_TRUE(s_phones
.Step());
2384 EXPECT_EQ("00000000-0000-0000-0000-000000000001", s_phones
.ColumnString(0));
2385 EXPECT_EQ(ASCIIToUTF16("1.800.555.1234"), s_phones
.ColumnString16(1));
2387 ASSERT_TRUE(s_phones
.Step());
2388 EXPECT_EQ("00000000-0000-0000-0000-000000000001", s_phones
.ColumnString(0));
2389 EXPECT_EQ(ASCIIToUTF16("+1 (800) 555-4321"), s_phones
.ColumnString16(1));
2391 ASSERT_TRUE(s_phones
.Step());
2392 EXPECT_EQ("00000000-0000-0000-0000-000000000002", s_phones
.ColumnString(0));
2393 EXPECT_EQ(base::string16(), s_phones
.ColumnString16(1));
2395 ASSERT_TRUE(s_phones
.Step());
2396 EXPECT_EQ("00000000-0000-0000-0000-000000000003", s_phones
.ColumnString(0));
2397 EXPECT_EQ(ASCIIToUTF16("6505557890"), s_phones
.ColumnString16(1));
2399 ASSERT_TRUE(s_phones
.Step());
2400 EXPECT_EQ("00000000-0000-0000-0000-000000000004", s_phones
.ColumnString(0));
2401 EXPECT_EQ(base::string16(), s_phones
.ColumnString16(1));
2403 EXPECT_FALSE(s_phones
.Step());
2407 // Tests that migrating from version 54 to version 55 drops the autofill_dates
2408 // table, and merges the appropriate dates into the autofill table.
2409 TEST_F(WebDatabaseMigrationTest
, MigrateVersion54ToCurrent
) {
2410 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_54.sql")));
2412 // Verify pre-conditions. These are expectations for version 54 of the
2415 sql::Connection connection
;
2416 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2418 EXPECT_TRUE(connection
.DoesTableExist("autofill_dates"));
2419 EXPECT_FALSE(connection
.DoesColumnExist("autofill", "date_created"));
2420 EXPECT_FALSE(connection
.DoesColumnExist("autofill", "date_last_used"));
2422 // Verify the incoming data.
2423 sql::Statement
s_autofill(connection
.GetUniqueStatement(
2424 "SELECT name, value, value_lower, pair_id, count FROM autofill"));
2425 sql::Statement
s_dates(connection
.GetUniqueStatement(
2426 "SELECT pair_id, date_created FROM autofill_dates"));
2428 // An entry with one timestamp.
2429 ASSERT_TRUE(s_autofill
.Step());
2430 EXPECT_EQ(ASCIIToUTF16("Name"), s_autofill
.ColumnString16(0));
2431 EXPECT_EQ(ASCIIToUTF16("John Doe"), s_autofill
.ColumnString16(1));
2432 EXPECT_EQ(ASCIIToUTF16("john doe"), s_autofill
.ColumnString16(2));
2433 EXPECT_EQ(10, s_autofill
.ColumnInt(3));
2434 EXPECT_EQ(1, s_autofill
.ColumnInt(4));
2435 ASSERT_TRUE(s_dates
.Step());
2436 EXPECT_EQ(10, s_dates
.ColumnInt(0));
2437 EXPECT_EQ(1384299100, s_dates
.ColumnInt64(1));
2439 // Another entry with one timestamp, differing from the previous one in case
2441 ASSERT_TRUE(s_autofill
.Step());
2442 EXPECT_EQ(ASCIIToUTF16("Name"), s_autofill
.ColumnString16(0));
2443 EXPECT_EQ(ASCIIToUTF16("john doe"), s_autofill
.ColumnString16(1));
2444 EXPECT_EQ(ASCIIToUTF16("john doe"), s_autofill
.ColumnString16(2));
2445 EXPECT_EQ(11, s_autofill
.ColumnInt(3));
2446 EXPECT_EQ(1, s_autofill
.ColumnInt(4));
2447 ASSERT_TRUE(s_dates
.Step());
2448 EXPECT_EQ(11, s_dates
.ColumnInt(0));
2449 EXPECT_EQ(1384299200, s_dates
.ColumnInt64(1));
2451 // An entry with two timestamps (with count > 2; this is realistic).
2452 ASSERT_TRUE(s_autofill
.Step());
2453 EXPECT_EQ(ASCIIToUTF16("Email"), s_autofill
.ColumnString16(0));
2454 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s_autofill
.ColumnString16(1));
2455 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s_autofill
.ColumnString16(2));
2456 EXPECT_EQ(20, s_autofill
.ColumnInt(3));
2457 EXPECT_EQ(3, s_autofill
.ColumnInt(4));
2458 ASSERT_TRUE(s_dates
.Step());
2459 EXPECT_EQ(20, s_dates
.ColumnInt(0));
2460 EXPECT_EQ(1384299300, s_dates
.ColumnInt64(1));
2461 ASSERT_TRUE(s_dates
.Step());
2462 EXPECT_EQ(20, s_dates
.ColumnInt(0));
2463 EXPECT_EQ(1384299301, s_dates
.ColumnInt64(1));
2465 // An entry with more than two timestamps, which are stored out of order.
2466 ASSERT_TRUE(s_autofill
.Step());
2467 EXPECT_EQ(ASCIIToUTF16("Email"), s_autofill
.ColumnString16(0));
2468 EXPECT_EQ(ASCIIToUTF16("jane.doe@example.org"),
2469 s_autofill
.ColumnString16(1));
2470 EXPECT_EQ(ASCIIToUTF16("jane.doe@example.org"),
2471 s_autofill
.ColumnString16(2));
2472 EXPECT_EQ(21, s_autofill
.ColumnInt(3));
2473 EXPECT_EQ(4, s_autofill
.ColumnInt(4));
2474 ASSERT_TRUE(s_dates
.Step());
2475 EXPECT_EQ(21, s_dates
.ColumnInt(0));
2476 EXPECT_EQ(1384299401, s_dates
.ColumnInt64(1));
2477 ASSERT_TRUE(s_dates
.Step());
2478 EXPECT_EQ(21, s_dates
.ColumnInt(0));
2479 EXPECT_EQ(1384299400, s_dates
.ColumnInt64(1));
2480 ASSERT_TRUE(s_dates
.Step());
2481 EXPECT_EQ(21, s_dates
.ColumnInt(0));
2482 EXPECT_EQ(1384299403, s_dates
.ColumnInt64(1));
2483 ASSERT_TRUE(s_dates
.Step());
2484 EXPECT_EQ(21, s_dates
.ColumnInt(0));
2485 EXPECT_EQ(1384299402, s_dates
.ColumnInt64(1));
2487 // No more entries expected.
2488 ASSERT_FALSE(s_autofill
.Step());
2489 ASSERT_FALSE(s_dates
.Step());
2494 // Verify post-conditions. These are expectations for current version of the
2497 sql::Connection connection
;
2498 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2499 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2502 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2504 // The autofill_dates table should have been dropped, and its columns should
2505 // have been migrated to the autofill table.
2506 EXPECT_FALSE(connection
.DoesTableExist("autofill_dates"));
2507 EXPECT_TRUE(connection
.DoesColumnExist("autofill", "date_created"));
2508 EXPECT_TRUE(connection
.DoesColumnExist("autofill", "date_last_used"));
2510 // Data should have been preserved. Note that it appears out of order
2511 // relative to the previous table, as it's been alphabetized. That's ok.
2513 connection
.GetUniqueStatement(
2514 "SELECT name, value, value_lower, date_created, date_last_used,"
2517 "ORDER BY name, value ASC"));
2519 // "jane.doe@example.org": Timestamps should be parsed correctly, and only
2520 // the first and last should be kept.
2521 ASSERT_TRUE(s
.Step());
2522 EXPECT_EQ(ASCIIToUTF16("Email"), s
.ColumnString16(0));
2523 EXPECT_EQ(ASCIIToUTF16("jane.doe@example.org"), s
.ColumnString16(1));
2524 EXPECT_EQ(ASCIIToUTF16("jane.doe@example.org"), s
.ColumnString16(2));
2525 EXPECT_EQ(1384299400, s
.ColumnInt64(3));
2526 EXPECT_EQ(1384299403, s
.ColumnInt64(4));
2527 EXPECT_EQ(4, s
.ColumnInt(5));
2529 // "jane@example.com": Timestamps should be parsed correctly.
2530 ASSERT_TRUE(s
.Step());
2531 EXPECT_EQ(ASCIIToUTF16("Email"), s
.ColumnString16(0));
2532 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s
.ColumnString16(1));
2533 EXPECT_EQ(ASCIIToUTF16("jane@example.com"), s
.ColumnString16(2));
2534 EXPECT_EQ(1384299300, s
.ColumnInt64(3));
2535 EXPECT_EQ(1384299301, s
.ColumnInt64(4));
2536 EXPECT_EQ(3, s
.ColumnInt(5));
2538 // "John Doe": The single timestamp should be assigned as both the creation
2539 // and the last use timestamp.
2540 ASSERT_TRUE(s
.Step());
2541 EXPECT_EQ(ASCIIToUTF16("Name"), s
.ColumnString16(0));
2542 EXPECT_EQ(ASCIIToUTF16("John Doe"), s
.ColumnString16(1));
2543 EXPECT_EQ(ASCIIToUTF16("john doe"), s
.ColumnString16(2));
2544 EXPECT_EQ(1384299100, s
.ColumnInt64(3));
2545 EXPECT_EQ(1384299100, s
.ColumnInt64(4));
2546 EXPECT_EQ(1, s
.ColumnInt(5));
2548 // "john doe": Should not be merged with "John Doe" (case-sensitivity).
2549 ASSERT_TRUE(s
.Step());
2550 EXPECT_EQ(ASCIIToUTF16("Name"), s
.ColumnString16(0));
2551 EXPECT_EQ(ASCIIToUTF16("john doe"), s
.ColumnString16(1));
2552 EXPECT_EQ(ASCIIToUTF16("john doe"), s
.ColumnString16(2));
2553 EXPECT_EQ(1384299200, s
.ColumnInt64(3));
2554 EXPECT_EQ(1384299200, s
.ColumnInt64(4));
2555 EXPECT_EQ(1, s
.ColumnInt(5));
2557 // No more entries expected.
2558 ASSERT_FALSE(s
.Step());
2562 // Tests that migrating from version 55 to version 56 adds the language_code
2563 // column to autofill_profiles table.
2564 TEST_F(WebDatabaseMigrationTest
, MigrateVersion55ToCurrent
) {
2565 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_55.sql")));
2567 // Verify pre-conditions. These are expectations for version 55 of the
2570 sql::Connection connection
;
2571 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2572 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2575 connection
.DoesColumnExist("autofill_profiles", "language_code"));
2580 // Verify post-conditions. These are expectations for current version of the
2583 sql::Connection connection
;
2584 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2585 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2588 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2590 // The language_code column should have been added to autofill_profiles
2593 connection
.DoesColumnExist("autofill_profiles", "language_code"));
2595 // Data should have been preserved. Language code should have been set to
2597 sql::Statement
s_profiles(
2598 connection
.GetUniqueStatement(
2599 "SELECT guid, company_name, street_address, dependent_locality,"
2600 " city, state, zipcode, sorting_code, country_code, date_modified,"
2601 " origin, language_code "
2602 "FROM autofill_profiles"));
2604 ASSERT_TRUE(s_profiles
.Step());
2605 EXPECT_EQ("00000000-0000-0000-0000-000000000001",
2606 s_profiles
.ColumnString(0));
2607 EXPECT_EQ(ASCIIToUTF16("Google Inc"), s_profiles
.ColumnString16(1));
2608 EXPECT_EQ(ASCIIToUTF16("340 Main St"),
2609 s_profiles
.ColumnString16(2));
2610 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(3));
2611 EXPECT_EQ(ASCIIToUTF16("Los Angeles"), s_profiles
.ColumnString16(4));
2612 EXPECT_EQ(ASCIIToUTF16("CA"), s_profiles
.ColumnString16(5));
2613 EXPECT_EQ(ASCIIToUTF16("90291"), s_profiles
.ColumnString16(6));
2614 EXPECT_EQ(base::string16(), s_profiles
.ColumnString16(7));
2615 EXPECT_EQ(ASCIIToUTF16("US"), s_profiles
.ColumnString16(8));
2616 EXPECT_EQ(1395948829, s_profiles
.ColumnInt(9));
2617 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles
.ColumnString16(10));
2618 EXPECT_EQ(std::string(), s_profiles
.ColumnString(11));
2620 // No more entries expected.
2621 ASSERT_FALSE(s_profiles
.Step());
2625 // Tests that migrating from version 56 to version 57 adds the full_name
2626 // column to autofill_profile_names table.
2627 TEST_F(WebDatabaseMigrationTest
, MigrateVersion56ToCurrent
) {
2628 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_56.sql")));
2630 // Verify pre-conditions. These are expectations for version 56 of the
2633 sql::Connection connection
;
2634 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2635 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2638 connection
.DoesColumnExist("autofill_profile_names", "full_name"));
2640 // Verify the starting data.
2641 sql::Statement
s_names(
2642 connection
.GetUniqueStatement(
2643 "SELECT guid, first_name, middle_name, last_name "
2644 "FROM autofill_profile_names"));
2645 ASSERT_TRUE(s_names
.Step());
2646 EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names
.ColumnString(0));
2647 EXPECT_EQ(ASCIIToUTF16("Jon"), s_names
.ColumnString16(1));
2648 EXPECT_EQ(base::string16(), s_names
.ColumnString16(2));
2649 EXPECT_EQ(ASCIIToUTF16("Smith"), s_names
.ColumnString16(3));
2654 // Verify post-conditions. These are expectations for current version of the
2657 sql::Connection connection
;
2658 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2659 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2662 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2664 // The full_name column should have been added to autofill_profile_names
2667 connection
.DoesColumnExist("autofill_profile_names", "full_name"));
2669 // Data should have been preserved. Full name should have been set to the
2671 sql::Statement
s_names(
2672 connection
.GetUniqueStatement(
2673 "SELECT guid, first_name, middle_name, last_name, full_name "
2674 "FROM autofill_profile_names"));
2676 ASSERT_TRUE(s_names
.Step());
2677 EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names
.ColumnString(0));
2678 EXPECT_EQ(ASCIIToUTF16("Jon"), s_names
.ColumnString16(1));
2679 EXPECT_EQ(base::string16(), s_names
.ColumnString16(2));
2680 EXPECT_EQ(ASCIIToUTF16("Smith"), s_names
.ColumnString16(3));
2681 EXPECT_EQ(base::string16(), s_names
.ColumnString16(4));
2683 // No more entries expected.
2684 ASSERT_FALSE(s_names
.Step());
2688 // Tests that migrating from version 57 to version 58 drops the web_intents and
2690 TEST_F(WebDatabaseMigrationTest
, MigrateVersion57ToCurrent
) {
2691 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_57.sql")));
2693 // Verify pre-conditions. These are expectations for version 57 of the
2696 sql::Connection connection
;
2697 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2698 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2700 EXPECT_TRUE(connection
.DoesTableExist("web_apps"));
2701 EXPECT_TRUE(connection
.DoesTableExist("web_app_icons"));
2702 EXPECT_TRUE(connection
.DoesTableExist("web_intents"));
2703 EXPECT_TRUE(connection
.DoesTableExist("web_intents_defaults"));
2708 // Verify post-conditions. These are expectations for current version of the
2711 sql::Connection connection
;
2712 ASSERT_TRUE(connection
.Open(GetDatabasePath()));
2713 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection
));
2716 EXPECT_EQ(kCurrentTestedVersionNumber
, VersionFromConnection(&connection
));
2718 EXPECT_FALSE(connection
.DoesTableExist("web_apps"));
2719 EXPECT_FALSE(connection
.DoesTableExist("web_app_icons"));
2720 EXPECT_FALSE(connection
.DoesTableExist("web_intents"));
2721 EXPECT_FALSE(connection
.DoesTableExist("web_intents_defaults"));