Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: components/webdata/common/web_database_migration_unittest.cc

Issue 382703002: Remove unused SQLLite tables from WebData (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 2 Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/webdata/common/web_database.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 // The web_apps and web_apps_icons tables are obsolete as of version 58.
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_app_icons"));
318 EXPECT_TRUE(connection.DoesTableExist("web_intents_defaults")); 312 // The web_intents and web_intents_defaults tables are obsolete as of
313 // version 58.
314 EXPECT_FALSE(connection.DoesTableExist("web_intents"));
315 EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults"));
319 } 316 }
320 } 317 }
321 318
322 // Tests that absent Autofill tables do not create any problems when migrating 319 // 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. 320 // from a DB written by the earliest publicly released version of Chrome.
324 TEST_F(WebDatabaseMigrationTest, MigrateVersion20ToCurrent) { 321 TEST_F(WebDatabaseMigrationTest, MigrateVersion20ToCurrent) {
325 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_20.sql"))); 322 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_20.sql")));
326 323
327 // Verify pre-conditions. 324 // Verify pre-conditions.
328 { 325 {
(...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 // Two columns should have been removed. 1867 // Two columns should have been removed.
1871 EXPECT_FALSE(connection.DoesColumnExist("keywords", 1868 EXPECT_FALSE(connection.DoesColumnExist("keywords",
1872 "autogenerate_keyword")); 1869 "autogenerate_keyword"));
1873 EXPECT_FALSE(connection.DoesColumnExist("keywords", "logo_id")); 1870 EXPECT_FALSE(connection.DoesColumnExist("keywords", "logo_id"));
1874 1871
1875 // Backup data should have been removed. 1872 // Backup data should have been removed.
1876 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table)); 1873 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table));
1877 } 1874 }
1878 } 1875 }
1879 1876
1880 // Tests that the web_intents and web_intents_defaults tables are 1877 // Previously, this tested that the web_intents and web_intents_defaults tables
1881 // modified to include "scheme" columns. 1878 // were modified to include "scheme" columns. Since the web_intents and
1879 // web_intents_defaults tables are now obsolete, this test checks to ensure that
1880 // they are properly removed.
1882 TEST_F(WebDatabaseMigrationTest, MigrateVersion45ToCurrent) { 1881 TEST_F(WebDatabaseMigrationTest, MigrateVersion45ToCurrent) {
1883 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_45.sql"))); 1882 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_45.sql")));
1884 1883
1885 // Verify pre-conditions. These are expectations for version 45 of the 1884 // Verify pre-conditions. These are expectations for version 45 of the
1886 // database. 1885 // database.
1887 { 1886 {
1888 sql::Connection connection; 1887 sql::Connection connection;
1889 ASSERT_TRUE(connection.Open(GetDatabasePath())); 1888 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1890 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); 1889 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1891 1890
(...skipping 16 matching lines...) Expand all
1908 1907
1909 // Check version. 1908 // Check version.
1910 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); 1909 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1911 1910
1912 sql::MetaTable meta_table; 1911 sql::MetaTable meta_table;
1913 ASSERT_TRUE(meta_table.Init( 1912 ASSERT_TRUE(meta_table.Init(
1914 &connection, 1913 &connection,
1915 kCurrentTestedVersionNumber, 1914 kCurrentTestedVersionNumber,
1916 kCurrentTestedVersionNumber)); 1915 kCurrentTestedVersionNumber));
1917 1916
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 1917 // finally ensure the migration code cleaned up after itself
1950 EXPECT_FALSE(connection.DoesTableExist("old_web_intents")); 1918 EXPECT_FALSE(connection.DoesTableExist("web_intents"));
1951 EXPECT_FALSE(connection.DoesTableExist("old_web_intents_defaults")); 1919 EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults"));
1952 } 1920 }
1953 } 1921 }
1954 1922
1955 // Tests that the web_intents and web_intents_defaults tables are 1923 // Previously, this tested that the web_intents and web_intents_defaults tables
1956 // modified to include "scheme" columns. 1924 // were modified to include "scheme" columns. Since the web_intents and
1925 // web_intents_defaults tables are now obsolete, this test checks to ensure that
1926 // they are properly removed.
1957 TEST_F(WebDatabaseMigrationTest, MigrateVersion45InvalidToCurrent) { 1927 TEST_F(WebDatabaseMigrationTest, MigrateVersion45InvalidToCurrent) {
1958 ASSERT_NO_FATAL_FAILURE( 1928 ASSERT_NO_FATAL_FAILURE(
1959 LoadDatabase(FILE_PATH_LITERAL("version_45_invalid.sql"))); 1929 LoadDatabase(FILE_PATH_LITERAL("version_45_invalid.sql")));
1960 1930
1961 // Verify pre-conditions. These are expectations for version 45 of the 1931 // Verify pre-conditions. These are expectations for version 45 of the
1962 // database. 1932 // database.
1963 { 1933 {
1964 sql::Connection connection; 1934 sql::Connection connection;
1965 ASSERT_TRUE(connection.Open(GetDatabasePath())); 1935 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1966 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); 1936 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
(...skipping 17 matching lines...) Expand all
1984 1954
1985 // Check version. 1955 // Check version.
1986 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); 1956 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1987 1957
1988 sql::MetaTable meta_table; 1958 sql::MetaTable meta_table;
1989 ASSERT_TRUE(meta_table.Init( 1959 ASSERT_TRUE(meta_table.Init(
1990 &connection, 1960 &connection,
1991 kCurrentTestedVersionNumber, 1961 kCurrentTestedVersionNumber,
1992 kCurrentTestedVersionNumber)); 1962 kCurrentTestedVersionNumber));
1993 1963
1994 // A new "scheme" column should have been added to each web_intents table. 1964 EXPECT_FALSE(connection.DoesTableExist("web_intents"));
1995 EXPECT_TRUE(connection.DoesColumnExist("web_intents", "scheme")); 1965 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 } 1966 }
2016 } 1967 }
2017 1968
2018 // Check that current version is forced to compatible version before migration, 1969 // Check that current version is forced to compatible version before migration,
2019 // if the former is smaller. 1970 // if the former is smaller.
2020 TEST_F(WebDatabaseMigrationTest, MigrateVersion45CompatibleToCurrent) { 1971 TEST_F(WebDatabaseMigrationTest, MigrateVersion45CompatibleToCurrent) {
2021 ASSERT_NO_FATAL_FAILURE( 1972 ASSERT_NO_FATAL_FAILURE(
2022 LoadDatabase(FILE_PATH_LITERAL("version_45_compatible.sql"))); 1973 LoadDatabase(FILE_PATH_LITERAL("version_45_compatible.sql")));
2023 1974
2024 // Verify pre-conditions. These are expectations for version 45 of the 1975 // Verify pre-conditions. These are expectations for version 45 of the
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
2726 EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names.ColumnString(0)); 2677 EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names.ColumnString(0));
2727 EXPECT_EQ(ASCIIToUTF16("Jon"), s_names.ColumnString16(1)); 2678 EXPECT_EQ(ASCIIToUTF16("Jon"), s_names.ColumnString16(1));
2728 EXPECT_EQ(base::string16(), s_names.ColumnString16(2)); 2679 EXPECT_EQ(base::string16(), s_names.ColumnString16(2));
2729 EXPECT_EQ(ASCIIToUTF16("Smith"), s_names.ColumnString16(3)); 2680 EXPECT_EQ(ASCIIToUTF16("Smith"), s_names.ColumnString16(3));
2730 EXPECT_EQ(base::string16(), s_names.ColumnString16(4)); 2681 EXPECT_EQ(base::string16(), s_names.ColumnString16(4));
2731 2682
2732 // No more entries expected. 2683 // No more entries expected.
2733 ASSERT_FALSE(s_names.Step()); 2684 ASSERT_FALSE(s_names.Step());
2734 } 2685 }
2735 } 2686 }
2687
2688 // Tests that migrating from version 57 to version 58 drops the web_intents and
2689 // web_apps tables.
2690 TEST_F(WebDatabaseMigrationTest, MigrateVersion57ToCurrent) {
2691 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_57.sql")));
2692
2693 // Verify pre-conditions. These are expectations for version 57 of the
2694 // database.
2695 {
2696 sql::Connection connection;
2697 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2698 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
2699
2700 EXPECT_TRUE(connection.DoesTableExist("web_apps"));
2701 EXPECT_TRUE(connection.DoesTableExist("web_app_icons"));
2702 EXPECT_TRUE(connection.DoesTableExist("web_intents"));
2703 EXPECT_TRUE(connection.DoesTableExist("web_intents_defaults"));
2704 }
2705
2706 DoMigration();
2707
2708 // Verify post-conditions. These are expectations for current version of the
2709 // database.
2710 {
2711 sql::Connection connection;
2712 ASSERT_TRUE(connection.Open(GetDatabasePath()));
2713 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
2714
2715 // Check version.
2716 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
2717
2718 EXPECT_FALSE(connection.DoesTableExist("web_apps"));
2719 EXPECT_FALSE(connection.DoesTableExist("web_app_icons"));
2720 EXPECT_FALSE(connection.DoesTableExist("web_intents"));
2721 EXPECT_FALSE(connection.DoesTableExist("web_intents_defaults"));
2722 }
2723 }
OLDNEW
« no previous file with comments | « components/webdata/common/web_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698