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_apps")); |
Peter Kasting
2014/07/15 19:15:04
Nit: Add a comment about these similar to the comm
Cait (Slow)
2014/07/17 15:35:50
Done.
| |
316 EXPECT_TRUE(connection.DoesTableExist("web_apps")); | 310 EXPECT_FALSE(connection.DoesTableExist("web_app_icons")); |
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 1542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1871 EXPECT_FALSE(connection.DoesColumnExist("keywords", | 1865 EXPECT_FALSE(connection.DoesColumnExist("keywords", |
1872 "autogenerate_keyword")); | 1866 "autogenerate_keyword")); |
1873 EXPECT_FALSE(connection.DoesColumnExist("keywords", "logo_id")); | 1867 EXPECT_FALSE(connection.DoesColumnExist("keywords", "logo_id")); |
1874 | 1868 |
1875 // Backup data should have been removed. | 1869 // Backup data should have been removed. |
1876 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table)); | 1870 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table)); |
1877 } | 1871 } |
1878 } | 1872 } |
1879 | 1873 |
1880 // Tests that the web_intents and web_intents_defaults tables are | 1874 // Tests that the web_intents and web_intents_defaults tables are |
1881 // modified to include "scheme" columns. | 1875 // modified to include "scheme" columns. |
Peter Kasting
2014/07/15 19:15:04
I disagree with Scott that these two tests should
Cait (Slow)
2014/07/17 15:35:50
Done.
| |
1882 TEST_F(WebDatabaseMigrationTest, MigrateVersion45ToCurrent) { | 1876 TEST_F(WebDatabaseMigrationTest, MigrateVersion45ToCurrent) { |
1883 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_45.sql"))); | 1877 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_45.sql"))); |
1884 | 1878 |
1885 // Verify pre-conditions. These are expectations for version 45 of the | 1879 // Verify pre-conditions. These are expectations for version 45 of the |
1886 // database. | 1880 // database. |
1887 { | 1881 { |
1888 sql::Connection connection; | 1882 sql::Connection connection; |
1889 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 1883 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
1890 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 1884 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
1891 | 1885 |
(...skipping 16 matching lines...) Expand all Loading... | |
1908 | 1902 |
1909 // Check version. | 1903 // Check version. |
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. | |
1919 EXPECT_TRUE(connection.DoesColumnExist("web_intents", "scheme")); | |
1920 EXPECT_TRUE(connection.DoesColumnExist("web_intents_defaults", "scheme")); | |
1921 | |
1922 // Verify existing user data was copied. | |
1923 sql::Statement s1( | |
1924 connection.GetUniqueStatement("SELECT * FROM web_intents")); | |
1925 | |
1926 ASSERT_TRUE(s1.Step()); | |
1927 EXPECT_EQ("http://poodles.com/fuzzer", s1.ColumnString(0)); | |
1928 EXPECT_EQ(ASCIIToUTF16("fuzz"), s1.ColumnString16(1)); | |
1929 EXPECT_EQ(ASCIIToUTF16("poodle/*"), s1.ColumnString16(2)); | |
1930 EXPECT_EQ(ASCIIToUTF16("Poodle Fuzzer"), s1.ColumnString16(3)); | |
1931 EXPECT_EQ(ASCIIToUTF16("window"), s1.ColumnString16(4)); | |
1932 EXPECT_EQ(ASCIIToUTF16(""), s1.ColumnString16(5)); | |
1933 ASSERT_FALSE(s1.Step()); | |
1934 | |
1935 // Now we want to verify existing user data was copied | |
1936 sql::Statement s2( | |
1937 connection.GetUniqueStatement("SELECT * FROM web_intents_defaults")); | |
1938 | |
1939 ASSERT_TRUE(s2.Step()); | |
1940 EXPECT_EQ("fuzz", s2.ColumnString(0)); | |
1941 EXPECT_EQ(ASCIIToUTF16("poodle/*"), s2.ColumnString16(1)); | |
1942 EXPECT_EQ(ASCIIToUTF16(""), s2.ColumnString16(2)); | |
1943 EXPECT_EQ(0, s2.ColumnInt(3)); | |
1944 EXPECT_EQ(0, s2.ColumnInt(4)); | |
1945 EXPECT_EQ(ASCIIToUTF16("http://poodles.com/fuzzer"), s2.ColumnString16(5)); | |
1946 EXPECT_EQ(ASCIIToUTF16(""), s2.ColumnString16(6)); | |
1947 ASSERT_FALSE(s2.Step()); | |
1948 | |
1949 // finally ensure the migration code cleaned up after itself | 1912 // finally ensure the migration code cleaned up after itself |
1950 EXPECT_FALSE(connection.DoesTableExist("old_web_intents")); | 1913 EXPECT_FALSE(connection.DoesTableExist("web_intents")); |
1951 EXPECT_FALSE(connection.DoesTableExist("old_web_intents_defaults")); | 1914 EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults")); |
1952 } | 1915 } |
1953 } | 1916 } |
1954 | 1917 |
1955 // Tests that the web_intents and web_intents_defaults tables are | 1918 // Tests that the web_intents and web_intents_defaults tables are |
1956 // modified to include "scheme" columns. | 1919 // modified to include "scheme" columns. |
1957 TEST_F(WebDatabaseMigrationTest, MigrateVersion45InvalidToCurrent) { | 1920 TEST_F(WebDatabaseMigrationTest, MigrateVersion45InvalidToCurrent) { |
1958 ASSERT_NO_FATAL_FAILURE( | 1921 ASSERT_NO_FATAL_FAILURE( |
1959 LoadDatabase(FILE_PATH_LITERAL("version_45_invalid.sql"))); | 1922 LoadDatabase(FILE_PATH_LITERAL("version_45_invalid.sql"))); |
1960 | 1923 |
1961 // Verify pre-conditions. These are expectations for version 45 of the | 1924 // Verify pre-conditions. These are expectations for version 45 of the |
(...skipping 22 matching lines...) Expand all Loading... | |
1984 | 1947 |
1985 // Check version. | 1948 // Check version. |
1986 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 1949 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
1987 | 1950 |
1988 sql::MetaTable meta_table; | 1951 sql::MetaTable meta_table; |
1989 ASSERT_TRUE(meta_table.Init( | 1952 ASSERT_TRUE(meta_table.Init( |
1990 &connection, | 1953 &connection, |
1991 kCurrentTestedVersionNumber, | 1954 kCurrentTestedVersionNumber, |
1992 kCurrentTestedVersionNumber)); | 1955 kCurrentTestedVersionNumber)); |
1993 | 1956 |
1994 // A new "scheme" column should have been added to each web_intents table. | 1957 EXPECT_FALSE(connection.DoesTableExist("web_intents")); |
1995 EXPECT_TRUE(connection.DoesColumnExist("web_intents", "scheme")); | 1958 EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults")); |
1996 EXPECT_TRUE(connection.DoesColumnExist("web_intents_defaults", "scheme")); | |
1997 | |
1998 // Verify existing user data was copied. | |
1999 sql::Statement s1( | |
2000 connection.GetUniqueStatement("SELECT * FROM web_intents")); | |
2001 | |
2002 ASSERT_FALSE(s1.Step()); // Basically should be empty at this point. | |
2003 | |
2004 // Now we want to verify existing user data was copied | |
2005 sql::Statement s2( | |
2006 connection.GetUniqueStatement("SELECT * FROM web_intents_defaults")); | |
2007 | |
2008 // We were able to create the new tables, but unable to copy any data | |
2009 // Given the initial bad state of the tables. | |
2010 ASSERT_FALSE(s2.Step()); | |
2011 | |
2012 // Finally ensure the migration code cleaned up after itself. | |
2013 EXPECT_FALSE(connection.DoesTableExist("old_web_intents")); | |
2014 EXPECT_FALSE(connection.DoesTableExist("old_web_intents_defaults")); | |
2015 } | 1959 } |
2016 } | 1960 } |
2017 | 1961 |
2018 // Check that current version is forced to compatible version before migration, | 1962 // Check that current version is forced to compatible version before migration, |
2019 // if the former is smaller. | 1963 // if the former is smaller. |
2020 TEST_F(WebDatabaseMigrationTest, MigrateVersion45CompatibleToCurrent) { | 1964 TEST_F(WebDatabaseMigrationTest, MigrateVersion45CompatibleToCurrent) { |
2021 ASSERT_NO_FATAL_FAILURE( | 1965 ASSERT_NO_FATAL_FAILURE( |
2022 LoadDatabase(FILE_PATH_LITERAL("version_45_compatible.sql"))); | 1966 LoadDatabase(FILE_PATH_LITERAL("version_45_compatible.sql"))); |
2023 | 1967 |
2024 // Verify pre-conditions. These are expectations for version 45 of the | 1968 // Verify pre-conditions. These are expectations for version 45 of the |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2726 EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names.ColumnString(0)); | 2670 EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names.ColumnString(0)); |
2727 EXPECT_EQ(ASCIIToUTF16("Jon"), s_names.ColumnString16(1)); | 2671 EXPECT_EQ(ASCIIToUTF16("Jon"), s_names.ColumnString16(1)); |
2728 EXPECT_EQ(base::string16(), s_names.ColumnString16(2)); | 2672 EXPECT_EQ(base::string16(), s_names.ColumnString16(2)); |
2729 EXPECT_EQ(ASCIIToUTF16("Smith"), s_names.ColumnString16(3)); | 2673 EXPECT_EQ(ASCIIToUTF16("Smith"), s_names.ColumnString16(3)); |
2730 EXPECT_EQ(base::string16(), s_names.ColumnString16(4)); | 2674 EXPECT_EQ(base::string16(), s_names.ColumnString16(4)); |
2731 | 2675 |
2732 // No more entries expected. | 2676 // No more entries expected. |
2733 ASSERT_FALSE(s_names.Step()); | 2677 ASSERT_FALSE(s_names.Step()); |
2734 } | 2678 } |
2735 } | 2679 } |
2680 | |
2681 // Tests that migrating from version 57 to version 58 drops the web_intents and | |
2682 // web_apps tables. | |
2683 TEST_F(WebDatabaseMigrationTest, MigrateVersion57ToCurrent) { | |
2684 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_57.sql"))); | |
2685 | |
2686 // Verify pre-conditions. These are expectations for version 57 of the | |
2687 // database. | |
2688 { | |
2689 sql::Connection connection; | |
2690 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
2691 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
2692 | |
2693 EXPECT_TRUE(connection.DoesTableExist("web_apps")); | |
2694 EXPECT_TRUE(connection.DoesTableExist("web_app_icons")); | |
2695 EXPECT_TRUE(connection.DoesTableExist("web_intents")); | |
2696 EXPECT_TRUE(connection.DoesTableExist("web_intents_defaults")); | |
2697 } | |
2698 | |
2699 DoMigration(); | |
2700 | |
2701 // Verify post-conditions. These are expectations for current version of the | |
2702 // database. | |
2703 { | |
2704 sql::Connection connection; | |
2705 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
2706 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
2707 | |
2708 // Check version. | |
2709 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | |
2710 | |
2711 EXPECT_FALSE(connection.DoesTableExist("web_apps")); | |
2712 EXPECT_FALSE(connection.DoesTableExist("web_app_icons")); | |
2713 EXPECT_FALSE(connection.DoesTableExist("web_intents")); | |
2714 EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults")); | |
2715 } | |
2716 } | |
OLD | NEW |