OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/webdata/web_apps_table.h" | |
20 #include "chrome/browser/webdata/web_intents_table.h" | |
21 #include "components/autofill/core/browser/autofill_country.h" | 19 #include "components/autofill/core/browser/autofill_country.h" |
22 #include "components/autofill/core/browser/autofill_profile.h" | 20 #include "components/autofill/core/browser/autofill_profile.h" |
23 #include "components/autofill/core/browser/autofill_type.h" | 21 #include "components/autofill/core/browser/autofill_type.h" |
24 #include "components/autofill/core/browser/credit_card.h" | 22 #include "components/autofill/core/browser/credit_card.h" |
25 #include "components/autofill/core/browser/webdata/autofill_change.h" | 23 #include "components/autofill/core/browser/webdata/autofill_change.h" |
26 #include "components/autofill/core/browser/webdata/autofill_entry.h" | 24 #include "components/autofill/core/browser/webdata/autofill_entry.h" |
27 #include "components/autofill/core/browser/webdata/autofill_table.h" | 25 #include "components/autofill/core/browser/webdata/autofill_table.h" |
28 #include "components/password_manager/core/browser/webdata/logins_table.h" | 26 #include "components/password_manager/core/browser/webdata/logins_table.h" |
29 #include "components/search_engines/keyword_table.h" | 27 #include "components/search_engines/keyword_table.h" |
30 #include "components/signin/core/browser/webdata/token_service_table.h" | 28 #include "components/signin/core/browser/webdata/token_service_table.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 // the current version. | 180 // the current version. |
183 void DoMigration() { | 181 void DoMigration() { |
184 // TODO(joi): This whole unit test file needs to stay in //chrome | 182 // TODO(joi): This whole unit test file needs to stay in //chrome |
185 // for now, as it needs to know about all the different table | 183 // for now, as it needs to know about all the different table |
186 // types. Once all webdata datatypes have been componentized, this | 184 // types. Once all webdata datatypes have been componentized, this |
187 // could move to components_unittests. | 185 // could move to components_unittests. |
188 AutofillTable autofill_table("en-US"); | 186 AutofillTable autofill_table("en-US"); |
189 KeywordTable keyword_table; | 187 KeywordTable keyword_table; |
190 LoginsTable logins_table; | 188 LoginsTable logins_table; |
191 TokenServiceTable token_service_table; | 189 TokenServiceTable token_service_table; |
192 WebAppsTable web_apps_table; | |
193 WebIntentsTable web_intents_table; | |
194 | 190 |
195 WebDatabase db; | 191 WebDatabase db; |
196 db.AddTable(&autofill_table); | 192 db.AddTable(&autofill_table); |
197 db.AddTable(&keyword_table); | 193 db.AddTable(&keyword_table); |
198 db.AddTable(&logins_table); | 194 db.AddTable(&logins_table); |
199 db.AddTable(&token_service_table); | 195 db.AddTable(&token_service_table); |
200 db.AddTable(&web_apps_table); | |
201 db.AddTable(&web_intents_table); | |
202 | 196 |
203 // This causes the migration to occur. | 197 // This causes the migration to occur. |
204 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); | 198 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
205 } | 199 } |
206 | 200 |
207 protected: | 201 protected: |
208 // Current tested version number. When adding a migration in | 202 // Current tested version number. When adding a migration in |
209 // |WebDatabase::MigrateOldVersionsAsNeeded()| and changing the version number | 203 // |WebDatabase::MigrateOldVersionsAsNeeded()| and changing the version number |
210 // |kCurrentVersionNumber| this value should change to reflect the new version | 204 // |kCurrentVersionNumber| this value should change to reflect the new version |
211 // number and a new migration test added below. | 205 // number and a new migration test added below. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 // > .output version_nn.sql | 243 // > .output version_nn.sql |
250 // > .dump | 244 // > .dump |
251 void LoadDatabase(const base::FilePath::StringType& file); | 245 void LoadDatabase(const base::FilePath::StringType& file); |
252 | 246 |
253 private: | 247 private: |
254 base::ScopedTempDir temp_dir_; | 248 base::ScopedTempDir temp_dir_; |
255 | 249 |
256 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); | 250 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); |
257 }; | 251 }; |
258 | 252 |
259 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 57; | 253 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 58; |
260 | 254 |
261 void WebDatabaseMigrationTest::LoadDatabase( | 255 void WebDatabaseMigrationTest::LoadDatabase( |
262 const base::FilePath::StringType& file) { | 256 const base::FilePath::StringType& file) { |
263 std::string contents; | 257 std::string contents; |
264 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); | 258 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); |
265 | 259 |
266 sql::Connection connection; | 260 sql::Connection connection; |
267 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 261 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
268 ASSERT_TRUE(connection.Execute(contents.data())); | 262 ASSERT_TRUE(connection.Execute(contents.data())); |
269 } | 263 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 // The autofill_dates table is obsolete. (It's been merged into the autofill | 299 // The autofill_dates table is obsolete. (It's been merged into the autofill |
306 // table.) | 300 // table.) |
307 EXPECT_FALSE(connection.DoesTableExist("autofill_dates")); | 301 EXPECT_FALSE(connection.DoesTableExist("autofill_dates")); |
308 EXPECT_TRUE(connection.DoesTableExist("autofill_profiles")); | 302 EXPECT_TRUE(connection.DoesTableExist("autofill_profiles")); |
309 EXPECT_TRUE(connection.DoesTableExist("credit_cards")); | 303 EXPECT_TRUE(connection.DoesTableExist("credit_cards")); |
310 EXPECT_TRUE(connection.DoesTableExist("keywords")); | 304 EXPECT_TRUE(connection.DoesTableExist("keywords")); |
311 // The logins table is obsolete. (We used to store saved passwords here.) | 305 // The logins table is obsolete. (We used to store saved passwords here.) |
312 EXPECT_FALSE(connection.DoesTableExist("logins")); | 306 EXPECT_FALSE(connection.DoesTableExist("logins")); |
313 EXPECT_TRUE(connection.DoesTableExist("meta")); | 307 EXPECT_TRUE(connection.DoesTableExist("meta")); |
314 EXPECT_TRUE(connection.DoesTableExist("token_service")); | 308 EXPECT_TRUE(connection.DoesTableExist("token_service")); |
315 EXPECT_TRUE(connection.DoesTableExist("web_app_icons")); | 309 EXPECT_FALSE(connection.DoesTableExist("web_app_icons")); |
316 EXPECT_TRUE(connection.DoesTableExist("web_apps")); | 310 EXPECT_FALSE(connection.DoesTableExist("web_apps")); |
317 EXPECT_TRUE(connection.DoesTableExist("web_intents")); | 311 EXPECT_FALSE(connection.DoesTableExist("web_intents")); |
318 EXPECT_TRUE(connection.DoesTableExist("web_intents_defaults")); | 312 EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults")); |
319 } | 313 } |
320 } | 314 } |
321 | 315 |
322 // Tests that absent Autofill tables do not create any problems when migrating | 316 // Tests that absent Autofill tables do not create any problems when migrating |
323 // from a DB written by the earliest publicly released version of Chrome. | 317 // from a DB written by the earliest publicly released version of Chrome. |
324 TEST_F(WebDatabaseMigrationTest, MigrateVersion20ToCurrent) { | 318 TEST_F(WebDatabaseMigrationTest, MigrateVersion20ToCurrent) { |
325 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_20.sql"))); | 319 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_20.sql"))); |
326 | 320 |
327 // Verify pre-conditions. | 321 // Verify pre-conditions. |
328 { | 322 { |
(...skipping 1581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1910 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 1904 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
1911 | 1905 |
1912 sql::MetaTable meta_table; | 1906 sql::MetaTable meta_table; |
1913 ASSERT_TRUE(meta_table.Init( | 1907 ASSERT_TRUE(meta_table.Init( |
1914 &connection, | 1908 &connection, |
1915 kCurrentTestedVersionNumber, | 1909 kCurrentTestedVersionNumber, |
1916 kCurrentTestedVersionNumber)); | 1910 kCurrentTestedVersionNumber)); |
1917 | 1911 |
1918 // A new "scheme" column should have been added to each web_intents table. | 1912 // A new "scheme" column should have been added to each web_intents table. |
1919 EXPECT_TRUE(connection.DoesColumnExist("web_intents", "scheme")); | 1913 EXPECT_TRUE(connection.DoesColumnExist("web_intents", "scheme")); |
1920 EXPECT_TRUE(connection.DoesColumnExist("web_intents_defaults", "scheme")); | 1914 EXPECT_TRUE(connection.DoesColumnExist("web_intents_defaults", "scheme")); |
Scott Hess - ex-Googler
2014/07/10 01:55:53
For instance, since this is testing migration to "
Peter Kasting
2014/07/10 17:50:47
I believe all the web_intents stuff is gone entire
Scott Hess - ex-Googler
2014/07/10 19:19:39
Yeah, if the data is being removed because it is s
Cait (Slow)
2014/07/14 23:09:45
To confirm, yes, the code that used these tables h
Scott Hess - ex-Googler
2014/07/14 23:27:53
OK, so my position:
1) have a test which tests th
| |
1921 | 1915 |
1922 // Verify existing user data was copied. | 1916 // Verify existing user data was copied. |
1923 sql::Statement s1( | 1917 sql::Statement s1( |
1924 connection.GetUniqueStatement("SELECT * FROM web_intents")); | 1918 connection.GetUniqueStatement("SELECT * FROM web_intents")); |
1925 | 1919 |
1926 ASSERT_TRUE(s1.Step()); | 1920 ASSERT_TRUE(s1.Step()); |
1927 EXPECT_EQ("http://poodles.com/fuzzer", s1.ColumnString(0)); | 1921 EXPECT_EQ("http://poodles.com/fuzzer", s1.ColumnString(0)); |
1928 EXPECT_EQ(ASCIIToUTF16("fuzz"), s1.ColumnString16(1)); | 1922 EXPECT_EQ(ASCIIToUTF16("fuzz"), s1.ColumnString16(1)); |
1929 EXPECT_EQ(ASCIIToUTF16("poodle/*"), s1.ColumnString16(2)); | 1923 EXPECT_EQ(ASCIIToUTF16("poodle/*"), s1.ColumnString16(2)); |
1930 EXPECT_EQ(ASCIIToUTF16("Poodle Fuzzer"), s1.ColumnString16(3)); | 1924 EXPECT_EQ(ASCIIToUTF16("Poodle Fuzzer"), s1.ColumnString16(3)); |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2726 EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names.ColumnString(0)); | 2720 EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names.ColumnString(0)); |
2727 EXPECT_EQ(ASCIIToUTF16("Jon"), s_names.ColumnString16(1)); | 2721 EXPECT_EQ(ASCIIToUTF16("Jon"), s_names.ColumnString16(1)); |
2728 EXPECT_EQ(base::string16(), s_names.ColumnString16(2)); | 2722 EXPECT_EQ(base::string16(), s_names.ColumnString16(2)); |
2729 EXPECT_EQ(ASCIIToUTF16("Smith"), s_names.ColumnString16(3)); | 2723 EXPECT_EQ(ASCIIToUTF16("Smith"), s_names.ColumnString16(3)); |
2730 EXPECT_EQ(base::string16(), s_names.ColumnString16(4)); | 2724 EXPECT_EQ(base::string16(), s_names.ColumnString16(4)); |
2731 | 2725 |
2732 // No more entries expected. | 2726 // No more entries expected. |
2733 ASSERT_FALSE(s_names.Step()); | 2727 ASSERT_FALSE(s_names.Step()); |
2734 } | 2728 } |
2735 } | 2729 } |
2730 | |
2731 // Tests that migrating from version 57 to version 58 drops the web_intents and | |
2732 // web_apps tables. | |
2733 TEST_F(WebDatabaseMigrationTest, MigrateVersion57ToCurrent) { | |
2734 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_57.sql"))); | |
2735 | |
2736 // Verify pre-conditions. These are expectations for version 57 of the | |
2737 // database. | |
2738 { | |
2739 sql::Connection connection; | |
2740 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
2741 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
2742 | |
2743 EXPECT_TRUE(connection.DoesTableExist("web_apps")); | |
2744 EXPECT_TRUE(connection.DoesTableExist("web_intents")); | |
2745 EXPECT_TRUE(connection.DoesTableExist("web_app_icons")); | |
Scott Hess - ex-Googler
2014/07/10 19:19:39
Order this above "web_intents", just because. Als
Cait (Slow)
2014/07/14 23:09:45
Done.
| |
2746 EXPECT_TRUE(connection.DoesTableExist("web_intents_defaults")); | |
2747 } | |
2748 | |
2749 DoMigration(); | |
2750 | |
2751 // Verify post-conditions. These are expectations for current version of the | |
2752 // database. | |
2753 { | |
2754 sql::Connection connection; | |
2755 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
2756 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
2757 | |
2758 // Check version. | |
2759 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | |
2760 | |
2761 EXPECT_FALSE(connection.DoesTableExist("web_apps")); | |
2762 EXPECT_FALSE(connection.DoesTableExist("web_intents")); | |
2763 EXPECT_FALSE(connection.DoesTableExist("web_app_icons")); | |
2764 EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults")); | |
2765 } | |
2766 } | |
OLD | NEW |