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