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/files/file_util.h" | 7 #include "base/files/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" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 | 226 |
227 static int VersionFromConnection(sql::Connection* connection) { | 227 static int VersionFromConnection(sql::Connection* connection) { |
228 // Get version. | 228 // Get version. |
229 sql::Statement s(connection->GetUniqueStatement( | 229 sql::Statement s(connection->GetUniqueStatement( |
230 "SELECT value FROM meta WHERE key='version'")); | 230 "SELECT value FROM meta WHERE key='version'")); |
231 if (!s.Step()) | 231 if (!s.Step()) |
232 return 0; | 232 return 0; |
233 return s.ColumnInt(0); | 233 return s.ColumnInt(0); |
234 } | 234 } |
235 | 235 |
236 // The sql files located in "chrome/test/data/web_database" were generated by | 236 // The sql files located in "components/test/data/web_database" were generated |
237 // launching the Chromium application prior to schema change, then using the | 237 // by launching the Chromium application prior to schema change, then using |
238 // sqlite3 command-line application to dump the contents of the "Web Data" | 238 // the sqlite3 command-line application to dump the contents of the "Web Data" |
239 // database. | 239 // database. |
240 // Like this: | 240 // Like this: |
241 // > .output version_nn.sql | 241 // > .output version_nn.sql |
242 // > .dump | 242 // > .dump |
243 void LoadDatabase(const base::FilePath::StringType& file); | 243 void LoadDatabase(const base::FilePath::StringType& file); |
244 | 244 |
245 private: | 245 private: |
246 base::ScopedTempDir temp_dir_; | 246 base::ScopedTempDir temp_dir_; |
247 | 247 |
248 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); | 248 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); |
249 }; | 249 }; |
250 | 250 |
251 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 61; | 251 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 62; |
252 | 252 |
253 void WebDatabaseMigrationTest::LoadDatabase( | 253 void WebDatabaseMigrationTest::LoadDatabase( |
254 const base::FilePath::StringType& file) { | 254 const base::FilePath::StringType& file) { |
255 std::string contents; | 255 std::string contents; |
256 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); | 256 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); |
257 | 257 |
258 sql::Connection connection; | 258 sql::Connection connection; |
259 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 259 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
260 ASSERT_TRUE(connection.Execute(contents.data())); | 260 ASSERT_TRUE(connection.Execute(contents.data())); |
261 } | 261 } |
(...skipping 2541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2803 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 2803 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
2804 | 2804 |
2805 // Check version. | 2805 // Check version. |
2806 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 2806 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
2807 | 2807 |
2808 ASSERT_TRUE(connection.DoesTableExist("masked_credit_cards")); | 2808 ASSERT_TRUE(connection.DoesTableExist("masked_credit_cards")); |
2809 ASSERT_TRUE(connection.DoesTableExist("unmasked_credit_cards")); | 2809 ASSERT_TRUE(connection.DoesTableExist("unmasked_credit_cards")); |
2810 ASSERT_TRUE(connection.DoesTableExist("server_addresses")); | 2810 ASSERT_TRUE(connection.DoesTableExist("server_addresses")); |
2811 } | 2811 } |
2812 } | 2812 } |
2813 | |
2814 // Tests addition of use_count and use_date fields to autofill profiles and | |
2815 // credit cards. | |
2816 TEST_F(WebDatabaseMigrationTest, MigrateVersion60ToCurrent) { | |
2817 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_60.sql"))); | |
2818 | |
2819 // Verify pre-conditions. | |
2820 { | |
2821 sql::Connection connection; | |
2822 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
2823 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
2824 | |
2825 sql::MetaTable meta_table; | |
2826 ASSERT_TRUE(meta_table.Init(&connection, 60, 60)); | |
2827 | |
2828 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "use_count")); | |
2829 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "use_date")); | |
2830 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "use_count")); | |
2831 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "use_date")); | |
2832 } | |
2833 | |
2834 DoMigration(); | |
2835 | |
2836 // Verify post-conditions. | |
2837 { | |
2838 sql::Connection connection; | |
2839 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
2840 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
2841 | |
2842 // Check version. | |
2843 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | |
2844 | |
2845 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "use_count")); | |
2846 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "use_date")); | |
2847 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "use_count")); | |
2848 EXPECT_TRUE(connection.DoesColumnExist("autofill_profiles", "use_date")); | |
Peter Kasting
2015/02/21 02:30:59
Is it worth checking the actual counts or dates in
Evan Stade
2015/02/21 02:32:56
I'm not a huge fan of testing a constant by copyin
Peter Kasting
2015/02/21 02:44:53
Sounds like the answer is no, then. :)
brettw
2015/02/23 19:04:34
FWIW I would have done it like Evan did. I haven't
Peter Kasting
2015/02/23 21:14:42
I'm not sure which way you're thinking I prefer?
| |
2849 } | |
2850 } | |
2851 | |
2852 // Tests addition of use_count and use_date fields to unmasked server cards. | |
2853 TEST_F(WebDatabaseMigrationTest, MigrateVersion61ToCurrent) { | |
2854 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_61.sql"))); | |
2855 | |
2856 // Verify pre-conditions. | |
2857 { | |
2858 sql::Connection connection; | |
2859 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
2860 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
2861 | |
2862 sql::MetaTable meta_table; | |
2863 ASSERT_TRUE(meta_table.Init(&connection, 61, 61)); | |
2864 | |
2865 EXPECT_FALSE(connection.DoesColumnExist("unmasked_credit_cards", | |
2866 "use_count")); | |
2867 EXPECT_FALSE(connection.DoesColumnExist("unmasked_credit_cards", | |
2868 "use_date")); | |
2869 } | |
2870 | |
2871 DoMigration(); | |
2872 | |
2873 // Verify post-conditions. | |
2874 { | |
2875 sql::Connection connection; | |
2876 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
2877 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
2878 | |
2879 // Check version. | |
2880 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | |
2881 | |
2882 EXPECT_TRUE(connection.DoesColumnExist("unmasked_credit_cards", | |
2883 "use_count")); | |
2884 EXPECT_TRUE(connection.DoesColumnExist("unmasked_credit_cards", | |
2885 "use_date")); | |
2886 } | |
2887 } | |
OLD | NEW |